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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 51 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
52 #include "platform/RuntimeEnabledFeatures.h" | 52 #include "platform/RuntimeEnabledFeatures.h" |
53 #include "platform/weborigin/SchemeRegistry.h" | 53 #include "platform/weborigin/SchemeRegistry.h" |
54 #include "public/platform/WebString.h" | 54 #include "public/platform/WebString.h" |
55 #include "public/platform/WebURL.h" | 55 #include "public/platform/WebURL.h" |
56 #include "public/platform/modules/serviceworker/WebServiceWorker.h" | 56 #include "public/platform/modules/serviceworker/WebServiceWorker.h" |
57 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" | 57 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" |
58 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h" | 58 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h" |
59 #include "wtf/PtrUtil.h" | 59 #include "wtf/PtrUtil.h" |
60 #include <memory> | 60 #include <memory> |
| 61 #include <utility> |
61 | 62 |
62 namespace blink { | 63 namespace blink { |
63 | 64 |
64 class RegistrationCallback | 65 class RegistrationCallback |
65 : public WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks { | 66 : public WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks { |
66 public: | 67 public: |
67 explicit RegistrationCallback(ScriptPromiseResolver* resolver) | 68 explicit RegistrationCallback(ScriptPromiseResolver* resolver) |
68 : m_resolver(resolver) {} | 69 : m_resolver(resolver) {} |
69 ~RegistrationCallback() override {} | 70 ~RegistrationCallback() override {} |
70 | 71 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 callbacks->onError(WebServiceWorkerError( | 315 callbacks->onError(WebServiceWorkerError( |
315 WebServiceWorkerError::ErrorTypeSecurity, | 316 WebServiceWorkerError::ErrorTypeSecurity, |
316 String( | 317 String( |
317 "Failed to register a ServiceWorker: The provided scriptURL ('" + | 318 "Failed to register a ServiceWorker: The provided scriptURL ('" + |
318 scriptURL.getString() + | 319 scriptURL.getString() + |
319 "') violates the Content Security Policy."))); | 320 "') violates the Content Security Policy."))); |
320 return; | 321 return; |
321 } | 322 } |
322 } | 323 } |
323 | 324 |
324 m_provider->registerServiceWorker(patternURL, scriptURL, callbacks.release()); | 325 m_provider->registerServiceWorker(patternURL, scriptURL, |
| 326 std::move(callbacks)); |
325 } | 327 } |
326 | 328 |
327 ScriptPromise ServiceWorkerContainer::registerServiceWorker( | 329 ScriptPromise ServiceWorkerContainer::registerServiceWorker( |
328 ScriptState* scriptState, | 330 ScriptState* scriptState, |
329 const String& url, | 331 const String& url, |
330 const RegistrationOptions& options) { | 332 const RegistrationOptions& options) { |
331 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 333 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
332 ScriptPromise promise = resolver->promise(); | 334 ScriptPromise promise = resolver->promise(); |
333 | 335 |
334 if (!m_provider) { | 336 if (!m_provider) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 SecurityOrigin::create(completedURL); | 408 SecurityOrigin::create(completedURL); |
407 resolver->reject( | 409 resolver->reject( |
408 DOMException::create(SecurityError, | 410 DOMException::create(SecurityError, |
409 "Failed to get a ServiceWorkerRegistration: The " | 411 "Failed to get a ServiceWorkerRegistration: The " |
410 "origin of the provided documentURL ('" + | 412 "origin of the provided documentURL ('" + |
411 documentURLOrigin->toString() + | 413 documentURLOrigin->toString() + |
412 "') does not match the current origin ('" + | 414 "') does not match the current origin ('" + |
413 documentOrigin->toString() + "').")); | 415 documentOrigin->toString() + "').")); |
414 return promise; | 416 return promise; |
415 } | 417 } |
416 m_provider->getRegistration(completedURL, | 418 m_provider->getRegistration( |
417 new GetRegistrationCallback(resolver)); | 419 completedURL, WTF::makeUnique<GetRegistrationCallback>(resolver)); |
418 | 420 |
419 return promise; | 421 return promise; |
420 } | 422 } |
421 | 423 |
422 ScriptPromise ServiceWorkerContainer::getRegistrations( | 424 ScriptPromise ServiceWorkerContainer::getRegistrations( |
423 ScriptState* scriptState) { | 425 ScriptState* scriptState) { |
424 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 426 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
425 ScriptPromise promise = resolver->promise(); | 427 ScriptPromise promise = resolver->promise(); |
426 | 428 |
427 if (!m_provider) { | 429 if (!m_provider) { |
(...skipping 16 matching lines...) Expand all Loading... |
444 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers( | 446 if (!SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers( |
445 pageURL.protocol())) { | 447 pageURL.protocol())) { |
446 resolver->reject(DOMException::create( | 448 resolver->reject(DOMException::create( |
447 SecurityError, | 449 SecurityError, |
448 "Failed to get ServiceWorkerRegistration objects: The URL protocol of " | 450 "Failed to get ServiceWorkerRegistration objects: The URL protocol of " |
449 "the current origin ('" + | 451 "the current origin ('" + |
450 documentOrigin->toString() + "') is not supported.")); | 452 documentOrigin->toString() + "') is not supported.")); |
451 return promise; | 453 return promise; |
452 } | 454 } |
453 | 455 |
454 m_provider->getRegistrations(new GetRegistrationsCallback(resolver)); | 456 m_provider->getRegistrations( |
| 457 WTF::makeUnique<GetRegistrationsCallback>(resolver)); |
455 | 458 |
456 return promise; | 459 return promise; |
457 } | 460 } |
458 | 461 |
459 ServiceWorkerContainer::ReadyProperty* | 462 ServiceWorkerContainer::ReadyProperty* |
460 ServiceWorkerContainer::createReadyProperty() { | 463 ServiceWorkerContainer::createReadyProperty() { |
461 return new ReadyProperty(getExecutionContext(), this, ReadyProperty::Ready); | 464 return new ReadyProperty(getExecutionContext(), this, ReadyProperty::Ready); |
462 } | 465 } |
463 | 466 |
464 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState) { | 467 ScriptPromise ServiceWorkerContainer::ready(ScriptState* callerState) { |
465 if (!getExecutionContext()) | 468 if (!getExecutionContext()) |
466 return ScriptPromise(); | 469 return ScriptPromise(); |
467 | 470 |
468 if (!callerState->world().isMainWorld()) { | 471 if (!callerState->world().isMainWorld()) { |
469 // FIXME: Support .ready from isolated worlds when | 472 // FIXME: Support .ready from isolated worlds when |
470 // ScriptPromiseProperty can vend Promises in isolated worlds. | 473 // ScriptPromiseProperty can vend Promises in isolated worlds. |
471 return ScriptPromise::rejectWithDOMException( | 474 return ScriptPromise::rejectWithDOMException( |
472 callerState, | 475 callerState, |
473 DOMException::create(NotSupportedError, | 476 DOMException::create(NotSupportedError, |
474 "'ready' is only supported in pages.")); | 477 "'ready' is only supported in pages.")); |
475 } | 478 } |
476 | 479 |
477 if (!m_ready) { | 480 if (!m_ready) { |
478 m_ready = createReadyProperty(); | 481 m_ready = createReadyProperty(); |
479 if (m_provider) | 482 if (m_provider) { |
480 m_provider->getRegistrationForReady( | 483 m_provider->getRegistrationForReady( |
481 new GetRegistrationForReadyCallback(m_ready.get())); | 484 WTF::makeUnique<GetRegistrationForReadyCallback>(m_ready.get())); |
| 485 } |
482 } | 486 } |
483 | 487 |
484 return m_ready->promise(callerState->world()); | 488 return m_ready->promise(callerState->world()); |
485 } | 489 } |
486 | 490 |
487 void ServiceWorkerContainer::setController( | 491 void ServiceWorkerContainer::setController( |
488 std::unique_ptr<WebServiceWorker::Handle> handle, | 492 std::unique_ptr<WebServiceWorker::Handle> handle, |
489 bool shouldNotifyControllerChange) { | 493 bool shouldNotifyControllerChange) { |
490 if (!getExecutionContext()) | 494 if (!getExecutionContext()) |
491 return; | 495 return; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 | 531 |
528 if (ServiceWorkerContainerClient* client = | 532 if (ServiceWorkerContainerClient* client = |
529 ServiceWorkerContainerClient::from(executionContext)) { | 533 ServiceWorkerContainerClient::from(executionContext)) { |
530 m_provider = client->provider(); | 534 m_provider = client->provider(); |
531 if (m_provider) | 535 if (m_provider) |
532 m_provider->setClient(this); | 536 m_provider->setClient(this); |
533 } | 537 } |
534 } | 538 } |
535 | 539 |
536 } // namespace blink | 540 } // namespace blink |
OLD | NEW |