Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / parser / HTMLPreloadScanner.cpp
index a6c98ea..f9199cc 100644 (file)
@@ -29,9 +29,9 @@
 #include "core/html/parser/HTMLPreloadScanner.h"
 
 #include "HTMLNames.h"
+#include "InputTypeNames.h"
 #include "RuntimeEnabledFeatures.h"
 #include "core/html/LinkRelAttribute.h"
-#include "core/html/forms/InputTypeNames.h"
 #include "core/html/parser/HTMLParserIdioms.h"
 #include "core/html/parser/HTMLSrcsetParser.h"
 #include "core/html/parser/HTMLTokenizer.h"
@@ -47,17 +47,17 @@ static bool match(const StringImpl* impl, const QualifiedName& qName)
     return impl == qName.localName().impl();
 }
 
-static bool match(const HTMLIdentifier& name, const QualifiedName& qName)
-{
-    return match(name.asStringImpl(), qName);
-}
-
 static bool match(const AtomicString& name, const QualifiedName& qName)
 {
     ASSERT(isMainThread());
     return qName.localName() == name;
 }
 
+static bool match(const String& name, const QualifiedName& qName)
+{
+    return threadSafeMatch(name, qName);
+}
+
 static const StringImpl* tagImplFor(const HTMLToken::DataVector& data)
 {
     AtomicString tagName(data);
@@ -67,9 +67,9 @@ static const StringImpl* tagImplFor(const HTMLToken::DataVector& data)
     return 0;
 }
 
-static const StringImpl* tagImplFor(const HTMLIdentifier& tagName)
+static const StringImpl* tagImplFor(const String& tagName)
 {
-    const StringImpl* result = tagName.asStringImpl();
+    const StringImpl* result = tagName.impl();
     if (result->isStatic())
         return result;
     return 0;
@@ -98,6 +98,8 @@ public:
         , m_inputIsImage(false)
         , m_deviceScaleFactor(deviceScaleFactor)
         , m_encounteredImgSrc(false)
+        , m_isCORSEnabled(false)
+        , m_allowCredentials(DoNotAllowStoredCredentials)
     {
         if (!match(m_tagImpl, imgTag)
             && !match(m_tagImpl, inputTag)
@@ -139,7 +141,8 @@ public:
         TRACE_EVENT_INSTANT1("net", "PreloadRequest", "url", m_urlToLoad.ascii());
         TextPosition position = TextPosition(source.currentLine(), source.currentColumn());
         OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_tagImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), m_mediaAttribute);
-        request->setCrossOriginModeAllowsCookies(crossOriginModeAllowsCookies());
+        if (isCORSEnabled())
+            request->setCrossOriginEnabled(allowCredentials());
         request->setCharset(charset());
         return request.release();
     }
@@ -154,14 +157,14 @@ private:
         if (match(m_tagImpl, scriptTag)) {
             if (match(attributeName, srcAttr))
                 setUrlToLoad(attributeValue, DisallowURLReplacement);
-            else if (match(attributeName, crossoriginAttr) && !attributeValue.isNull())
-                m_crossOriginMode = stripLeadingAndTrailingHTMLSpaces(attributeValue);
+            else if (match(attributeName, crossoriginAttr))
+                setCrossOriginAllowed(attributeValue);
         } else if (match(m_tagImpl, imgTag)) {
             if (match(attributeName, srcAttr) && !m_encounteredImgSrc) {
                 m_encounteredImgSrc = true;
                 setUrlToLoad(bestFitSourceForImageAttributes(m_deviceScaleFactor, attributeValue, m_srcsetImageCandidate), AllowURLReplacement);
-            } else if (match(attributeName, crossoriginAttr) && !attributeValue.isNull()) {
-                m_crossOriginMode = stripLeadingAndTrailingHTMLSpaces(attributeValue);
+            } else if (match(attributeName, crossoriginAttr)) {
+                setCrossOriginAllowed(attributeValue);
             } else if (RuntimeEnabledFeatures::srcsetEnabled()
                 && match(attributeName, srcsetAttr)
                 && m_srcsetImageCandidate.isEmpty()) {
@@ -175,11 +178,13 @@ private:
                 m_linkIsStyleSheet = relAttributeIsStyleSheet(attributeValue);
             else if (match(attributeName, mediaAttr))
                 m_mediaAttribute = attributeValue;
+            else if (match(attributeName, crossoriginAttr))
+                setCrossOriginAllowed(attributeValue);
         } else if (match(m_tagImpl, inputTag)) {
             if (match(attributeName, srcAttr))
                 setUrlToLoad(attributeValue, DisallowURLReplacement);
             else if (match(attributeName, typeAttr))
-                m_inputIsImage = equalIgnoringCase(attributeValue, InputTypeNames::image());
+                m_inputIsImage = equalIgnoringCase(attributeValue, InputTypeNames::image);
         }
     }
 
@@ -221,7 +226,7 @@ private:
         return Resource::Raw;
     }
 
-    bool shouldPreload()
+    bool shouldPreload() const
     {
         if (m_urlToLoad.isEmpty())
             return false;
@@ -232,21 +237,36 @@ private:
         return true;
     }
 
-    bool crossOriginModeAllowsCookies()
+    bool isCORSEnabled() const
+    {
+        return m_isCORSEnabled;
+    }
+
+    StoredCredentials allowCredentials() const
+    {
+        return m_allowCredentials;
+    }
+
+    void setCrossOriginAllowed(const String& corsSetting)
     {
-        return m_crossOriginMode.isNull() || equalIgnoringCase(m_crossOriginMode, "use-credentials");
+        m_isCORSEnabled = true;
+        if (!corsSetting.isNull() && equalIgnoringCase(stripLeadingAndTrailingHTMLSpaces(corsSetting), "use-credentials"))
+            m_allowCredentials = AllowStoredCredentials;
+        else
+            m_allowCredentials = DoNotAllowStoredCredentials;
     }
 
     const StringImpl* m_tagImpl;
     String m_urlToLoad;
     ImageCandidate m_srcsetImageCandidate;
     String m_charset;
-    String m_crossOriginMode;
     bool m_linkIsStyleSheet;
     String m_mediaAttribute;
     bool m_inputIsImage;
     float m_deviceScaleFactor;
     bool m_encounteredImgSrc;
+    bool m_isCORSEnabled;
+    StoredCredentials m_allowCredentials;
 };
 
 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, float deviceScaleFactor)
@@ -381,7 +401,7 @@ void HTMLPreloadScanner::scan(HTMLResourcePreloader* preloader, const KURL& star
 
     while (m_tokenizer->nextToken(m_source, m_token)) {
         if (m_token.type() == HTMLToken::StartTag)
-            m_tokenizer->updateStateFor(AtomicString(m_token.name()));
+            m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name(), Likely8Bit));
         m_scanner.scan(m_token, m_source, requests);
         m_token.clear();
     }