| 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 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 #include "config.h" | 30 #include "config.h" |
| 31 #include "modules/serviceworkers/ServiceWorkerContainer.h" | 31 #include "modules/serviceworkers/ServiceWorkerContainer.h" |
| 32 | 32 |
| 33 #include "RuntimeEnabledFeatures.h" | 33 #include "RuntimeEnabledFeatures.h" |
| 34 #include "bindings/v8/CallbackPromiseAdapter.h" | 34 #include "bindings/v8/CallbackPromiseAdapter.h" |
| 35 #include "bindings/v8/ScriptPromiseResolver.h" | 35 #include "bindings/v8/NewScriptState.h" |
| 36 #include "bindings/v8/ScriptPromiseResolverWithContext.h" |
| 36 #include "core/dom/ExecutionContext.h" | 37 #include "core/dom/ExecutionContext.h" |
| 37 #include "modules/serviceworkers/RegistrationOptionList.h" | 38 #include "modules/serviceworkers/RegistrationOptionList.h" |
| 38 #include "modules/serviceworkers/ServiceWorker.h" | 39 #include "modules/serviceworkers/ServiceWorker.h" |
| 39 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 40 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
| 40 #include "modules/serviceworkers/ServiceWorkerError.h" | 41 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 41 #include "public/platform/WebServiceWorkerProvider.h" | 42 #include "public/platform/WebServiceWorkerProvider.h" |
| 42 #include "public/platform/WebString.h" | 43 #include "public/platform/WebString.h" |
| 43 #include "public/platform/WebURL.h" | 44 #include "public/platform/WebURL.h" |
| 44 | 45 |
| 45 using blink::WebServiceWorkerProvider; | 46 using blink::WebServiceWorkerProvider; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 60 if (m_provider) { | 61 if (m_provider) { |
| 61 m_provider->setClient(0); | 62 m_provider->setClient(0); |
| 62 m_provider = 0; | 63 m_provider = 0; |
| 63 } | 64 } |
| 64 } | 65 } |
| 65 | 66 |
| 66 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ExecutionContext* ex
ecutionContext, const String& url, const Dictionary& dictionary) | 67 ScriptPromise ServiceWorkerContainer::registerServiceWorker(ExecutionContext* ex
ecutionContext, const String& url, const Dictionary& dictionary) |
| 67 { | 68 { |
| 68 RegistrationOptionList options(dictionary); | 69 RegistrationOptionList options(dictionary); |
| 69 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 70 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 70 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(execu
tionContext); | 71 RefPtr<ScriptPromiseResolverWithContext> resolver = ScriptPromiseResolverWit
hContext::create(NewScriptState::current(toIsolate(executionContext))); |
| 71 ScriptPromise promise = resolver->promise(); | 72 ScriptPromise promise = resolver->promise(); |
| 72 | 73 |
| 73 if (!m_provider) { | 74 if (!m_provider) { |
| 74 resolver->reject(DOMError::create(InvalidStateError, "No associated prov
ider is available")); | 75 resolver->reject(DOMError::create(InvalidStateError, "No associated prov
ider is available")); |
| 75 return promise; | 76 return promise; |
| 76 } | 77 } |
| 77 | 78 |
| 78 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 79 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
| 79 KURL patternURL = executionContext->completeURL(options.scope); | 80 KURL patternURL = executionContext->completeURL(options.scope); |
| 80 if (!documentOrigin->canRequest(patternURL)) { | 81 if (!documentOrigin->canRequest(patternURL)) { |
| 81 resolver->reject(DOMError::create(SecurityError, "Can only register for
patterns in the document's origin.")); | 82 resolver->reject(DOMError::create(SecurityError, "Can only register for
patterns in the document's origin.")); |
| 82 return promise; | 83 return promise; |
| 83 } | 84 } |
| 84 | 85 |
| 85 KURL scriptURL = executionContext->completeURL(url); | 86 KURL scriptURL = executionContext->completeURL(url); |
| 86 if (!documentOrigin->canRequest(scriptURL)) { | 87 if (!documentOrigin->canRequest(scriptURL)) { |
| 87 resolver->reject(DOMError::create(SecurityError, "Script must be in docu
ment's origin.")); | 88 resolver->reject(DOMError::create(SecurityError, "Script must be in docu
ment's origin.")); |
| 88 return promise; | 89 return promise; |
| 89 } | 90 } |
| 90 | 91 |
| 91 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise
Adapter<ServiceWorker, ServiceWorkerError>(resolver, executionContext)); | 92 m_provider->registerServiceWorker(patternURL, scriptURL, new CallbackPromise
Adapter<ServiceWorker, ServiceWorkerError>(resolver)); |
| 92 return promise; | 93 return promise; |
| 93 } | 94 } |
| 94 | 95 |
| 95 ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ExecutionContext*
executionContext, const String& pattern) | 96 ScriptPromise ServiceWorkerContainer::unregisterServiceWorker(ExecutionContext*
executionContext, const String& pattern) |
| 96 { | 97 { |
| 97 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 98 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 98 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(execu
tionContext); | 99 RefPtr<ScriptPromiseResolverWithContext> resolver = ScriptPromiseResolverWit
hContext::create(NewScriptState::current(toIsolate(executionContext))); |
| 99 ScriptPromise promise = resolver->promise(); | 100 ScriptPromise promise = resolver->promise(); |
| 100 | 101 |
| 101 if (!m_provider) { | 102 if (!m_provider) { |
| 102 resolver->reject(DOMError::create(InvalidStateError, "No associated prov
ider is available")); | 103 resolver->reject(DOMError::create(InvalidStateError, "No associated prov
ider is available")); |
| 103 return promise; | 104 return promise; |
| 104 } | 105 } |
| 105 | 106 |
| 106 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); | 107 RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
| 107 KURL patternURL = executionContext->completeURL(pattern); | 108 KURL patternURL = executionContext->completeURL(pattern); |
| 108 if (!pattern.isEmpty() && !documentOrigin->canRequest(patternURL)) { | 109 if (!pattern.isEmpty() && !documentOrigin->canRequest(patternURL)) { |
| 109 resolver->reject(DOMError::create(SecurityError, "Can only unregister fo
r patterns in the document's origin.")); | 110 resolver->reject(DOMError::create(SecurityError, "Can only unregister fo
r patterns in the document's origin.")); |
| 110 return promise; | 111 return promise; |
| 111 } | 112 } |
| 112 | 113 |
| 113 m_provider->unregisterServiceWorker(patternURL, new CallbackPromiseAdapter<S
erviceWorker, ServiceWorkerError>(resolver, executionContext)); | 114 m_provider->unregisterServiceWorker(patternURL, new CallbackPromiseAdapter<S
erviceWorker, ServiceWorkerError>(resolver)); |
| 114 return promise; | 115 return promise; |
| 115 } | 116 } |
| 116 | 117 |
| 117 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) | 118 ServiceWorkerContainer::ServiceWorkerContainer(ExecutionContext* executionContex
t) |
| 118 : m_provider(0) | 119 : m_provider(0) |
| 119 { | 120 { |
| 120 ScriptWrappable::init(this); | 121 ScriptWrappable::init(this); |
| 121 | 122 |
| 122 if (!executionContext) | 123 if (!executionContext) |
| 123 return; | 124 return; |
| 124 | 125 |
| 125 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { | 126 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) { |
| 126 m_provider = client->provider(); | 127 m_provider = client->provider(); |
| 127 if (m_provider) | 128 if (m_provider) |
| 128 m_provider->setClient(this); | 129 m_provider->setClient(this); |
| 129 } | 130 } |
| 130 } | 131 } |
| 131 | 132 |
| 132 } // namespace WebCore | 133 } // namespace WebCore |
| OLD | NEW |