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

Unified Diff: content/browser/service_worker/service_worker_dispatcher_host.cc

Issue 1181973004: ServiceWorker: Route unregister() through WebServiceWorkerRegistration for refactoring (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove ifdef 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_dispatcher_host.cc
diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc
index f65ee2decaa9edecc1c97463c2d1d90a4fc1665d..9031354c2cc0ea18788d44a216ed3505778008b5 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc
@@ -168,6 +168,8 @@ bool ServiceWorkerDispatcherHost::OnMessageReceived(
OnRegisterServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UpdateServiceWorker,
OnUpdateServiceWorker)
+ IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_DeprecatedUnregisterServiceWorker,
+ OnDeprecatedUnregisterServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
OnUnregisterServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration,
@@ -424,7 +426,7 @@ void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id,
true /* force_bypass_cache */);
}
-void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
+void ServiceWorkerDispatcherHost::OnDeprecatedUnregisterServiceWorker(
int thread_id,
int request_id,
int provider_id,
@@ -498,6 +500,75 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
request_id));
}
+void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
+ int thread_id,
+ int request_id,
+ int provider_id,
+ int64 registration_id) {
+ TRACE_EVENT0("ServiceWorker",
+ "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker");
+ if (!GetContext()) {
+ Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
+ thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort,
+ base::ASCIIToUTF16(kShutdownErrorMessage)));
+ return;
+ }
+
+ ServiceWorkerProviderHost* provider_host =
+ GetContext()->GetProviderHost(render_process_id_, provider_id);
+ if (!provider_host) {
+ bad_message::ReceivedBadMessage(this, bad_message::SWDH_UNREGISTER_NO_HOST);
+ return;
+ }
+ if (!provider_host->IsContextAlive()) {
+ Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
+ thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort,
+ base::ASCIIToUTF16(kShutdownErrorMessage)));
+ return;
+ }
+
+ // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed.
+ if (provider_host->document_url().is_empty()) {
+ Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
+ thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity,
+ base::ASCIIToUTF16(kNoDocumentURLErrorMessage)));
+ return;
+ }
+
+ ServiceWorkerRegistration* registration =
+ GetContext()->GetLiveRegistration(registration_id);
+ if (!registration) {
+ // |registration| must be alive because a renderer retains a registration
+ // reference at this point.
+ bad_message::ReceivedBadMessage(
+ this, bad_message::SWDH_UNREGISTER_BAD_REGISTRATION_ID);
+ return;
+ }
+
+ if (!CanUnregisterServiceWorker(provider_host->document_url(),
+ registration->pattern())) {
+ bad_message::ReceivedBadMessage(this, bad_message::SWDH_UNREGISTER_CANNOT);
+ return;
+ }
+
+ if (!GetContentClient()->browser()->AllowServiceWorker(
+ registration->pattern(), provider_host->topmost_frame_url(),
+ resource_context_, render_process_id_, provider_host->frame_id())) {
+ Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
+ thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown,
+ base::ASCIIToUTF16(kUserDeniedPermissionMessage)));
+ return;
+ }
+
+ TRACE_EVENT_ASYNC_BEGIN1(
+ "ServiceWorker", "ServiceWorkerDispatcherHost::UnregisterServiceWorker",
+ request_id, "Pattern", registration->pattern().spec());
+ GetContext()->UnregisterServiceWorker(
+ registration->pattern(),
+ base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete, this,
+ thread_id, request_id));
+}
+
void ServiceWorkerDispatcherHost::OnGetRegistration(
int thread_id,
int request_id,

Powered by Google App Engine
This is Rietveld 408576698