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