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

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: rebase 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/renderer/shared_worker/embedded_shared_worker_stub.h"
6
7 #include "base/message_loop/message_loop_proxy.h"
8 #include "content/child/scoped_child_process_reference.h"
9 #include "content/child/shared_worker_devtools_agent.h"
10 #include "content/child/webmessageportchannel_impl.h"
11 #include "content/common/worker_messages.h"
12 #include "content/renderer/render_thread_impl.h"
13 #include "ipc/ipc_message_macros.h"
14 #include "third_party/WebKit/public/web/WebSharedWorker.h"
15 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h"
16
17 namespace content {
18
19 EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub(
20 const GURL& url,
21 const base::string16& name,
22 const base::string16& content_security_policy,
23 blink::WebContentSecurityPolicyType security_policy_type,
24 int route_id)
25 : route_id_(route_id),
26 name_(name),
27 runing_(false),
28 url_(url) {
29 RenderThreadImpl::current()->AddRoute(route_id_, this);
30 impl_ = blink::WebSharedWorker::create(this);
31 worker_devtools_agent_.reset(
32 new SharedWorkerDevToolsAgent(route_id, impl_));
33 impl_->startWorkerContext(url, name_,
34 content_security_policy, security_policy_type);
35 }
36
37 EmbeddedSharedWorkerStub::~EmbeddedSharedWorkerStub() {
38 RenderThreadImpl::current()->RemoveRoute(route_id_);
39 }
40
41 bool EmbeddedSharedWorkerStub::OnMessageReceived(
42 const IPC::Message& message) {
43 if (worker_devtools_agent_->OnMessageReceived(message))
44 return true;
45 bool handled = true;
46 IPC_BEGIN_MESSAGE_MAP(EmbeddedSharedWorkerStub, message)
47 IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext,
48 OnTerminateWorkerContext)
49 IPC_MESSAGE_HANDLER(WorkerMsg_Connect, OnConnect)
50 IPC_MESSAGE_UNHANDLED(handled = false)
51 IPC_END_MESSAGE_MAP()
52 return handled;
53 }
54
55 void EmbeddedSharedWorkerStub::OnChannelError() {
56 OnTerminateWorkerContext();
57 }
58
59 void EmbeddedSharedWorkerStub::workerScriptLoaded() {
60 Send(new WorkerHostMsg_WorkerScriptLoaded(route_id_));
61 runing_ = true;
62 // Process any pending connections.
63 for (PendingChannelList::const_iterator iter = pending_channels_.begin();
64 iter != pending_channels_.end();
65 ++iter) {
66 impl_->connect(*iter);
67 Send(new WorkerHostMsg_WorkerConnected((*iter)->message_port_id(),
68 route_id_));
69 }
70 pending_channels_.clear();
71 }
72
73 void EmbeddedSharedWorkerStub::workerScriptLoadFailed() {
74 Send(new WorkerHostMsg_WorkerScriptLoadFailed(route_id_));
75 for (PendingChannelList::const_iterator iter = pending_channels_.begin();
76 iter != pending_channels_.end();
77 ++iter) {
78 blink::WebMessagePortChannel* channel = *iter;
79 channel->destroy();
80 }
81 pending_channels_.clear();
82 Shutdown();
83 }
84
85 void EmbeddedSharedWorkerStub::workerContextClosed() {
86 Send(new WorkerHostMsg_WorkerContextClosed(route_id_));
87 }
88
89 void EmbeddedSharedWorkerStub::workerContextDestroyed() {
90 Send(new WorkerHostMsg_WorkerContextDestroyed(route_id_));
91 Shutdown();
92 }
93
94 void EmbeddedSharedWorkerStub::selectAppCacheID(long long) {
95 // TODO(horo): implement this.
96 }
97
98 blink::WebNotificationPresenter*
99 EmbeddedSharedWorkerStub::notificationPresenter() {
100 // TODO(horo): delete this method if we have no plan to implement this.
101 NOTREACHED();
102 return NULL;
103 }
104
105 blink::WebApplicationCacheHost*
106 EmbeddedSharedWorkerStub::createApplicationCacheHost(
107 blink::WebApplicationCacheHostClient*) {
108 // TODO(horo): implement this.
109 return NULL;
110 }
111
112 blink::WebWorkerPermissionClientProxy*
113 EmbeddedSharedWorkerStub::createWorkerPermissionClientProxy(
114 const blink::WebSecurityOrigin& origin) {
115 // TODO(horo): implement this.
116 return NULL;
117 }
118
119 void EmbeddedSharedWorkerStub::dispatchDevToolsMessage(
120 const blink::WebString& message) {
121 worker_devtools_agent_->SendDevToolsMessage(message);
122 }
123
124 void EmbeddedSharedWorkerStub::saveDevToolsAgentState(
125 const blink::WebString& state) {
126 worker_devtools_agent_->SaveDevToolsAgentState(state);
127 }
128
129 void EmbeddedSharedWorkerStub::Shutdown() {
130 delete this;
131 }
132
133 bool EmbeddedSharedWorkerStub::Send(IPC::Message* message) {
134 return RenderThreadImpl::current()->Send(message);
135 }
136
137 void EmbeddedSharedWorkerStub::OnConnect(int sent_message_port_id,
138 int routing_id) {
139 WebMessagePortChannelImpl* channel =
140 new WebMessagePortChannelImpl(routing_id,
141 sent_message_port_id,
142 base::MessageLoopProxy::current().get());
143 if (runing_) {
144 impl_->connect(channel);
145 } else {
146 // If two documents try to load a SharedWorker at the same time, the
147 // WorkerMsg_Connect for one of the documents can come in before the
148 // worker is started. Just queue up the connect and deliver it once the
149 // worker starts.
150 pending_channels_.push_back(channel);
151 }
152 }
153
154 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() {
155 runing_ = false;
156 impl_->terminateWorkerContext();
157 }
158
159 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698