OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/workers/InProcessWorkerBase.h" | 5 #include "core/workers/InProcessWorkerBase.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "core/events/MessageEvent.h" | 10 #include "core/events/MessageEvent.h" |
11 #include "core/frame/csp/ContentSecurityPolicy.h" | 11 #include "core/frame/csp/ContentSecurityPolicy.h" |
12 #include "core/inspector/InspectorInstrumentation.h" | 12 #include "core/inspector/InspectorInstrumentation.h" |
13 #include "core/workers/InProcessWorkerMessagingProxy.h" | 13 #include "core/workers/InProcessWorkerMessagingProxy.h" |
14 #include "core/workers/WorkerScriptLoader.h" | 14 #include "core/workers/WorkerScriptLoader.h" |
15 #include "platform/loader/fetch/ResourceFetcher.h" | 15 #include "platform/loader/fetch/ResourceFetcher.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 InProcessWorkerBase::InProcessWorkerBase(ExecutionContext* context) | 19 InProcessWorkerBase::InProcessWorkerBase(ExecutionContext* context) |
20 : AbstractWorker(context), | 20 : AbstractWorker(context), m_contextProxy(nullptr) {} |
21 m_contextProxy(nullptr) {} | |
22 | 21 |
23 InProcessWorkerBase::~InProcessWorkerBase() { | 22 InProcessWorkerBase::~InProcessWorkerBase() { |
24 DCHECK(isMainThread()); | 23 DCHECK(isMainThread()); |
25 if (!m_contextProxy) | 24 if (!m_contextProxy) |
26 return; | 25 return; |
27 m_contextProxy->parentObjectDestroyed(); | 26 m_contextProxy->parentObjectDestroyed(); |
28 } | 27 } |
29 | 28 |
30 void InProcessWorkerBase::postMessage(ScriptState* scriptState, | 29 void InProcessWorkerBase::postMessage(ScriptState* scriptState, |
31 PassRefPtr<SerializedScriptValue> message, | 30 PassRefPtr<SerializedScriptValue> message, |
32 const MessagePortArray& ports, | 31 const MessagePortArray& ports, |
33 ExceptionState& exceptionState) { | 32 ExceptionState& exceptionState) { |
34 DCHECK(m_contextProxy); | 33 DCHECK(m_contextProxy); |
35 // Disentangle the port in preparation for sending it to the remote context. | 34 // Disentangle the port in preparation for sending it to the remote context. |
36 MessagePortChannelArray channels = | 35 MessagePortChannelArray channels = MessagePort::disentanglePorts( |
37 MessagePort::disentanglePorts(scriptState->getExecutionContext(), ports, | 36 scriptState->getExecutionContext(), ports, exceptionState); |
38 exceptionState); | |
39 if (exceptionState.hadException()) | 37 if (exceptionState.hadException()) |
40 return; | 38 return; |
41 m_contextProxy->postMessageToWorkerGlobalScope(std::move(message), | 39 m_contextProxy->postMessageToWorkerGlobalScope(std::move(message), |
42 std::move(channels)); | 40 std::move(channels)); |
43 } | 41 } |
44 | 42 |
45 bool InProcessWorkerBase::initialize(ExecutionContext* context, | 43 bool InProcessWorkerBase::initialize(ExecutionContext* context, |
46 const String& url, | 44 const String& url, |
47 ExceptionState& exceptionState) { | 45 ExceptionState& exceptionState) { |
48 // TODO(mkwst): Revisit the context as | 46 // TODO(mkwst): Revisit the context as |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 m_scriptLoader->script()); | 105 m_scriptLoader->script()); |
108 } | 106 } |
109 m_scriptLoader = nullptr; | 107 m_scriptLoader = nullptr; |
110 } | 108 } |
111 | 109 |
112 DEFINE_TRACE(InProcessWorkerBase) { | 110 DEFINE_TRACE(InProcessWorkerBase) { |
113 AbstractWorker::trace(visitor); | 111 AbstractWorker::trace(visitor); |
114 } | 112 } |
115 | 113 |
116 } // namespace blink | 114 } // namespace blink |
OLD | NEW |