Chromium Code Reviews| 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) { | |
|
nhiroki
2017/08/04 09:24:50
Can you sync this implementation with ParseUpdateV
yuryu
2017/08/17 07:36:35
Done.
| |
| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 visitor->Trace(ready_); | 161 visitor->Trace(ready_); |
| 150 visitor->Trace(navigator_); | 162 visitor->Trace(navigator_); |
| 151 EventTargetWithInlineData::Trace(visitor); | 163 EventTargetWithInlineData::Trace(visitor); |
| 152 ContextLifecycleObserver::Trace(visitor); | 164 ContextLifecycleObserver::Trace(visitor); |
| 153 } | 165 } |
| 154 | 166 |
| 155 void ServiceWorkerContainer::RegisterServiceWorkerImpl( | 167 void ServiceWorkerContainer::RegisterServiceWorkerImpl( |
| 156 ExecutionContext* execution_context, | 168 ExecutionContext* execution_context, |
| 157 const KURL& raw_script_url, | 169 const KURL& raw_script_url, |
| 158 const KURL& scope, | 170 const KURL& scope, |
| 171 WebServiceWorkerUpdateViaCache update_via_cache, | |
| 159 std::unique_ptr<RegistrationCallbacks> callbacks) { | 172 std::unique_ptr<RegistrationCallbacks> callbacks) { |
| 160 if (!provider_) { | 173 if (!provider_) { |
| 161 callbacks->OnError( | 174 callbacks->OnError( |
| 162 WebServiceWorkerError(WebServiceWorkerError::kErrorTypeState, | 175 WebServiceWorkerError(WebServiceWorkerError::kErrorTypeState, |
| 163 "Failed to register a ServiceWorker: The " | 176 "Failed to register a ServiceWorker: The " |
| 164 "document is in an invalid state.")); | 177 "document is in an invalid state.")); |
| 165 return; | 178 return; |
| 166 } | 179 } |
| 167 | 180 |
| 168 RefPtr<SecurityOrigin> document_origin = | 181 RefPtr<SecurityOrigin> document_origin = |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 callbacks->OnError(WebServiceWorkerError( | 267 callbacks->OnError(WebServiceWorkerError( |
| 255 WebServiceWorkerError::kErrorTypeSecurity, | 268 WebServiceWorkerError::kErrorTypeSecurity, |
| 256 String( | 269 String( |
| 257 "Failed to register a ServiceWorker: The provided scriptURL ('" + | 270 "Failed to register a ServiceWorker: The provided scriptURL ('" + |
| 258 script_url.GetString() + | 271 script_url.GetString() + |
| 259 "') violates the Content Security Policy."))); | 272 "') violates the Content Security Policy."))); |
| 260 return; | 273 return; |
| 261 } | 274 } |
| 262 } | 275 } |
| 263 | 276 |
| 264 provider_->RegisterServiceWorker(pattern_url, script_url, | 277 provider_->RegisterServiceWorker(pattern_url, script_url, update_via_cache, |
| 265 std::move(callbacks)); | 278 std::move(callbacks)); |
| 266 } | 279 } |
| 267 | 280 |
| 268 ScriptPromise ServiceWorkerContainer::registerServiceWorker( | 281 ScriptPromise ServiceWorkerContainer::registerServiceWorker( |
| 269 ScriptState* script_state, | 282 ScriptState* script_state, |
| 270 const String& url, | 283 const String& url, |
| 271 const RegistrationOptions& options) { | 284 const RegistrationOptions& options) { |
| 272 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 285 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 273 ScriptPromise promise = resolver->Promise(); | 286 ScriptPromise promise = resolver->Promise(); |
| 274 | 287 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 287 | 300 |
| 288 KURL script_url = execution_context->CompleteURL(url); | 301 KURL script_url = execution_context->CompleteURL(url); |
| 289 script_url.RemoveFragmentIdentifier(); | 302 script_url.RemoveFragmentIdentifier(); |
| 290 | 303 |
| 291 KURL pattern_url; | 304 KURL pattern_url; |
| 292 if (options.scope().IsNull()) | 305 if (options.scope().IsNull()) |
| 293 pattern_url = KURL(script_url, "./"); | 306 pattern_url = KURL(script_url, "./"); |
| 294 else | 307 else |
| 295 pattern_url = execution_context->CompleteURL(options.scope()); | 308 pattern_url = execution_context->CompleteURL(options.scope()); |
| 296 | 309 |
| 310 WebServiceWorkerUpdateViaCache update_via_cache = | |
| 311 ParseUpdateViaCache(options.updateViaCache()); | |
| 312 | |
| 297 RegisterServiceWorkerImpl( | 313 RegisterServiceWorkerImpl( |
| 298 execution_context, script_url, pattern_url, | 314 execution_context, script_url, pattern_url, update_via_cache, |
| 299 WTF::MakeUnique<CallbackPromiseAdapter<ServiceWorkerRegistration, | 315 WTF::MakeUnique<CallbackPromiseAdapter<ServiceWorkerRegistration, |
| 300 ServiceWorkerErrorForUpdate>>( | 316 ServiceWorkerErrorForUpdate>>( |
| 301 resolver)); | 317 resolver)); |
| 302 | 318 |
| 303 return promise; | 319 return promise; |
| 304 } | 320 } |
| 305 | 321 |
| 306 ScriptPromise ServiceWorkerContainer::getRegistration( | 322 ScriptPromise ServiceWorkerContainer::getRegistration( |
| 307 ScriptState* script_state, | 323 ScriptState* script_state, |
| 308 const String& document_url) { | 324 const String& document_url) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 | 503 |
| 488 if (ServiceWorkerContainerClient* client = | 504 if (ServiceWorkerContainerClient* client = |
| 489 ServiceWorkerContainerClient::From(execution_context)) { | 505 ServiceWorkerContainerClient::From(execution_context)) { |
| 490 provider_ = client->Provider(); | 506 provider_ = client->Provider(); |
| 491 if (provider_) | 507 if (provider_) |
| 492 provider_->SetClient(this); | 508 provider_->SetClient(this); |
| 493 } | 509 } |
| 494 } | 510 } |
| 495 | 511 |
| 496 } // namespace blink | 512 } // namespace blink |
| OLD | NEW |