Title: [125805] trunk/Source/WebCore
Revision
125805
Author
[email protected]
Date
2012-08-16 13:30:13 -0700 (Thu, 16 Aug 2012)

Log Message

Remove StyleSheetContents::m_finalURL 
https://bugs.webkit.org/show_bug.cgi?id=94140

Reviewed by Andreas Kling.

It is equal (or empty in case of inline stylesheets) to the baseURL passed in CSSParserContext.
Removing it simplifies the constructors and the related code.

* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::createInline):
(WebCore::CSSStyleSheet::canAccessRules):
(WebCore::CSSStyleSheet::rules):
(WebCore::CSSStyleSheet::cssRules):

    - factor access check to a function
    - allow document always access rules of its inline stylesheets

* css/StyleRuleImport.cpp:
(WebCore::StyleRuleImport::setCSSStyleSheet):
(WebCore::StyleRuleImport::requestStyleSheet):
* css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::StyleSheetContents):
(WebCore::StyleSheetContents::parseAuthorStyleSheet):
* css/StyleSheetContents.h:
(WebCore::StyleSheetContents::create):
(WebCore::StyleSheetContents::originalURL):
(StyleSheetContents):
* dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::setCSSStyleSheet):
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::setCSSStyleSheet):
* inspector/InspectorStyleSheet.cpp:
(WebCore::fillMediaListChain):
(WebCore::InspectorStyleSheet::styleSheetURL):
* xml/XSLImportRule.cpp:
(WebCore::XSLImportRule::loadSheet):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (125804 => 125805)


--- trunk/Source/WebCore/ChangeLog	2012-08-16 20:11:48 UTC (rev 125804)
+++ trunk/Source/WebCore/ChangeLog	2012-08-16 20:30:13 UTC (rev 125805)
@@ -1,3 +1,42 @@
+2012-08-15  Antti Koivisto  <[email protected]>
+
+        Remove StyleSheetContents::m_finalURL 
+        https://bugs.webkit.org/show_bug.cgi?id=94140
+
+        Reviewed by Andreas Kling.
+
+        It is equal (or empty in case of inline stylesheets) to the baseURL passed in CSSParserContext.
+        Removing it simplifies the constructors and the related code.
+
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::createInline):
+        (WebCore::CSSStyleSheet::canAccessRules):
+        (WebCore::CSSStyleSheet::rules):
+        (WebCore::CSSStyleSheet::cssRules):
+
+            - factor access check to a function
+            - allow document always access rules of its inline stylesheets
+
+        * css/StyleRuleImport.cpp:
+        (WebCore::StyleRuleImport::setCSSStyleSheet):
+        (WebCore::StyleRuleImport::requestStyleSheet):
+        * css/StyleSheetContents.cpp:
+        (WebCore::StyleSheetContents::StyleSheetContents):
+        (WebCore::StyleSheetContents::parseAuthorStyleSheet):
+        * css/StyleSheetContents.h:
+        (WebCore::StyleSheetContents::create):
+        (WebCore::StyleSheetContents::originalURL):
+        (StyleSheetContents):
+        * dom/ProcessingInstruction.cpp:
+        (WebCore::ProcessingInstruction::setCSSStyleSheet):
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::setCSSStyleSheet):
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::fillMediaListChain):
+        (WebCore::InspectorStyleSheet::styleSheetURL):
+        * xml/XSLImportRule.cpp:
+        (WebCore::XSLImportRule::loadSheet):
+
 2012-08-16  Justin Novosad  <[email protected]>
 
         [Chromium] Changing Canvas2DLayerBridge to use SkDeferredCanvas's notification client API

Modified: trunk/Source/WebCore/css/CSSStyleSheet.cpp (125804 => 125805)


