| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } | 117 } |
| 116 | 118 |
| 117 KURL scriptURL = executionContext->completeURL(scriptSrc); | 119 KURL scriptURL = executionContext->completeURL(scriptSrc); |
| 118 if (documentOrigin->canRequest(scriptURL)) { | 120 if (documentOrigin->canRequest(scriptURL)) { |
| 119 es.throwSecurityError("Script must be in document's origin."); | 121 es.throwSecurityError("Script must be in document's origin."); |
| 120 return ScriptPromise(); | 122 return ScriptPromise(); |
| 121 } | 123 } |
| 122 | 124 |
| 123 ScriptPromise promise = ScriptPromise::createPending(executionContext); | 125 ScriptPromise promise = ScriptPromise::createPending(executionContext); |
| 124 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); | 126 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); |
| 125 ensureProvider()->registerServiceWorker(patternURL, scriptURL, new CallbackP
romiseAdapter<ServiceWorker, ServiceWorker>(resolver, executionContext)); | 127 ensureProvider()->registerServiceWorker(patternURL, scriptURL, new CallbackP
romiseAdapter<ServiceWorker, ServiceWorkerError>(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()); |
| 137 Frame* frame = m_navigator->frame(); | 139 Frame* frame = m_navigator->frame(); |
| 138 if (!frame) { | 140 if (!frame) { |
| 139 es.throwDOMException(InvalidStateError, "No document available."); | 141 es.throwDOMException(InvalidStateError, "No document available."); |
| 140 return ScriptPromise(); | 142 return ScriptPromise(); |
| 141 } | 143 } |
| 142 | 144 |
| 143 RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); | 145 RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); |
| 144 | 146 |
| 145 KURL patternURL = executionContext->completeURL(pattern); | 147 KURL patternURL = executionContext->completeURL(pattern); |
| 146 if (documentOrigin->canRequest(patternURL)) { | 148 if (documentOrigin->canRequest(patternURL)) { |
| 147 es.throwSecurityError("Can only unregister for patterns in the document'
s origin."); | 149 es.throwSecurityError("Can only unregister for patterns in the document'
s origin."); |
| 148 return ScriptPromise(); | 150 return ScriptPromise(); |
| 149 } | 151 } |
| 150 | 152 |
| 151 ScriptPromise promise = ScriptPromise::createPending(executionContext); | 153 ScriptPromise promise = ScriptPromise::createPending(executionContext); |
| 152 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); | 154 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, executionContext); |
| 153 ensureProvider()->unregisterServiceWorker(patternURL, new CallbackPromiseAda
pter<ServiceWorker, ServiceWorker>(resolver, executionContext)); | 155 ensureProvider()->unregisterServiceWorker(patternURL, new CallbackPromiseAda
pter<ServiceWorker, ServiceWorkerError>(resolver, executionContext)); |
| 154 return promise; | 156 return promise; |
| 155 } | 157 } |
| 156 | 158 |
| 157 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() | 159 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() |
| 158 { | 160 { |
| 159 m_provider = nullptr; | 161 m_provider = nullptr; |
| 160 DOMWindowProperty::willDetachGlobalObjectFromFrame(); | 162 DOMWindowProperty::willDetachGlobalObjectFromFrame(); |
| 161 } | 163 } |
| 162 | 164 |
| 163 | 165 |
| 164 } // namespace WebCore | 166 } // namespace WebCore |
| OLD | NEW |