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_devtools_agent.h" |
20 #include "content/worker/worker_thread.h" | 20 #include "content/worker/worker_thread.h" |
21 #include "content/worker/worker_webapplicationcachehost_impl.h" | 21 #include "content/worker/worker_webapplicationcachehost_impl.h" |
22 #include "ipc/ipc_logging.h" | 22 #include "ipc/ipc_logging.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback
s.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback
s.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptVa
lue.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorker.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorker.h" |
30 | 31 |
31 using WebKit::WebApplicationCacheHost; | 32 using WebKit::WebApplicationCacheHost; |
32 using WebKit::WebFrame; | 33 using WebKit::WebFrame; |
33 using WebKit::WebMessagePortChannel; | 34 using WebKit::WebMessagePortChannel; |
34 using WebKit::WebMessagePortChannelArray; | 35 #ifdef WebTransferableReceipt_h |
| 36 using WebKit::WebMessagePortReceipt; |
| 37 #endif |
| 38 using WebKit::WebTransferableReceiptArray; |
| 39 using WebKit::WebSerializedScriptValue; |
35 using WebKit::WebSecurityOrigin; | 40 using WebKit::WebSecurityOrigin; |
36 using WebKit::WebString; | 41 using WebKit::WebString; |
37 using WebKit::WebWorker; | 42 using WebKit::WebWorker; |
38 using WebKit::WebWorkerClient; | 43 using WebKit::WebWorkerClient; |
39 | 44 |
40 // How long to wait for worker to finish after it's been told to terminate. | 45 // How long to wait for worker to finish after it's been told to terminate. |
41 #define kMaxTimeForRunawayWorkerMs 3000 | 46 #define kMaxTimeForRunawayWorkerMs 3000 |
42 | 47 |
43 WebWorkerClientProxy::WebWorkerClientProxy(int route_id, | 48 WebWorkerClientProxy::WebWorkerClientProxy(int route_id, |
44 WebWorkerStubBase* stub) | 49 WebWorkerStubBase* stub) |
45 : route_id_(route_id), | 50 : route_id_(route_id), |
46 appcache_host_id_(0), | 51 appcache_host_id_(0), |
47 stub_(stub), | 52 stub_(stub), |
48 ALLOW_THIS_IN_INITIALIZER_LIST(kill_process_factory_(this)), | 53 ALLOW_THIS_IN_INITIALIZER_LIST(kill_process_factory_(this)), |
49 devtools_agent_(NULL) { | 54 devtools_agent_(NULL) { |
50 } | 55 } |
51 | 56 |
52 WebWorkerClientProxy::~WebWorkerClientProxy() { | 57 WebWorkerClientProxy::~WebWorkerClientProxy() { |
53 } | 58 } |
54 | 59 |
55 void WebWorkerClientProxy::postMessageToWorkerObject( | 60 void WebWorkerClientProxy::postMessageToWorkerObject( |
56 const WebString& message, | 61 const WebString& raw_message, |
57 const WebMessagePortChannelArray& channels) { | 62 const WebTransferableReceiptArray& receipts) { |
58 std::vector<int> message_port_ids(channels.size()); | 63 size_t unflattenable_count; |
59 std::vector<int> routing_ids(channels.size()); | 64 #ifndef WebTransferableReceipt_h |
60 for (size_t i = 0; i < channels.size(); ++i) { | 65 WebString message = raw_message; |
61 WebMessagePortChannelImpl* webchannel = | 66 unflattenable_count = receipts.size(); |
62 static_cast<WebMessagePortChannelImpl*>(channels[i]); | 67 #else |
63 message_port_ids[i] = webchannel->message_port_id(); | 68 WebString message = WebSerializedScriptValue::flattenReceiptList( |
64 webchannel->QueueMessages(); | 69 raw_message, receipts, &unflattenable_count); |
65 DCHECK(message_port_ids[i] != MSG_ROUTING_NONE); | 70 #endif |
66 routing_ids[i] = MSG_ROUTING_NONE; | 71 std::vector<int> message_port_ids(unflattenable_count); |
| 72 std::vector<int> routing_ids(unflattenable_count); |
| 73 size_t next_unflattenable = 0; |
| 74 for (size_t i = 0; i < receipts.size(); ++i) { |
| 75 #ifndef WebTransferableReceipt_h |
| 76 { |
| 77 #else |
| 78 if (!WebSerializedScriptValue::isFlattenable(receipts[i])) { |
| 79 DCHECK(toWebMessagePortReceipt(receipts[i])); |
| 80 #endif |
| 81 DCHECK(next_unflattenable < unflattenable_count); |
| 82 WebMessagePortChannelImpl* webchannel = |
| 83 #ifndef WebTransferableReceipt_h |
| 84 static_cast<WebMessagePortChannelImpl*>(receipts[i]); |
| 85 #else |
| 86 static_cast<WebMessagePortChannelImpl*>( |
| 87 static_cast<WebMessagePortReceipt*>(receipts[i])->channel()); |
| 88 #endif |
| 89 message_port_ids[next_unflattenable] = webchannel->message_port_id(); |
| 90 webchannel->QueueMessages(); |
| 91 CHECK(message_port_ids[next_unflattenable] != MSG_ROUTING_NONE); |
| 92 routing_ids[next_unflattenable] = MSG_ROUTING_NONE; |
| 93 ++next_unflattenable; |
| 94 } |
67 } | 95 } |
| 96 DCHECK(next_unflattenable == unflattenable_count); |
68 | 97 |
69 Send(new WorkerMsg_PostMessage( | 98 Send(new WorkerMsg_PostMessage( |
70 route_id_, message, message_port_ids, routing_ids)); | 99 route_id_, message, message_port_ids, routing_ids)); |
71 } | 100 } |
72 | 101 |
73 void WebWorkerClientProxy::postExceptionToWorkerObject( | 102 void WebWorkerClientProxy::postExceptionToWorkerObject( |
74 const WebString& error_message, | 103 const WebString& error_message, |
75 int line_number, | 104 int line_number, |
76 const WebString& source_url) { | 105 const WebString& source_url) { |
77 Send(new WorkerHostMsg_PostExceptionToWorkerObject( | 106 Send(new WorkerHostMsg_PostExceptionToWorkerObject( |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 229 |
201 // This shuts down the process cleanly from the perspective of the browser | 230 // This shuts down the process cleanly from the perspective of the browser |
202 // process, and avoids the crashed worker infobar from appearing to the new | 231 // process, and avoids the crashed worker infobar from appearing to the new |
203 // page. It's ok to post several of theese, because the first executed task | 232 // page. It's ok to post several of theese, because the first executed task |
204 // will exit the message loop and subsequent ones won't be executed. | 233 // will exit the message loop and subsequent ones won't be executed. |
205 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 234 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
206 kill_process_factory_.NewRunnableMethod( | 235 kill_process_factory_.NewRunnableMethod( |
207 &WebWorkerClientProxy::workerContextDestroyed), | 236 &WebWorkerClientProxy::workerContextDestroyed), |
208 kMaxTimeForRunawayWorkerMs); | 237 kMaxTimeForRunawayWorkerMs); |
209 } | 238 } |
OLD | NEW |