| 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 21 matching lines...) Expand all Loading... |
| 32 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) | 32 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) |
| 33 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) | 33 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) |
| 34 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent) | 34 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent) |
| 35 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Message, OnPostMessage) | 35 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Message, OnPostMessage) |
| 36 IPC_MESSAGE_UNHANDLED(handled = false) | 36 IPC_MESSAGE_UNHANDLED(handled = false) |
| 37 IPC_END_MESSAGE_MAP() | 37 IPC_END_MESSAGE_MAP() |
| 38 DCHECK(handled); | 38 DCHECK(handled); |
| 39 current_request_id_ = kInvalidServiceWorkerRequestId; | 39 current_request_id_ = kInvalidServiceWorkerRequestId; |
| 40 } | 40 } |
| 41 | 41 |
| 42 void ServiceWorkerScriptContext::DidHandleInstallEvent(int request_id) { | 42 void ServiceWorkerScriptContext::DidHandleInstallEvent( |
| 43 Send(request_id, ServiceWorkerHostMsg_InstallEventFinished()); | 43 int request_id, |
| 44 blink::WebServiceWorkerEventResult result) { |
| 45 Send(request_id, ServiceWorkerHostMsg_InstallEventFinished(result)); |
| 44 } | 46 } |
| 45 | 47 |
| 46 void ServiceWorkerScriptContext::DidHandleFetchEvent( | 48 void ServiceWorkerScriptContext::DidHandleFetchEvent( |
| 47 int request_id, | 49 int request_id, |
| 48 ServiceWorkerFetchEventResult result, | 50 ServiceWorkerFetchEventResult result, |
| 49 const ServiceWorkerResponse& response) { | 51 const ServiceWorkerResponse& response) { |
| 50 Send(request_id, ServiceWorkerHostMsg_FetchEventFinished(result, response)); | 52 Send(request_id, ServiceWorkerHostMsg_FetchEventFinished(result, response)); |
| 51 } | 53 } |
| 52 | 54 |
| 53 void ServiceWorkerScriptContext::Send(int request_id, | 55 void ServiceWorkerScriptContext::Send(int request_id, |
| 54 const IPC::Message& message) { | 56 const IPC::Message& message) { |
| 55 embedded_context_->SendMessageToBrowser(request_id, message); | 57 embedded_context_->SendMessageToBrowser(request_id, message); |
| 56 } | 58 } |
| 57 | 59 |
| 58 void ServiceWorkerScriptContext::OnInstallEvent( | 60 void ServiceWorkerScriptContext::OnInstallEvent(int active_version_id) { |
| 59 int active_version_embedded_worker_id) { | |
| 60 proxy_->dispatchInstallEvent(current_request_id_); | 61 proxy_->dispatchInstallEvent(current_request_id_); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void ServiceWorkerScriptContext::OnFetchEvent( | 64 void ServiceWorkerScriptContext::OnFetchEvent( |
| 64 const ServiceWorkerFetchRequest& request) { | 65 const ServiceWorkerFetchRequest& request) { |
| 65 // TODO(falken): Pass in the request. | 66 // TODO(falken): Pass in the request. |
| 66 proxy_->dispatchFetchEvent(current_request_id_); | 67 proxy_->dispatchFetchEvent(current_request_id_); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void ServiceWorkerScriptContext::OnPostMessage( | 70 void ServiceWorkerScriptContext::OnPostMessage( |
| 70 const base::string16& message, | 71 const base::string16& message, |
| 71 const std::vector<int>& sent_message_port_ids, | 72 const std::vector<int>& sent_message_port_ids, |
| 72 const std::vector<int>& new_routing_ids) { | 73 const std::vector<int>& new_routing_ids) { |
| 73 std::vector<WebMessagePortChannelImpl*> ports; | 74 std::vector<WebMessagePortChannelImpl*> ports; |
| 74 if (!sent_message_port_ids.empty()) { | 75 if (!sent_message_port_ids.empty()) { |
| 75 base::MessageLoopProxy* loop_proxy = embedded_context_->main_thread_proxy(); | 76 base::MessageLoopProxy* loop_proxy = embedded_context_->main_thread_proxy(); |
| 76 ports.resize(sent_message_port_ids.size()); | 77 ports.resize(sent_message_port_ids.size()); |
| 77 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { | 78 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { |
| 78 ports[i] = new WebMessagePortChannelImpl( | 79 ports[i] = new WebMessagePortChannelImpl( |
| 79 new_routing_ids[i], sent_message_port_ids[i], loop_proxy); | 80 new_routing_ids[i], sent_message_port_ids[i], loop_proxy); |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 | 83 |
| 83 proxy_->dispatchMessageEvent(message, ports); | 84 proxy_->dispatchMessageEvent(message, ports); |
| 84 } | 85 } |
| 85 | 86 |
| 86 } // namespace content | 87 } // namespace content |
| OLD | NEW |