| 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 "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "content/child/notifications/notification_data_conversions.h" | 11 #include "content/child/notifications/notification_data_conversions.h" |
| 12 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 12 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 13 #include "content/child/thread_safe_sender.h" | 13 #include "content/child/thread_safe_sender.h" |
| 14 #include "content/child/webmessageportchannel_impl.h" | 14 #include "content/child/webmessageportchannel_impl.h" |
| 15 #include "content/common/message_port_messages.h" | 15 #include "content/common/message_port_messages.h" |
| 16 #include "content/common/service_worker/service_worker_messages.h" | 16 #include "content/common/service_worker/service_worker_messages.h" |
| 17 #include "content/public/common/referrer.h" | 17 #include "content/public/common/referrer.h" |
| 18 #include "content/renderer/service_worker/embedded_worker_context_client.h" | 18 #include "content/renderer/service_worker/embedded_worker_context_client.h" |
| 19 #include "content/renderer/service_worker/webserviceworkercachestorage_impl.h" |
| 19 #include "ipc/ipc_message.h" | 20 #include "ipc/ipc_message.h" |
| 20 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h
" | 21 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h
" |
| 21 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 22 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
| 22 #include "third_party/WebKit/public/platform/WebServiceWorkerClientQueryOptions.
h" | 23 #include "third_party/WebKit/public/platform/WebServiceWorkerClientQueryOptions.
h" |
| 23 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" | 24 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" |
| 24 #include "third_party/WebKit/public/platform/WebString.h" | 25 #include "third_party/WebKit/public/platform/WebString.h" |
| 25 #include "third_party/WebKit/public/platform/WebURL.h" | 26 #include "third_party/WebKit/public/platform/WebURL.h" |
| 26 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" | 27 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" |
| 27 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" | 28 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" |
| 28 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" | 29 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 web_client_info.clientType = client_info.client_type; | 91 web_client_info.clientType = client_info.client_type; |
| 91 | 92 |
| 92 return web_client_info; | 93 return web_client_info; |
| 93 } | 94 } |
| 94 | 95 |
| 95 } // namespace | 96 } // namespace |
| 96 | 97 |
| 97 ServiceWorkerScriptContext::ServiceWorkerScriptContext( | 98 ServiceWorkerScriptContext::ServiceWorkerScriptContext( |
| 98 EmbeddedWorkerContextClient* embedded_context, | 99 EmbeddedWorkerContextClient* embedded_context, |
| 99 blink::WebServiceWorkerContextProxy* proxy) | 100 blink::WebServiceWorkerContextProxy* proxy) |
| 100 : cache_storage_dispatcher_(new ServiceWorkerCacheStorageDispatcher(this)), | 101 : embedded_context_(embedded_context), |
| 101 embedded_context_(embedded_context), | 102 cache_storage_(new WebServiceWorkerCacheStorageImpl( |
| 103 embedded_context->thread_safe_sender(), |
| 104 embedded_context->origin())), |
| 102 proxy_(proxy) { | 105 proxy_(proxy) { |
| 103 } | 106 } |
| 104 | 107 |
| 105 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {} | 108 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {} |
| 106 | 109 |
| 107 void ServiceWorkerScriptContext::OnMessageReceived( | 110 void ServiceWorkerScriptContext::OnMessageReceived( |
| 108 const IPC::Message& message) { | 111 const IPC::Message& message) { |
| 109 bool handled = true; | 112 bool handled = true; |
| 110 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) | 113 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) |
| 111 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) | 114 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 129 OnOpenWindowError) | 132 OnOpenWindowError) |
| 130 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, | 133 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, |
| 131 OnFocusClientResponse) | 134 OnFocusClientResponse) |
| 132 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) | 135 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) |
| 133 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) | 136 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) |
| 134 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) | 137 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) |
| 135 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); | 138 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); |
| 136 IPC_MESSAGE_UNHANDLED(handled = false) | 139 IPC_MESSAGE_UNHANDLED(handled = false) |
| 137 IPC_END_MESSAGE_MAP() | 140 IPC_END_MESSAGE_MAP() |
| 138 | 141 |
| 139 // TODO(gavinp): Would it be preferable to put an AddListener() method to | |
| 140 // EmbeddedWorkerContextClient? | |
| 141 if (!handled) | |
| 142 handled = cache_storage_dispatcher_->OnMessageReceived(message); | |
| 143 | |
| 144 DCHECK(handled); | 142 DCHECK(handled); |
| 145 } | 143 } |
| 146 | 144 |
| 147 void ServiceWorkerScriptContext::SetRegistrationInServiceWorkerGlobalScope( | 145 void ServiceWorkerScriptContext::SetRegistrationInServiceWorkerGlobalScope( |
| 148 scoped_ptr<WebServiceWorkerRegistrationImpl> registration) { | 146 scoped_ptr<WebServiceWorkerRegistrationImpl> registration) { |
| 149 proxy_->setRegistration(registration.release()); | 147 proxy_->setRegistration(registration.release()); |
| 150 } | 148 } |
| 151 | 149 |
| 152 void ServiceWorkerScriptContext::DidHandleActivateEvent( | 150 void ServiceWorkerScriptContext::DidHandleActivateEvent( |
| 153 int request_id, | 151 int request_id, |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 new blink::WebServiceWorkerError(error_type, message)); | 582 new blink::WebServiceWorkerError(error_type, message)); |
| 585 callbacks->onError(error.release()); | 583 callbacks->onError(error.release()); |
| 586 pending_claim_clients_callbacks_.Remove(request_id); | 584 pending_claim_clients_callbacks_.Remove(request_id); |
| 587 } | 585 } |
| 588 | 586 |
| 589 void ServiceWorkerScriptContext::OnPing() { | 587 void ServiceWorkerScriptContext::OnPing() { |
| 590 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); | 588 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); |
| 591 } | 589 } |
| 592 | 590 |
| 593 } // namespace content | 591 } // namespace content |
| OLD | NEW |