| 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 #ifndef InProcessWorkerBase_h | 5 #ifndef InProcessWorkerBase_h |
| 6 #define InProcessWorkerBase_h | 6 #define InProcessWorkerBase_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ActiveScriptWrappable.h" |
| 8 #include "core/CoreExport.h" | 9 #include "core/CoreExport.h" |
| 9 #include "core/dom/ActiveDOMObject.h" | 10 #include "core/dom/ActiveDOMObject.h" |
| 10 #include "core/dom/MessagePort.h" | 11 #include "core/dom/MessagePort.h" |
| 11 #include "core/events/EventListener.h" | 12 #include "core/events/EventListener.h" |
| 12 #include "core/events/EventTarget.h" | 13 #include "core/events/EventTarget.h" |
| 13 #include "core/workers/AbstractWorker.h" | 14 #include "core/workers/AbstractWorker.h" |
| 14 #include "platform/heap/Handle.h" | 15 #include "platform/heap/Handle.h" |
| 15 #include "wtf/Forward.h" | 16 #include "wtf/Forward.h" |
| 16 #include "wtf/PassRefPtr.h" | 17 #include "wtf/PassRefPtr.h" |
| 17 #include "wtf/RefPtr.h" | 18 #include "wtf/RefPtr.h" |
| 18 #include "wtf/text/AtomicStringHash.h" | 19 #include "wtf/text/AtomicStringHash.h" |
| 19 | 20 |
| 20 namespace blink { | 21 namespace blink { |
| 21 | 22 |
| 22 class ExceptionState; | 23 class ExceptionState; |
| 23 class ExecutionContext; | 24 class ExecutionContext; |
| 24 class WorkerGlobalScopeProxy; | 25 class WorkerGlobalScopeProxy; |
| 25 class WorkerScriptLoader; | 26 class WorkerScriptLoader; |
| 26 | 27 |
| 27 // Base class for workers that operate in the same process as the document that | 28 // Base class for workers that operate in the same process as the document that |
| 28 // creates them. | 29 // creates them. |
| 29 class CORE_EXPORT InProcessWorkerBase : public AbstractWorker { | 30 class CORE_EXPORT InProcessWorkerBase : public AbstractWorker, public ActiveScri
ptWrappable { |
| 30 public: | 31 public: |
| 31 ~InProcessWorkerBase() override; | 32 ~InProcessWorkerBase() override; |
| 32 | 33 |
| 33 void postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> messag
e, const MessagePortArray*, ExceptionState&); | 34 void postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> messag
e, const MessagePortArray*, ExceptionState&); |
| 34 void terminate(); | 35 void terminate(); |
| 35 | 36 |
| 36 // ActiveDOMObject | 37 // ActiveDOMObject |
| 37 void stop() override; | 38 void stop() override; |
| 38 bool hasPendingActivity() const override; | 39 |
| 40 // ActiveScriptWrappable |
| 41 bool hasPendingActivity() const final; |
| 39 | 42 |
| 40 ContentSecurityPolicy* contentSecurityPolicy(); | 43 ContentSecurityPolicy* contentSecurityPolicy(); |
| 41 | 44 |
| 42 DEFINE_ATTRIBUTE_EVENT_LISTENER(message); | 45 DEFINE_ATTRIBUTE_EVENT_LISTENER(message); |
| 43 | 46 |
| 44 DECLARE_VIRTUAL_TRACE(); | 47 DECLARE_VIRTUAL_TRACE(); |
| 45 | 48 |
| 46 protected: | 49 protected: |
| 47 explicit InProcessWorkerBase(ExecutionContext*); | 50 explicit InProcessWorkerBase(ExecutionContext*); |
| 48 bool initialize(ExecutionContext*, const String&, ExceptionState&); | 51 bool initialize(ExecutionContext*, const String&, ExceptionState&); |
| 49 | 52 |
| 50 // Creates a proxy to allow communicating with the worker's global scope. In
ProcessWorkerBase does not take ownership of the | 53 // Creates a proxy to allow communicating with the worker's global scope. In
ProcessWorkerBase does not take ownership of the |
| 51 // created proxy. The proxy is expected to manage its own lifetime, and dele
te itself in response to terminateWorkerGlobalScope(). | 54 // created proxy. The proxy is expected to manage its own lifetime, and dele
te itself in response to terminateWorkerGlobalScope(). |
| 52 virtual WorkerGlobalScopeProxy* createWorkerGlobalScopeProxy(ExecutionContex
t*) = 0; | 55 virtual WorkerGlobalScopeProxy* createWorkerGlobalScopeProxy(ExecutionContex
t*) = 0; |
| 53 | 56 |
| 54 private: | 57 private: |
| 55 // Callbacks for m_scriptLoader. | 58 // Callbacks for m_scriptLoader. |
| 56 void onResponse(); | 59 void onResponse(); |
| 57 void onFinished(); | 60 void onFinished(); |
| 58 | 61 |
| 59 RefPtr<WorkerScriptLoader> m_scriptLoader; | 62 RefPtr<WorkerScriptLoader> m_scriptLoader; |
| 60 RefPtrWillBeMember<ContentSecurityPolicy> m_contentSecurityPolicy; | 63 RefPtrWillBeMember<ContentSecurityPolicy> m_contentSecurityPolicy; |
| 61 WorkerGlobalScopeProxy* m_contextProxy; // The proxy outlives the worker to
perform thread shutdown. | 64 WorkerGlobalScopeProxy* m_contextProxy; // The proxy outlives the worker to
perform thread shutdown. |
| 62 }; | 65 }; |
| 63 | 66 |
| 64 } // namespace blink | 67 } // namespace blink |
| 65 | 68 |
| 66 #endif // InProcessWorkerBase_h | 69 #endif // InProcessWorkerBase_h |
| OLD | NEW |