OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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/renderer/webworker_base.h" | 5 #include "content/renderer/webworker_base.h" |
6 | 6 |
7 #include "content/common/child_thread.h" | 7 #include "content/common/child_thread.h" |
8 #include "content/common/view_messages.h" | 8 #include "content/common/view_messages.h" |
9 #include "content/common/webmessageportchannel_impl.h" | 9 #include "content/common/webmessageportchannel_impl.h" |
10 #include "content/common/worker_messages.h" | 10 #include "content/common/worker_messages.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerClient.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerClient.h" |
13 | 13 |
14 using WebKit::WebMessagePortChannel; | 14 using WebKit::WebMessagePortChannel; |
15 using WebKit::WebMessagePortChannelArray; | 15 using WebKit::WebMessagePortChannelArray; |
16 using WebKit::WebString; | 16 using WebKit::WebString; |
17 using WebKit::WebURL; | 17 using WebKit::WebURL; |
18 using WebKit::WebWorkerClient; | 18 using WebKit::WebWorkerClient; |
19 | 19 |
20 WebWorkerBase::WebWorkerBase( | 20 WebWorkerBase::WebWorkerBase( |
21 ChildThread* child_thread, | 21 ChildThread* child_thread, |
22 unsigned long long document_id, | 22 unsigned long long document_id, |
23 int route_id, | 23 int route_id, |
24 int render_view_route_id, | 24 int render_view_route_id, |
25 int parent_appcache_host_id) | 25 int parent_appcache_host_id, |
| 26 DevToolsDelegate* devtools_delegate) |
26 : route_id_(route_id), | 27 : route_id_(route_id), |
27 render_view_route_id_(render_view_route_id), | 28 render_view_route_id_(render_view_route_id), |
28 child_thread_(child_thread), | 29 child_thread_(child_thread), |
| 30 devtools_delegate_(devtools_delegate), |
29 document_id_(document_id), | 31 document_id_(document_id), |
30 parent_appcache_host_id_(parent_appcache_host_id) { | 32 parent_appcache_host_id_(parent_appcache_host_id) { |
31 if (route_id_ != MSG_ROUTING_NONE) | 33 if (route_id_ != MSG_ROUTING_NONE) |
32 child_thread_->AddRoute(route_id_, this); | 34 child_thread_->AddRoute(route_id_, this); |
33 } | 35 } |
34 | 36 |
35 WebWorkerBase::~WebWorkerBase() { | 37 WebWorkerBase::~WebWorkerBase() { |
36 Disconnect(); | 38 Disconnect(); |
37 | 39 |
38 // Free up any unsent queued messages. | 40 // Free up any unsent queued messages. |
39 for (size_t i = 0; i < queued_messages_.size(); ++i) | 41 for (size_t i = 0; i < queued_messages_.size(); ++i) |
40 delete queued_messages_[i]; | 42 delete queued_messages_[i]; |
41 } | 43 } |
42 | 44 |
43 void WebWorkerBase::Disconnect() { | 45 void WebWorkerBase::Disconnect() { |
44 if (route_id_ == MSG_ROUTING_NONE) | 46 if (route_id_ == MSG_ROUTING_NONE) |
45 return; | 47 return; |
46 | 48 |
47 // So the messages from WorkerContext (like WorkerContextDestroyed) do not | 49 // So the messages from WorkerContext (like WorkerContextDestroyed) do not |
48 // come after nobody is listening. Since Worker and WorkerContext can | 50 // come after nobody is listening. Since Worker and WorkerContext can |
49 // terminate independently, already sent messages may still be in the pipe. | 51 // terminate independently, already sent messages may still be in the pipe. |
50 child_thread_->RemoveRoute(route_id_); | 52 child_thread_->RemoveRoute(route_id_); |
51 | 53 |
52 route_id_ = MSG_ROUTING_NONE; | 54 route_id_ = MSG_ROUTING_NONE; |
| 55 |
| 56 if (devtools_delegate_.get()) |
| 57 devtools_delegate_->SetRouteId(MSG_ROUTING_NONE); |
53 } | 58 } |
54 | 59 |
55 void WebWorkerBase::CreateWorkerContext(const GURL& script_url, | 60 void WebWorkerBase::CreateWorkerContext(const GURL& script_url, |
56 bool is_shared, | 61 bool is_shared, |
57 const string16& name, | 62 const string16& name, |
58 const string16& user_agent, | 63 const string16& user_agent, |
59 const string16& source_code, | 64 const string16& source_code, |
60 int pending_route_id, | 65 int pending_route_id, |
61 int64 script_resource_appcache_id) { | 66 int64 script_resource_appcache_id) { |
62 DCHECK(route_id_ == MSG_ROUTING_NONE); | 67 DCHECK(route_id_ == MSG_ROUTING_NONE); |
63 ViewHostMsg_CreateWorker_Params params; | 68 ViewHostMsg_CreateWorker_Params params; |
64 params.url = script_url; | 69 params.url = script_url; |
65 params.is_shared = is_shared; | 70 params.is_shared = is_shared; |
66 params.name = name; | 71 params.name = name; |
67 params.document_id = document_id_; | 72 params.document_id = document_id_; |
68 params.render_view_route_id = render_view_route_id_; | 73 params.render_view_route_id = render_view_route_id_; |
69 params.route_id = pending_route_id; | 74 params.route_id = pending_route_id; |
70 params.parent_appcache_host_id = parent_appcache_host_id_; | 75 params.parent_appcache_host_id = parent_appcache_host_id_; |
71 params.script_resource_appcache_id = script_resource_appcache_id; | 76 params.script_resource_appcache_id = script_resource_appcache_id; |
72 IPC::Message* create_message = new ViewHostMsg_CreateWorker( | 77 IPC::Message* create_message = new ViewHostMsg_CreateWorker( |
73 params, &route_id_); | 78 params, &route_id_); |
74 child_thread_->Send(create_message); | 79 child_thread_->Send(create_message); |
75 if (route_id_ == MSG_ROUTING_NONE) | 80 if (route_id_ == MSG_ROUTING_NONE) |
76 return; | 81 return; |
77 | 82 |
78 child_thread_->AddRoute(route_id_, this); | 83 child_thread_->AddRoute(route_id_, this); |
79 | 84 |
| 85 if (devtools_delegate_.get()) |
| 86 devtools_delegate_->SetRouteId(route_id_); |
| 87 |
80 // We make sure that the start message is the first, since postMessage or | 88 // We make sure that the start message is the first, since postMessage or |
81 // connect might have already been called. | 89 // connect might have already been called. |
82 queued_messages_.insert(queued_messages_.begin(), | 90 queued_messages_.insert(queued_messages_.begin(), |
83 new WorkerMsg_StartWorkerContext( | 91 new WorkerMsg_StartWorkerContext( |
84 route_id_, script_url, user_agent, source_code)); | 92 route_id_, script_url, user_agent, source_code)); |
85 } | 93 } |
86 | 94 |
87 bool WebWorkerBase::IsStarted() { | 95 bool WebWorkerBase::IsStarted() { |
88 // Worker is started if we have a route ID and there are no queued messages | 96 // Worker is started if we have a route ID and there are no queued messages |
89 // (meaning we've sent the WorkerMsg_StartWorkerContext already). | 97 // (meaning we've sent the WorkerMsg_StartWorkerContext already). |
(...skipping 20 matching lines...) Expand all Loading... |
110 | 118 |
111 void WebWorkerBase::SendQueuedMessages() { | 119 void WebWorkerBase::SendQueuedMessages() { |
112 DCHECK(queued_messages_.size()); | 120 DCHECK(queued_messages_.size()); |
113 std::vector<IPC::Message*> queued_messages = queued_messages_; | 121 std::vector<IPC::Message*> queued_messages = queued_messages_; |
114 queued_messages_.clear(); | 122 queued_messages_.clear(); |
115 for (size_t i = 0; i < queued_messages.size(); ++i) { | 123 for (size_t i = 0; i < queued_messages.size(); ++i) { |
116 queued_messages[i]->set_routing_id(route_id_); | 124 queued_messages[i]->set_routing_id(route_id_); |
117 Send(queued_messages[i]); | 125 Send(queued_messages[i]); |
118 } | 126 } |
119 } | 127 } |
OLD | NEW |