Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Side by Side Diff: content/renderer/websharedworker_proxy.cc

Issue 2607753002: SharedWorker: Make sure route_id is always valid in WebSharedWorkerProxy (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/websharedworker_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/renderer/websharedworker_proxy.h" 5 #include "content/renderer/websharedworker_proxy.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "content/child/webmessageportchannel_impl.h" 9 #include "content/child/webmessageportchannel_impl.h"
10 #include "content/common/view_messages.h" 10 #include "content/common/view_messages.h"
11 #include "content/common/worker_messages.h" 11 #include "content/common/worker_messages.h"
12 #include "ipc/message_router.h" 12 #include "ipc/message_router.h"
13 #include "third_party/WebKit/public/platform/WebURL.h" 13 #include "third_party/WebKit/public/platform/WebURL.h"
14 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h" 14 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 WebSharedWorkerProxy::WebSharedWorkerProxy(IPC::MessageRouter* router, 18 WebSharedWorkerProxy::WebSharedWorkerProxy(IPC::MessageRouter* router,
19 int route_id) 19 int route_id)
20 : route_id_(route_id), 20 : route_id_(route_id),
21 router_(router), 21 router_(router),
22 connect_listener_(nullptr), 22 connect_listener_(nullptr),
23 created_(false) { 23 created_(false) {
24 DCHECK_NE(MSG_ROUTING_NONE, route_id_);
24 router_->AddRoute(route_id_, this); 25 router_->AddRoute(route_id_, this);
25 } 26 }
26 27
27 WebSharedWorkerProxy::~WebSharedWorkerProxy() { 28 WebSharedWorkerProxy::~WebSharedWorkerProxy() {
28 Disconnect();
29 }
30
31 void WebSharedWorkerProxy::Disconnect() {
32 if (route_id_ == MSG_ROUTING_NONE)
33 return;
34
35 // So the messages from WorkerContext (like WorkerContextDestroyed) do not
36 // come after nobody is listening. Since Worker and WorkerContext can
37 // terminate independently, already sent messages may still be in the pipe.
38 router_->RemoveRoute(route_id_); 29 router_->RemoveRoute(route_id_);
39
40 route_id_ = MSG_ROUTING_NONE;
41 } 30 }
42 31
43 bool WebSharedWorkerProxy::Send(std::unique_ptr<IPC::Message> message) { 32 bool WebSharedWorkerProxy::Send(std::unique_ptr<IPC::Message> message) {
44 // It's possible that messages will be sent before the worker is created, in 33 // The worker object can be interacted with before the browser process told us
45 // which case route_id_ will be none. Or the worker object can be interacted 34 // that it started, in which case we want to queue the message.
46 // with before the browser process told us that it started, in which case we
47 // also want to queue the message.
48 if (!created_) { 35 if (!created_) {
49 queued_messages_.push_back(std::move(message)); 36 queued_messages_.push_back(std::move(message));
50 return true; 37 return true;
51 } 38 }
52 39
53 // For now we proxy all messages to the worker process through the browser. 40 // For now we proxy all messages to the worker process through the browser.
54 // Revisit if we find this slow. 41 // Revisit if we find this slow.
55 // TODO(jabdelmalek): handle sync messages if we need them. 42 // TODO(jabdelmalek): handle sync messages if we need them.
56 return router_->Send(new ViewHostMsg_ForwardToWorker(*message)); 43 return router_->Send(new ViewHostMsg_ForwardToWorker(*message));
57 } 44 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 OnWorkerScriptLoadFailed) 76 OnWorkerScriptLoadFailed)
90 IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected, 77 IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected,
91 OnWorkerConnected) 78 OnWorkerConnected)
92 IPC_MESSAGE_UNHANDLED(handled = false) 79 IPC_MESSAGE_UNHANDLED(handled = false)
93 IPC_END_MESSAGE_MAP() 80 IPC_END_MESSAGE_MAP()
94 return handled; 81 return handled;
95 } 82 }
96 83
97 void WebSharedWorkerProxy::OnWorkerCreated() { 84 void WebSharedWorkerProxy::OnWorkerCreated() {
98 created_ = true; 85 created_ = true;
99 // The worker is created - now send off the WorkerMsg_Connect message and 86 // The worker is created - now send off the WorkerMsg_Connect message.
100 // any other queued messages
101 SendQueuedMessages(); 87 SendQueuedMessages();
102 } 88 }
103 89
104 void WebSharedWorkerProxy::OnWorkerScriptLoadFailed() { 90 void WebSharedWorkerProxy::OnWorkerScriptLoadFailed() {
105 if (connect_listener_) { 91 if (connect_listener_) {
106 // This can result in this object being freed. 92 // This can result in this object being freed.
107 connect_listener_->scriptLoadFailed(); 93 connect_listener_->scriptLoadFailed();
108 } 94 }
109 } 95 }
110 96
111 void WebSharedWorkerProxy::OnWorkerConnected() { 97 void WebSharedWorkerProxy::OnWorkerConnected() {
112 if (connect_listener_) { 98 if (connect_listener_) {
113 // This can result in this object being freed. 99 // This can result in this object being freed.
114 connect_listener_->connected(); 100 connect_listener_->connected();
115 } 101 }
116 } 102 }
117 103
118 } // namespace content 104 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/websharedworker_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698