| 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 0a9402b302f3e530645f10d5a6397add4059de80..b04a42626e385ebbf6415db5d7b782c6bb7e633d 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())
|
| @@ -751,21 +778,9 @@ bool ScriptLoader::doExecuteScript(const ScriptSourceCode& sourceCode) {
|
| logScriptMIMEType(frame, resource, mimeType);
|
| }
|
|
|
| - 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;
|
|
|
| @@ -791,7 +806,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.
|
| @@ -816,11 +835,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();
|
| @@ -829,6 +849,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);
|
|
|