blob: 203ec6bb39b9260c5b1297f6ec4548b5fdce6f39 [file] [log] [blame]
[email protected]6898bbe2009-11-05 16:27:061// 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
[email protected]6f516082011-03-17 19:15:355#include "content/renderer/websharedworker_proxy.h"
[email protected]6898bbe2009-11-05 16:27:066
[email protected]59f4f2fa2011-03-23 01:00:557#include "content/common/view_messages.h"
[email protected]e93e04e2011-03-14 00:27:108#include "content/common/webmessageportchannel_impl.h"
[email protected]4d223d32011-03-12 06:38:569#include "content/common/worker_messages.h"
[email protected]8bd0fe62011-01-17 06:44:3710#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
[email protected]6898bbe2009-11-05 16:27:0611
12WebSharedWorkerProxy::WebSharedWorkerProxy(ChildThread* child_thread,
[email protected]0791d3a2010-01-28 01:28:4913 unsigned long long document_id,
[email protected]6de0bcf2010-02-17 22:00:5114 bool exists,
[email protected]9c00f002009-11-05 22:37:4215 int route_id,
16 int render_view_route_id)
[email protected]6de0bcf2010-02-17 22:00:5117 : WebWorkerBase(child_thread,
18 document_id,
19 exists ? route_id : MSG_ROUTING_NONE,
[email protected]14396e92010-05-06 20:40:5620 render_view_route_id,
[email protected]55c76bd2011-10-07 07:41:0421 0),
[email protected]6de0bcf2010-02-17 22:00:5122 pending_route_id_(route_id),
[email protected]30447b62009-11-13 01:13:3723 connect_listener_(NULL) {
[email protected]6898bbe2009-11-05 16:27:0624}
25
26bool WebSharedWorkerProxy::isStarted() {
27 return IsStarted();
28}
29
30void WebSharedWorkerProxy::startWorkerContext(
31 const WebKit::WebURL& script_url,
32 const WebKit::WebString& name,
33 const WebKit::WebString& user_agent,
[email protected]b7ab0262010-05-05 21:54:2134 const WebKit::WebString& source_code,
35 long long script_resource_appcache_id) {
[email protected]30447b62009-11-13 01:13:3736 DCHECK(!isStarted());
[email protected]14396e92010-05-06 20:40:5637 CreateSharedWorkerContext(script_url, name, user_agent, source_code,
38 pending_route_id_, script_resource_appcache_id);
[email protected]6898bbe2009-11-05 16:27:0639}
40
[email protected]9c00f002009-11-05 22:37:4241void WebSharedWorkerProxy::terminateWorkerContext() {
42 // This API should only be invoked from worker context.
43 NOTREACHED();
44}
45
46void WebSharedWorkerProxy::clientDestroyed() {
47 // This API should only be invoked from worker context.
48 NOTREACHED();
49}
50
[email protected]702690422009-11-09 04:23:2651void WebSharedWorkerProxy::connect(WebKit::WebMessagePortChannel* channel,
52 ConnectListener* listener) {
[email protected]6898bbe2009-11-05 16:27:0653 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));
[email protected]702690422009-11-09 04:23:2661 if (HasQueuedMessages()) {
[email protected]30447b62009-11-13 01:13:3762 connect_listener_ = listener;
[email protected]4a3dab22009-11-11 17:36:5063 } else {
[email protected]702690422009-11-09 04:23:2664 listener->connected();
65 // The listener may free this object, so do not access the object after
66 // this point.
[email protected]4a3dab22009-11-11 17:36:5067 }
[email protected]6898bbe2009-11-05 16:27:0668}
69
[email protected]a95986a82010-12-24 06:19:2870bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) {
71 bool handled = true;
[email protected]6898bbe2009-11-05 16:27:0672 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message)
73 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated)
[email protected]a95986a82010-12-24 06:19:2874 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]6898bbe2009-11-05 16:27:0675 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:2876 return handled;
[email protected]6898bbe2009-11-05 16:27:0677}
78
79void WebSharedWorkerProxy::OnWorkerCreated() {
80 // The worker is created - now send off the CreateWorkerContext message and
81 // any other queued messages
82 SendQueuedMessages();
[email protected]702690422009-11-09 04:23:2683
84 // Inform any listener that the pending connect event has been sent
85 // (this can result in this object being freed).
[email protected]30447b62009-11-13 01:13:3786 if (connect_listener_) {
87 connect_listener_->connected();
[email protected]702690422009-11-09 04:23:2688 }
[email protected]6898bbe2009-11-05 16:27:0689}