| Index: Source/modules/background_sync/SyncManager.cpp
|
| diff --git a/Source/modules/push_messaging/PushManager.cpp b/Source/modules/background_sync/SyncManager.cpp
|
| similarity index 32%
|
| copy from Source/modules/push_messaging/PushManager.cpp
|
| copy to Source/modules/background_sync/SyncManager.cpp
|
| index 53e46b5424efcadcb879d8a2040dfdc934df471d..c092afd2c8b77f21db5e48bc432ecee53e7a0313 100644
|
| --- a/Source/modules/push_messaging/PushManager.cpp
|
| +++ b/Source/modules/background_sync/SyncManager.cpp
|
| @@ -1,9 +1,9 @@
|
| -// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| #include "config.h"
|
| -#include "modules/push_messaging/PushManager.h"
|
| +#include "modules/background_sync/SyncManager.h"
|
|
|
| #include "bindings/core/v8/CallbackPromiseAdapter.h"
|
| #include "bindings/core/v8/ScriptPromise.h"
|
| @@ -13,84 +13,97 @@
|
| #include "core/dom/Document.h"
|
| #include "core/dom/ExceptionCode.h"
|
| #include "core/dom/ExecutionContext.h"
|
| -#include "modules/push_messaging/PushController.h"
|
| -#include "modules/push_messaging/PushError.h"
|
| -#include "modules/push_messaging/PushPermissionStatusCallbacks.h"
|
| -#include "modules/push_messaging/PushSubscription.h"
|
| -#include "modules/push_messaging/PushSubscriptionCallbacks.h"
|
| +#include "modules/background_sync/SyncCallbacks.h"
|
| +#include "modules/background_sync/SyncRegistrationOptions.h"
|
| #include "modules/serviceworkers/ServiceWorkerRegistration.h"
|
| #include "public/platform/Platform.h"
|
| -#include "public/platform/modules/push_messaging/WebPushClient.h"
|
| -#include "public/platform/modules/push_messaging/WebPushProvider.h"
|
| +#include "public/platform/modules/background_sync/WebSyncProvider.h"
|
| +#include "public/platform/modules/background_sync/WebSyncRegistration.h"
|
| #include "wtf/RefPtr.h"
|
|
|
| +
|
| namespace blink {
|
| namespace {
|
|
|
| -WebPushProvider* pushProvider()
|
| +/* This is the minimum period which will be allowed by the Background
|
| + * Sync manager process. It is recorded here in order to be able to
|
| + * respond to syncManager.minAllowablePeriod.
|
| + * The time is expressed in milliseconds,
|
| + */
|
| +unsigned long kMinAllowablePeriod = 12 * 60 * 60 * 1000;
|
| +
|
| +WebSyncProvider* backgroundSyncProvider()
|
| {
|
| - WebPushProvider* webPushProvider = Platform::current()->pushProvider();
|
| - ASSERT(webPushProvider);
|
| - return webPushProvider;
|
| + WebSyncProvider* webSyncProvider = Platform::current()->backgroundSyncProvider();
|
| + ASSERT(webSyncProvider);
|
| + return webSyncProvider;
|
| }
|
|
|
| -} // namespace
|
| +}
|
|
|
| -PushManager::PushManager(ServiceWorkerRegistration* registration)
|
| +SyncManager::SyncManager(ServiceWorkerRegistration* registration)
|
| : m_registration(registration)
|
| {
|
| ASSERT(registration);
|
| }
|
|
|
| -ScriptPromise PushManager::subscribe(ScriptState* scriptState)
|
| +unsigned long SyncManager::minAllowablePeriod()
|
| +{
|
| + return kMinAllowablePeriod;
|
| +}
|
| +
|
| +ScriptPromise SyncManager::registerFunction(blink::ScriptState* scriptState, const SyncRegistrationOptions& options)
|
| {
|
| if (!m_registration->active())
|
| - return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Subscription failed - no active Service Worker"));
|
| + return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Registration failed - no active Service Worker"));
|
|
|
| RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
|
| ScriptPromise promise = resolver->promise();
|
|
|
| - // The document context is the only reasonable context from which to ask the user for permission
|
| - // to use the Push API. The embedder should persist the permission so that later calls in
|
| - // different contexts can succeed.
|
| - if (scriptState->executionContext()->isDocument()) {
|
| - Document* document = toDocument(scriptState->executionContext());
|
| - // FIXME: add test coverage for this condition - https://crbug.com/440431
|
| - if (!document->domWindow() || !document->frame())
|
| - return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "Document is detached from window."));
|
| - PushController::clientFrom(document->frame()).registerPushMessaging(m_registration->webRegistration(), new PushSubscriptionCallbacks(resolver, m_registration));
|
| + WebSyncRegistration::NetworkType networkType;
|
| + String minRequiredNetwork = options.minRequiredNetwork();
|
| + if (minRequiredNetwork == "network-any") {
|
| + networkType = WebSyncRegistration::NetworkType::NetworkTypeAny;
|
| + } else if (minRequiredNetwork == "network-non-mobile") {
|
| + networkType = WebSyncRegistration::NetworkType::NetworkTypeNonMobile;
|
| + } else if (minRequiredNetwork == "network-offline") {
|
| + networkType = WebSyncRegistration::NetworkType::NetworkTypeOffline;
|
| } else {
|
| - pushProvider()->registerPushMessaging(m_registration->webRegistration(), new PushSubscriptionCallbacks(resolver, m_registration));
|
| + networkType = WebSyncRegistration::NetworkType::NetworkTypeOnline;
|
| }
|
| + WebSyncRegistration webSyncRegistration = WebSyncRegistration(options.id(), options.minDelay(), options.maxDelay(), options.minPeriod(), networkType, options.allowOnBattery(), options.idleRequired());
|
| + backgroundSyncProvider()->registerBackgroundSync(&webSyncRegistration, m_registration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registration));
|
|
|
| return promise;
|
| }
|
|
|
| -ScriptPromise PushManager::getSubscription(ScriptState* scriptState)
|
| +ScriptPromise SyncManager::getRegistration(blink::ScriptState* scriptState, const String& syncRegistrationId)
|
| {
|
| + if (!m_registration->active())
|
| + return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Operation failed - no active Service Worker"));
|
| +
|
| RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
|
| ScriptPromise promise = resolver->promise();
|
|
|
| - pushProvider()->getRegistration(m_registration->webRegistration(), new PushSubscriptionCallbacks(resolver, m_registration));
|
| + backgroundSyncProvider()->getRegistration(syncRegistrationId, m_registration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registration));
|
| +
|
| return promise;
|
| }
|
|
|
| -ScriptPromise PushManager::hasPermission(ScriptState* scriptState)
|
| +ScriptPromise SyncManager::getRegistrations(blink::ScriptState* scriptState)
|
| {
|
| - if (scriptState->executionContext()->isDocument()) {
|
| - Document* document = toDocument(scriptState->executionContext());
|
| - // FIXME: add test coverage for this condition - https://crbug.com/440431
|
| - if (!document->domWindow() || !document->frame())
|
| - return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "Document is detached from window."));
|
| - }
|
| + if (!m_registration->active())
|
| + return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Operation failed - no active Service Worker"));
|
|
|
| RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
|
| ScriptPromise promise = resolver->promise();
|
| - pushProvider()->getPermissionStatus(m_registration->webRegistration(), new PushPermissionStatusCallbacks(resolver));
|
| +
|
| + backgroundSyncProvider()->getRegistrations(m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(resolver, m_registration));
|
| +
|
| return promise;
|
| }
|
|
|
| -DEFINE_TRACE(PushManager)
|
| +DEFINE_TRACE(SyncManager)
|
| {
|
| visitor->trace(m_registration);
|
| }
|
|
|