diff options
Diffstat (limited to 'chromium/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp')
-rw-r--r-- | chromium/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/chromium/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp b/chromium/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp index 0f2041a2080..b5ea3f7c47f 100644 --- a/chromium/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp +++ b/chromium/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp @@ -30,25 +30,43 @@ #include "config.h" #include "ServiceWorkerGlobalScope.h" -#include "bindings/v8/ScriptObject.h" +#include "CachePolyfill.h" +#include "CacheStoragePolyfill.h" +#include "FetchPolyfill.h" +#include "bindings/v8/ScriptPromise.h" +#include "bindings/v8/ScriptState.h" +#include "bindings/v8/V8ThrowException.h" #include "core/workers/WorkerClients.h" #include "core/workers/WorkerThreadStartupData.h" +#include "modules/EventTargetModules.h" +#include "modules/serviceworkers/FetchManager.h" +#include "modules/serviceworkers/Request.h" +#include "modules/serviceworkers/ServiceWorkerClients.h" +#include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" #include "modules/serviceworkers/ServiceWorkerThread.h" +#include "platform/network/ResourceRequest.h" #include "platform/weborigin/KURL.h" +#include "public/platform/WebURL.h" #include "wtf/CurrentTime.h" namespace WebCore { -PassRefPtr<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::create(ServiceWorkerThread* thread, PassOwnPtr<WorkerThreadStartupData> startupData) +PassRefPtrWillBeRawPtr<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::create(ServiceWorkerThread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> startupData) { - RefPtr<ServiceWorkerGlobalScope> context = adoptRef(new ServiceWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAgent, thread, monotonicallyIncreasingTime(), startupData->m_workerClients.release())); + RefPtrWillBeRawPtr<ServiceWorkerGlobalScope> context = adoptRefWillBeRefCountedGarbageCollected(new ServiceWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAgent, thread, monotonicallyIncreasingTime(), startupData->m_workerClients.release())); context->applyContentSecurityPolicyFromString(startupData->m_contentSecurityPolicy, startupData->m_contentSecurityPolicyType); + + context->script()->evaluate(String(fetchPolyfillJs, sizeof(fetchPolyfillJs))); + context->script()->evaluate(String(cachePolyfillJs, sizeof(cachePolyfillJs))); + context->script()->evaluate(String(cacheStoragePolyfillJs, sizeof(cacheStoragePolyfillJs))); + return context.release(); } -ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const KURL& url, const String& userAgent, ServiceWorkerThread* thread, double timeOrigin, PassOwnPtr<WorkerClients> workerClients) : - WorkerGlobalScope(url, userAgent, thread, timeOrigin, workerClients) +ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const KURL& url, const String& userAgent, ServiceWorkerThread* thread, double timeOrigin, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients) + : WorkerGlobalScope(url, userAgent, thread, timeOrigin, workerClients) + , m_fetchManager(adoptPtr(new FetchManager(this))) { ScriptWrappable::init(this); } @@ -57,9 +75,47 @@ ServiceWorkerGlobalScope::~ServiceWorkerGlobalScope() { } +void ServiceWorkerGlobalScope::stopFetch() +{ + m_fetchManager.clear(); +} + +String ServiceWorkerGlobalScope::scope(ExecutionContext* context) +{ + return ServiceWorkerGlobalScopeClient::from(context)->scope().string(); +} + +ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, Request* request) +{ + OwnPtr<ResourceRequest> resourceRequest(request->createResourceRequest()); + return m_fetchManager->fetch(scriptState, resourceRequest.release()); +} + +ScriptPromise ServiceWorkerGlobalScope::fetch(ScriptState* scriptState, const String& urlstring) +{ + KURL url = completeURL(urlstring); + if (!url.isValid()) + return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError("Invalid URL", scriptState->isolate())); + OwnPtr<ResourceRequest> resourceRequest = adoptPtr(new ResourceRequest(url)); + resourceRequest->setHTTPMethod("GET"); + return m_fetchManager->fetch(scriptState, resourceRequest.release()); +} + +PassRefPtr<ServiceWorkerClients> ServiceWorkerGlobalScope::clients() +{ + if (!m_clients) + m_clients = ServiceWorkerClients::create(); + return m_clients; +} + const AtomicString& ServiceWorkerGlobalScope::interfaceName() const { return EventTargetNames::ServiceWorkerGlobalScope; } +void ServiceWorkerGlobalScope::trace(Visitor* visitor) +{ + WorkerGlobalScope::trace(visitor); +} + } // namespace WebCore |