Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Unified Diff: Source/core/html/parser/HTMLPreloadScanner.cpp

Issue 457413002: Defer late and async scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Lower priorities for late/async scripts Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/parser/HTMLPreloadScanner.h ('k') | Source/core/html/parser/HTMLResourcePreloader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/parser/HTMLPreloadScanner.cpp
diff --git a/Source/core/html/parser/HTMLPreloadScanner.cpp b/Source/core/html/parser/HTMLPreloadScanner.cpp
index 1b21bc89b4408a9bbe189b2d614297b7651b7a3c..08fe987f5d53ccd22b4c15b0022c7adf7062710d 100644
--- a/Source/core/html/parser/HTMLPreloadScanner.cpp
+++ b/Source/core/html/parser/HTMLPreloadScanner.cpp
@@ -111,6 +111,7 @@ public:
, m_sourceSize(0)
, m_sourceSizeSet(false)
, m_isCORSEnabled(false)
+ , m_execAsync(false)
, m_allowCredentials(DoNotAllowStoredCredentials)
, m_mediaValues(mediaValues)
{
@@ -170,6 +171,7 @@ public:
if (isCORSEnabled())
request->setCrossOriginEnabled(allowStoredCredentials());
request->setCharset(charset());
+ request->setExecAsync(m_execAsync);
return request.release();
}
@@ -182,6 +184,10 @@ private:
setUrlToLoad(attributeValue, DisallowURLReplacement);
else if (match(attributeName, crossoriginAttr))
setCrossOriginAllowed(attributeValue);
+ else if (match(attributeName, asyncAttr))
+ setExecAsync(true);
+ else if (match(attributeName, deferAttr))
+ setExecAsync(true);
}
template<typename NameType>
@@ -337,6 +343,16 @@ private:
m_allowCredentials = DoNotAllowStoredCredentials;
}
+ void setExecAsync(const bool execAsync)
+ {
+ m_execAsync = execAsync;
+ }
+
+ bool execAsync() const
+ {
+ return m_execAsync;
+ }
+
const StringImpl* m_tagImpl;
String m_urlToLoad;
ImageCandidate m_srcsetImageCandidate;
@@ -349,6 +365,7 @@ private:
unsigned m_sourceSize;
bool m_sourceSizeSet;
bool m_isCORSEnabled;
+ bool m_execAsync;
StoredCredentials m_allowCredentials;
RefPtr<MediaValues> m_mediaValues;
};
@@ -357,6 +374,7 @@ TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med
: m_documentURL(documentURL)
, m_inStyle(false)
, m_inPicture(false)
+ , m_isBeforeBody(true)
, m_templateCount(0)
, m_mediaValues(mediaValues)
{
@@ -369,7 +387,7 @@ TokenPreloadScanner::~TokenPreloadScanner()
TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint()
{
TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size();
- m_checkpoints.append(Checkpoint(m_predictedBaseElementURL, m_inStyle, m_templateCount));
+ m_checkpoints.append(Checkpoint(m_predictedBaseElementURL, m_inStyle, m_isBeforeBody, m_templateCount));
return checkpoint;
}
@@ -379,8 +397,10 @@ void TokenPreloadScanner::rewindTo(TokenPreloadScannerCheckpoint checkpointIndex
const Checkpoint& checkpoint = m_checkpoints[checkpointIndex];
m_predictedBaseElementURL = checkpoint.predictedBaseElementURL;
m_inStyle = checkpoint.inStyle;
+ m_isBeforeBody = checkpoint.isBeforeBody;
m_templateCount = checkpoint.templateCount;
m_cssScanner.reset();
+ m_cssScanner.setIsBeforeBody(m_isBeforeBody);
m_checkpoints.clear();
}
@@ -433,6 +453,10 @@ void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
m_inStyle = true;
return;
}
+ if (m_isBeforeBody && match(tagImpl, bodyTag)) {
+ m_isBeforeBody = false;
+ m_cssScanner.setIsBeforeBody(m_isBeforeBody);
+ }
if (match(tagImpl, baseTag)) {
// The first <base> element is the one that wins.
if (!m_predictedBaseElementURL.isEmpty())
@@ -451,8 +475,10 @@ void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString&
if (m_inPicture)
scanner.handlePictureSourceURL(m_pictureSourceURL);
OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predictedBaseElementURL, source);
- if (request)
+ if (request) {
+ request->setIsBeforeBody(m_isBeforeBody);
requests.append(request.release());
+ }
return;
}
default: {
« no previous file with comments | « Source/core/html/parser/HTMLPreloadScanner.h ('k') | Source/core/html/parser/HTMLResourcePreloader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698