Index: Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp |
diff --git a/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp b/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp |
index ce9d7cfcef6e5a27c13fc0978000f1db1960b23b..62bf2724d9b773815f8f79dd20f6eb0804c470b1 100644 |
--- a/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp |
+++ b/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp |
@@ -32,9 +32,12 @@ |
#include "CachePolyfill.h" |
#include "FetchPolyfill.h" |
+#include "bindings/v8/ScriptPromiseResolver.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" |
@@ -58,6 +61,7 @@ PassRefPtrWillBeRawPtr<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::creat |
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); |
} |
@@ -66,11 +70,36 @@ 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()) { |
+ RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
yhirano
2014/06/11 09:10:49
[opt] You can use ScriptPromise::reject, if you pr
horo
2014/06/11 11:22:12
Done.
|
+ ScriptPromise promise = resolver->promise(); |
+ resolver->reject(V8ThrowException::createTypeError("Invalid URL", scriptState->isolate())); |
+ return promise; |
+ } |
+ OwnPtr<ResourceRequest> resourceRequest = adoptPtr(new ResourceRequest(url)); |
+ resourceRequest->setHTTPMethod("GET"); |
+ return m_fetchManager->fetch(scriptState, resourceRequest.release()); |
+} |
+ |
PassRefPtr<ServiceWorkerClients> ServiceWorkerGlobalScope::clients() |
{ |
if (!m_clients) |