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

Side by Side Diff: content/renderer/shared_worker/embedded_shared_worker_stub.cc

Issue 158953008: Implementations of SharedWorker in the renderer process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WorkerMessages
Patch Set: move shared_worker_devtools_agent to content/child Created 6 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/websharedworker_stub.h" 5 #include "content/renderer/shared_worker/embedded_shared_worker_stub.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/message_loop/message_loop_proxy.h"
8 #include "content/child/child_process.h"
9 #include "content/child/child_thread.h" 8 #include "content/child/child_thread.h"
10 #include "content/child/fileapi/file_system_dispatcher.h" 9 #include "content/child/scoped_child_process_reference.h"
10 #include "content/child/shared_worker_devtools_agent.h"
11 #include "content/child/thread_safe_sender.h"
11 #include "content/child/webmessageportchannel_impl.h" 12 #include "content/child/webmessageportchannel_impl.h"
13 #include "content/child/worker_thread_task_runner.h"
kinuko 2014/02/13 09:06:48 Not necessary?
horo 2014/02/13 09:38:28 Done.
12 #include "content/common/worker_messages.h" 14 #include "content/common/worker_messages.h"
13 #include "content/worker/shared_worker_devtools_agent.h" 15 #include "content/renderer/render_thread_impl.h"
14 #include "content/worker/worker_thread.h" 16 #include "ipc/ipc_message_macros.h"
15 #include "third_party/WebKit/public/web/WebSharedWorker.h" 17 #include "third_party/WebKit/public/web/WebSharedWorker.h"
16 #include "third_party/WebKit/public/platform/WebString.h" 18 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h"
17 #include "third_party/WebKit/public/platform/WebURL.h"
18 19
19 namespace content { 20 namespace content {
20 21
21 WebSharedWorkerStub::WebSharedWorkerStub( 22 EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub(
22 const GURL& url, 23 const GURL& url,
23 const base::string16& name, 24 const base::string16& name,
24 const base::string16& content_security_policy, 25 const base::string16& content_security_policy,
25 blink::WebContentSecurityPolicyType security_policy_type, 26 blink::WebContentSecurityPolicyType security_policy_type,
26 int route_id) 27 int route_id)
27 : route_id_(route_id), 28 : route_id_(route_id),
28 client_(route_id, this), 29 name_(name),
29 running_(false), 30 runing_(false),
30 url_(url) { 31 url_(url) {
31 32 RenderThreadImpl::current()->AddRoute(route_id_, this);
32 WorkerThread* worker_thread = WorkerThread::current(); 33 impl_ = blink::WebSharedWorker::create(this);
33 DCHECK(worker_thread); 34 worker_devtools_agent_.reset(
34 worker_thread->AddWorkerStub(this); 35 new SharedWorkerDevToolsAgent(route_id, impl_));
35 // Start processing incoming IPCs for this worker. 36 impl_->startWorkerContext(url, name_,
36 worker_thread->AddRoute(route_id_, this);
37
38 // TODO(atwilson): Add support for NaCl when they support MessagePorts.
39 impl_ = blink::WebSharedWorker::create(client());
40 worker_devtools_agent_.reset(new SharedWorkerDevToolsAgent(route_id, impl_));
41 client()->set_devtools_agent(worker_devtools_agent_.get());
42 impl_->startWorkerContext(url_, name,
43 content_security_policy, security_policy_type); 37 content_security_policy, security_policy_type);
44 } 38 }
45 39
46 WebSharedWorkerStub::~WebSharedWorkerStub() { 40 EmbeddedSharedWorkerStub::~EmbeddedSharedWorkerStub() {
47 impl_->clientDestroyed(); 41 RenderThreadImpl::current()->RemoveRoute(route_id_);
48 WorkerThread* worker_thread = WorkerThread::current();
49 DCHECK(worker_thread);
50 worker_thread->RemoveWorkerStub(this);
51 worker_thread->RemoveRoute(route_id_);
52 } 42 }
53 43
54 void WebSharedWorkerStub::Shutdown() { 44 bool EmbeddedSharedWorkerStub::OnMessageReceived(
55 // The worker has exited - free ourselves and the client. 45 const IPC::Message& message) {
56 delete this;
57 }
58
59 void WebSharedWorkerStub::EnsureWorkerContextTerminates() {
60 client_.EnsureWorkerContextTerminates();
61 }
62
63 bool WebSharedWorkerStub::OnMessageReceived(const IPC::Message& message) {
64 if (worker_devtools_agent_->OnMessageReceived(message)) 46 if (worker_devtools_agent_->OnMessageReceived(message))
65 return true; 47 return true;
66
67 bool handled = true; 48 bool handled = true;
68 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerStub, message) 49 IPC_BEGIN_MESSAGE_MAP(EmbeddedSharedWorkerStub, message)
69 IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext, 50 IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext,
70 OnTerminateWorkerContext) 51 OnTerminateWorkerContext)
71 IPC_MESSAGE_HANDLER(WorkerMsg_Connect, OnConnect) 52 IPC_MESSAGE_HANDLER(WorkerMsg_Connect, OnConnect)
72 IPC_MESSAGE_UNHANDLED(handled = false) 53 IPC_MESSAGE_UNHANDLED(handled = false)
73 IPC_END_MESSAGE_MAP() 54 IPC_END_MESSAGE_MAP()
74 return handled; 55 return handled;
75 } 56 }
76 57
77 void WebSharedWorkerStub::OnChannelError() { 58 void EmbeddedSharedWorkerStub::OnChannelError() {
78 OnTerminateWorkerContext(); 59 OnTerminateWorkerContext();
79 } 60 }
80 61
81 const GURL& WebSharedWorkerStub::url() { 62 void EmbeddedSharedWorkerStub::workerScriptLoaded() {
82 return url_; 63 Send(new WorkerHostMsg_WorkerScriptLoaded(route_id_));
83 } 64 runing_ = true;
84
85 void WebSharedWorkerStub::OnConnect(int sent_message_port_id, int routing_id) {
86 WebMessagePortChannelImpl* channel =
87 new WebMessagePortChannelImpl(routing_id,
88 sent_message_port_id,
89 base::MessageLoopProxy::current().get());
90 if (running_) {
91 impl_->connect(channel);
92 WorkerThread::current()->Send(
93 new WorkerHostMsg_WorkerConnected(channel->message_port_id(),
94 route_id_));
95 } else {
96 // If two documents try to load a SharedWorker at the same time, the
97 // WorkerMsg_Connect for one of the documents can come in before the
98 // worker is started. Just queue up the connect and deliver it once the
99 // worker starts.
100 pending_channels_.push_back(channel);
101 }
102 }
103
104 void WebSharedWorkerStub::OnTerminateWorkerContext() {
105 impl_->terminateWorkerContext();
106
107 // Call the client to make sure context exits.
108 EnsureWorkerContextTerminates();
109 running_ = false;
110 }
111
112 void WebSharedWorkerStub::WorkerScriptLoaded() {
113 running_ = true;
114 // Process any pending connections. 65 // Process any pending connections.
115 for (PendingChannelList::const_iterator iter = pending_channels_.begin(); 66 for (PendingChannelList::const_iterator iter = pending_channels_.begin();
116 iter != pending_channels_.end(); 67 iter != pending_channels_.end();
117 ++iter) { 68 ++iter) {
118 impl_->connect(*iter); 69 impl_->connect(*iter);
119 WorkerThread::current()->Send( 70 Send(new WorkerHostMsg_WorkerConnected((*iter)->message_port_id(),
120 new WorkerHostMsg_WorkerConnected((*iter)->message_port_id(), 71 route_id_));
121 route_id_));
122 } 72 }
123 pending_channels_.clear(); 73 pending_channels_.clear();
124 } 74 }
125 75
126 void WebSharedWorkerStub::WorkerScriptLoadFailed() { 76 void EmbeddedSharedWorkerStub::workerScriptLoadFailed() {
77 Send(new WorkerHostMsg_WorkerScriptLoadFailed(route_id_));
127 for (PendingChannelList::const_iterator iter = pending_channels_.begin(); 78 for (PendingChannelList::const_iterator iter = pending_channels_.begin();
128 iter != pending_channels_.end(); 79 iter != pending_channels_.end();
129 ++iter) { 80 ++iter) {
130 blink::WebMessagePortChannel* channel = *iter; 81 blink::WebMessagePortChannel* channel = *iter;
131 channel->destroy(); 82 channel->destroy();
132 } 83 }
133 pending_channels_.clear(); 84 pending_channels_.clear();
134 Shutdown(); 85 Shutdown();
135 } 86 }
136 87
88 void EmbeddedSharedWorkerStub::workerContextClosed() {
89 Send(new WorkerHostMsg_WorkerContextClosed(route_id_));
90 }
91
92 void EmbeddedSharedWorkerStub::workerContextDestroyed() {
93 Send(new WorkerHostMsg_WorkerContextDestroyed(route_id_));
94 Shutdown();
95 }
96
97 void EmbeddedSharedWorkerStub::selectAppCacheID(long long) {
98 // TODO(horo): implement this.
99 }
100
101 blink::WebNotificationPresenter*
102 EmbeddedSharedWorkerStub::notificationPresenter() {
103 // TODO(horo): delete this method if we have no plan to implement this.
104 NOTREACHED();
105 return NULL;
106 }
107
108 blink::WebApplicationCacheHost*
109 EmbeddedSharedWorkerStub::createApplicationCacheHost(
110 blink::WebApplicationCacheHostClient*) {
111 // TODO(horo): implement this.
112 return NULL;
113 }
114
115 blink::WebWorkerPermissionClientProxy*
116 EmbeddedSharedWorkerStub::createWorkerPermissionClientProxy(
117 const blink::WebSecurityOrigin& origin) {
118 // TODO(horo): implement this.
119 return NULL;
120 }
121
122 void EmbeddedSharedWorkerStub::dispatchDevToolsMessage(
123 const blink::WebString& message) {
124 worker_devtools_agent_->SendDevToolsMessage(message);
125 }
126
127 void EmbeddedSharedWorkerStub::saveDevToolsAgentState(
128 const blink::WebString& state) {
129 worker_devtools_agent_->SaveDevToolsAgentState(state);
130 }
131
132 void EmbeddedSharedWorkerStub::Shutdown() {
133 delete this;
134 }
135
136 bool EmbeddedSharedWorkerStub::Send(IPC::Message* message) {
137 return RenderThreadImpl::current()->Send(message);
138 }
139
140 void EmbeddedSharedWorkerStub::OnConnect(int sent_message_port_id,
141 int routing_id) {
142 WebMessagePortChannelImpl* channel =
143 new WebMessagePortChannelImpl(routing_id,
144 sent_message_port_id,
145 base::MessageLoopProxy::current().get());
146 if (runing_) {
147 impl_->connect(channel);
148 } else {
149 // If two documents try to load a SharedWorker at the same time, the
150 // WorkerMsg_Connect for one of the documents can come in before the
151 // worker is started. Just queue up the connect and deliver it once the
152 // worker starts.
153 pending_channels_.push_back(channel);
154 }
155 }
156
157 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() {
158 runing_ = false;
159 impl_->terminateWorkerContext();
160 }
161
137 } // namespace content 162 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/shared_worker/embedded_shared_worker_stub.h ('k') | content/worker/shared_worker_devtools_agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698