Commit c219b34a authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Worker: Move implementation of the "fetch a module worker script graph" algorithm

This CL moves implementation of the "fetch a module worker script graph"
algorithm from WorkletGlobalScope to WorkerOrWorkletGlobalScope so that it can
be reused for module workers.

There is no behavioral change.

Bug: 680046
Change-Id: I7eba8ec1e1dc65396ec2aea8486b22fd1d829fa2
Reviewed-on: https://chromium-review.googlesource.com/826206Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524641}
parent 635de947
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "core/frame/Deprecation.h" #include "core/frame/Deprecation.h"
#include "core/inspector/ConsoleMessage.h" #include "core/inspector/ConsoleMessage.h"
#include "core/loader/WorkerFetchContext.h" #include "core/loader/WorkerFetchContext.h"
#include "core/loader/modulescript/ModuleScriptFetchRequest.h"
#include "core/probe/CoreProbes.h" #include "core/probe/CoreProbes.h"
#include "core/workers/MainThreadWorkletGlobalScope.h" #include "core/workers/MainThreadWorkletGlobalScope.h"
#include "core/workers/WorkerReportingProxy.h" #include "core/workers/WorkerReportingProxy.h"
...@@ -195,6 +196,28 @@ void WorkerOrWorkletGlobalScope::ApplyContentSecurityPolicyFromVector( ...@@ -195,6 +196,28 @@ void WorkerOrWorkletGlobalScope::ApplyContentSecurityPolicyFromVector(
GetContentSecurityPolicy()->BindToExecutionContext(GetExecutionContext()); GetContentSecurityPolicy()->BindToExecutionContext(GetExecutionContext());
} }
void WorkerOrWorkletGlobalScope::FetchModuleScript(
const KURL& module_url_record,
network::mojom::FetchCredentialsMode credentials_mode,
ModuleTreeClient* client) {
// Step 2: "Let options be a script fetch options whose cryptographic nonce is
// the empty string,
String nonce;
// integrity metadata is the empty string,
String integrity_attribute;
// parser metadata is "not-parser-inserted",
ParserDisposition parser_state = kNotParserInserted;
// and credentials mode is credentials mode."
ScriptFetchOptions options(nonce, IntegrityMetadataSet(), integrity_attribute,
parser_state, credentials_mode);
Modulator* modulator = Modulator::From(ScriptController()->GetScriptState());
// Step 3. "Perform the internal module script graph fetching procedure ..."
ModuleScriptFetchRequest module_request(
module_url_record, modulator->GetReferrerPolicy(), options);
modulator->FetchTree(module_request, client);
}
void WorkerOrWorkletGlobalScope::Trace(blink::Visitor* visitor) { void WorkerOrWorkletGlobalScope::Trace(blink::Visitor* visitor) {
visitor->Trace(resource_fetcher_); visitor->Trace(resource_fetcher_);
visitor->Trace(script_controller_); visitor->Trace(script_controller_);
......
...@@ -14,10 +14,12 @@ ...@@ -14,10 +14,12 @@
#include "core/workers/WorkerClients.h" #include "core/workers/WorkerClients.h"
#include "core/workers/WorkerEventQueue.h" #include "core/workers/WorkerEventQueue.h"
#include "platform/wtf/BitVector.h" #include "platform/wtf/BitVector.h"
#include "services/network/public/interfaces/fetch_api.mojom-shared.h"
namespace blink { namespace blink {
class Modulator; class Modulator;
class ModuleTreeClient;
class ResourceFetcher; class ResourceFetcher;
class V8AbstractEventListener; class V8AbstractEventListener;
class WorkerOrWorkletScriptController; class WorkerOrWorkletScriptController;
...@@ -112,6 +114,13 @@ class CORE_EXPORT WorkerOrWorkletGlobalScope : public EventTargetWithInlineData, ...@@ -112,6 +114,13 @@ class CORE_EXPORT WorkerOrWorkletGlobalScope : public EventTargetWithInlineData,
void ApplyContentSecurityPolicyFromVector( void ApplyContentSecurityPolicyFromVector(
const Vector<CSPHeaderAndType>& headers); const Vector<CSPHeaderAndType>& headers);
// Implementation of the "fetch a module worker script graph" algorithm in the
// HTML spec:
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree
void FetchModuleScript(const KURL& module_url_record,
network::mojom::FetchCredentialsMode,
ModuleTreeClient*);
private: private:
CrossThreadPersistent<WorkerClients> worker_clients_; CrossThreadPersistent<WorkerClients> worker_clients_;
Member<ResourceFetcher> resource_fetcher_; Member<ResourceFetcher> resource_fetcher_;
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "bindings/core/v8/WorkerOrWorkletScriptController.h" #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
#include "core/dom/Modulator.h" #include "core/dom/Modulator.h"
#include "core/inspector/MainThreadDebugger.h" #include "core/inspector/MainThreadDebugger.h"
#include "core/loader/modulescript/ModuleScriptFetchRequest.h"
#include "core/probe/CoreProbes.h" #include "core/probe/CoreProbes.h"
#include "core/workers/GlobalScopeCreationParams.h" #include "core/workers/GlobalScopeCreationParams.h"
#include "core/workers/WorkerReportingProxy.h" #include "core/workers/WorkerReportingProxy.h"
...@@ -100,30 +99,14 @@ void WorkletGlobalScope::FetchAndInvokeScript( ...@@ -100,30 +99,14 @@ void WorkletGlobalScope::FetchAndInvokeScript(
// moduleURLRecord, moduleResponsesMap, credentialOptions, outsideSettings, // moduleURLRecord, moduleResponsesMap, credentialOptions, outsideSettings,
// and insideSettings when it asynchronously completes." // and insideSettings when it asynchronously completes."
// [FMWST]
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree
// [FMWST] Step 2: "Let options be a script fetch options whose cryptographic
// nonce is the empty string,
String nonce;
// integrity metadata is the empty string,
String integrity_attribute;
// parser metadata is "not-parser-inserted",
ParserDisposition parser_state = kNotParserInserted;
// and credentials mode is credentials mode.
ScriptFetchOptions options(nonce, IntegrityMetadataSet(), integrity_attribute,
parser_state, credentials_mode);
Modulator* modulator = Modulator::From(ScriptController()->GetScriptState()); Modulator* modulator = Modulator::From(ScriptController()->GetScriptState());
// [FMWST] Step 3. "Perform the internal module script graph fetching
// procedure ..."
ModuleScriptFetchRequest module_request(
module_url_record, modulator->GetReferrerPolicy(), options);
// Step 3 to 5 are implemented in // Step 3 to 5 are implemented in
// WorkletModuleTreeClient::NotifyModuleTreeLoadFinished. // WorkletModuleTreeClient::NotifyModuleTreeLoadFinished.
WorkletModuleTreeClient* client = new WorkletModuleTreeClient( WorkletModuleTreeClient* client = new WorkletModuleTreeClient(
modulator, std::move(outside_settings_task_runner), pending_tasks); modulator, std::move(outside_settings_task_runner), pending_tasks);
modulator->FetchTree(module_request, client);
FetchModuleScript(module_url_record, credentials_mode, client);
} }
WorkletModuleResponsesMapProxy* WorkletGlobalScope::ModuleResponsesMapProxy() WorkletModuleResponsesMapProxy* WorkletGlobalScope::ModuleResponsesMapProxy()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment