Commit 9c05a61a authored by inferno@chromium.org's avatar inferno@chromium.org

2011-01-26 Emil A Eklund <eae@chromium.org>

        Reviewed by Alexey Proskuryakov.

        Remove cached document reference from CSSStyleSheet and XSLStyleSheet.
        https://bugs.webkit.org/show_bug.cgi?id=52084

        Test: fast/dom/css-delete-doc.html

        * css/CSSMediaRule.cpp:
        (WebCore::CSSMediaRule::insertRule):
        (WebCore::CSSMediaRule::deleteRule):
        * css/CSSStyleSheet.cpp:
        (WebCore::CSSStyleSheet::CSSStyleSheet):
        (WebCore::CSSStyleSheet::document):
        * css/CSSStyleSheet.h:
        * xml/XSLStyleSheet.h:
        (WebCore::XSLStyleSheet::parentStyleSheet):
        * xml/XSLStyleSheetLibxslt.cpp:
        (WebCore::XSLStyleSheet::XSLStyleSheet):
        (WebCore::XSLStyleSheet::cachedResourceLoader):
        (WebCore::XSLStyleSheet::setParentStyleSheet):
        (WebCore::XSLStyleSheet::ownerDocument):
        * xml/XSLStyleSheetQt.cpp:
        (WebCore::XSLStyleSheet::XSLStyleSheet):
        (WebCore::XSLStyleSheet::cachedResourceLoader):
        (WebCore::XSLStyleSheet::ownerDocument):
2011-01-26  Emil A Eklund  <eae@chromium.org>

        Reviewed by Alexey Proskuryakov.

        Remove cached document reference from CSSStyleSheet and XSLStyleSheet.
        https://bugs.webkit.org/show_bug.cgi?id=52084

        Added test for accessing a style sheet associated with a document that
        has been removed.

        * fast/dom/css-delete-doc-expected.txt: Added.
        * fast/dom/css-delete-doc.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76728 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent e6101180
