| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/renderer/websharedworker_proxy.h" | |
| 6 | |
| 7 #include "chrome/common/render_messages.h" | |
| 8 #include "content/common/webmessageportchannel_impl.h" | |
| 9 #include "content/common/worker_messages.h" | |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | |
| 11 | |
| 12 WebSharedWorkerProxy::WebSharedWorkerProxy(ChildThread* child_thread, | |
| 13 unsigned long long document_id, | |
| 14 bool exists, | |
| 15 int route_id, | |
| 16 int render_view_route_id) | |
| 17 : WebWorkerBase(child_thread, | |
| 18 document_id, | |
| 19 exists ? route_id : MSG_ROUTING_NONE, | |
| 20 render_view_route_id, | |
| 21 0), | |
| 22 pending_route_id_(route_id), | |
| 23 connect_listener_(NULL) { | |
| 24 } | |
| 25 | |
| 26 bool WebSharedWorkerProxy::isStarted() { | |
| 27 return IsStarted(); | |
| 28 } | |
| 29 | |
| 30 void WebSharedWorkerProxy::startWorkerContext( | |
| 31 const WebKit::WebURL& script_url, | |
| 32 const WebKit::WebString& name, | |
| 33 const WebKit::WebString& user_agent, | |
| 34 const WebKit::WebString& source_code, | |
| 35 long long script_resource_appcache_id) { | |
| 36 DCHECK(!isStarted()); | |
| 37 CreateSharedWorkerContext(script_url, name, user_agent, source_code, | |
| 38 pending_route_id_, script_resource_appcache_id); | |
| 39 } | |
| 40 | |
| 41 void WebSharedWorkerProxy::terminateWorkerContext() { | |
| 42 // This API should only be invoked from worker context. | |
| 43 NOTREACHED(); | |
| 44 } | |
| 45 | |
| 46 void WebSharedWorkerProxy::clientDestroyed() { | |
| 47 // This API should only be invoked from worker context. | |
| 48 NOTREACHED(); | |
| 49 } | |
| 50 | |
| 51 void WebSharedWorkerProxy::connect(WebKit::WebMessagePortChannel* channel, | |
| 52 ConnectListener* listener) { | |
| 53 WebMessagePortChannelImpl* webchannel = | |
| 54 static_cast<WebMessagePortChannelImpl*>(channel); | |
| 55 | |
| 56 int message_port_id = webchannel->message_port_id(); | |
| 57 DCHECK(message_port_id != MSG_ROUTING_NONE); | |
| 58 webchannel->QueueMessages(); | |
| 59 | |
| 60 Send(new WorkerMsg_Connect(route_id_, message_port_id, MSG_ROUTING_NONE)); | |
| 61 if (HasQueuedMessages()) { | |
| 62 connect_listener_ = listener; | |
| 63 } else { | |
| 64 listener->connected(); | |
| 65 // The listener may free this object, so do not access the object after | |
| 66 // this point. | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) { | |
| 71 bool handled = true; | |
| 72 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message) | |
| 73 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) | |
| 74 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 75 IPC_END_MESSAGE_MAP() | |
| 76 return handled; | |
| 77 } | |
| 78 | |
| 79 void WebSharedWorkerProxy::OnWorkerCreated() { | |
| 80 // The worker is created - now send off the CreateWorkerContext message and | |
| 81 // any other queued messages | |
| 82 SendQueuedMessages(); | |
| 83 | |
| 84 // Inform any listener that the pending connect event has been sent | |
| 85 // (this can result in this object being freed). | |
| 86 if (connect_listener_) { | |
| 87 connect_listener_->connected(); | |
| 88 } | |
| 89 } | |
| OLD | NEW |