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 "CachePolyfill.h" | 33 #include "CachePolyfill.h" |
34 #include "CacheStoragePolyfill.h" | 34 #include "CacheStoragePolyfill.h" |
35 #include "FetchPolyfill.h" | 35 #include "FetchPolyfill.h" |
| 36 #include "bindings/v8/ScriptPromise.h" |
| 37 #include "bindings/v8/ScriptState.h" |
| 38 #include "bindings/v8/V8ThrowException.h" |
36 #include "core/workers/WorkerClients.h" | 39 #include "core/workers/WorkerClients.h" |
37 #include "core/workers/WorkerThreadStartupData.h" | 40 #include "core/workers/WorkerThreadStartupData.h" |
38 #include "modules/EventTargetModules.h" | 41 #include "modules/EventTargetModules.h" |
| 42 #include "modules/serviceworkers/FetchManager.h" |
| 43 #include "modules/serviceworkers/Request.h" |
39 #include "modules/serviceworkers/ServiceWorkerClients.h" | 44 #include "modules/serviceworkers/ServiceWorkerClients.h" |
40 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 45 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
41 #include "modules/serviceworkers/ServiceWorkerThread.h" | 46 #include "modules/serviceworkers/ServiceWorkerThread.h" |
| 47 #include "platform/network/ResourceRequest.h" |
42 #include "platform/weborigin/KURL.h" | 48 #include "platform/weborigin/KURL.h" |
43 #include "public/platform/WebURL.h" | 49 #include "public/platform/WebURL.h" |
44 #include "wtf/CurrentTime.h" | 50 #include "wtf/CurrentTime.h" |
45 | 51 |
46 namespace WebCore { | 52 namespace WebCore { |
47 | 53 |
48 PassRefPtrWillBeRawPtr<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::creat
e(ServiceWorkerThread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> s
tartupData) | 54 PassRefPtrWillBeRawPtr<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::creat
e(ServiceWorkerThread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> s
tartupData) |
49 { | 55 { |
50 RefPtrWillBeRawPtr<ServiceWorkerGlobalScope> context = adoptRefWillBeRefCoun
tedGarbageCollected(new ServiceWorkerGlobalScope(startupData->m_scriptURL, start
upData->m_userAgent, thread, monotonicallyIncreasingTime(), startupData->m_worke
rClients.release())); | 56 RefPtrWillBeRawPtr<ServiceWorkerGlobalScope> context = adoptRefWillBeRefCoun
tedGarbageCollected(new ServiceWorkerGlobalScope(startupData->m_scriptURL, start
upData->m_userAgent, thread, monotonicallyIncreasingTime(), startupData->m_worke
rClients.release())); |
51 | 57 |
52 context->applyContentSecurityPolicyFromString(startupData->m_contentSecurity
Policy, startupData->m_contentSecurityPolicyType); | 58 context->applyContentSecurityPolicyFromString(startupData->m_contentSecurity
Policy, startupData->m_contentSecurityPolicyType); |
53 | 59 |
54 context->script()->evaluate(String(fetchPolyfillJs, sizeof(fetchPolyfillJs))
); | 60 context->script()->evaluate(String(fetchPolyfillJs, sizeof(fetchPolyfillJs))
); |
55 context->script()->evaluate(String(cachePolyfillJs, sizeof(cachePolyfillJs))
); | 61 context->script()->evaluate(String(cachePolyfillJs, sizeof(cachePolyfillJs))
); |
56 context->script()->evaluate(String(cacheStoragePolyfillJs, sizeof(cacheStora
gePolyfillJs))); | 62 context->script()->evaluate(String(cacheStoragePolyfillJs, sizeof(cacheStora
gePolyfillJs))); |
57 | 63 |
58 return context.release(); | 64 return context.release(); |
59 } | 65 } |
60 | 66 |
61 ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const KURL& url, const String
& userAgent, ServiceWorkerThread* thread, double timeOrigin, PassOwnPtrWillBeRaw
Ptr<WorkerClients> workerClients) | 67 ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const KURL& url, const String
& userAgent, ServiceWorkerThread* thread, double timeOrigin, PassOwnPtrWillBeRaw
Ptr<WorkerClients> workerClients) |
62 : WorkerGlobalScope(url, userAgent, thread, timeOrigin, workerClients) | 68 : WorkerGlobalScope(url, userAgent, thread, timeOrigin, workerClients) |
| 69 , m_fetchManager(adoptPtr(new FetchManager(this))) |
63 { | 70 { |
64 ScriptWrappable::init(this); | 71 ScriptWrappable::init(this); |
65 } | 72 } |
66 | 73 |
67 ServiceWorkerGlobalScope::~ServiceWorkerGlobalScope() | 74 ServiceWorkerGlobalScope::~ServiceWorkerGlobalScope() |
68 { | 75 { |
69 } | 76 } |
70 | 77 |
| 78 void ServiceWorkerGlobalScope::stopFetch() |
| 79 { |
| 80 m_fetchManager.clear(); |
| 81 } |
| 82 |
71 String ServiceWorkerGlobalScope::scope(ExecutionContext* context) | 83 String ServiceWorkerGlobalScope::scope(ExecutionContext* context) |
72 { | 84 { |
73 return ServiceWorkerGlobalScopeClient::from(context)->scope().string(); | 85 return ServiceWorkerGlobalScopeClient::from(context)->scope().string(); |
74 } | 86 } |
75 | 87 |
| 88 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, Request*
request) |
| 89 { |
| 90 OwnPtr<ResourceRequest> resourceRequest(request->createResourceRequest()); |
| 91 return m_fetchManager->fetch(scriptState, resourceRequest.release()); |
| 92 } |
| 93 |
| 94 ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, const St
ring& urlstring) |
| 95 { |
| 96 KURL url = completeURL(urlstring); |
| 97 if (!url.isValid()) |
| 98 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror("Invalid URL", scriptState->isolate())); |
| 99 OwnPtr<ResourceRequest> resourceRequest = adoptPtr(new ResourceRequest(url))
; |
| 100 resourceRequest->setHTTPMethod("GET"); |
| 101 return m_fetchManager->fetch(scriptState, resourceRequest.release()); |
| 102 } |
| 103 |
76 PassRefPtr<ServiceWorkerClients> ServiceWorkerGlobalScope::clients() | 104 PassRefPtr<ServiceWorkerClients> ServiceWorkerGlobalScope::clients() |
77 { | 105 { |
78 if (!m_clients) | 106 if (!m_clients) |
79 m_clients = ServiceWorkerClients::create(); | 107 m_clients = ServiceWorkerClients::create(); |
80 return m_clients; | 108 return m_clients; |
81 } | 109 } |
82 | 110 |
83 const AtomicString& ServiceWorkerGlobalScope::interfaceName() const | 111 const AtomicString& ServiceWorkerGlobalScope::interfaceName() const |
84 { | 112 { |
85 return EventTargetNames::ServiceWorkerGlobalScope; | 113 return EventTargetNames::ServiceWorkerGlobalScope; |
86 } | 114 } |
87 | 115 |
88 void ServiceWorkerGlobalScope::trace(Visitor* visitor) | 116 void ServiceWorkerGlobalScope::trace(Visitor* visitor) |
89 { | 117 { |
90 WorkerGlobalScope::trace(visitor); | 118 WorkerGlobalScope::trace(visitor); |
91 } | 119 } |
92 | 120 |
93 } // namespace WebCore | 121 } // namespace WebCore |
OLD | NEW |