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 15 matching lines...) Expand all Loading... |
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/FetchPolyfill.h" | 44 #include "modules/FetchPolyfill.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 WebCore { | 55 namespace WebCore { |
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 20 matching lines...) Expand all Loading... |
82 m_fetchManager.clear(); | 83 m_fetchManager.clear(); |
83 } | 84 } |
84 | 85 |
85 String ServiceWorkerGlobalScope::scope(ExecutionContext* context) | 86 String ServiceWorkerGlobalScope::scope(ExecutionContext* context) |
86 { | 87 { |
87 return ServiceWorkerGlobalScopeClient::from(context)->scope().string(); | 88 return ServiceWorkerGlobalScopeClient::from(context)->scope().string(); |
88 } | 89 } |
89 | 90 |
90 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, Request*
request) | 91 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, Request*
request) |
91 { | 92 { |
92 OwnPtr<ResourceRequest> resourceRequest(request->createResourceRequest()); | 93 if (!m_fetchManager) |
93 resourceRequest->setRequestContext(blink::WebURLRequest::RequestContextFetch
); | 94 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror("ServiceWorkerGlobalScope is shutting down.", scriptState->isolate())); |
94 return m_fetchManager->fetch(scriptState, resourceRequest.release()); | 95 // "Let |r| be the associated request of the result of invoking the initial |
| 96 // value of Request as constructor with |input| and |init| as arguments. If |
| 97 // this throws an exception, reject |p| with it." |
| 98 TrackExceptionState exceptionState; |
| 99 RefPtr<Request> r = Request::create(this, request, exceptionState); |
| 100 if (exceptionState.hadException()) |
| 101 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(exceptionState.message(), scriptState->isolate())); |
| 102 return m_fetchManager->fetch(scriptState, r->request()); |
| 103 } |
| 104 |
| 105 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, Request*
request, const Dictionary& requestInit) |
| 106 { |
| 107 if (!m_fetchManager) |
| 108 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror("ServiceWorkerGlobalScope is shutting down.", scriptState->isolate())); |
| 109 // "Let |r| be the associated request of the result of invoking the initial |
| 110 // value of Request as constructor with |input| and |init| as arguments. If |
| 111 // this throws an exception, reject |p| with it." |
| 112 TrackExceptionState exceptionState; |
| 113 RefPtr<Request> r = Request::create(this, request, requestInit, exceptionSta
te); |
| 114 if (exceptionState.hadException()) |
| 115 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(exceptionState.message(), scriptState->isolate())); |
| 116 return m_fetchManager->fetch(scriptState, r->request()); |
95 } | 117 } |
96 | 118 |
97 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, const St
ring& urlstring) | 119 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, const St
ring& urlstring) |
98 { | 120 { |
99 KURL url = completeURL(urlstring); | 121 if (!m_fetchManager) |
100 if (!url.isValid()) | 122 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror("ServiceWorkerGlobalScope is shutting down.", scriptState->isolate())); |
101 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror("Invalid URL", scriptState->isolate())); | 123 // "Let |r| be the associated request of the result of invoking the initial |
102 OwnPtr<ResourceRequest> resourceRequest = adoptPtr(new ResourceRequest(url))
; | 124 // value of Request as constructor with |input| and |init| as arguments. If |
103 resourceRequest->setRequestContext(blink::WebURLRequest::RequestContextFetch
); | 125 // this throws an exception, reject |p| with it." |
104 resourceRequest->setHTTPMethod("GET"); | 126 TrackExceptionState exceptionState; |
105 return m_fetchManager->fetch(scriptState, resourceRequest.release()); | 127 RefPtr<Request> r = Request::create(this, urlstring, exceptionState); |
| 128 if (exceptionState.hadException()) |
| 129 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(exceptionState.message(), scriptState->isolate())); |
| 130 return m_fetchManager->fetch(scriptState, r->request()); |
| 131 } |
| 132 |
| 133 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, const St
ring& urlstring, const Dictionary& requestInit) |
| 134 { |
| 135 if (!m_fetchManager) |
| 136 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror("ServiceWorkerGlobalScope is shutting down.", scriptState->isolate())); |
| 137 // "Let |r| be the associated request of the result of invoking the initial |
| 138 // value of Request as constructor with |input| and |init| as arguments. If |
| 139 // this throws an exception, reject |p| with it." |
| 140 TrackExceptionState exceptionState; |
| 141 RefPtr<Request> r = Request::create(this, urlstring, requestInit, exceptionS
tate); |
| 142 if (exceptionState.hadException()) |
| 143 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(exceptionState.message(), scriptState->isolate())); |
| 144 return m_fetchManager->fetch(scriptState, r->request()); |
106 } | 145 } |
107 | 146 |
108 PassRefPtrWillBeRawPtr<ServiceWorkerClients> ServiceWorkerGlobalScope::clients() | 147 PassRefPtrWillBeRawPtr<ServiceWorkerClients> ServiceWorkerGlobalScope::clients() |
109 { | 148 { |
110 if (!m_clients) | 149 if (!m_clients) |
111 m_clients = ServiceWorkerClients::create(); | 150 m_clients = ServiceWorkerClients::create(); |
112 return m_clients; | 151 return m_clients; |
113 } | 152 } |
114 | 153 |
115 const AtomicString& ServiceWorkerGlobalScope::interfaceName() const | 154 const AtomicString& ServiceWorkerGlobalScope::interfaceName() const |
116 { | 155 { |
117 return EventTargetNames::ServiceWorkerGlobalScope; | 156 return EventTargetNames::ServiceWorkerGlobalScope; |
118 } | 157 } |
119 | 158 |
120 void ServiceWorkerGlobalScope::trace(Visitor* visitor) | 159 void ServiceWorkerGlobalScope::trace(Visitor* visitor) |
121 { | 160 { |
122 visitor->trace(m_clients); | 161 visitor->trace(m_clients); |
123 WorkerGlobalScope::trace(visitor); | 162 WorkerGlobalScope::trace(visitor); |
124 } | 163 } |
125 | 164 |
126 void ServiceWorkerGlobalScope::logExceptionToConsole(const String& errorMessage,
const String& sourceURL, int lineNumber, int columnNumber, PassRefPtrWillBeRawP
tr<ScriptCallStack> callStack) | 165 void ServiceWorkerGlobalScope::logExceptionToConsole(const String& errorMessage,
const String& sourceURL, int lineNumber, int columnNumber, PassRefPtrWillBeRawP
tr<ScriptCallStack> callStack) |
127 { | 166 { |
128 WorkerGlobalScope::logExceptionToConsole(errorMessage, sourceURL, lineNumber
, columnNumber, callStack); | 167 WorkerGlobalScope::logExceptionToConsole(errorMessage, sourceURL, lineNumber
, columnNumber, callStack); |
129 addMessageToWorkerConsole(JSMessageSource, ErrorMessageLevel, errorMessage,
sourceURL, lineNumber, callStack, 0); | 168 addMessageToWorkerConsole(JSMessageSource, ErrorMessageLevel, errorMessage,
sourceURL, lineNumber, callStack, 0); |
130 } | 169 } |
131 | 170 |
132 } // namespace WebCore | 171 } // namespace WebCore |
OLD | NEW |