Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/child_thread.h" | |
| 9 #include "content/child/scoped_child_process_reference.h" | |
| 10 #include "content/child/thread_safe_sender.h" | |
| 11 #include "content/child/webmessageportchannel_impl.h" | |
| 12 #include "content/child/worker_thread_task_runner.h" | |
| 13 #include "content/common/worker_messages.h" | |
| 14 #include "content/renderer/render_thread_impl.h" | |
| 15 #include "content/renderer/shared_worker/embedded_shared_worker_devtools_agent.h " | |
| 16 #include "ipc/ipc_message_macros.h" | |
| 17 | |
|
kinuko
2014/02/12 11:49:33
nit: extra empty line
horo
2014/02/13 05:30:01
Done.
| |
| 18 #include "third_party/WebKit/public/web/WebSharedWorker.h" | |
| 19 #include "third_party/WebKit/public/web/WebSharedWorkerClient.h" | |
| 20 | |
| 21 namespace blink { | |
| 22 class WebNotificationPresenter; | |
| 23 class WebApplicationCacheHost; | |
| 24 } | |
|
kinuko
2014/02/12 11:49:33
Do we need this in .cc?
horo
2014/02/13 05:30:01
Done.
| |
| 25 | |
| 26 namespace content { | |
|
kinuko
2014/02/12 11:49:33
nit: have empty line after namespace {
horo
2014/02/13 05:30:01
Done.
| |
| 27 EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub( | |
| 28 const GURL& url, | |
| 29 const base::string16& name, | |
| 30 const base::string16& content_security_policy, | |
| 31 blink::WebContentSecurityPolicyType security_policy_type, | |
| 32 int route_id) | |
| 33 : route_id_(route_id), | |
| 34 name_(name), | |
| 35 runing_(false), | |
| 36 url_(url) { | |
|
kinuko
2014/02/12 11:49:33
Will we call RenderThreadImpl::current()->AddRoute
horo
2014/02/13 05:30:01
Done.
| |
| 37 impl_ = blink::WebSharedWorker::create(this); | |
| 38 worker_devtools_agent_.reset( | |
| 39 new EmbeddedSharedWorkerDevToolsAgent(route_id, impl_)); | |
| 40 impl_->startWorkerContext(url, name_, | |
| 41 content_security_policy, security_policy_type); | |
| 42 } | |
| 43 | |
| 44 EmbeddedSharedWorkerStub::~EmbeddedSharedWorkerStub() { | |
| 45 } | |
| 46 | |
| 47 bool EmbeddedSharedWorkerStub::OnMessageReceived( | |
| 48 const IPC::Message& message) { | |
| 49 if (worker_devtools_agent_->OnMessageReceived(message)) | |
| 50 return true; | |
| 51 bool handled = true; | |
| 52 IPC_BEGIN_MESSAGE_MAP(EmbeddedSharedWorkerStub, message) | |
| 53 IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext, | |
| 54 OnTerminateWorkerContext) | |
| 55 IPC_MESSAGE_HANDLER(WorkerMsg_Connect, OnConnect) | |
| 56 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 57 IPC_END_MESSAGE_MAP() | |
| 58 return handled; | |
| 59 } | |
| 60 | |
| 61 void EmbeddedSharedWorkerStub::OnChannelError() { | |
| 62 OnTerminateWorkerContext(); | |
| 63 } | |
| 64 | |
| 65 void EmbeddedSharedWorkerStub::workerScriptLoaded() { | |
| 66 Send(new WorkerHostMsg_WorkerScriptLoaded(route_id_)); | |
| 67 runing_ = true; | |
| 68 // Process any pending connections. | |
| 69 for (PendingChannelList::const_iterator iter = pending_channels_.begin(); | |
| 70 iter != pending_channels_.end(); | |
| 71 ++iter) { | |
| 72 impl_->connect(*iter); | |
| 73 Send(new WorkerHostMsg_WorkerConnected((*iter)->message_port_id(), | |
| 74 route_id_)); | |
| 75 } | |
| 76 pending_channels_.clear(); | |
| 77 } | |
| 78 | |
| 79 void EmbeddedSharedWorkerStub::workerScriptLoadFailed() { | |
| 80 Send(new WorkerHostMsg_WorkerScriptLoadFailed(route_id_)); | |
| 81 for (PendingChannelList::const_iterator iter = pending_channels_.begin(); | |
| 82 iter != pending_channels_.end(); | |
| 83 ++iter) { | |
| 84 blink::WebMessagePortChannel* channel = *iter; | |
| 85 channel->destroy(); | |
| 86 } | |
| 87 pending_channels_.clear(); | |
| 88 Shutdown(); | |
| 89 } | |
| 90 | |
| 91 void EmbeddedSharedWorkerStub::workerContextClosed() { | |
| 92 Send(new WorkerHostMsg_WorkerContextClosed(route_id_)); | |
| 93 } | |
| 94 | |
| 95 void EmbeddedSharedWorkerStub::workerContextDestroyed() { | |
| 96 Send(new WorkerHostMsg_WorkerContextDestroyed(route_id_)); | |
| 97 Shutdown(); | |
| 98 } | |
| 99 | |
| 100 void EmbeddedSharedWorkerStub::selectAppCacheID(long long) { | |
| 101 //TODO(horo): implement this. | |
| 102 } | |
| 103 | |
| 104 blink::WebNotificationPresenter* | |
| 105 EmbeddedSharedWorkerStub::notificationPresenter() { | |
| 106 // TODO(johnnyg): Notifications are not yet hooked up to workers. | |
| 107 // Coming soon. | |
|
kinuko
2014/02/12 11:49:33
Is this TODO still applicable / do we need this?
horo
2014/02/13 05:30:01
This is copied from websharedworkerclient_proxy.cc
kinuko
2014/02/13 06:09:36
Afaik johnny's transferred to another team (youtub
horo
2014/02/13 08:54:20
Done.
| |
| 108 NOTREACHED(); | |
| 109 return NULL; | |
| 110 } | |
| 111 | |
| 112 blink::WebApplicationCacheHost* | |
| 113 EmbeddedSharedWorkerStub::createApplicationCacheHost( | |
| 114 blink::WebApplicationCacheHostClient*) { | |
| 115 //TODO(horo): implement this. | |
| 116 return NULL; | |
| 117 } | |
| 118 | |
| 119 blink::WebWorkerPermissionClientProxy* | |
| 120 EmbeddedSharedWorkerStub::createWorkerPermissionClientProxy( | |
| 121 const blink::WebSecurityOrigin& origin) { | |
| 122 //TODO(horo): implement this. | |
| 123 return NULL; | |
| 124 } | |
| 125 | |
| 126 void EmbeddedSharedWorkerStub::dispatchDevToolsMessage( | |
| 127 const blink::WebString& message) { | |
| 128 worker_devtools_agent_->SendDevToolsMessage(message); | |
| 129 } | |
| 130 | |
| 131 void EmbeddedSharedWorkerStub::saveDevToolsAgentState( | |
| 132 const blink::WebString& state) { | |
| 133 worker_devtools_agent_->SaveDevToolsAgentState(state); | |
| 134 } | |
| 135 | |
| 136 void EmbeddedSharedWorkerStub::Shutdown() { | |
| 137 delete this; | |
| 138 } | |
| 139 | |
| 140 bool EmbeddedSharedWorkerStub::Send(IPC::Message* message) { | |
| 141 return RenderThreadImpl::current()->Send(message); | |
| 142 } | |
| 143 | |
| 144 void EmbeddedSharedWorkerStub::OnConnect(int sent_message_port_id, | |
| 145 int routing_id) { | |
| 146 WebMessagePortChannelImpl* channel = | |
| 147 new WebMessagePortChannelImpl(routing_id, | |
| 148 sent_message_port_id, | |
| 149 base::MessageLoopProxy::current().get()); | |
| 150 if (runing_) { | |
| 151 impl_->connect(channel); | |
| 152 } else { | |
| 153 // If two documents try to load a SharedWorker at the same time, the | |
| 154 // WorkerMsg_Connect for one of the documents can come in before the | |
| 155 // worker is started. Just queue up the connect and deliver it once the | |
| 156 // worker starts. | |
| 157 pending_channels_.push_back(channel); | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() { | |
| 162 runing_ = false; | |
| 163 impl_->terminateWorkerContext(); | |
|
kinuko
2014/02/12 11:49:33
Will we have 'ensure worker context terminates' pa
horo
2014/02/13 05:30:01
I think we don't need to call EnsureWorkerContextT
kinuko
2014/02/13 06:09:36
I don't know, just wondered why you didn't copy th
horo
2014/02/13 08:54:20
I think we don't need WebSharedWorkerClientProxy::
| |
| 164 } | |
| 165 | |
| 166 } // namespace content | |
| OLD | NEW |