OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #ifndef WebWorkerClientImpl_h |
| 32 #define WebWorkerClientImpl_h |
| 33 |
| 34 #if ENABLE(WORKERS) |
| 35 |
| 36 // FIXME: fix to just "WebWorkerClient.h" once nobody in glue depends on us. |
| 37 #include "../public/WebWorkerClient.h" |
| 38 |
| 39 #include "WorkerContextProxy.h" |
| 40 #include <wtf/PassOwnPtr.h> |
| 41 #include <wtf/RefPtr.h> |
| 42 |
| 43 namespace WebCore { |
| 44 class ScriptExecutionContext; |
| 45 } |
| 46 |
| 47 namespace WebKit { |
| 48 class WebWorker; |
| 49 |
| 50 // The purpose of this class is to provide a WorkerContextProxy |
| 51 // implementation that we can give to WebKit. Internally, it converts the |
| 52 // data types to Chrome compatible ones so that renderer code can use it over |
| 53 // IPC. |
| 54 class WebWorkerClientImpl : public WebCore::WorkerContextProxy |
| 55 , public WebWorkerClient { |
| 56 public: |
| 57 WebWorkerClientImpl(WebCore::Worker*); |
| 58 |
| 59 // WebCore::WorkerContextProxy Factory. |
| 60 static WebCore::WorkerContextProxy* createWorkerContextProxy(WebCore::Worker*); |
| 61 void setWebWorker(WebWorker*); |
| 62 |
| 63 // WebCore::WorkerContextProxy methods: |
| 64 // These are called on the thread that created the worker. In the renderer |
| 65 // process, this will be the main WebKit thread. In the worker process, this |
| 66 // will be the thread of the executing worker (not the main WebKit thread). |
| 67 virtual void startWorkerContext(const WebCore::KURL&, |
| 68 const WebCore::String&, |
| 69 const WebCore::String&); |
| 70 virtual void terminateWorkerContext(); |
| 71 virtual void postMessageToWorkerContext( |
| 72 PassRefPtr<WebCore::SerializedScriptValue> message, |
| 73 PassOwnPtr<WebCore::MessagePortChannelArray> channels); |
| 74 virtual bool hasPendingActivity() const; |
| 75 virtual void workerObjectDestroyed(); |
| 76 |
| 77 // WebWorkerClient methods: |
| 78 // These are called on the main WebKit thread. |
| 79 virtual void postMessageToWorkerObject(const WebString&, const WebMessagePortChannelArray&); |
| 80 virtual void postExceptionToWorkerObject(const WebString&, int, const WebString&); |
| 81 virtual void postConsoleMessageToWorkerObject(int, int, int, int, const WebString&, |
| 82 int, const WebString&); |
| 83 virtual void confirmMessageFromWorkerObject(bool); |
| 84 virtual void reportPendingActivity(bool); |
| 85 virtual void workerContextDestroyed(); |
| 86 virtual WebWorker* createWorker(WebWorkerClient*) { return 0; } |
| 87 virtual WebNotificationPresenter* notificationPresenter() |
| 88 { |
| 89 // FIXME: Notifications not yet supported in workers. |
| 90 return 0; |
| 91 } |
| 92 |
| 93 private: |
| 94 virtual ~WebWorkerClientImpl(); |
| 95 |
| 96 // Methods used to support WebWorkerClientImpl being constructed on worker |
| 97 // threads. |
| 98 // These tasks are dispatched on the WebKit thread. |
| 99 static void startWorkerContextTask(WebCore::ScriptExecutionContext* context, |
| 100 WebWorkerClientImpl* thisPtr, |
| 101 const WebCore::String& scriptURL, |
| 102 const WebCore::String& userAgent, |
| 103 const WebCore::String& sourceCode); |
| 104 static void terminateWorkerContextTask(WebCore::ScriptExecutionContext* context, |
| 105 WebWorkerClientImpl* thisPtr); |
| 106 static void postMessageToWorkerContextTask(WebCore::ScriptExecutionContext* context, |
| 107 WebWorkerClientImpl* thisPtr, |
| 108 const WebCore::String& message, |
| 109 PassOwnPtr<WebCore::MessagePortChannelArray> channels); |
| 110 static void workerObjectDestroyedTask(WebCore::ScriptExecutionContext* context, |
| 111 WebWorkerClientImpl* thisPtr); |
| 112 |
| 113 // These tasks are dispatched on the thread that created the worker (i.e. |
| 114 // main WebKit thread in renderer process, and the worker thread in the |
| 115 // worker process). |
| 116 static void postMessageToWorkerObjectTask(WebCore::ScriptExecutionContext* context, |
| 117 WebWorkerClientImpl* thisPtr, |
| 118 const WebCore::String& message, |
| 119 PassOwnPtr<WebCore::MessagePortChannelArray> channels); |
| 120 static void postExceptionToWorkerObjectTask(WebCore::ScriptExecutionContext* context, |
| 121 WebWorkerClientImpl* thisPtr, |
| 122 const WebCore::String& message, |
| 123 int lineNumber, |
| 124 const WebCore::String& sourceURL); |
| 125 static void postConsoleMessageToWorkerObjectTask(WebCore::ScriptExecutionContext* context, |
| 126 WebWorkerClientImpl* thisPtr, |
| 127 int destinationId, |
| 128 int sourceId, |
| 129 int messageType, |
| 130 int messageLevel, |
| 131 const WebCore::String& message, |
| 132 int lineNumber, |
| 133 const WebCore::String& sourceURL); |
| 134 static void confirmMessageFromWorkerObjectTask(WebCore::ScriptExecutionContext* context, |
| 135 WebWorkerClientImpl* thisPtr); |
| 136 static void reportPendingActivityTask(WebCore::ScriptExecutionContext* context, |
| 137 WebWorkerClientImpl* thisPtr, |
| 138 bool hasPendingActivity); |
| 139 |
| 140 // Guard against context from being destroyed before a worker exits. |
| 141 RefPtr<WebCore::ScriptExecutionContext> m_scriptExecutionContext; |
| 142 |
| 143 WebCore::Worker* m_worker; |
| 144 WebWorker* m_webWorker; |
| 145 bool m_askedToTerminate; |
| 146 uint32 m_unconfirmedMessageCount; |
| 147 bool m_workerContextHadPendingActivity; |
| 148 ThreadIdentifier m_workerThreadId; |
| 149 }; |
| 150 |
| 151 } // namespace WebKit; |
| 152 |
| 153 #endif // ENABLE(WORKERS) |
| 154 |
| 155 #endif |
OLD | NEW |