--- trunk/Source/WebCore/css/CSSStyleSheet.cpp	2012-08-16 20:11:48 UTC (rev 125804)
+++ trunk/Source/WebCore/css/CSSStyleSheet.cpp	2012-08-16 20:30:13 UTC (rev 125805)
@@ -85,18 +85,19 @@
 
 PassRefPtr<CSSStyleSheet> CSSStyleSheet::create(PassRefPtr<StyleSheetContents> sheet, Node* ownerNode)
 { 
-    return adoptRef(new CSSStyleSheet(sheet, ownerNode));
+    return adoptRef(new CSSStyleSheet(sheet, ownerNode, false));
 }
 
 PassRefPtr<CSSStyleSheet> CSSStyleSheet::createInline(Node* ownerNode, const KURL& baseURL, const String& encoding)
 {
     CSSParserContext parserContext(ownerNode->document(), baseURL, encoding);
-    RefPtr<StyleSheetContents> sheet = StyleSheetContents::create(baseURL.string(), baseURL, parserContext);
-    return adoptRef(new CSSStyleSheet(sheet.release(), ownerNode));
+    RefPtr<StyleSheetContents> sheet = StyleSheetContents::create(baseURL.string(), parserContext);
+    return adoptRef(new CSSStyleSheet(sheet.release(), ownerNode, true));
 }
 
 CSSStyleSheet::CSSStyleSheet(PassRefPtr<StyleSheetContents> contents, CSSImportRule* ownerRule)
     : m_contents(contents)
+    , m_isInlineStylesheet(false)
     , m_isDisabled(false)
     , m_ownerNode(0)
     , m_ownerRule(ownerRule)
@@ -104,8 +105,9 @@
     m_contents->registerClient(this);
 }
 
-CSSStyleSheet::CSSStyleSheet(PassRefPtr<StyleSheetContents> contents, Node* ownerNode)
+CSSStyleSheet::CSSStyleSheet(PassRefPtr<StyleSheetContents> contents, Node* ownerNode, bool isInlineStylesheet)
     : m_contents(contents)
+    , m_isInlineStylesheet(isInlineStylesheet)
     , m_isDisabled(false)
     , m_ownerNode(ownerNode)
     , m_ownerRule(0)
@@ -227,11 +229,24 @@
     return cssRule.get();
 }
 
