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