| 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/child/webmessageportchannel_impl.h" |
| 9 #include "content/common/service_worker/service_worker_messages.h" | 9 #include "content/common/service_worker/service_worker_messages.h" |
| 10 #include "content/renderer/service_worker/embedded_worker_context_client.h" | 10 #include "content/renderer/service_worker/embedded_worker_context_client.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {} | 24 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {} |
| 25 | 25 |
| 26 void ServiceWorkerScriptContext::OnMessageReceived( | 26 void ServiceWorkerScriptContext::OnMessageReceived( |
| 27 int request_id, | 27 int request_id, |
| 28 const IPC::Message& message) { | 28 const IPC::Message& message) { |
| 29 DCHECK_EQ(kInvalidServiceWorkerRequestId, current_request_id_); | 29 DCHECK_EQ(kInvalidServiceWorkerRequestId, current_request_id_); |
| 30 current_request_id_ = request_id; | 30 current_request_id_ = request_id; |
| 31 bool handled = true; | 31 bool handled = true; |
| 32 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) | 32 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) |
| 33 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) |
| 34 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent) |
| 33 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) | 35 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) |
| 34 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent) | |
| 35 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Message, OnPostMessage) | 36 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Message, OnPostMessage) |
| 36 IPC_MESSAGE_UNHANDLED(handled = false) | 37 IPC_MESSAGE_UNHANDLED(handled = false) |
| 37 IPC_END_MESSAGE_MAP() | 38 IPC_END_MESSAGE_MAP() |
| 38 DCHECK(handled); | 39 DCHECK(handled); |
| 39 current_request_id_ = kInvalidServiceWorkerRequestId; | 40 current_request_id_ = kInvalidServiceWorkerRequestId; |
| 40 } | 41 } |
| 41 | 42 |
| 43 void ServiceWorkerScriptContext::DidHandleActivateEvent( |
| 44 int request_id, |
| 45 blink::WebServiceWorkerEventResult result) { |
| 46 Send(request_id, ServiceWorkerHostMsg_ActivateEventFinished(result)); |
| 47 } |
| 48 |
| 42 void ServiceWorkerScriptContext::DidHandleInstallEvent( | 49 void ServiceWorkerScriptContext::DidHandleInstallEvent( |
| 43 int request_id, | 50 int request_id, |
| 44 blink::WebServiceWorkerEventResult result) { | 51 blink::WebServiceWorkerEventResult result) { |
| 45 Send(request_id, ServiceWorkerHostMsg_InstallEventFinished(result)); | 52 Send(request_id, ServiceWorkerHostMsg_InstallEventFinished(result)); |
| 46 } | 53 } |
| 47 | 54 |
| 48 void ServiceWorkerScriptContext::DidHandleFetchEvent( | 55 void ServiceWorkerScriptContext::DidHandleFetchEvent( |
| 49 int request_id, | 56 int request_id, |
| 50 ServiceWorkerFetchEventResult result, | 57 ServiceWorkerFetchEventResult result, |
| 51 const ServiceWorkerResponse& response) { | 58 const ServiceWorkerResponse& response) { |
| 52 Send(request_id, ServiceWorkerHostMsg_FetchEventFinished(result, response)); | 59 Send(request_id, ServiceWorkerHostMsg_FetchEventFinished(result, response)); |
| 53 } | 60 } |
| 54 | 61 |
| 55 void ServiceWorkerScriptContext::Send(int request_id, | 62 void ServiceWorkerScriptContext::Send(int request_id, |
| 56 const IPC::Message& message) { | 63 const IPC::Message& message) { |
| 57 embedded_context_->SendMessageToBrowser(request_id, message); | 64 embedded_context_->SendMessageToBrowser(request_id, message); |
| 58 } | 65 } |
| 59 | 66 |
| 67 void ServiceWorkerScriptContext::OnActivateEvent() { |
| 68 proxy_->dispatchActivateEvent(current_request_id_); |
| 69 } |
| 70 |
| 60 void ServiceWorkerScriptContext::OnInstallEvent(int active_version_id) { | 71 void ServiceWorkerScriptContext::OnInstallEvent(int active_version_id) { |
| 61 proxy_->dispatchInstallEvent(current_request_id_); | 72 proxy_->dispatchInstallEvent(current_request_id_); |
| 62 } | 73 } |
| 63 | 74 |
| 64 void ServiceWorkerScriptContext::OnFetchEvent( | 75 void ServiceWorkerScriptContext::OnFetchEvent( |
| 65 const ServiceWorkerFetchRequest& request) { | 76 const ServiceWorkerFetchRequest& request) { |
| 66 // TODO(falken): Pass in the request. | 77 // TODO(falken): Pass in the request. |
| 67 proxy_->dispatchFetchEvent(current_request_id_); | 78 proxy_->dispatchFetchEvent(current_request_id_); |
| 68 } | 79 } |
| 69 | 80 |
| 70 void ServiceWorkerScriptContext::OnPostMessage( | 81 void ServiceWorkerScriptContext::OnPostMessage( |
| 71 const base::string16& message, | 82 const base::string16& message, |
| 72 const std::vector<int>& sent_message_port_ids, | 83 const std::vector<int>& sent_message_port_ids, |
| 73 const std::vector<int>& new_routing_ids) { | 84 const std::vector<int>& new_routing_ids) { |
| 74 std::vector<WebMessagePortChannelImpl*> ports; | 85 std::vector<WebMessagePortChannelImpl*> ports; |
| 75 if (!sent_message_port_ids.empty()) { | 86 if (!sent_message_port_ids.empty()) { |
| 76 base::MessageLoopProxy* loop_proxy = embedded_context_->main_thread_proxy(); | 87 base::MessageLoopProxy* loop_proxy = embedded_context_->main_thread_proxy(); |
| 77 ports.resize(sent_message_port_ids.size()); | 88 ports.resize(sent_message_port_ids.size()); |
| 78 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { | 89 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { |
| 79 ports[i] = new WebMessagePortChannelImpl( | 90 ports[i] = new WebMessagePortChannelImpl( |
| 80 new_routing_ids[i], sent_message_port_ids[i], loop_proxy); | 91 new_routing_ids[i], sent_message_port_ids[i], loop_proxy); |
| 81 } | 92 } |
| 82 } | 93 } |
| 83 | 94 |
| 84 proxy_->dispatchMessageEvent(message, ports); | 95 proxy_->dispatchMessageEvent(message, ports); |
| 85 } | 96 } |
| 86 | 97 |
| 87 } // namespace content | 98 } // namespace content |
| OLD | NEW |