+bool CSSStyleSheet::canAccessRules() const
+{
+    if (m_isInlineStylesheet)
+        return true;
+    KURL baseURL = m_contents->baseURL();
+    if (baseURL.isEmpty())
+        return true;
+    Document* document = ownerDocument();
+    if (!document)
+        return true;
+    if (document->securityOrigin()->canRequest(baseURL))
+        return true;
+    return false;
+}
+
 PassRefPtr<CSSRuleList> CSSStyleSheet::rules()
 {
-    KURL url = ""
-    Document* document = ownerDocument();
-    if (!url.isEmpty() && document && !document->securityOrigin()->canRequest(url))
+    if (!canAccessRules())
         return 0;
     // IE behavior.
     RefPtr<StaticCSSRuleList> nonCharsetRules = StaticCSSRuleList::create();
@@ -310,9 +325,7 @@
 
 PassRefPtr<CSSRuleList> CSSStyleSheet::cssRules()
 {
-    KURL url = ""
-    Document* document = ownerDocument();
-    if (!url.isEmpty() && document && !document->securityOrigin()->canRequest(url))
+    if (!canAccessRules())
         return 0;
     if (!m_ruleListCSSOMWrapper)
         m_ruleListCSSOMWrapper = adoptPtr(new StyleSheetCSSRuleList(this));

Modified: trunk/Source/WebCore/css/CSSStyleSheet.h (125804 => 125805)


--- trunk/Source/WebCore/css/CSSStyleSheet.h	2012-08-16 20:11:48 UTC (rev 125804)
+++ trunk/Source/WebCore/css/CSSStyleSheet.h	2012-08-16 20:30:13 UTC (rev 125805)
@@ -110,12 +110,15 @@
 
 private:
     CSSStyleSheet(PassRefPtr<StyleSheetContents>, CSSImportRule* ownerRule);
-    CSSStyleSheet(PassRefPtr<StyleSheetContents>, Node* ownerNode);
+    CSSStyleSheet(PassRefPtr<StyleSheetContents>, Node* ownerNode, bool isInlineStylesheet);
 
     virtual bool isCSSStyleSheet() const { return true; }
     virtual String type() const { return "text/css"; }
+
+    bool canAccessRules() const;
     
     RefPtr<StyleSheetContents> m_contents;
+    bool m_isInlineStylesheet;
     bool m_isDisabled;
     String m_title;
     RefPtr<MediaQuerySet> m_mediaQueries;

Modified: trunk/Source/WebCore/css/StyleRuleImport.cpp (125804 => 125805)


--- trunk/Source/WebCore/css/StyleRuleImport.cpp	2012-08-16 20:11:48 UTC (rev 125804)
+++ trunk/Source/WebCore/css/StyleRuleImport.cpp	2012-08-16 20:30:13 UTC (rev 125805)
@@ -68,7 +68,7 @@
     if (!baseURL.isNull())
         context.baseURL = baseURL;
 
-    m_styleSheet = StyleSheetContents::create(this, href, baseURL, context);
+    m_styleSheet = StyleSheetContents::create(this, href, context);
 
     Document* document = m_parentStyleSheet ? m_parentStyleSheet->singleOwnerDocument() : 0;
     m_styleSheet->parseAuthorStyleSheet(cachedStyleSheet, document ? document->securityOrigin() : 0);
@@ -99,15 +99,15 @@
         return;
 
     String absHref = m_strHref;
-    if (!m_parentStyleSheet->finalURL().isNull())
+    if (!m_parentStyleSheet->baseURL().isNull())
         // use parent styleheet's URL as the base URL
-        absHref = KURL(m_parentStyleSheet->finalURL(), m_strHref).string();
+        absHref = KURL(m_parentStyleSheet->baseURL(), m_strHref).string();
 
     // Check for a cycle in our import chain.  If we encounter a stylesheet
     // in our parent chain with the same URL, then just bail.
     StyleSheetContents* rootSheet = m_parentStyleSheet;
     for (StyleSheetContents* sheet = m_parentStyleSheet; sheet; sheet = sheet->parentStyleSheet()) {
-        if (absHref == sheet->finalURL().string() || absHref == sheet->originalURL())
+        if (absHref == sheet->baseURL().string() || absHref == sheet->originalURL())
             return;
         rootSheet = sheet;
     }

Modified: trunk/Source/WebCore/css/StyleSheetContents.cpp (125804 => 125805)


--- trunk/Source/WebCore/css/StyleSheetContents.cpp	2012-08-16 20:11:48 UTC (rev 125804)
+++ trunk/Source/WebCore/css/StyleSheetContents.cpp	2012-08-16 20:30:13 UTC (rev 125805)
@@ -54,10 +54,9 @@
     return size;
 }
 
-StyleSheetContents::StyleSheetContents(StyleRuleImport* ownerRule, const String& originalURL, const KURL& finalURL, const CSSParserContext& context)
+StyleSheetContents::StyleSheetContents(StyleRuleImport* ownerRule, const String& originalURL, const CSSParserContext& context)
     : m_ownerRule(ownerRule)
     , m_originalURL(originalURL)
-    , m_finalURL(finalURL)
     , m_loadCompleted(false)
     , m_isUserStyleSheet(ownerRule && ownerRule->parentStyleSheet() && ownerRule->parentStyleSheet()->isUserStyleSheet())
     , m_hasSyntacticallyValidCSSHeader(true)
@@ -73,7 +72,6 @@
     : RefCounted<StyleSheetContents>()
     , m_ownerRule(0)
     , m_originalURL(o.m_originalURL)
-    , m_finalURL(o.m_finalURL)
     , m_encodingFromCharsetRule(o.m_encodingFromCharsetRule)
     , m_importRules(o.m_importRules.size())
     , m_childRules(o.m_childRules.size())
@@ -283,7 +281,7 @@
     // to at least start with a syntactically valid CSS rule.
     // This prevents an attacker playing games by injecting CSS strings into HTML, XML, JSON, etc. etc.
     if (!hasValidMIMEType && !hasSyntacticallyValidCSSHeader()) {
-        bool isCrossOriginCSS = !securityOrigin || !securityOrigin->canRequest(finalURL());
+        bool isCrossOriginCSS = !securityOrigin || !securityOrigin->canRequest(baseURL());
         if (isCrossOriginCSS) {
             clearRules();
             return;
@@ -295,7 +293,7 @@
         DEFINE_STATIC_LOCAL(const String, mediaWikiKHTMLFixesStyleSheet, ("/* KHTML fix stylesheet */\n/* work around the horizontal scrollbars */\n#column-content { margin-left: 0; }\n\n"));
         // There are two variants of KHTMLFixes.css. One is equal to mediaWikiKHTMLFixesStyleSheet,
         // while the other lacks the second trailing newline.
-        if (finalURL().string().endsWith(slashKHTMLFixesDotCss) && !sheetText.isNull() && mediaWikiKHTMLFixesStyleSheet.startsWith(sheetText)
+        if (baseURL().string().endsWith(slashKHTMLFixesDotCss) && !sheetText.isNull() && mediaWikiKHTMLFixesStyleSheet.startsWith(sheetText)
             && sheetText.length() >= mediaWikiKHTMLFixesStyleSheet.length() - 1)
             clearRules();
     }
@@ -489,7 +487,6 @@
 {
     MemoryClassInfo info(memoryObjectInfo, this, MemoryInstrumentation::CSS);
     info.addMember(m_originalURL);
-    info.addMember(m_finalURL);
     info.addMember(m_encodingFromCharsetRule);
     info.addVector(m_importRules);
     info.addInstrumentedVector(m_childRules);

Modified: trunk/Source/WebCore/css/StyleSheetContents.h (125804 => 125805)


--- trunk/Source/WebCore/css/StyleSheetContents.h	2012-08-16 20:11:48 UTC (rev 125804)
+++ trunk/Source/WebCore/css/StyleSheetContents.h	2012-08-16 20:30:13 UTC (rev 125805)
@@ -44,15 +44,15 @@
 public:
     static PassRefPtr<StyleSheetContents> create(const CSSParserContext& context = CSSParserContext(CSSStrictMode))
     {
-        return adoptRef(new StyleSheetContents(0, String(), KURL(), context));
+        return adoptRef(new StyleSheetContents(0, String(), context));
     }
-    static PassRefPtr<StyleSheetContents> create(const String& originalURL, const KURL& finalURL, const CSSParserContext& context)
+    static PassRefPtr<StyleSheetContents> create(const String& originalURL, const CSSParserContext& context)
     {
-        return adoptRef(new StyleSheetContents(0, originalURL, finalURL, context));
+        return adoptRef(new StyleSheetContents(0, originalURL, context));
     }
-    static PassRefPtr<StyleSheetContents> create(StyleRuleImport* ownerRule, const String& originalURL, const KURL& finalURL, const CSSParserContext& context)
+    static PassRefPtr<StyleSheetContents> create(StyleRuleImport* ownerRule, const String& originalURL, const CSSParserContext& context)
     {
-        return adoptRef(new StyleSheetContents(ownerRule, originalURL, finalURL, context));
+        return adoptRef(new StyleSheetContents(ownerRule, originalURL, context));
     }
 
     ~StyleSheetContents();
@@ -112,8 +112,6 @@
     // this style sheet. This property probably isn't useful for much except
     // the _javascript_ binding (which needs to use this value for security).
     String originalURL() const { return m_originalURL; }
-    
-    const KURL& finalURL() const { return m_finalURL; }
     const KURL& baseURL() const { return m_parserContext.baseURL; }
 
     unsigned ruleCount() const;
@@ -142,7 +140,7 @@
     void reportMemoryUsage(MemoryObjectInfo*) const;
 
 private:
-    StyleSheetContents(StyleRuleImport* ownerRule, const String& originalURL, const KURL& baseURL, const CSSParserContext&);
+    StyleSheetContents(StyleRuleImport* ownerRule, const String& originalURL, const CSSParserContext&);
     StyleSheetContents(const StyleSheetContents&);
 
     void clearCharsetRule();
@@ -150,7 +148,6 @@
     StyleRuleImport* m_ownerRule;
 
     String m_originalURL;
-    KURL m_finalURL;
 
     String m_encodingFromCharsetRule;
     Vector<RefPtr<StyleRuleImport> > m_importRules;

Modified: trunk/Source/WebCore/dom/ProcessingInstruction.cpp (125804 => 125805)


--- trunk/Source/WebCore/dom/ProcessingInstruction.cpp	2012-08-16 20:11:48 UTC (rev 125804)
+++ trunk/Source/WebCore/dom/ProcessingInstruction.cpp	2012-08-16 20:30:13 UTC (rev 125805)
@@ -214,7 +214,7 @@
     ASSERT(m_isCSS);
     CSSParserContext parserContext(document(), baseURL, charset);
 
-    RefPtr<StyleSheetContents> newSheet = StyleSheetContents::create(href, baseURL, parserContext);
+    RefPtr<StyleSheetContents> newSheet = StyleSheetContents::create(href, parserContext);
 
     RefPtr<CSSStyleSheet> cssSheet = CSSStyleSheet::create(newSheet, this);
     cssSheet->setDisabled(m_alternate);

Modified: trunk/Source/WebCore/html/HTMLLinkElement.cpp (125804 => 125805)


--- trunk/Source/WebCore/html/HTMLLinkElement.cpp	2012-08-16 20:11:48 UTC (rev 125804)
+++ trunk/Source/WebCore/html/HTMLLinkElement.cpp	2012-08-16 20:30:13 UTC (rev 125805)
@@ -317,7 +317,7 @@
     }
 #endif
 
-    RefPtr<StyleSheetContents> styleSheet = StyleSheetContents::create(href, baseURL, parserContext);
+    RefPtr<StyleSheetContents> styleSheet = StyleSheetContents::create(href, parserContext);
 
     m_sheet = CSSStyleSheet::create(styleSheet, this);
     m_sheet->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(m_media));

Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp (125804 => 125805)


--- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2012-08-16 20:11:48 UTC (rev 125804)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2012-08-16 20:30:13 UTC (rev 125805)
@@ -231,7 +231,7 @@
             mediaList = 0;
 
         if (parentStyleSheet) {
-            sourceURL = parentStyleSheet->contents()->finalURL();
+            sourceURL = parentStyleSheet->contents()->baseURL();
             if (sourceURL.isEmpty())
                 sourceURL = InspectorDOMAgent::documentURLString(parentStyleSheet->ownerDocument());
         } else
@@ -250,8 +250,8 @@
                     Document* doc = styleSheet->ownerDocument();
                     if (doc)
                         sourceURL = doc->url();
-                    else if (!styleSheet->contents()->finalURL().isEmpty())
-                        sourceURL = styleSheet->contents()->finalURL();
+                    else if (!styleSheet->contents()->baseURL().isEmpty())
+                        sourceURL = styleSheet->contents()->baseURL();
                     else
                         sourceURL = "";
                     mediaArray->addItem(buildMediaObject(mediaList, styleSheet->ownerNode() ? MediaListSourceLinkedSheet : MediaListSourceInlineSheet, sourceURL));
@@ -707,8 +707,8 @@
 // static
 String InspectorStyleSheet::styleSheetURL(CSSStyleSheet* pageStyleSheet)
 {
-    if (pageStyleSheet && !pageStyleSheet->contents()->finalURL().isEmpty())
-        return pageStyleSheet->contents()->finalURL().string();
+    if (pageStyleSheet && !pageStyleSheet->contents()->baseURL().isEmpty())
+        return pageStyleSheet->contents()->baseURL().string();
     return emptyString();
 }
 

Modified: trunk/Source/WebCore/xml/XSLImportRule.cpp (125804 => 125805)


--- trunk/Source/WebCore/xml/XSLImportRule.cpp	2012-08-16 20:11:48 UTC (rev 125804)
+++ trunk/Source/WebCore/xml/XSLImportRule.cpp	2012-08-16 20:30:13 UTC (rev 125805)
@@ -87,14 +87,14 @@
     
     String absHref = m_strHref;
     XSLStyleSheet* parentSheet = parentStyleSheet();
-    if (!parentSheet->finalURL().isNull())
+    if (!parentSheet->baseURL().isNull())
         // use parent styleheet's URL as the base URL
-        absHref = KURL(parentSheet->finalURL(), m_strHref).string();
+        absHref = KURL(parentSheet->baseURL(), m_strHref).string();
     
     // Check for a cycle in our import chain.  If we encounter a stylesheet
     // in our parent chain with the same URL, then just bail.
     for (XSLStyleSheet* parentSheet = parentStyleSheet(); parentSheet; parentSheet = parentSheet->parentStyleSheet()) {
-        if (absHref == parentSheet->finalURL().string())
+        if (absHref == parentSheet->baseURL().string())
             return;
     }
     
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to