#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"
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);
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;
, m_inputIsImage(false)
, m_deviceScaleFactor(deviceScaleFactor)
, m_encounteredImgSrc(false)
+ , m_isCORSEnabled(false)
+ , m_allowCredentials(DoNotAllowStoredCredentials)
{
if (!match(m_tagImpl, imgTag)
&& !match(m_tagImpl, inputTag)
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();
}
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()) {
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);
}
}
return Resource::Raw;
}
- bool shouldPreload()
+ bool shouldPreload() const
{
if (m_urlToLoad.isEmpty())
return false;
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)
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();
}