2011-01-26 Emil A Eklund <eae@chromium.org>
Reviewed by Alexey Proskuryakov.
Remove cached document reference from CSSStyleSheet and XSLStyleSheet.
https://bugs.webkit.org/show_bug.cgi?id=52084
Added test for accessing a style sheet associated with a document that
has been removed.
* fast/dom/css-delete-doc-expected.txt: Added.
* fast/dom/css-delete-doc.html: Added.
2011-01-26 Dave Hyatt <hyatt@apple.com>
Reviewed by Dan Bernstein.
<html>
<head>
<script src="../js/resources/js-test-pre.js"></script>
<script>
window.jsTestIsAsync = true;
var iteration = 0;
var sheet, rules;
function step1(opt_media)
{
var doc = document.implementation.createHTMLDocument();
var style = doc.createElement('style');
doc.head.appendChild(style);
sheet = style.sheet;
if (opt_media) {
sheet.insertRule('@media screen { body { background: red; } p { color: white; } }', 0);
rules = sheet.rules[0];
sheet.removeRule(0);
sheet = 0;
}
doc.head.removeChild(style);
document.adoptNode(style);
delete doc;
gc();
setTimeout(opt_media ? step2a : step2b, 10);
}
function step2a()
{
try {
rules.insertRule('a { }', 1);
if (iteration++ == 10) {
iteration = 0;
step1(true);
return;
}
setTimeout('step1(false)', 0);
}
catch(e) {
document.body.innerText = 'FAIL, threw exception.';
if (window.layoutTestController)
layoutTestController.notifyDone();
}
}
function step2b()
{
try {
sheet.insertRule('a { }', 0);
if (iteration++ == 10) {
document.body.innerText = 'PASS';
if (window.layoutTestController)
layoutTestController.notifyDone();
return;
}
setTimeout('step1(true)', 0);
}
catch(e) {
document.body.innerText = 'FAIL, threw exception.';
if (window.layoutTestController)
layoutTestController.notifyDone();
}
}
</script>
<script src="../js/resources/js-test-post.js"></script>
</head>
<body onload="step1()">
Running...
</body>
</html>
2011-01-26 Emil A Eklund <eae@chromium.org>
Reviewed by Alexey Proskuryakov.
Remove cached document reference from CSSStyleSheet and XSLStyleSheet.
https://bugs.webkit.org/show_bug.cgi?id=52084
Test: fast/dom/css-delete-doc.html
* css/CSSMediaRule.cpp:
(WebCore::CSSMediaRule::insertRule):
(WebCore::CSSMediaRule::deleteRule):
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::CSSStyleSheet):
(WebCore::CSSStyleSheet::document):
* css/CSSStyleSheet.h:
* xml/XSLStyleSheet.h:
(WebCore::XSLStyleSheet::parentStyleSheet):
* xml/XSLStyleSheetLibxslt.cpp:
(WebCore::XSLStyleSheet::XSLStyleSheet):
(WebCore::XSLStyleSheet::cachedResourceLoader):
(WebCore::XSLStyleSheet::setParentStyleSheet):
(WebCore::XSLStyleSheet::ownerDocument):
* xml/XSLStyleSheetQt.cpp:
(WebCore::XSLStyleSheet::XSLStyleSheet):
(WebCore::XSLStyleSheet::cachedResourceLoader):
(WebCore::XSLStyleSheet::ownerDocument):
2011-01-25 Dimitri Glazkov <dglazkov@chromium.org>
Reviewed by Kent Tamura.
......@@ -88,8 +88,8 @@ unsigned CSSMediaRule::insertRule(const String& rule, unsigned index, ExceptionC
newRule->setParent(this);
unsigned returnedIndex = m_lstCSSRules->insertRule(newRule.get(), index);
// stylesheet() can only return 0 for computed style declarations.
stylesheet()->styleSheetChanged();
if (stylesheet())
stylesheet()->styleSheetChanged();
return returnedIndex;
}
......@@ -105,8 +105,8 @@ void CSSMediaRule::deleteRule(unsigned index, ExceptionCode& ec)
m_lstCSSRules->deleteRule(index);
// stylesheet() can only return 0 for computed style declarations.
stylesheet()->styleSheetChanged();
if (stylesheet())
stylesheet()->styleSheetChanged();
}
String CSSMediaRule::cssText() const
......
......@@ -53,7 +53,6 @@ static bool isAcceptableCSSStyleSheetParent(Node* parentNode)
CSSStyleSheet::CSSStyleSheet(CSSStyleSheet* parentSheet, const String& href, const KURL& baseURL, const String& charset)
: StyleSheet(parentSheet, href, baseURL)
, m_document(parentSheet ? parentSheet->document() : 0)
, m_charset(charset)
, m_loadCompleted(false)
, m_strictParsing(!parentSheet || parentSheet->useStrictParsing())
......@@ -64,7 +63,6 @@ CSSStyleSheet::CSSStyleSheet(CSSStyleSheet* parentSheet, const String& href, con
CSSStyleSheet::CSSStyleSheet(Node* parentNode, const String& href, const KURL& baseURL, const String& charset)
: StyleSheet(parentNode, href, baseURL)
, m_document(parentNode->document())
, m_charset(charset)
, m_loadCompleted(false)
, m_strictParsing(false)
......@@ -82,7 +80,6 @@ CSSStyleSheet::CSSStyleSheet(CSSRule* ownerRule, const String& href, const KURL&
, m_hasSyntacticallyValidCSSHeader(true)
{
CSSStyleSheet* parentSheet = ownerRule ? ownerRule->parentStyleSheet() : 0;
m_document = parentSheet ? parentSheet->document() : 0;
m_isUserStyleSheet = parentSheet ? parentSheet->isUserStyleSheet() : false;
}
......@@ -233,6 +230,24 @@ void CSSStyleSheet::checkLoaded()
m_loadCompleted = ownerNode() ? ownerNode()->sheetLoaded() : true;
}
Document* CSSStyleSheet::document()
{
StyleBase* styleObject = this;
while (styleObject) {
if (styleObject->isCSSStyleSheet()) {
Node* ownerNode = static_cast<CSSStyleSheet*>(styleObject)->ownerNode();
if (ownerNode)
return ownerNode->document();
}
if (styleObject->isRule())
styleObject = static_cast<CSSRule*>(styleObject)->parentStyleSheet();
else
styleObject = styleObject->parent();
}
return 0;
}
void CSSStyleSheet::styleSheetChanged()
{
StyleBase* root = this;
......
......@@ -87,7 +87,7 @@ public:
virtual void checkLoaded();
Document* document() { return m_document; }
Document* document();
const String& charset() const { return m_charset; }
......@@ -112,7 +112,6 @@ private:
virtual bool isCSSStyleSheet() const { return true; }
virtual String type() const { return "text/css"; }
Document* m_document;
OwnPtr<CSSNamespace> m_namespaces;
String m_charset;
bool m_loadCompleted : 1;
......
......@@ -79,7 +79,8 @@ public:
CachedResourceLoader* cachedResourceLoader();
Document* ownerDocument() { return m_ownerDocument; }
Document* ownerDocument();
XSLStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; }
void setParentStyleSheet(XSLStyleSheet* parent);
#if USE(QXMLQUERY)
......
......@@ -56,7 +56,6 @@ namespace WebCore {
XSLStyleSheet::XSLStyleSheet(XSLImportRule* parentRule, const String& originalURL, const KURL& finalURL)
: StyleSheet(parentRule, originalURL, finalURL)
, m_ownerDocument(0)
, m_embedded(false)
, m_processed(false) // Child sheets get marked as processed when the libxslt engine has finally seen them.
, m_stylesheetDoc(0)
......@@ -67,7 +66,6 @@ XSLStyleSheet::XSLStyleSheet(XSLImportRule* parentRule, const String& originalUR
XSLStyleSheet::XSLStyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL, bool embedded)
: StyleSheet(parentNode, originalURL, finalURL)
, m_ownerDocument(parentNode->document())
, m_embedded(embedded)
, m_processed(true) // The root sheet starts off processed.
, m_stylesheetDoc(0)
......@@ -129,9 +127,10 @@ void XSLStyleSheet::clearDocuments()
CachedResourceLoader* XSLStyleSheet::cachedResourceLoader()
{
if (!m_ownerDocument)
Document* document = ownerDocument();
if (!document)
return 0;
return m_ownerDocument->cachedResourceLoader();
return document->cachedResourceLoader();
}
bool XSLStyleSheet::parseString(const String& string, bool)
......@@ -257,8 +256,16 @@ xsltStylesheetPtr XSLStyleSheet::compileStyleSheet()
void XSLStyleSheet::setParentStyleSheet(XSLStyleSheet* parent)
{
m_parentStyleSheet = parent;
if (parent)
m_ownerDocument = parent->ownerDocument();
}
Document* XSLStyleSheet::ownerDocument()
{
for (XSLStyleSheet* styleSheet = this; styleSheet; styleSheet = styleSheet->parentStyleSheet()) {
Node* node = styleSheet->ownerNode();
if (node)
return node->document();
}
return 0;
}
xmlDocPtr XSLStyleSheet::locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri)
......
......@@ -34,7 +34,6 @@ namespace WebCore {
XSLStyleSheet::XSLStyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL, bool embedded)
: StyleSheet(parentNode, originalURL, finalURL)
, m_ownerDocument(parentNode->document())
, m_embedded(embedded)
{
}
......@@ -62,9 +61,10 @@ void XSLStyleSheet::clearDocuments()
CachedResourceLoader* XSLStyleSheet::cachedResourceLoader()
{
if (!m_ownerDocument)
Document* document = ownerDocument();
if (!document)
return 0;
return m_ownerDocument->cachedResourceLoader();
return document->cachedResourceLoader();
}
bool XSLStyleSheet::parseString(const String& string, bool)
......@@ -87,6 +87,12 @@ void XSLStyleSheet::loadChildSheet(const String&)
notImplemented();
}
Document* XSLStyleSheet::ownerDocument()
{
Node* node = ownerNode();
return node ? node->document() : 0;
}
void XSLStyleSheet::setParentStyleSheet(XSLStyleSheet*)
{
notImplemented();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment