Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: content/browser/service_worker/service_worker_dispatcher_host.cc

Issue 1186803002: ServiceWorker: Route unregister() through WebServiceWorkerRegistration for refactoring (4) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@route_web_sw_reg_2
Patch Set: rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/service_worker/service_worker_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/profiler/scoped_tracker.h" 8 #include "base/profiler/scoped_tracker.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"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 161 }
162 162
163 bool ServiceWorkerDispatcherHost::OnMessageReceived( 163 bool ServiceWorkerDispatcherHost::OnMessageReceived(
164 const IPC::Message& message) { 164 const IPC::Message& message) {
165 bool handled = true; 165 bool handled = true;
166 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) 166 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message)
167 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, 167 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker,
168 OnRegisterServiceWorker) 168 OnRegisterServiceWorker)
169 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UpdateServiceWorker, 169 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UpdateServiceWorker,
170 OnUpdateServiceWorker) 170 OnUpdateServiceWorker)
171 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_DeprecatedUnregisterServiceWorker,
172 OnDeprecatedUnregisterServiceWorker)
173 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, 171 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
174 OnUnregisterServiceWorker) 172 OnUnregisterServiceWorker)
175 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, 173 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration,
176 OnGetRegistration) 174 OnGetRegistration)
177 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrations, 175 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrations,
178 OnGetRegistrations) 176 OnGetRegistrations)
179 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady, 177 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady,
180 OnGetRegistrationForReady) 178 OnGetRegistrationForReady)
181 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, 179 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated,
182 OnProviderCreated) 180 OnProviderCreated)
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 // Abort the following steps according to the spec. 417 // Abort the following steps according to the spec.
420 return; 418 return;
421 } 419 }
422 420
423 // The spec says, "update() pings the server for an updated version of this 421 // The spec says, "update() pings the server for an updated version of this
424 // script without consulting caches", so set |force_bypass_cache| to true. 422 // script without consulting caches", so set |force_bypass_cache| to true.
425 GetContext()->UpdateServiceWorker(registration, 423 GetContext()->UpdateServiceWorker(registration,
426 true /* force_bypass_cache */); 424 true /* force_bypass_cache */);
427 } 425 }
428 426
429 void ServiceWorkerDispatcherHost::OnDeprecatedUnregisterServiceWorker(
430 int thread_id,
431 int request_id,
432 int provider_id,
433 const GURL& pattern) {
434 TRACE_EVENT0("ServiceWorker",
435 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker");
436 if (!GetContext()) {
437 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
438 thread_id,
439 request_id,
440 blink::WebServiceWorkerError::ErrorTypeAbort,
441 base::ASCIIToUTF16(kShutdownErrorMessage)));
442 return;
443 }
444 if (!pattern.is_valid()) {
445 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UNREGISTER_BAD_URL);
446 return;
447 }
448
449 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost(
450 render_process_id_, provider_id);
451 if (!provider_host) {
452 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UNREGISTER_NO_HOST);
453 return;
454 }
455 if (!provider_host->IsContextAlive()) {
456 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
457 thread_id,
458 request_id,
459 blink::WebServiceWorkerError::ErrorTypeAbort,
460 base::ASCIIToUTF16(kShutdownErrorMessage)));
461 return;
462 }
463
464 // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed.
465 if (provider_host->document_url().is_empty()) {
466 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
467 thread_id,
468 request_id,
469 WebServiceWorkerError::ErrorTypeSecurity,
470 base::ASCIIToUTF16(kNoDocumentURLErrorMessage)));
471 return;
472 }
473
474 if (!CanUnregisterServiceWorker(provider_host->document_url(), pattern)) {
475 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UNREGISTER_CANNOT);
476 return;
477 }
478
479 if (!GetContentClient()->browser()->AllowServiceWorker(
480 pattern, provider_host->topmost_frame_url(), resource_context_,
481 render_process_id_, provider_host->frame_id())) {
482 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
483 thread_id,
484 request_id,
485 WebServiceWorkerError::ErrorTypeUnknown,
486 base::ASCIIToUTF16(kUserDeniedPermissionMessage)));
487 return;
488 }
489
490 TRACE_EVENT_ASYNC_BEGIN1(
491 "ServiceWorker",
492 "ServiceWorkerDispatcherHost::UnregisterServiceWorker",
493 request_id,
494 "Pattern", pattern.spec());
495 GetContext()->UnregisterServiceWorker(
496 pattern,
497 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete,
498 this,
499 thread_id,
500 request_id));
501 }
502
503 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( 427 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
504 int thread_id, 428 int thread_id,
505 int request_id, 429 int request_id,
506 int provider_id, 430 int provider_id,
507 int64 registration_id) { 431 int64 registration_id) {
508 TRACE_EVENT0("ServiceWorker", 432 TRACE_EVENT0("ServiceWorker",
509 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker"); 433 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker");
510 if (!GetContext()) { 434 if (!GetContext()) {
511 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( 435 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
512 thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort, 436 thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort,
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 if (!handle) { 1231 if (!handle) {
1308 bad_message::ReceivedBadMessage(this, 1232 bad_message::ReceivedBadMessage(this,
1309 bad_message::SWDH_TERMINATE_BAD_HANDLE); 1233 bad_message::SWDH_TERMINATE_BAD_HANDLE);
1310 return; 1234 return;
1311 } 1235 }
1312 handle->version()->StopWorker( 1236 handle->version()->StopWorker(
1313 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1237 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1314 } 1238 }
1315 1239
1316 } // namespace content 1240 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698