OLD | NEW |
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 Loading... |
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 == "all") |
| 73 return WebServiceWorkerUpdateViaCache::kAll; |
| 74 if (value == "none") |
| 75 return WebServiceWorkerUpdateViaCache::kNone; |
| 76 return WebServiceWorkerUpdateViaCache::kImports; |
| 77 } |
| 78 |
| 79 } // namespace |
| 80 |
69 class GetRegistrationCallback : public WebServiceWorkerProvider:: | 81 class GetRegistrationCallback : public WebServiceWorkerProvider:: |
70 WebServiceWorkerGetRegistrationCallbacks { | 82 WebServiceWorkerGetRegistrationCallbacks { |
71 public: | 83 public: |
72 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver) | 84 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver) |
73 : resolver_(resolver) {} | 85 : resolver_(resolver) {} |
74 ~GetRegistrationCallback() override {} | 86 ~GetRegistrationCallback() override {} |
75 | 87 |
76 void OnSuccess(std::unique_ptr<WebServiceWorkerRegistration::Handle> | 88 void OnSuccess(std::unique_ptr<WebServiceWorkerRegistration::Handle> |
77 web_pass_handle) override { | 89 web_pass_handle) override { |
78 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle = | 90 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle = |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 visitor->Trace(ready_); | 160 visitor->Trace(ready_); |
149 visitor->Trace(navigator_); | 161 visitor->Trace(navigator_); |
150 EventTargetWithInlineData::Trace(visitor); | 162 EventTargetWithInlineData::Trace(visitor); |
151 ContextLifecycleObserver::Trace(visitor); | 163 ContextLifecycleObserver::Trace(visitor); |
152 } | 164 } |
153 | 165 |
154 void ServiceWorkerContainer::RegisterServiceWorkerImpl( | 166 void ServiceWorkerContainer::RegisterServiceWorkerImpl( |
155 ExecutionContext* execution_context, | 167 ExecutionContext* execution_context, |
156 const KURL& raw_script_url, | 168 const KURL& raw_script_url, |
157 const KURL& scope, | 169 const KURL& scope, |
| 170 WebServiceWorkerUpdateViaCache update_via_cache, |
158 std::unique_ptr<RegistrationCallbacks> callbacks) { | 171 std::unique_ptr<RegistrationCallbacks> callbacks) { |
159 if (!provider_) { | 172 if (!provider_) { |
160 callbacks->OnError( | 173 callbacks->OnError( |
161 WebServiceWorkerError(WebServiceWorkerError::kErrorTypeState, | 174 WebServiceWorkerError(WebServiceWorkerError::kErrorTypeState, |
162 "Failed to register a ServiceWorker: The " | 175 "Failed to register a ServiceWorker: The " |
163 "document is in an invalid state.")); | 176 "document is in an invalid state.")); |
164 return; | 177 return; |
165 } | 178 } |
166 | 179 |
167 RefPtr<SecurityOrigin> document_origin = | 180 RefPtr<SecurityOrigin> document_origin = |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 callbacks->OnError(WebServiceWorkerError( | 266 callbacks->OnError(WebServiceWorkerError( |
254 WebServiceWorkerError::kErrorTypeSecurity, | 267 WebServiceWorkerError::kErrorTypeSecurity, |
255 String( | 268 String( |
256 "Failed to register a ServiceWorker: The provided scriptURL ('" + | 269 "Failed to register a ServiceWorker: The provided scriptURL ('" + |
257 script_url.GetString() + | 270 script_url.GetString() + |
258 "') violates the Content Security Policy."))); | 271 "') violates the Content Security Policy."))); |
259 return; | 272 return; |
260 } | 273 } |
261 } | 274 } |
262 | 275 |
263 provider_->RegisterServiceWorker(pattern_url, script_url, | 276 provider_->RegisterServiceWorker(pattern_url, script_url, update_via_cache, |
264 std::move(callbacks)); | 277 std::move(callbacks)); |
265 } | 278 } |
266 | 279 |
267 ScriptPromise ServiceWorkerContainer::registerServiceWorker( | 280 ScriptPromise ServiceWorkerContainer::registerServiceWorker( |
268 ScriptState* script_state, | 281 ScriptState* script_state, |
269 const String& url, | 282 const String& url, |
270 const RegistrationOptions& options) { | 283 const RegistrationOptions& options) { |
271 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 284 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
272 ScriptPromise promise = resolver->Promise(); | 285 ScriptPromise promise = resolver->Promise(); |
273 | 286 |
(...skipping 12 matching lines...) Expand all Loading... |
286 | 299 |
287 KURL script_url = execution_context->CompleteURL(url); | 300 KURL script_url = execution_context->CompleteURL(url); |
288 script_url.RemoveFragmentIdentifier(); | 301 script_url.RemoveFragmentIdentifier(); |
289 | 302 |
290 KURL pattern_url; | 303 KURL pattern_url; |
291 if (options.scope().IsNull()) | 304 if (options.scope().IsNull()) |
292 pattern_url = KURL(script_url, "./"); | 305 pattern_url = KURL(script_url, "./"); |
293 else | 306 else |
294 pattern_url = execution_context->CompleteURL(options.scope()); | 307 pattern_url = execution_context->CompleteURL(options.scope()); |
295 | 308 |
| 309 WebServiceWorkerUpdateViaCache update_via_cache = |
| 310 ParseUpdateViaCache(options.updateViaCache()); |
| 311 |
296 RegisterServiceWorkerImpl( | 312 RegisterServiceWorkerImpl( |
297 execution_context, script_url, pattern_url, | 313 execution_context, script_url, pattern_url, update_via_cache, |
298 WTF::MakeUnique<CallbackPromiseAdapter<ServiceWorkerRegistration, | 314 WTF::MakeUnique<CallbackPromiseAdapter<ServiceWorkerRegistration, |
299 ServiceWorkerErrorForUpdate>>( | 315 ServiceWorkerErrorForUpdate>>( |
300 resolver)); | 316 resolver)); |
301 | 317 |
302 return promise; | 318 return promise; |
303 } | 319 } |
304 | 320 |
305 ScriptPromise ServiceWorkerContainer::getRegistration( | 321 ScriptPromise ServiceWorkerContainer::getRegistration( |
306 ScriptState* script_state, | 322 ScriptState* script_state, |
307 const String& document_url) { | 323 const String& document_url) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 502 |
487 if (ServiceWorkerContainerClient* client = | 503 if (ServiceWorkerContainerClient* client = |
488 ServiceWorkerContainerClient::From(execution_context)) { | 504 ServiceWorkerContainerClient::From(execution_context)) { |
489 provider_ = client->Provider(); | 505 provider_ = client->Provider(); |
490 if (provider_) | 506 if (provider_) |
491 provider_->SetClient(this); | 507 provider_->SetClient(this); |
492 } | 508 } |
493 } | 509 } |
494 | 510 |
495 } // namespace blink | 511 } // namespace blink |
OLD | NEW |