| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "content/worker/webworkerclient_proxy.h" | 5 #include "content/worker/webworkerclient_proxy.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "content/common/content_switches.h" | 9 #include "content/common/content_switches.h" |
| 10 #include "content/common/file_system/file_system_dispatcher.h" | 10 #include "content/common/file_system/file_system_dispatcher.h" |
| 11 #include "content/common/file_system/webfilesystem_callback_dispatcher.h" | 11 #include "content/common/file_system/webfilesystem_callback_dispatcher.h" |
| 12 #include "content/common/webmessageportchannel_impl.h" | 12 #include "content/common/webmessageportchannel_impl.h" |
| 13 #include "content/common/worker_messages.h" | 13 #include "content/common/worker_messages.h" |
| 14 // TODO(jam): uncomment this and WebWorkerClientProxy::createWorker when the | 14 // TODO(jam): uncomment this and WebWorkerClientProxy::createWorker when the |
| 15 // renderer worker code moves to content. This code isn't used now since we | 15 // renderer worker code moves to content. This code isn't used now since we |
| 16 // don't support nested workers anyways. | 16 // don't support nested workers anyways. |
| 17 //#include "content/renderer/webworker_proxy.h" | 17 //#include "content/renderer/webworker_proxy.h" |
| 18 #include "content/worker/webworker_stub_base.h" | 18 #include "content/worker/webworker_stub_base.h" |
| 19 #include "content/worker/worker_devtools_agent.h" |
| 19 #include "content/worker/worker_thread.h" | 20 #include "content/worker/worker_thread.h" |
| 20 #include "content/worker/worker_webapplicationcachehost_impl.h" | 21 #include "content/worker/worker_webapplicationcachehost_impl.h" |
| 21 #include "ipc/ipc_logging.h" | 22 #include "ipc/ipc_logging.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback
s.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback
s.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorker.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorker.h" |
| 28 | 29 |
| 29 using WebKit::WebApplicationCacheHost; | 30 using WebKit::WebApplicationCacheHost; |
| 30 using WebKit::WebFrame; | 31 using WebKit::WebFrame; |
| 31 using WebKit::WebMessagePortChannel; | 32 using WebKit::WebMessagePortChannel; |
| 32 using WebKit::WebMessagePortChannelArray; | 33 using WebKit::WebMessagePortChannelArray; |
| 33 using WebKit::WebSecurityOrigin; | 34 using WebKit::WebSecurityOrigin; |
| 34 using WebKit::WebString; | 35 using WebKit::WebString; |
| 35 using WebKit::WebWorker; | 36 using WebKit::WebWorker; |
| 36 using WebKit::WebWorkerClient; | 37 using WebKit::WebWorkerClient; |
| 37 | 38 |
| 38 // How long to wait for worker to finish after it's been told to terminate. | 39 // How long to wait for worker to finish after it's been told to terminate. |
| 39 #define kMaxTimeForRunawayWorkerMs 3000 | 40 #define kMaxTimeForRunawayWorkerMs 3000 |
| 40 | 41 |
| 41 WebWorkerClientProxy::WebWorkerClientProxy(int route_id, | 42 WebWorkerClientProxy::WebWorkerClientProxy(int route_id, |
| 42 WebWorkerStubBase* stub) | 43 WebWorkerStubBase* stub) |
| 43 : route_id_(route_id), | 44 : route_id_(route_id), |
| 44 appcache_host_id_(0), | 45 appcache_host_id_(0), |
| 45 stub_(stub), | 46 stub_(stub), |
| 46 ALLOW_THIS_IN_INITIALIZER_LIST(kill_process_factory_(this)) { | 47 ALLOW_THIS_IN_INITIALIZER_LIST(kill_process_factory_(this)), |
| 48 devtools_agent_(NULL) { |
| 47 } | 49 } |
| 48 | 50 |
| 49 WebWorkerClientProxy::~WebWorkerClientProxy() { | 51 WebWorkerClientProxy::~WebWorkerClientProxy() { |
| 50 } | 52 } |
| 51 | 53 |
| 52 void WebWorkerClientProxy::postMessageToWorkerObject( | 54 void WebWorkerClientProxy::postMessageToWorkerObject( |
| 53 const WebString& message, | 55 const WebString& message, |
| 54 const WebMessagePortChannelArray& channels) { | 56 const WebMessagePortChannelArray& channels) { |
| 55 std::vector<int> message_port_ids(channels.size()); | 57 std::vector<int> message_port_ids(channels.size()); |
| 56 std::vector<int> routing_ids(channels.size()); | 58 std::vector<int> routing_ids(channels.size()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 void WebWorkerClientProxy::openFileSystem( | 168 void WebWorkerClientProxy::openFileSystem( |
| 167 WebKit::WebFileSystem::Type type, | 169 WebKit::WebFileSystem::Type type, |
| 168 long long size, | 170 long long size, |
| 169 bool create, | 171 bool create, |
| 170 WebKit::WebFileSystemCallbacks* callbacks) { | 172 WebKit::WebFileSystemCallbacks* callbacks) { |
| 171 ChildThread::current()->file_system_dispatcher()->OpenFileSystem( | 173 ChildThread::current()->file_system_dispatcher()->OpenFileSystem( |
| 172 stub_->url().GetOrigin(), static_cast<fileapi::FileSystemType>(type), | 174 stub_->url().GetOrigin(), static_cast<fileapi::FileSystemType>(type), |
| 173 size, create, new WebFileSystemCallbackDispatcher(callbacks)); | 175 size, create, new WebFileSystemCallbackDispatcher(callbacks)); |
| 174 } | 176 } |
| 175 | 177 |
| 178 void WebWorkerClientProxy::dispatchDevToolsMessage(const WebString& message) { |
| 179 if (devtools_agent_) |
| 180 devtools_agent_->SendDevToolsMessage(message); |
| 181 } |
| 182 |
| 176 bool WebWorkerClientProxy::Send(IPC::Message* message) { | 183 bool WebWorkerClientProxy::Send(IPC::Message* message) { |
| 177 return WorkerThread::current()->Send(message); | 184 return WorkerThread::current()->Send(message); |
| 178 } | 185 } |
| 179 | 186 |
| 180 void WebWorkerClientProxy::EnsureWorkerContextTerminates() { | 187 void WebWorkerClientProxy::EnsureWorkerContextTerminates() { |
| 181 // Avoid a worker doing a while(1) from never exiting. | 188 // Avoid a worker doing a while(1) from never exiting. |
| 182 if (CommandLine::ForCurrentProcess()->HasSwitch( | 189 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 183 switches::kWebWorkerShareProcesses)) { | 190 switches::kWebWorkerShareProcesses)) { |
| 184 // Can't kill the process since there could be workers from other | 191 // Can't kill the process since there could be workers from other |
| 185 // renderer process. | 192 // renderer process. |
| 186 NOTIMPLEMENTED(); | 193 NOTIMPLEMENTED(); |
| 187 return; | 194 return; |
| 188 } | 195 } |
| 189 | 196 |
| 190 // This shuts down the process cleanly from the perspective of the browser | 197 // This shuts down the process cleanly from the perspective of the browser |
| 191 // process, and avoids the crashed worker infobar from appearing to the new | 198 // process, and avoids the crashed worker infobar from appearing to the new |
| 192 // page. It's ok to post several of theese, because the first executed task | 199 // page. It's ok to post several of theese, because the first executed task |
| 193 // will exit the message loop and subsequent ones won't be executed. | 200 // will exit the message loop and subsequent ones won't be executed. |
| 194 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 201 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 195 kill_process_factory_.NewRunnableMethod( | 202 kill_process_factory_.NewRunnableMethod( |
| 196 &WebWorkerClientProxy::workerContextDestroyed), | 203 &WebWorkerClientProxy::workerContextDestroyed), |
| 197 kMaxTimeForRunawayWorkerMs); | 204 kMaxTimeForRunawayWorkerMs); |
| 198 } | 205 } |
| OLD | NEW |