Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: Source/modules/serviceworkers/NavigatorServiceWorker.cpp

Issue 27278002: Add an Error class for ServiceWorkers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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/ScriptExecutionContext.h" 40 #include "core/dom/ScriptExecutionContext.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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return ScriptPromise(); 116 return ScriptPromise();
115 } 117 }
116 118
117 KURL scriptURL = scriptExecutionContext->completeURL(scriptSrc); 119 KURL scriptURL = scriptExecutionContext->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 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext); 125 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext);
124 ensureProvider()->registerServiceWorker(patternURL, scriptURL, new CallbackP romiseAdapter<ServiceWorker, ServiceWorker>(resolver, scriptExecutionContext)); 126 ensureProvider()->registerServiceWorker(patternURL, scriptURL, new CallbackP romiseAdapter<ServiceWorker, ServiceWorkerError>(resolver, scriptExecutionContex t));
125 return resolver->promise(); 127 return resolver->promise();
126 } 128 }
127 129
128 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* context, Navigator* navigator, const String& pattern, ExceptionState& es) 130 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* context, Navigator* navigator, const String& pattern, ExceptionState& es)
129 { 131 {
130 return from(navigator)->unregisterServiceWorker(context, pattern, es); 132 return from(navigator)->unregisterServiceWorker(context, pattern, es);
131 } 133 }
132 134
133 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* scriptExecutionContext, const String& pattern, ExceptionState& es) 135 ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon text* scriptExecutionContext, const String& pattern, ExceptionState& es)
134 { 136 {
135 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled()); 137 ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
136 Frame* frame = m_navigator->frame(); 138 Frame* frame = m_navigator->frame();
137 if (!frame) { 139 if (!frame) {
138 es.throwDOMException(InvalidStateError, "No document available."); 140 es.throwDOMException(InvalidStateError, "No document available.");
139 return ScriptPromise(); 141 return ScriptPromise();
140 } 142 }
141 143
142 RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); 144 RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin();
143 145
144 KURL patternURL = scriptExecutionContext->completeURL(pattern); 146 KURL patternURL = scriptExecutionContext->completeURL(pattern);
145 if (documentOrigin->canRequest(patternURL)) { 147 if (documentOrigin->canRequest(patternURL)) {
146 es.throwSecurityError("Can only unregister for patterns in the document' s origin."); 148 es.throwSecurityError("Can only unregister for patterns in the document' s origin.");
147 return ScriptPromise(); 149 return ScriptPromise();
148 } 150 }
149 151
150 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext); 152 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tExecutionContext);
151 ensureProvider()->unregisterServiceWorker(patternURL, new CallbackPromiseAda pter<ServiceWorker, ServiceWorker>(resolver, scriptExecutionContext)); 153 ensureProvider()->unregisterServiceWorker(patternURL, new CallbackPromiseAda pter<ServiceWorker, ServiceWorkerError>(resolver, scriptExecutionContext));
152 return resolver->promise(); 154 return resolver->promise();
153 } 155 }
154 156
155 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame() 157 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame()
156 { 158 {
157 m_provider = nullptr; 159 m_provider = nullptr;
158 DOMWindowProperty::willDetachGlobalObjectFromFrame(); 160 DOMWindowProperty::willDetachGlobalObjectFromFrame();
159 } 161 }
160 162
161 163
162 } // namespace WebCore 164 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | Source/modules/serviceworkers/ServiceWorkerError.h » ('j') | Source/modules/serviceworkers/ServiceWorkerError.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698