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

Side by Side Diff: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainer.cpp

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: fix IPC Created 3 years, 4 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 #include "platform/weborigin/SecurityViolationReportingPolicy.h" 59 #include "platform/weborigin/SecurityViolationReportingPolicy.h"
60 #include "platform/wtf/PtrUtil.h" 60 #include "platform/wtf/PtrUtil.h"
61 #include "public/platform/WebString.h" 61 #include "public/platform/WebString.h"
62 #include "public/platform/WebURL.h" 62 #include "public/platform/WebURL.h"
63 #include "public/platform/modules/serviceworker/WebServiceWorker.h" 63 #include "public/platform/modules/serviceworker/WebServiceWorker.h"
64 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" 64 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h"
65 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h" 65 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h"
66 66
67 namespace blink { 67 namespace blink {
68 68
69 namespace {
70
71 WebServiceWorkerUpdateViaCache ParseUpdateViaCache(const String& value) {
72 if (value == "imports")
73 return WebServiceWorkerUpdateViaCache::kImports;
74 if (value == "all")
75 return WebServiceWorkerUpdateViaCache::kAll;
76 if (value == "none")
77 return WebServiceWorkerUpdateViaCache::kNone;
78 // Default value
79 return WebServiceWorkerUpdateViaCache::kImports;
80 }
81
82 } // namespace
83
69 class GetRegistrationCallback : public WebServiceWorkerProvider:: 84 class GetRegistrationCallback : public WebServiceWorkerProvider::
70 WebServiceWorkerGetRegistrationCallbacks { 85 WebServiceWorkerGetRegistrationCallbacks {
71 public: 86 public:
72 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver) 87 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver)
73 : resolver_(resolver) {} 88 : resolver_(resolver) {}
74 ~GetRegistrationCallback() override {} 89 ~GetRegistrationCallback() override {}
75 90
76 void OnSuccess(std::unique_ptr<WebServiceWorkerRegistration::Handle> 91 void OnSuccess(std::unique_ptr<WebServiceWorkerRegistration::Handle>
77 web_pass_handle) override { 92 web_pass_handle) override {
78 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle = 93 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle =
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 visitor->Trace(ready_); 164 visitor->Trace(ready_);
150 visitor->Trace(navigator_); 165 visitor->Trace(navigator_);
151 EventTargetWithInlineData::Trace(visitor); 166 EventTargetWithInlineData::Trace(visitor);
152 ContextLifecycleObserver::Trace(visitor); 167 ContextLifecycleObserver::Trace(visitor);
153 } 168 }
154 169
155 void ServiceWorkerContainer::RegisterServiceWorkerImpl( 170 void ServiceWorkerContainer::RegisterServiceWorkerImpl(
156 ExecutionContext* execution_context, 171 ExecutionContext* execution_context,
157 const KURL& raw_script_url, 172 const KURL& raw_script_url,
158 const KURL& scope, 173 const KURL& scope,
174 WebServiceWorkerUpdateViaCache update_via_cache,
159 std::unique_ptr<RegistrationCallbacks> callbacks) { 175 std::unique_ptr<RegistrationCallbacks> callbacks) {
160 if (!provider_) { 176 if (!provider_) {
161 callbacks->OnError( 177 callbacks->OnError(
162 WebServiceWorkerError(WebServiceWorkerError::kErrorTypeState, 178 WebServiceWorkerError(WebServiceWorkerError::kErrorTypeState,
163 "Failed to register a ServiceWorker: The " 179 "Failed to register a ServiceWorker: The "
164 "document is in an invalid state.")); 180 "document is in an invalid state."));
165 return; 181 return;
166 } 182 }
167 183
168 RefPtr<SecurityOrigin> document_origin = 184 RefPtr<SecurityOrigin> document_origin =
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 callbacks->OnError(WebServiceWorkerError( 270 callbacks->OnError(WebServiceWorkerError(
255 WebServiceWorkerError::kErrorTypeSecurity, 271 WebServiceWorkerError::kErrorTypeSecurity,
256 String( 272 String(
257 "Failed to register a ServiceWorker: The provided scriptURL ('" + 273 "Failed to register a ServiceWorker: The provided scriptURL ('" +
258 script_url.GetString() + 274 script_url.GetString() +
259 "') violates the Content Security Policy."))); 275 "') violates the Content Security Policy.")));
260 return; 276 return;
261 } 277 }
262 } 278 }
263 279
264 provider_->RegisterServiceWorker(pattern_url, script_url, 280 provider_->RegisterServiceWorker(pattern_url, script_url, update_via_cache,
265 std::move(callbacks)); 281 std::move(callbacks));
266 } 282 }
267 283
268 ScriptPromise ServiceWorkerContainer::registerServiceWorker( 284 ScriptPromise ServiceWorkerContainer::registerServiceWorker(
269 ScriptState* script_state, 285 ScriptState* script_state,
270 const String& url, 286 const String& url,
271 const RegistrationOptions& options) { 287 const RegistrationOptions& options) {
272 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); 288 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
273 ScriptPromise promise = resolver->Promise(); 289 ScriptPromise promise = resolver->Promise();
274 290
(...skipping 12 matching lines...) Expand all
287 303
288 KURL script_url = execution_context->CompleteURL(url); 304 KURL script_url = execution_context->CompleteURL(url);
289 script_url.RemoveFragmentIdentifier(); 305 script_url.RemoveFragmentIdentifier();
290 306
291 KURL pattern_url; 307 KURL pattern_url;
292 if (options.scope().IsNull()) 308 if (options.scope().IsNull())
293 pattern_url = KURL(script_url, "./"); 309 pattern_url = KURL(script_url, "./");
294 else 310 else
295 pattern_url = execution_context->CompleteURL(options.scope()); 311 pattern_url = execution_context->CompleteURL(options.scope());
296 312
313 WebServiceWorkerUpdateViaCache update_via_cache =
314 ParseUpdateViaCache(options.updateViaCache());
315
297 RegisterServiceWorkerImpl( 316 RegisterServiceWorkerImpl(
298 execution_context, script_url, pattern_url, 317 execution_context, script_url, pattern_url, update_via_cache,
299 WTF::MakeUnique<CallbackPromiseAdapter<ServiceWorkerRegistration, 318 WTF::MakeUnique<CallbackPromiseAdapter<ServiceWorkerRegistration,
300 ServiceWorkerErrorForUpdate>>( 319 ServiceWorkerErrorForUpdate>>(
301 resolver)); 320 resolver));
302 321
303 return promise; 322 return promise;
304 } 323 }
305 324
306 ScriptPromise ServiceWorkerContainer::getRegistration( 325 ScriptPromise ServiceWorkerContainer::getRegistration(
307 ScriptState* script_state, 326 ScriptState* script_state,
308 const String& document_url) { 327 const String& document_url) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 506
488 if (ServiceWorkerContainerClient* client = 507 if (ServiceWorkerContainerClient* client =
489 ServiceWorkerContainerClient::From(execution_context)) { 508 ServiceWorkerContainerClient::From(execution_context)) {
490 provider_ = client->Provider(); 509 provider_ = client->Provider();
491 if (provider_) 510 if (provider_)
492 provider_->SetClient(this); 511 provider_->SetClient(this);
493 } 512 }
494 } 513 }
495 514
496 } // namespace blink 515 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698