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 : route_id_(route_id), | 26 : route_id_(route_id), |
27 render_view_route_id_(render_view_route_id), | 27 render_view_route_id_(render_view_route_id), |
28 child_thread_(child_thread), | 28 child_thread_(child_thread), |
29 devtools_delegate_(0), | |
29 document_id_(document_id), | 30 document_id_(document_id), |
30 parent_appcache_host_id_(parent_appcache_host_id) { | 31 parent_appcache_host_id_(parent_appcache_host_id) { |
31 if (route_id_ != MSG_ROUTING_NONE) | 32 if (route_id_ != MSG_ROUTING_NONE) |
32 child_thread_->AddRoute(route_id_, this); | 33 child_thread_->AddRoute(route_id_, this); |
33 } | 34 } |
34 | 35 |
35 WebWorkerBase::~WebWorkerBase() { | 36 WebWorkerBase::~WebWorkerBase() { |
37 if (devtools_delegate_) | |
38 devtools_delegate_->WorkerProxyDestroyed(); | |
36 Disconnect(); | 39 Disconnect(); |
37 | 40 |
38 // Free up any unsent queued messages. | 41 // Free up any unsent queued messages. |
39 for (size_t i = 0; i < queued_messages_.size(); ++i) | 42 for (size_t i = 0; i < queued_messages_.size(); ++i) |
40 delete queued_messages_[i]; | 43 delete queued_messages_[i]; |
41 } | 44 } |
42 | 45 |
43 void WebWorkerBase::Disconnect() { | 46 void WebWorkerBase::Disconnect() { |
44 if (route_id_ == MSG_ROUTING_NONE) | 47 if (route_id_ == MSG_ROUTING_NONE) |
45 return; | 48 return; |
46 | 49 |
47 // So the messages from WorkerContext (like WorkerContextDestroyed) do not | 50 // So the messages from WorkerContext (like WorkerContextDestroyed) do not |
48 // come after nobody is listening. Since Worker and WorkerContext can | 51 // come after nobody is listening. Since Worker and WorkerContext can |
49 // terminate independently, already sent messages may still be in the pipe. | 52 // terminate independently, already sent messages may still be in the pipe. |
50 child_thread_->RemoveRoute(route_id_); | 53 child_thread_->RemoveRoute(route_id_); |
51 | 54 |
52 route_id_ = MSG_ROUTING_NONE; | 55 route_id_ = MSG_ROUTING_NONE; |
56 | |
57 if (devtools_delegate_) | |
58 devtools_delegate_->SetRouteId(route_id_); | |
Dmitry Titov
2011/05/25 01:38:44
If MSG_ROUTING_NONE was used directly here, it'd b
| |
53 } | 59 } |
54 | 60 |
55 void WebWorkerBase::CreateWorkerContext(const GURL& script_url, | 61 void WebWorkerBase::CreateWorkerContext(const GURL& script_url, |
56 bool is_shared, | 62 bool is_shared, |
57 const string16& name, | 63 const string16& name, |
58 const string16& user_agent, | 64 const string16& user_agent, |
59 const string16& source_code, | 65 const string16& source_code, |
60 int pending_route_id, | 66 int pending_route_id, |
61 int64 script_resource_appcache_id) { | 67 int64 script_resource_appcache_id) { |
62 DCHECK(route_id_ == MSG_ROUTING_NONE); | 68 DCHECK(route_id_ == MSG_ROUTING_NONE); |
63 ViewHostMsg_CreateWorker_Params params; | 69 ViewHostMsg_CreateWorker_Params params; |
64 params.url = script_url; | 70 params.url = script_url; |
65 params.is_shared = is_shared; | 71 params.is_shared = is_shared; |
66 params.name = name; | 72 params.name = name; |
67 params.document_id = document_id_; | 73 params.document_id = document_id_; |
68 params.render_view_route_id = render_view_route_id_; | 74 params.render_view_route_id = render_view_route_id_; |
69 params.route_id = pending_route_id; | 75 params.route_id = pending_route_id; |
70 params.parent_appcache_host_id = parent_appcache_host_id_; | 76 params.parent_appcache_host_id = parent_appcache_host_id_; |
71 params.script_resource_appcache_id = script_resource_appcache_id; | 77 params.script_resource_appcache_id = script_resource_appcache_id; |
72 IPC::Message* create_message = new ViewHostMsg_CreateWorker( | 78 IPC::Message* create_message = new ViewHostMsg_CreateWorker( |
73 params, &route_id_); | 79 params, &route_id_); |
74 child_thread_->Send(create_message); | 80 child_thread_->Send(create_message); |
75 if (route_id_ == MSG_ROUTING_NONE) | 81 if (route_id_ == MSG_ROUTING_NONE) |
76 return; | 82 return; |
77 | 83 |
78 child_thread_->AddRoute(route_id_, this); | 84 child_thread_->AddRoute(route_id_, this); |
79 | 85 |
86 if (devtools_delegate_) | |
87 devtools_delegate_->SetRouteId(route_id_); | |
88 | |
80 // We make sure that the start message is the first, since postMessage or | 89 // We make sure that the start message is the first, since postMessage or |
81 // connect might have already been called. | 90 // connect might have already been called. |
82 queued_messages_.insert(queued_messages_.begin(), | 91 queued_messages_.insert(queued_messages_.begin(), |
83 new WorkerMsg_StartWorkerContext( | 92 new WorkerMsg_StartWorkerContext( |
84 route_id_, script_url, user_agent, source_code)); | 93 route_id_, script_url, user_agent, source_code)); |
85 } | 94 } |
86 | 95 |
87 bool WebWorkerBase::IsStarted() { | 96 bool WebWorkerBase::IsStarted() { |
88 // Worker is started if we have a route ID and there are no queued messages | 97 // Worker is started if we have a route ID and there are no queued messages |
89 // (meaning we've sent the WorkerMsg_StartWorkerContext already). | 98 // (meaning we've sent the WorkerMsg_StartWorkerContext already). |
(...skipping 20 matching lines...) Expand all Loading... | |
110 | 119 |
111 void WebWorkerBase::SendQueuedMessages() { | 120 void WebWorkerBase::SendQueuedMessages() { |
112 DCHECK(queued_messages_.size()); | 121 DCHECK(queued_messages_.size()); |
113 std::vector<IPC::Message*> queued_messages = queued_messages_; | 122 std::vector<IPC::Message*> queued_messages = queued_messages_; |
114 queued_messages_.clear(); | 123 queued_messages_.clear(); |
115 for (size_t i = 0; i < queued_messages.size(); ++i) { | 124 for (size_t i = 0; i < queued_messages.size(); ++i) { |
116 queued_messages[i]->set_routing_id(route_id_); | 125 queued_messages[i]->set_routing_id(route_id_); |
117 Send(queued_messages[i]); | 126 Send(queued_messages[i]); |
118 } | 127 } |
119 } | 128 } |
129 | |
130 void WebWorkerBase::set_devtools_delegate(DevToolsDelegate* delegate) { | |
131 DCHECK(!devtools_delegate_ && delegate); | |
132 devtools_delegate_ = delegate; | |
133 } | |
OLD | NEW |