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