| OLD | NEW |
| 1 /* | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 * | 3 // found in the LICENSE file. |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 * | |
| 25 */ | |
| 26 | 4 |
| 27 #ifndef InProcessWorkerMessagingProxy_h | 5 #ifndef ThreadedWorkletMessagingProxy_h |
| 28 #define InProcessWorkerMessagingProxy_h | 6 #define ThreadedWorkletMessagingProxy_h |
| 29 | 7 |
| 30 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 31 #include "core/dom/ExecutionContext.h" | 9 #include "core/inspector/ConsoleTypes.h" |
| 32 #include "core/workers/InProcessWorkerGlobalScopeProxy.h" | |
| 33 #include "core/workers/WorkerLoaderProxy.h" | 10 #include "core/workers/WorkerLoaderProxy.h" |
| 34 #include "platform/heap/Handle.h" | 11 #include "core/workers/WorkletGlobalScopeProxy.h" |
| 35 #include "wtf/Forward.h" | 12 #include <v8.h> |
| 36 #include "wtf/Noncopyable.h" | |
| 37 #include "wtf/PassRefPtr.h" | |
| 38 #include "wtf/RefPtr.h" | |
| 39 #include "wtf/Vector.h" | |
| 40 #include <memory> | |
| 41 | 13 |
| 42 namespace blink { | 14 namespace blink { |
| 43 | 15 |
| 44 class ExecutionContext; | 16 class LocalFrame; |
| 45 class InProcessWorkerBase; | 17 class ThreadedWorkletObjectProxy; |
| 46 class InProcessWorkerObjectProxy; | |
| 47 class ParentFrameTaskRunners; | |
| 48 class WorkerClients; | |
| 49 class WorkerInspectorProxy; | 18 class WorkerInspectorProxy; |
| 50 class WorkerThread; | 19 class WorkerThread; |
| 51 | 20 |
| 52 // TODO(nhiroki): "MessagingProxy" is not well-defined term among worker | 21 class CORE_EXPORT ThreadedWorkletMessagingProxy |
| 53 // components. Probably we should rename this to something more suitable. | 22 : public WorkletGlobalScopeProxy |
| 54 // (http://crbug.com/603785) | |
| 55 class CORE_EXPORT InProcessWorkerMessagingProxy | |
| 56 : public InProcessWorkerGlobalScopeProxy | |
| 57 , private WorkerLoaderProxyProvider { | 23 , private WorkerLoaderProxyProvider { |
| 58 WTF_MAKE_NONCOPYABLE(InProcessWorkerMessagingProxy); | 24 WTF_MAKE_NONCOPYABLE(ThreadedWorkletMessagingProxy); |
| 25 |
| 59 public: | 26 public: |
| 60 // Implementations of InProcessWorkerGlobalScopeProxy. | 27 ~ThreadedWorkletMessagingProxy() override; |
| 61 // (Only use these methods in the parent context thread.) | 28 |
| 62 void startWorkerGlobalScope(const KURL& scriptURL, const String& userAgent,
const String& sourceCode) override; | 29 void initialize(); |
| 63 void terminateWorkerGlobalScope() override; | 30 ExecutionContext* getExecutionContext() const { return m_executionContext; } |
| 64 void postMessageToWorkerGlobalScope(PassRefPtr<SerializedScriptValue>, std::
unique_ptr<MessagePortChannelArray>) override; | 31 |
| 65 bool hasPendingActivity() const final; | 32 virtual std::unique_ptr<WorkerThread> createWorkerThread() = 0; |
| 66 void workerObjectDestroyed() override; | 33 |
| 34 void workletObjectDestroyed(); |
| 35 |
| 36 // WorkletGlobalScopeProxy |
| 37 void evaluateScript(const ScriptSourceCode&) final; |
| 38 void terminateWorkletGlobalScope() final; |
| 67 | 39 |
| 68 // These methods come from worker context thread via | 40 // These methods come from worker context thread via |
| 69 // InProcessWorkerObjectProxy and are called on the parent context thread. | 41 // ThreadedWorkletMessagingProxy and are called on the main thread. |
| 70 void postMessageToWorkerObject(PassRefPtr<SerializedScriptValue>, std::uniqu
e_ptr<MessagePortChannelArray>); | |
| 71 void dispatchErrorEvent(const String& errorMessage, std::unique_ptr<SourceLo
cation>, int exceptionId); | |
| 72 void reportConsoleMessage(MessageSource, MessageLevel, const String& message
, std::unique_ptr<SourceLocation>); | 42 void reportConsoleMessage(MessageSource, MessageLevel, const String& message
, std::unique_ptr<SourceLocation>); |
| 73 void postMessageToPageInspector(const String&); | 43 void postMessageToPageInspector(const String&); |
| 74 | 44 void reportPendingActivity(bool hasPendingActivity); |
| 75 // 'virtual' for testing. | 45 void workerThreadTerminated(); |
| 76 virtual void confirmMessageFromWorkerObject(); | |
| 77 virtual void pendingActivityFinished(); | |
| 78 virtual void workerThreadTerminated(); | |
| 79 | |
| 80 void workerThreadCreated(); | 46 void workerThreadCreated(); |
| 81 | 47 |
| 82 ExecutionContext* getExecutionContext() const { return m_executionContext.ge
t(); } | |
| 83 | |
| 84 ParentFrameTaskRunners* getParentFrameTaskRunners() { return m_parentFrameTa
skRunners.get(); } | |
| 85 | |
| 86 // Number of live messaging proxies, used by leak detection. | |
| 87 static int proxyCount(); | |
| 88 | |
| 89 protected: | 48 protected: |
| 90 InProcessWorkerMessagingProxy(InProcessWorkerBase*, WorkerClients*); | 49 explicit ThreadedWorkletMessagingProxy(LocalFrame*); |
| 91 ~InProcessWorkerMessagingProxy() override; | |
| 92 | |
| 93 virtual std::unique_ptr<WorkerThread> createWorkerThread(double originTime)
= 0; | |
| 94 | 50 |
| 95 PassRefPtr<WorkerLoaderProxy> loaderProxy() { return m_loaderProxy; } | 51 PassRefPtr<WorkerLoaderProxy> loaderProxy() { return m_loaderProxy; } |
| 96 InProcessWorkerObjectProxy& workerObjectProxy() { return *m_workerObjectProx
y.get(); } | 52 ThreadedWorkletObjectProxy& workerObjectProxy(); |
| 97 | 53 |
| 98 private: | 54 private: |
| 99 friend class InProcessWorkerMessagingProxyForTest; | 55 // WorkerLoaderProxyProvider |
| 100 InProcessWorkerMessagingProxy(ExecutionContext*, InProcessWorkerBase*, Worke
rClients*); | 56 // These methods are called on different threads to schedule loading |
| 57 // requests and to send callbacks back to WorkerGlobalScope. |
| 58 void postTaskToLoader(const WebTraceLocation&, std::unique_ptr<ExecutionCont
extTask>) final; |
| 59 void postTaskToWorkerGlobalScope(const WebTraceLocation&, std::unique_ptr<Ex
ecutionContextTask>) final; |
| 101 | 60 |
| 102 void workerObjectDestroyedInternal(); | 61 void workerObjectDestroyedInternal(); |
| 103 | 62 |
| 104 // WorkerLoaderProxyProvider | |
| 105 // These methods are called on different threads to schedule loading | |
| 106 // requests and to send callbacks back to WorkerGlobalScope. | |
| 107 void postTaskToLoader(const WebTraceLocation&, std::unique_ptr<ExecutionCont
extTask>) override; | |
| 108 void postTaskToWorkerGlobalScope(const WebTraceLocation&, std::unique_ptr<Ex
ecutionContextTask>) override; | |
| 109 | |
| 110 // Returns true if this is called on the parent context thread. | |
| 111 bool isParentContextThread() const; | |
| 112 | |
| 113 Persistent<ExecutionContext> m_executionContext; | 63 Persistent<ExecutionContext> m_executionContext; |
| 114 std::unique_ptr<InProcessWorkerObjectProxy> m_workerObjectProxy; | 64 std::unique_ptr<ThreadedWorkletObjectProxy> m_workletObjectProxy; |
| 115 WeakPersistent<InProcessWorkerBase> m_workerObject; | |
| 116 bool m_mayBeDestroyed; | |
| 117 std::unique_ptr<WorkerThread> m_workerThread; | 65 std::unique_ptr<WorkerThread> m_workerThread; |
| 118 | 66 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
| 119 // Unconfirmed messages from the parent context thread to the worker thread. | |
| 120 unsigned m_unconfirmedMessageCount; | |
| 121 | |
| 122 bool m_workerGlobalScopeMayHavePendingActivity; | |
| 123 bool m_askedToTerminate; | |
| 124 | |
| 125 // Tasks are queued here until there's a thread object created. | |
| 126 Vector<std::unique_ptr<ExecutionContextTask>> m_queuedEarlyTasks; | |
| 127 | |
| 128 Persistent<WorkerInspectorProxy> m_workerInspectorProxy; | 67 Persistent<WorkerInspectorProxy> m_workerInspectorProxy; |
| 129 | 68 |
| 130 Persistent<WorkerClients> m_workerClients; | 69 bool m_workerThreadHadPendingActivity; |
| 131 | 70 bool m_askedToTerminate; |
| 132 Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; | 71 bool m_mayBeDestroyed; |
| 133 | |
| 134 RefPtr<WorkerLoaderProxy> m_loaderProxy; | |
| 135 }; | 72 }; |
| 136 | 73 |
| 137 } // namespace blink | 74 } // namespace blink |
| 138 | 75 |
| 139 #endif // InProcessWorkerMessagingProxy_h | 76 #endif // ThreadedWorkletMessagingProxy_h |
| OLD | NEW |