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

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

Issue 399543002: [ServiceWorker] Make fetch() method better conformance with the spec. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: incorporated falken's comment Created 6 years, 5 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
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 15 matching lines...) Expand all
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 "ServiceWorkerGlobalScope.h" 31 #include "ServiceWorkerGlobalScope.h"
32 32
33 #include "bindings/core/v8/ScriptPromise.h" 33 #include "bindings/core/v8/ScriptPromise.h"
34 #include "bindings/core/v8/ScriptState.h" 34 #include "bindings/core/v8/ScriptState.h"
35 #include "bindings/core/v8/V8ThrowException.h" 35 #include "bindings/core/v8/V8ThrowException.h"
36 #include "core/fetch/ResourceLoaderOptions.h"
36 #include "core/inspector/ScriptCallStack.h" 37 #include "core/inspector/ScriptCallStack.h"
38 #include "core/loader/ThreadableLoader.h"
37 #include "core/workers/WorkerClients.h" 39 #include "core/workers/WorkerClients.h"
38 #include "core/workers/WorkerThreadStartupData.h" 40 #include "core/workers/WorkerThreadStartupData.h"
39 #include "modules/CachePolyfill.h" 41 #include "modules/CachePolyfill.h"
40 #include "modules/CacheStoragePolyfill.h" 42 #include "modules/CacheStoragePolyfill.h"
41 #include "modules/EventTargetModules.h" 43 #include "modules/EventTargetModules.h"
42 #include "modules/serviceworkers/CacheStorage.h" 44 #include "modules/serviceworkers/CacheStorage.h"
43 #include "modules/serviceworkers/FetchManager.h" 45 #include "modules/serviceworkers/FetchManager.h"
44 #include "modules/serviceworkers/Request.h" 46 #include "modules/serviceworkers/Request.h"
45 #include "modules/serviceworkers/ServiceWorkerClients.h" 47 #include "modules/serviceworkers/ServiceWorkerClients.h"
46 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" 48 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
47 #include "modules/serviceworkers/ServiceWorkerThread.h" 49 #include "modules/serviceworkers/ServiceWorkerThread.h"
48 #include "platform/network/ResourceRequest.h" 50 #include "platform/network/ResourceRequest.h"
49 #include "platform/weborigin/KURL.h" 51 #include "platform/weborigin/KURL.h"
50 #include "public/platform/WebURL.h" 52 #include "public/platform/WebURL.h"
51 #include "public/platform/WebURLRequest.h"
52 #include "wtf/CurrentTime.h" 53 #include "wtf/CurrentTime.h"
53 54
54 namespace blink { 55 namespace blink {
55 56
56 PassRefPtrWillBeRawPtr<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::creat e(ServiceWorkerThread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> s tartupData) 57 PassRefPtrWillBeRawPtr<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::creat e(ServiceWorkerThread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> s tartupData)
57 { 58 {
58 RefPtrWillBeRawPtr<ServiceWorkerGlobalScope> context = adoptRefWillBeRefCoun tedGarbageCollected(new ServiceWorkerGlobalScope(startupData->m_scriptURL, start upData->m_userAgent, thread, monotonicallyIncreasingTime(), startupData->m_worke rClients.release())); 59 RefPtrWillBeRawPtr<ServiceWorkerGlobalScope> context = adoptRefWillBeRefCoun tedGarbageCollected(new ServiceWorkerGlobalScope(startupData->m_scriptURL, start upData->m_userAgent, thread, monotonicallyIncreasingTime(), startupData->m_worke rClients.release()));
59 60
60 context->applyContentSecurityPolicyFromString(startupData->m_contentSecurity Policy, startupData->m_contentSecurityPolicyType); 61 context->applyContentSecurityPolicyFromString(startupData->m_contentSecurity Policy, startupData->m_contentSecurityPolicyType);
61 62
(...skipping 26 matching lines...) Expand all
88 89
89 PassRefPtrWillBeRawPtr<CacheStorage> ServiceWorkerGlobalScope::caches(ExecutionC ontext* context) 90 PassRefPtrWillBeRawPtr<CacheStorage> ServiceWorkerGlobalScope::caches(ExecutionC ontext* context)
90 { 91 {
91 if (!m_cacheStorage) 92 if (!m_cacheStorage)
92 m_cacheStorage = CacheStorage::create(); 93 m_cacheStorage = CacheStorage::create();
93 return m_cacheStorage; 94 return m_cacheStorage;
94 } 95 }
95 96
96 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, Request* request) 97 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, Request* request)
97 { 98 {
98 OwnPtr<ResourceRequest> resourceRequest(request->createResourceRequest()); 99 if (!m_fetchManager)
99 resourceRequest->setRequestContext(blink::WebURLRequest::RequestContextFetch ); 100 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("ServiceWorkerGlobalScope is shutting down.", scriptState->isolate()));
100 return m_fetchManager->fetch(scriptState, resourceRequest.release()); 101 // "Let |r| be the associated request of the result of invoking the initial
102 // value of Request as constructor with |input| and |init| as arguments. If
103 // this throws an exception, reject |p| with it."
104 TrackExceptionState exceptionState;
105 RefPtr<Request> r = Request::create(this, request, exceptionState);
106 if (exceptionState.hadException()) {
107 // FIXME: We should throw the caught error.
108 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(exceptionState.message(), scriptState->isolate()));
109 }
110 return m_fetchManager->fetch(scriptState, r->request());
111 }
112
113 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, Request* request, const Dictionary& requestInit)
114 {
115 if (!m_fetchManager)
116 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("ServiceWorkerGlobalScope is shutting down.", scriptState->isolate()));
117 // "Let |r| be the associated request of the result of invoking the initial
118 // value of Request as constructor with |input| and |init| as arguments. If
119 // this throws an exception, reject |p| with it."
120 TrackExceptionState exceptionState;
121 RefPtr<Request> r = Request::create(this, request, requestInit, exceptionSta te);
122 if (exceptionState.hadException()) {
123 // FIXME: We should throw the caught error.
124 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(exceptionState.message(), scriptState->isolate()));
125 }
126 return m_fetchManager->fetch(scriptState, r->request());
101 } 127 }
102 128
103 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, const St ring& urlstring) 129 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, const St ring& urlstring)
104 { 130 {
105 KURL url = completeURL(urlstring); 131 if (!m_fetchManager)
106 if (!url.isValid()) 132 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("ServiceWorkerGlobalScope is shutting down.", scriptState->isolate()));
107 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("Invalid URL", scriptState->isolate())); 133 // "Let |r| be the associated request of the result of invoking the initial
108 OwnPtr<ResourceRequest> resourceRequest = adoptPtr(new ResourceRequest(url)) ; 134 // value of Request as constructor with |input| and |init| as arguments. If
109 resourceRequest->setRequestContext(blink::WebURLRequest::RequestContextFetch ); 135 // this throws an exception, reject |p| with it."
110 resourceRequest->setHTTPMethod("GET"); 136 TrackExceptionState exceptionState;
111 return m_fetchManager->fetch(scriptState, resourceRequest.release()); 137 RefPtr<Request> r = Request::create(this, urlstring, exceptionState);
138 if (exceptionState.hadException()) {
139 // FIXME: We should throw the caught error.
140 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(exceptionState.message(), scriptState->isolate()));
141 }
142 return m_fetchManager->fetch(scriptState, r->request());
143 }
144
145 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, const St ring& urlstring, const Dictionary& requestInit)
146 {
147 if (!m_fetchManager)
148 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("ServiceWorkerGlobalScope is shutting down.", scriptState->isolate()));
149 // "Let |r| be the associated request of the result of invoking the initial
150 // value of Request as constructor with |input| and |init| as arguments. If
151 // this throws an exception, reject |p| with it."
152 TrackExceptionState exceptionState;
153 RefPtr<Request> r = Request::create(this, urlstring, requestInit, exceptionS tate);
154 if (exceptionState.hadException()) {
155 // FIXME: We should throw the caught error.
156 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(exceptionState.message(), scriptState->isolate()));
157 }
158 return m_fetchManager->fetch(scriptState, r->request());
112 } 159 }
113 160
114 PassRefPtrWillBeRawPtr<ServiceWorkerClients> ServiceWorkerGlobalScope::clients() 161 PassRefPtrWillBeRawPtr<ServiceWorkerClients> ServiceWorkerGlobalScope::clients()
115 { 162 {
116 if (!m_clients) 163 if (!m_clients)
117 m_clients = ServiceWorkerClients::create(); 164 m_clients = ServiceWorkerClients::create();
118 return m_clients; 165 return m_clients;
119 } 166 }
120 167
121 const AtomicString& ServiceWorkerGlobalScope::interfaceName() const 168 const AtomicString& ServiceWorkerGlobalScope::interfaceName() const
122 { 169 {
123 return EventTargetNames::ServiceWorkerGlobalScope; 170 return EventTargetNames::ServiceWorkerGlobalScope;
124 } 171 }
125 172
126 void ServiceWorkerGlobalScope::trace(Visitor* visitor) 173 void ServiceWorkerGlobalScope::trace(Visitor* visitor)
127 { 174 {
128 visitor->trace(m_clients); 175 visitor->trace(m_clients);
129 visitor->trace(m_cacheStorage); 176 visitor->trace(m_cacheStorage);
130 WorkerGlobalScope::trace(visitor); 177 WorkerGlobalScope::trace(visitor);
131 } 178 }
132 179
133 void ServiceWorkerGlobalScope::logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, PassRefPtrWillBeRawP tr<ScriptCallStack> callStack) 180 void ServiceWorkerGlobalScope::logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, PassRefPtrWillBeRawP tr<ScriptCallStack> callStack)
134 { 181 {
135 WorkerGlobalScope::logExceptionToConsole(errorMessage, sourceURL, lineNumber , columnNumber, callStack); 182 WorkerGlobalScope::logExceptionToConsole(errorMessage, sourceURL, lineNumber , columnNumber, callStack);
136 addMessageToWorkerConsole(JSMessageSource, ErrorMessageLevel, errorMessage, sourceURL, lineNumber, callStack, 0); 183 addMessageToWorkerConsole(JSMessageSource, ErrorMessageLevel, errorMessage, sourceURL, lineNumber, callStack, 0);
137 } 184 }
138 185
139 } // namespace blink 186 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerGlobalScope.h ('k') | Source/modules/serviceworkers/ServiceWorkerGlobalScope.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698