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

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

Issue 1175823002: ServiceWorker: Implement ServiceWorkerRegistration.update() (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: trivial fix 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 16fb50bccb0a67e027eab7d8582195a4d1e3e39c..70e2cc56f9173fad198ff88a80ddf34077a6aa3c 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc
@@ -158,6 +158,8 @@ bool ServiceWorkerDispatcherHost::OnMessageReceived(
IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker,
OnRegisterServiceWorker)
+ IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UpdateServiceWorker,
+ OnUpdateServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
OnUnregisterServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration,
@@ -358,6 +360,43 @@ void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
request_id));
}
+void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id,
+ int64 registration_id) {
+ TRACE_EVENT0("ServiceWorker",
+ "ServiceWorkerDispatcherHost::OnUpdateServiceWorker");
+ if (!GetContext())
+ return;
+
+ ServiceWorkerProviderHost* provider_host =
+ GetContext()->GetProviderHost(render_process_id_, provider_id);
+ if (!provider_host) {
+ bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_NO_HOST);
+ return;
+ }
+ if (!provider_host->IsContextAlive())
+ return;
+
+ // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed.
+ if (provider_host->document_url().is_empty())
+ return;
+
+ if (!OriginCanAccessServiceWorkers(provider_host->document_url())) {
kinuko 2015/06/11 03:50:36 This check's not necessary now?
nhiroki 2015/06/11 05:48:33 Removed.
+ bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_CANNOT);
+ return;
+ }
+
+ if (!GetContentClient()->browser()->AllowServiceWorker(
+ provider_host->document_url(), provider_host->topmost_frame_url(),
+ resource_context_, render_process_id_, provider_host->frame_id())) {
+ return;
+ }
kinuko 2015/06/11 03:50:36 This check's not necessary now?
nhiroki 2015/06/11 05:48:33 Hmm... we may have to respect Cookie setting chang
kinuko 2015/06/11 06:33:05 Um, wasn't really reading the code. Let's keep it.
+
+ GetContext()->storage()->FindRegistrationForId(
+ registration_id, provider_host->document_url().GetOrigin(),
+ base::Bind(&ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate,
+ this));
+}
+
void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
int thread_id,
int request_id,
@@ -648,6 +687,24 @@ void ServiceWorkerDispatcherHost::OnSetHostedVersionId(
kDocumentMainThreadId, provider_id, info, attrs));
}
+void ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate(
+ ServiceWorkerStatusCode status,
+ const scoped_refptr<ServiceWorkerRegistration>& registration) {
+ if (status != SERVICE_WORKER_OK)
+ return;
+ if (!GetContext())
+ return;
+ if (!registration->GetNewestVersion()) {
+ // This can happen if update() is called during initial script evaluation.
+ // Abort the following steps according to the spec.
+ return;
+ }
kinuko 2015/06/11 03:50:36 It looks we don't check if the registration's for
nhiroki 2015/06/11 05:48:33 Good point. Added an origin check here.
+ // The spec says, "update() pings the server for an updated version of this
+ // script without consulting caches", so set |force_bypass_cache| to true.
+ GetContext()->UpdateServiceWorker(registration.get(),
+ true /* force_bypass_cache */);
+}
+
ServiceWorkerRegistrationHandle*
ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id,
int64 registration_id) {

Powered by Google App Engine
This is Rietveld 408576698