| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/workers/ThreadedWorkletMessagingProxy.h" | |
| 6 | |
| 7 #include "bindings/core/v8/ScriptSourceCode.h" | |
| 8 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | |
| 9 #include "core/dom/Document.h" | |
| 10 #include "core/dom/ExecutionContextTask.h" | |
| 11 #include "core/dom/SecurityContext.h" | |
| 12 #include "core/frame/csp/ContentSecurityPolicy.h" | |
| 13 #include "core/origin_trials/OriginTrialContext.h" | |
| 14 #include "core/workers/ThreadedWorkletObjectProxy.h" | |
| 15 #include "core/workers/WorkerInspectorProxy.h" | |
| 16 #include "core/workers/WorkerThreadStartupData.h" | |
| 17 #include "core/workers/WorkletGlobalScope.h" | |
| 18 #include "public/platform/WebTaskRunner.h" | |
| 19 | |
| 20 namespace blink { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 void evaluateScriptOnWorkletGlobalScope(const String& source, const KURL& script
URL, ExecutionContext* executionContext) | |
| 25 { | |
| 26 WorkletGlobalScope* globalScope = toWorkletGlobalScope(executionContext); | |
| 27 globalScope->scriptController()->evaluate(ScriptSourceCode(source, scriptURL
)); | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 ThreadedWorkletMessagingProxy::ThreadedWorkletMessagingProxy(ExecutionContext* e
xecutionContext) | |
| 33 : ThreadedMessagingProxyBase(executionContext) | |
| 34 , m_workletObjectProxy(ThreadedWorkletObjectProxy::create(this)) | |
| 35 { | |
| 36 } | |
| 37 | |
| 38 void ThreadedWorkletMessagingProxy::initialize() | |
| 39 { | |
| 40 DCHECK(isParentContextThread()); | |
| 41 if (askedToTerminate()) | |
| 42 return; | |
| 43 | |
| 44 Document* document = toDocument(getExecutionContext()); | |
| 45 SecurityOrigin* starterOrigin = document->getSecurityOrigin(); | |
| 46 KURL scriptURL = document->url(); | |
| 47 | |
| 48 ContentSecurityPolicy* csp = document->contentSecurityPolicy(); | |
| 49 DCHECK(csp); | |
| 50 | |
| 51 WorkerThreadStartMode startMode = workerInspectorProxy()->workerStartMode(do
cument); | |
| 52 std::unique_ptr<WorkerSettings> workerSettings = wrapUnique(new WorkerSettin
gs(document->settings())); | |
| 53 | |
| 54 // TODO(ikilpatrick): Decide on sensible a value for referrerPolicy. | |
| 55 std::unique_ptr<WorkerThreadStartupData> startupData = WorkerThreadStartupDa
ta::create(scriptURL, document->userAgent(), String(), nullptr, startMode, csp->
headers().get(), /* referrerPolicy */ String(), starterOrigin, nullptr, document
->addressSpace(), OriginTrialContext::getTokens(document).get(), std::move(worke
rSettings)); | |
| 56 | |
| 57 initializeWorkerThread(std::move(startupData)); | |
| 58 workerInspectorProxy()->workerThreadCreated(document, workerThread(), script
URL); | |
| 59 } | |
| 60 | |
| 61 void ThreadedWorkletMessagingProxy::evaluateScript(const ScriptSourceCode& scrip
tSourceCode) | |
| 62 { | |
| 63 postTaskToWorkerGlobalScope(BLINK_FROM_HERE, createCrossThreadTask(&evaluate
ScriptOnWorkletGlobalScope, scriptSourceCode.source(), scriptSourceCode.url())); | |
| 64 } | |
| 65 | |
| 66 void ThreadedWorkletMessagingProxy::terminateWorkletGlobalScope() | |
| 67 { | |
| 68 terminateGlobalScope(); | |
| 69 } | |
| 70 | |
| 71 } // namespace blink | |
| OLD | NEW |