OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer/service_worker/service_worker_script_context.h" | 5 #include "content/renderer/service_worker/service_worker_script_context.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/child/webmessageportchannel_impl.h" |
8 #include "content/common/service_worker/service_worker_messages.h" | 9 #include "content/common/service_worker/service_worker_messages.h" |
9 #include "content/renderer/service_worker/embedded_worker_context_client.h" | 10 #include "content/renderer/service_worker/embedded_worker_context_client.h" |
10 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
11 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" | 12 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 | 15 |
15 ServiceWorkerScriptContext::ServiceWorkerScriptContext( | 16 ServiceWorkerScriptContext::ServiceWorkerScriptContext( |
16 EmbeddedWorkerContextClient* embedded_context, | 17 EmbeddedWorkerContextClient* embedded_context, |
17 blink::WebServiceWorkerContextProxy* proxy) | 18 blink::WebServiceWorkerContextProxy* proxy) |
18 : embedded_context_(embedded_context), | 19 : embedded_context_(embedded_context), |
19 proxy_(proxy), | 20 proxy_(proxy), |
20 current_request_id_(kInvalidServiceWorkerRequestId) { | 21 current_request_id_(kInvalidServiceWorkerRequestId) { |
21 } | 22 } |
22 | 23 |
23 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {} | 24 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {} |
24 | 25 |
25 void ServiceWorkerScriptContext::OnMessageReceived( | 26 void ServiceWorkerScriptContext::OnMessageReceived( |
26 int request_id, | 27 int request_id, |
27 const IPC::Message& message) { | 28 const IPC::Message& message) { |
28 DCHECK_EQ(kInvalidServiceWorkerRequestId, current_request_id_); | 29 DCHECK_EQ(kInvalidServiceWorkerRequestId, current_request_id_); |
29 current_request_id_ = request_id; | 30 current_request_id_ = request_id; |
30 bool handled = true; | 31 bool handled = true; |
31 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) | 32 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) |
32 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) | 33 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) |
33 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent) | 34 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent) |
| 35 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Message, OnPostMessage) |
34 IPC_MESSAGE_UNHANDLED(handled = false) | 36 IPC_MESSAGE_UNHANDLED(handled = false) |
35 IPC_END_MESSAGE_MAP() | 37 IPC_END_MESSAGE_MAP() |
36 DCHECK(handled); | 38 DCHECK(handled); |
37 current_request_id_ = kInvalidServiceWorkerRequestId; | 39 current_request_id_ = kInvalidServiceWorkerRequestId; |
38 } | 40 } |
39 | 41 |
40 void ServiceWorkerScriptContext::DidHandleInstallEvent(int request_id) { | 42 void ServiceWorkerScriptContext::DidHandleInstallEvent(int request_id) { |
41 Send(request_id, ServiceWorkerHostMsg_InstallEventFinished()); | 43 Send(request_id, ServiceWorkerHostMsg_InstallEventFinished()); |
42 } | 44 } |
43 | 45 |
(...skipping 13 matching lines...) Expand all Loading... |
57 int active_version_embedded_worker_id) { | 59 int active_version_embedded_worker_id) { |
58 proxy_->dispatchInstallEvent(current_request_id_); | 60 proxy_->dispatchInstallEvent(current_request_id_); |
59 } | 61 } |
60 | 62 |
61 void ServiceWorkerScriptContext::OnFetchEvent( | 63 void ServiceWorkerScriptContext::OnFetchEvent( |
62 const ServiceWorkerFetchRequest& request) { | 64 const ServiceWorkerFetchRequest& request) { |
63 // TODO(falken): Pass in the request. | 65 // TODO(falken): Pass in the request. |
64 proxy_->dispatchFetchEvent(current_request_id_); | 66 proxy_->dispatchFetchEvent(current_request_id_); |
65 } | 67 } |
66 | 68 |
| 69 void ServiceWorkerScriptContext::OnPostMessage( |
| 70 const base::string16& message, |
| 71 const std::vector<int>& sent_message_port_ids, |
| 72 const std::vector<int>& new_routing_ids) { |
| 73 std::vector<WebMessagePortChannelImpl*> ports; |
| 74 if (!sent_message_port_ids.empty()) { |
| 75 base::MessageLoopProxy* loop_proxy = embedded_context_->main_thread_proxy(); |
| 76 ports.resize(sent_message_port_ids.size()); |
| 77 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { |
| 78 ports[i] = new WebMessagePortChannelImpl( |
| 79 new_routing_ids[i], sent_message_port_ids[i], loop_proxy); |
| 80 } |
| 81 } |
| 82 |
| 83 proxy_->dispatchMessageEvent(message, ports); |
| 84 } |
| 85 |
67 } // namespace content | 86 } // namespace content |
OLD | NEW |