| 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/NavigatorServiceWorker.h" | 31 #include "modules/serviceworkers/NavigatorServiceWorker.h" |
| 32 | 32 |
| 33 #include "RuntimeEnabledFeatures.h" | 33 #include "RuntimeEnabledFeatures.h" |
| 34 #include "V8ServiceWorker.h" | 34 #include "V8ServiceWorker.h" |
| 35 #include "bindings/V8DOMError.h" |
| 35 #include "bindings/v8/CallbackPromiseAdapter.h" | 36 #include "bindings/v8/CallbackPromiseAdapter.h" |
| 36 #include "bindings/v8/ScriptPromiseResolver.h" | 37 #include "bindings/v8/ScriptPromiseResolver.h" |
| 37 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
| 38 #include "core/dom/ExceptionCode.h" | 39 #include "core/dom/ExceptionCode.h" |
| 39 #include "core/dom/ExecutionContext.h" | 40 #include "core/dom/ExecutionContext.h" |
| 40 #include "core/frame/Frame.h" | 41 #include "core/frame/Frame.h" |
| 41 #include "core/frame/Navigator.h" | 42 #include "core/frame/Navigator.h" |
| 42 #include "core/loader/DocumentLoader.h" | 43 #include "core/loader/DocumentLoader.h" |
| 43 #include "core/loader/FrameLoaderClient.h" | 44 #include "core/loader/FrameLoaderClient.h" |
| 44 #include "core/workers/SharedWorker.h" | 45 #include "core/workers/SharedWorker.h" |
| 45 #include "modules/serviceworkers/ServiceWorker.h" | 46 #include "modules/serviceworkers/ServiceWorker.h" |
| 47 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 46 #include "public/platform/WebServiceWorkerProvider.h" | 48 #include "public/platform/WebServiceWorkerProvider.h" |
| 47 #include "public/platform/WebServiceWorkerProviderClient.h" | 49 #include "public/platform/WebServiceWorkerProviderClient.h" |
| 48 #include "public/platform/WebString.h" | 50 #include "public/platform/WebString.h" |
| 49 #include "public/platform/WebURL.h" | 51 #include "public/platform/WebURL.h" |
| 50 | 52 |
| 51 using WebKit::WebServiceWorkerProvider; | 53 using WebKit::WebServiceWorkerProvider; |
| 52 using WebKit::WebString; | 54 using WebKit::WebString; |
| 53 | 55 |
| 54 namespace WebCore { | 56 namespace WebCore { |
| 55 | 57 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 94 } |
| 93 | 95 |
| 94 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ExecutionContext* co
ntext, Navigator* navigator, const String& pattern, const String& url, Exception
State& es) | 96 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ExecutionContext* co
ntext, Navigator* navigator, const String& pattern, const String& url, Exception
State& es) |
| 95 { | 97 { |
| 96 return from(navigator)->registerServiceWorker(context, pattern, url, es); | 98 return from(navigator)->registerServiceWorker(context, pattern, url, es); |
| 97 } | 99 } |
| 98 | 100 |
| 99 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ExecutionContext* ex
ecutionContext, const String& pattern, const String& scriptSrc, ExceptionState&
es) | 101 ScriptPromise NavigatorServiceWorker::registerServiceWorker(ExecutionContext* ex
ecutionContext, const String& pattern, const String& scriptSrc, ExceptionState&
es) |
| 100 { | 102 { |
| 101 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 103 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 104 ScriptPromise promise = ScriptPromise::createPending(executionContext); |
| 105 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); |
| 106 |
| 102 Frame* frame = m_navigator->frame(); | 107 Frame* frame = m_navigator->frame(); |
| 103 | |
| 104 if (!frame) { | 108 if (!frame) { |
| 105 es.throwDOMException(InvalidStateError, "No document available."); | 109 resolver->reject(DOMError::create(InvalidStateError, "No document availa
ble.")); |
| 106 return ScriptPromise(); | 110 return promise; |
| 107 } | 111 } |
| 108 | 112 |
| 109 RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); | 113 RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); |
| 110 | 114 |
| 111 KURL patternURL = executionContext->completeURL(pattern); | 115 KURL patternURL = executionContext->completeURL(pattern); |
| 112 if (documentOrigin->canRequest(patternURL)) { | 116 if (!documentOrigin->canRequest(patternURL)) { |
| 113 es.throwSecurityError("Can only register for patterns in the document's
origin."); | 117 resolver->reject(DOMError::create(SecurityError, "Can only register for
patterns in the document's origin.")); |
| 114 return ScriptPromise(); | 118 return promise; |
| 115 } | 119 } |
| 116 | 120 |
| 117 KURL scriptURL = executionContext->completeURL(scriptSrc); | 121 KURL scriptURL = executionContext->completeURL(scriptSrc); |
| 118 if (documentOrigin->canRequest(scriptURL)) { | 122 if (!documentOrigin->canRequest(scriptURL)) { |
| 119 es.throwSecurityError("Script must be in document's origin."); | 123 resolver->reject(DOMError::create(SecurityError, "Script must be in docu
ment's origin.")); |
| 120 return ScriptPromise(); | 124 return promise; |
| 121 } | 125 } |
| 122 | 126 |
| 123 ScriptPromise promise = ScriptPromise::createPending(executionContext); | 127 ensureProvider()->registerServiceWorker(patternURL, scriptURL, new CallbackP
romiseAdapter<ServiceWorker, ServiceWorkerError>(resolver, executionContext)); |
| 124 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); | |
| 125 ensureProvider()->registerServiceWorker(patternURL, scriptURL, new CallbackP
romiseAdapter<ServiceWorker, ServiceWorker>(resolver, executionContext)); | |
| 126 return promise; | 128 return promise; |
| 127 } | 129 } |
| 128 | 130 |
| 129 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ExecutionContext*
context, Navigator* navigator, const String& pattern, ExceptionState& es) | 131 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ExecutionContext*
context, Navigator* navigator, const String& pattern, ExceptionState& es) |
| 130 { | 132 { |
| 131 return from(navigator)->unregisterServiceWorker(context, pattern, es); | 133 return from(navigator)->unregisterServiceWorker(context, pattern, es); |
| 132 } | 134 } |
| 133 | 135 |
| 134 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ExecutionContext*
executionContext, const String& pattern, ExceptionState& es) | 136 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ExecutionContext*
executionContext, const String& pattern, ExceptionState& es) |
| 135 { | 137 { |
| 136 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); | 138 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); |
| 139 ScriptPromise promise = ScriptPromise::createPending(executionContext); |
| 140 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); |
| 141 |
| 137 Frame* frame = m_navigator->frame(); | 142 Frame* frame = m_navigator->frame(); |
| 138 if (!frame) { | 143 if (!frame) { |
| 139 es.throwDOMException(InvalidStateError, "No document available."); | 144 resolver->reject(DOMError::create(InvalidStateError, "No document availa
ble.")); |
| 140 return ScriptPromise(); | 145 return promise; |
| 141 } | 146 } |
| 142 | 147 |
| 143 RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); | 148 RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); |
| 144 | 149 |
| 145 KURL patternURL = executionContext->completeURL(pattern); | 150 KURL patternURL = executionContext->completeURL(pattern); |
| 146 if (documentOrigin->canRequest(patternURL)) { | 151 if (!documentOrigin->canRequest(patternURL)) { |
| 147 es.throwSecurityError("Can only unregister for patterns in the document'
s origin."); | 152 resolver->reject(DOMError::create(SecurityError, "Can only unregister fo
r patterns in the document's origin.")); |
| 148 return ScriptPromise(); | 153 |
| 154 return promise; |
| 149 } | 155 } |
| 150 | 156 |
| 151 ScriptPromise promise = ScriptPromise::createPending(executionContext); | 157 ensureProvider()->unregisterServiceWorker(patternURL, new CallbackPromiseAda
pter<ServiceWorker, ServiceWorkerError>(resolver, executionContext)); |
| 152 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); | |
| 153 ensureProvider()->unregisterServiceWorker(patternURL, new CallbackPromiseAda
pter<ServiceWorker, ServiceWorker>(resolver, executionContext)); | |
| 154 return promise; | 158 return promise; |
| 155 } | 159 } |
| 156 | 160 |
| 157 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() | 161 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() |
| 158 { | 162 { |
| 159 m_provider = nullptr; | 163 m_provider = nullptr; |
| 160 DOMWindowProperty::willDetachGlobalObjectFromFrame(); | 164 DOMWindowProperty::willDetachGlobalObjectFromFrame(); |
| 161 } | 165 } |
| 162 | 166 |
| 163 | 167 |
| 164 } // namespace WebCore | 168 } // namespace WebCore |
| OLD | NEW |