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