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