Refactor TokenPreloadScanner::StartTagScanner::processAttribute()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Oct 2015 20:40:52 +0000 (20:40 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Oct 2015 20:40:52 +0000 (20:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=149847

Reviewed by Antti Koivisto.

Refactor TokenPreloadScanner::StartTagScanner::processAttribute() to only
process attributes that make sense given the current tagId. In particular,
- We only process the charset parameter if the tag is a link or a script.
- We only process the sizes / srcset attributes if the tag is an img.

* html/parser/HTMLPreloadScanner.cpp:
(WebCore::TokenPreloadScanner::StartTagScanner::processAttribute):
(WebCore::TokenPreloadScanner::StartTagScanner::setUrlToLoad): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190641 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/parser/HTMLPreloadScanner.cpp

index 80b619de02417148ce12fe63a1c7c433bbea286e..4294337364d61f8d66a29d5a44c5a38cf2a44ff1 100644 (file)
@@ -1,3 +1,19 @@
+2015-10-06  Chris Dumez  <cdumez@apple.com>
+
+        Refactor TokenPreloadScanner::StartTagScanner::processAttribute()
+        https://bugs.webkit.org/show_bug.cgi?id=149847
+
+        Reviewed by Antti Koivisto.
+
+        Refactor TokenPreloadScanner::StartTagScanner::processAttribute() to only
+        process attributes that make sense given the current tagId. In particular,
+        - We only process the charset parameter if the tag is a link or a script.
+        - We only process the sizes / srcset attributes if the tag is an img.
+
+        * html/parser/HTMLPreloadScanner.cpp:
+        (WebCore::TokenPreloadScanner::StartTagScanner::processAttribute):
+        (WebCore::TokenPreloadScanner::StartTagScanner::setUrlToLoad): Deleted.
+
 2015-10-06  Youenn Fablet  <youenn.fablet@crf.canon.fr>
 
         Binding generator XXConstructor::finishCreation should take references as parameters
index d039fa2793752fce643efd79fb8d96089ef8716d..a89f108e3a2429af92262e2530fe2843bbe1db9d 100644 (file)
@@ -140,38 +140,60 @@ public:
     }
 
 private:
-    template<typename NameType>
-    void processAttribute(const NameType& attributeName, const String& attributeValue)
+    void processImageAndScriptAttribute(const AtomicString& attributeName, const String& attributeValue)
     {
-        if (match(attributeName, charsetAttr))
+        if (match(attributeName, srcAttr))
+            setUrlToLoad(attributeValue);
+        else if (match(attributeName, crossoriginAttr) && !attributeValue.isNull())
+            m_crossOriginMode = stripLeadingAndTrailingHTMLSpaces(attributeValue);
+        else if (match(attributeName, charsetAttr))
             m_charset = attributeValue;
+    }
 
-        if (m_tagId == TagId::Script || m_tagId == TagId::Img) {
-            if (match(attributeName, srcAttr))
-                setUrlToLoad(attributeValue);
-            else if (match(attributeName, srcsetAttr) && m_srcSetAttribute.isNull())
+    void processAttribute(const AtomicString& attributeName, const String& attributeValue)
+    {
+        switch (m_tagId) {
+        case TagId::Img:
+            if (match(attributeName, srcsetAttr) && m_srcSetAttribute.isNull()) {
                 m_srcSetAttribute = attributeValue;
-            else if (match(attributeName, sizesAttr) && m_sizesAttribute.isNull())
+                break;
+            }
+            if (match(attributeName, sizesAttr) && m_sizesAttribute.isNull()) {
                 m_sizesAttribute = attributeValue;
-            else if (match(attributeName, crossoriginAttr) && !attributeValue.isNull())
-                m_crossOriginMode = stripLeadingAndTrailingHTMLSpaces(attributeValue);
-        } else if (m_tagId == TagId::Link) {
+                break;
+            }
+            processImageAndScriptAttribute(attributeName, attributeValue);
+            break;
+        case TagId::Script:
+            processImageAndScriptAttribute(attributeName, attributeValue);
+            break;
+        case TagId::Link:
             if (match(attributeName, hrefAttr))
                 setUrlToLoad(attributeValue);
             else if (match(attributeName, relAttr))
                 m_linkIsStyleSheet = relAttributeIsStyleSheet(attributeValue);
             else if (match(attributeName, mediaAttr))
                 m_mediaAttribute = attributeValue;
-        } else if (m_tagId == TagId::Input) {
+            else if (match(attributeName, charsetAttr))
+                m_charset = attributeValue;
+            break;
+        case TagId::Input:
             if (match(attributeName, srcAttr))
                 setUrlToLoad(attributeValue);
             else if (match(attributeName, typeAttr))
                 m_inputIsImage = equalIgnoringCase(attributeValue, InputTypeNames::image());
-        } else if (m_tagId == TagId::Meta) {
+            break;
+        case TagId::Meta:
             if (match(attributeName, contentAttr))
                 m_metaContent = attributeValue;
             else if (match(attributeName, nameAttr))
                 m_metaIsViewport = equalIgnoringCase(attributeValue, "viewport");
+            break;
+        case TagId::Base:
+        case TagId::Style:
+        case TagId::Template:
+        case TagId::Unknown:
+            break;
         }
     }
 
@@ -195,9 +217,6 @@ private:
 
     const String& charset() const
     {
-        // FIXME: Its not clear that this if is needed, the loader probably ignores charset for image requests anyway.
-        if (m_tagId == TagId::Img)
-            return emptyString();
         return m_charset;
     }