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

Unified Diff: third_party/WebKit/Source/core/dom/ScriptLoader.cpp

Issue 2695713015: WIP: Reland CompiledScript, prototype compiling in a separate task.
Patch Set: allow fetchFinished to finish when there is no frame Created 3 years, 10 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
Index: third_party/WebKit/Source/core/dom/ScriptLoader.cpp
diff --git a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
index 556fd9b9bc08b85524bea725d0620f317f46dbbf..a01ae243ea80b1e1ca876feb2b22be01d2b45170 100644
--- a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
+++ b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
@@ -111,6 +111,31 @@ DEFINE_TRACE(ScriptLoader) {
PendingScriptClient::trace(visitor);
}
+// static
+AccessControlStatus ScriptLoader::accessControlStatusForScript(
+ bool isExternalScript,
+ const ScriptResource* resource,
+ const SecurityOrigin* scriptElementOrigin) {
+ if (!isExternalScript)
+ return SharableCrossOrigin;
+
+ // TODO(jbroman): DCHECK(resource)?
+ if (!resource)
+ return NotSharableCrossOrigin;
+
+ const auto& response = resource->response();
+ if (response.wasFetchedViaServiceWorker()) {
+ return response.serviceWorkerResponseType() ==
+ WebServiceWorkerResponseTypeOpaque
+ ? OpaqueResource
+ : SharableCrossOrigin;
+ }
+
+ return resource->passesAccessControlCheck(scriptElementOrigin)
+ ? SharableCrossOrigin
+ : NotSharableCrossOrigin;
+}
+
void ScriptLoader::setFetchDocWrittenScriptDeferIdle() {
DCHECK(!m_createdDuringDocumentWrite);
m_documentWriteIntervention =
@@ -660,9 +685,10 @@ void ScriptLoader::logScriptMIMEType(LocalFrame* frame,
UseCounter::count(frame, feature);
}
-bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode) {
+bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode,
+ CompiledScript* compiledScript) {
double scriptExecStartTime = monotonicallyIncreasingTime();
- bool result = doExecuteScript(sourceCode);
+ bool result = doExecuteScript(sourceCode, compiledScript);
// NOTE: we do not check m_willBeParserExecuted here, since
// m_willBeParserExecuted is false for inline scripts, and we want to
@@ -682,7 +708,8 @@ bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode) {
// i.e. load/error events are dispatched by the caller.
// Steps 3--7 are implemented here in doExecuteScript().
// TODO(hiroshige): Move event dispatching code to doExecuteScript().
-bool ScriptLoader::doExecuteScript(const ScriptSourceCode& sourceCode) {
+bool ScriptLoader::doExecuteScript(const ScriptSourceCode& sourceCode,
+ CompiledScript* compiledScript) {
DCHECK(m_alreadyStarted);
if (sourceCode.isEmpty())
@@ -752,21 +779,9 @@ bool ScriptLoader::doExecuteScript(const ScriptSourceCode& sourceCode) {
}
}
- AccessControlStatus accessControlStatus = NotSharableCrossOrigin;
- if (!m_isExternalScript) {
- accessControlStatus = SharableCrossOrigin;
- } else if (sourceCode.resource()) {
- if (sourceCode.resource()->response().wasFetchedViaServiceWorker()) {
- if (sourceCode.resource()->response().serviceWorkerResponseType() ==
- WebServiceWorkerResponseTypeOpaque)
- accessControlStatus = OpaqueResource;
- else
- accessControlStatus = SharableCrossOrigin;
- } else if (sourceCode.resource()->passesAccessControlCheck(
- m_element->document().getSecurityOrigin())) {
- accessControlStatus = SharableCrossOrigin;
- }
- }
+ AccessControlStatus accessControlStatus =
+ accessControlStatusForScript(m_isExternalScript, sourceCode.resource(),
+ elementDocument->getSecurityOrigin());
const bool isImportedScript = contextDocument != elementDocument;
@@ -792,7 +807,11 @@ bool ScriptLoader::doExecuteScript(const ScriptSourceCode& sourceCode) {
// 2. "Run the classic script given by the script's script."
// Note: This is where the script is compiled and actually executed.
- frame->script().executeScriptInMainWorld(sourceCode, accessControlStatus);
+ if (compiledScript) {
+ frame->script().executeScriptInMainWorld(*compiledScript);
+ } else {
+ frame->script().executeScriptInMainWorld(sourceCode, accessControlStatus);
+ }
// - "module":
// TODO(hiroshige): Implement this.
@@ -817,11 +836,12 @@ void ScriptLoader::execute() {
DCHECK(m_pendingScript->resource());
bool errorOccurred = false;
ScriptSourceCode source = m_pendingScript->getSource(KURL(), errorOccurred);
+ CompiledScript* compiledScript = m_pendingScript->getCompiledScript();
detachPendingScript();
if (errorOccurred) {
dispatchErrorEvent();
} else if (!m_resource->wasCanceled()) {
- if (executeScript(source))
+ if (executeScript(source, compiledScript))
dispatchLoadEvent();
else
dispatchErrorEvent();
@@ -830,6 +850,8 @@ void ScriptLoader::execute() {
}
void ScriptLoader::pendingScriptFinished(PendingScript* pendingScript) {
+ LOG(ERROR) << "Finished loading pending script of size "
+ << pendingScript->resource()->size();
DCHECK(!m_willBeParserExecuted);
DCHECK_EQ(m_pendingScript, pendingScript);
DCHECK_EQ(pendingScript->resource(), m_resource);

Powered by Google App Engine
This is Rietveld 408576698