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_(kInvalidRequestId) { | 21 current_request_id_(kInvalidRequestId) { |
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(kInvalidRequestId, current_request_id_); | 29 DCHECK_EQ(kInvalidRequestId, 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, OnMessage) | |
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_ = kInvalidRequestId; | 39 current_request_id_ = kInvalidRequestId; |
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 14 matching lines...) Expand all Loading... | |
58 } | 60 } |
59 | 61 |
60 void ServiceWorkerScriptContext::OnFetchEvent( | 62 void ServiceWorkerScriptContext::OnFetchEvent( |
61 const ServiceWorkerFetchRequest& request) { | 63 const ServiceWorkerFetchRequest& request) { |
62 // TODO(falken): Dispatch the event to Blink and wait for the response from | 64 // TODO(falken): Dispatch the event to Blink and wait for the response from |
63 // respondWith. This is just a dummy response now. | 65 // respondWith. This is just a dummy response now. |
64 DidHandleFetchEvent(current_request_id_, ServiceWorkerFetchResponse( | 66 DidHandleFetchEvent(current_request_id_, ServiceWorkerFetchResponse( |
65 200, "OK", "GET", std::map<std::string, std::string>())); | 67 200, "OK", "GET", std::map<std::string, std::string>())); |
66 } | 68 } |
67 | 69 |
70 void ServiceWorkerScriptContext::OnMessage( | |
71 base::string16 message, | |
72 std::vector<int> sent_message_port_ids, | |
73 std::vector<int> new_routing_ids) { | |
michaeln
2014/03/11 23:17:34
const refs
jsbell
2014/03/12 18:16:16
Done.
| |
74 | |
75 std::vector<WebMessagePortChannelImpl*> ports; | |
76 if (!sent_message_port_ids.empty()) { | |
77 base::MessageLoopProxy* loop_proxy = embedded_context_->main_thread_proxy(); | |
78 ports.resize(sent_message_port_ids.size()); | |
79 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { | |
80 ports[i] = new WebMessagePortChannelImpl( | |
kinuko
2014/03/12 08:19:05
(It's a bit sad that WebMessagePortChannelImpl rel
| |
81 new_routing_ids[i], sent_message_port_ids[i], loop_proxy); | |
82 } | |
83 } | |
84 | |
85 proxy_->dispatchMessageEvent(message, ports); | |
86 } | |
87 | |
68 } // namespace content | 88 } // namespace content |
OLD | NEW |