| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 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 WEBKIT_GLUE_WEBWORKERCLIENT_IMPL_H_ | |
| 6 #define WEBKIT_GLUE_WEBWORKERCLIENT_IMPL_H_ | |
| 7 | |
| 8 #if ENABLE(WORKERS) | |
| 9 | |
| 10 #include "webkit/api/public/WebWorkerClient.h" | |
| 11 | |
| 12 #include "WorkerContextProxy.h" | |
| 13 #include <wtf/PassOwnPtr.h> | |
| 14 #include <wtf/RefPtr.h> | |
| 15 | |
| 16 namespace WebCore { | |
| 17 class ScriptExecutionContext; | |
| 18 } | |
| 19 namespace WebKit { | |
| 20 class WebWorker; | |
| 21 } | |
| 22 | |
| 23 // The purpose of this class is to provide a WorkerContextProxy | |
| 24 // implementation that we can give to WebKit. Internally, it converts the | |
| 25 // data types to Chrome compatible ones so that renderer code can use it over | |
| 26 // IPC. | |
| 27 class WebWorkerClientImpl : public WebCore::WorkerContextProxy, | |
| 28 public WebKit::WebWorkerClient { | |
| 29 public: | |
| 30 WebWorkerClientImpl(WebCore::Worker* worker); | |
| 31 | |
| 32 // WebCore::WorkerContextProxy Factory. | |
| 33 static WebCore::WorkerContextProxy* createWorkerContextProxy( | |
| 34 WebCore::Worker* worker); | |
| 35 | |
| 36 void set_webworker(WebKit::WebWorker* webworker); | |
| 37 | |
| 38 // WebCore::WorkerContextProxy methods: | |
| 39 // These are called on the thread that created the worker. In the renderer | |
| 40 // process, this will be the main WebKit thread. In the worker process, this | |
| 41 // will be the thread of the executing worker (not the main WebKit thread). | |
| 42 virtual void startWorkerContext(const WebCore::KURL& script_url, | |
| 43 const WebCore::String& user_agent, | |
| 44 const WebCore::String& source_code); | |
| 45 virtual void terminateWorkerContext(); | |
| 46 virtual void postMessageToWorkerContext( | |
| 47 WTF::PassRefPtr<WebCore::SerializedScriptValue> message, | |
| 48 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels); | |
| 49 virtual bool hasPendingActivity() const; | |
| 50 virtual void workerObjectDestroyed(); | |
| 51 | |
| 52 // WebWorkerClient methods: | |
| 53 // These are called on the main WebKit thread. | |
| 54 virtual void postMessageToWorkerObject( | |
| 55 const WebKit::WebString& message, | |
| 56 const WebKit::WebMessagePortChannelArray& channels); | |
| 57 virtual void postExceptionToWorkerObject( | |
| 58 const WebKit::WebString& error_message, | |
| 59 int line_number, | |
| 60 const WebKit::WebString& source_url); | |
| 61 virtual void postConsoleMessageToWorkerObject( | |
| 62 int destination_id, | |
| 63 int source_id, | |
| 64 int message_type, | |
| 65 int message_level, | |
| 66 const WebKit::WebString& message, | |
| 67 int line_number, | |
| 68 const WebKit::WebString& source_url); | |
| 69 virtual void confirmMessageFromWorkerObject(bool has_pending_activity); | |
| 70 virtual void reportPendingActivity(bool has_pending_activity); | |
| 71 virtual void workerContextDestroyed(); | |
| 72 virtual WebKit::WebWorker* createWorker(WebKit::WebWorkerClient* client) { | |
| 73 return NULL; | |
| 74 } | |
| 75 virtual WebKit::WebNotificationPresenter* notificationPresenter() { | |
| 76 // TODO(johnnyg): Notifications not yet supported in workers. | |
| 77 // Coming soon. | |
| 78 return NULL; | |
| 79 } | |
| 80 | |
| 81 private: | |
| 82 virtual ~WebWorkerClientImpl(); | |
| 83 | |
| 84 // Methods used to support WebWorkerClientImpl being constructed on worker | |
| 85 // threads. | |
| 86 // These tasks are dispatched on the WebKit thread. | |
| 87 static void StartWorkerContextTask( | |
| 88 WebCore::ScriptExecutionContext* context, | |
| 89 WebWorkerClientImpl* this_ptr, | |
| 90 const WebCore::String& script_url, | |
| 91 const WebCore::String& user_agent, | |
| 92 const WebCore::String& source_code); | |
| 93 static void TerminateWorkerContextTask( | |
| 94 WebCore::ScriptExecutionContext* context, | |
| 95 WebWorkerClientImpl* this_ptr); | |
| 96 static void PostMessageToWorkerContextTask( | |
| 97 WebCore::ScriptExecutionContext* context, | |
| 98 WebWorkerClientImpl* this_ptr, | |
| 99 const WebCore::String& message, | |
| 100 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels); | |
| 101 static void WorkerObjectDestroyedTask( | |
| 102 WebCore::ScriptExecutionContext* context, | |
| 103 WebWorkerClientImpl* this_ptr); | |
| 104 | |
| 105 // These tasks are dispatched on the thread that created the worker (i.e. | |
| 106 // main WebKit thread in renderer process, and the worker thread in the worker | |
| 107 // process). | |
| 108 static void PostMessageToWorkerObjectTask( | |
| 109 WebCore::ScriptExecutionContext* context, | |
| 110 WebWorkerClientImpl* this_ptr, | |
| 111 const WebCore::String& message, | |
| 112 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels); | |
| 113 static void PostExceptionToWorkerObjectTask( | |
| 114 WebCore::ScriptExecutionContext* context, | |
| 115 WebWorkerClientImpl* this_ptr, | |
| 116 const WebCore::String& error_message, | |
| 117 int line_number, | |
| 118 const WebCore::String& source_url); | |
| 119 static void PostConsoleMessageToWorkerObjectTask( | |
| 120 WebCore::ScriptExecutionContext* context, | |
| 121 WebWorkerClientImpl* this_ptr, | |
| 122 int destination_id, | |
| 123 int source_id, | |
| 124 int message_type, | |
| 125 int message_level, | |
| 126 const WebCore::String& message, | |
| 127 int line_number, | |
| 128 const WebCore::String& source_url); | |
| 129 static void ConfirmMessageFromWorkerObjectTask( | |
| 130 WebCore::ScriptExecutionContext* context, | |
| 131 WebWorkerClientImpl* this_ptr); | |
| 132 static void ReportPendingActivityTask( | |
| 133 WebCore::ScriptExecutionContext* context, | |
| 134 WebWorkerClientImpl* this_ptr, | |
| 135 bool has_pending_activity); | |
| 136 | |
| 137 // Guard against context from being destroyed before a worker exits. | |
| 138 WTF::RefPtr<WebCore::ScriptExecutionContext> script_execution_context_; | |
| 139 | |
| 140 WebCore::Worker* worker_; | |
| 141 WebKit::WebWorker* webworker_; | |
| 142 bool asked_to_terminate_; | |
| 143 uint32 unconfirmed_message_count_; | |
| 144 bool worker_context_had_pending_activity_; | |
| 145 WTF::ThreadIdentifier worker_thread_id_; | |
| 146 }; | |
| 147 | |
| 148 #endif | |
| 149 | |
| 150 #endif // WEBKIT_GLUE_WEBWORKERCLIENT_IMPL_H_ | |
| OLD | NEW |