Index: third_party/WebKit/Source/modules/background_fetch/BackgroundFetchManager.cpp |
diff --git a/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchManager.cpp b/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchManager.cpp |
index 27fabfcdbbd5b3b78f5878719ee0298e3428d57f..a1339f50c9bf2c09e144a890e6488f00270952ba 100644 |
--- a/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchManager.cpp |
+++ b/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchManager.cpp |
@@ -4,8 +4,11 @@ |
#include "modules/background_fetch/BackgroundFetchManager.h" |
+#include "bindings/core/v8/ScriptPromiseResolver.h" |
#include "bindings/core/v8/ScriptState.h" |
-#include "core/dom/DOMException.h" |
+#include "bindings/core/v8/V8ThrowException.h" |
+#include "modules/background_fetch/BackgroundFetchOptions.h" |
+#include "modules/background_fetch/BackgroundFetchRegistration.h" |
#include "modules/serviceworkers/ServiceWorkerRegistration.h" |
namespace blink { |
@@ -16,10 +19,70 @@ BackgroundFetchManager::BackgroundFetchManager( |
DCHECK(registration); |
} |
+ScriptPromise BackgroundFetchManager::fetch( |
+ ScriptState* scriptState, |
+ String tag, |
+ HeapVector<RequestOrUSVString> requests, |
+ const BackgroundFetchOptions& options) { |
+ if (!m_registration->active()) { |
+ return ScriptPromise::reject( |
+ scriptState, |
+ V8ThrowException::createTypeError(scriptState->isolate(), |
+ "No active registration available on " |
+ "the ServiceWorkerRegistration.")); |
+ } |
+ |
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
+ ScriptPromise promise = resolver->promise(); |
+ |
+ // TODO(peter): Register the fetch() with the browser process. The reject |
+ // cases there are storage errors and duplicated registrations for the `tag` |
+ // given the `m_registration`. |
+ BackgroundFetchRegistration* registration = new BackgroundFetchRegistration( |
+ m_registration.get(), tag, options.icons(), options.totalDownloadSize(), |
+ options.title()); |
+ |
+ resolver->resolve(registration); |
+ |
+ return promise; |
+} |
+ |
+ScriptPromise BackgroundFetchManager::get(ScriptState* scriptState, |
+ String tag) { |
+ if (!m_registration->active()) { |
+ return ScriptPromise::reject( |
+ scriptState, |
+ V8ThrowException::createTypeError(scriptState->isolate(), |
+ "No active registration available on " |
+ "the ServiceWorkerRegistration.")); |
+ } |
+ |
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
+ ScriptPromise promise = resolver->promise(); |
+ |
+ // TODO(peter): Get the background fetch registration for `tag` from the |
+ // browser process. There may not be one. |
+ resolver->resolve(v8::Null(scriptState->isolate())); |
+ |
+ return promise; |
+} |
+ |
ScriptPromise BackgroundFetchManager::getTags(ScriptState* scriptState) { |
- return ScriptPromise::rejectWithDOMException( |
- scriptState, |
- DOMException::create(NotSupportedError, "Not implemented yet.")); |
+ if (!m_registration->active()) { |
+ return ScriptPromise::reject( |
+ scriptState, |
+ V8ThrowException::createTypeError(scriptState->isolate(), |
+ "No active registration available on " |
+ "the ServiceWorkerRegistration.")); |
+ } |
+ |
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
+ ScriptPromise promise = resolver->promise(); |
+ |
+ // TODO(peter): Get a list of tags from the browser process. |
+ resolver->resolve(Vector<String>()); |
+ |
+ return promise; |
} |
DEFINE_TRACE(BackgroundFetchManager) { |