Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(580)

Unified Diff: third_party/WebKit/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp

Issue 1904163002: Move Web Notifications to use Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@skbitmap-blink
Patch Set: resolves the promise Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp
diff --git a/third_party/WebKit/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp b/third_party/WebKit/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp
index 47a5566a340bad62f9f1bd0e548821526b54c687..fef7a20a3d8585acdc666b480da8cb616ce22e11 100644
--- a/third_party/WebKit/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp
+++ b/third_party/WebKit/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp
@@ -11,42 +11,44 @@
#include "modules/notifications/GetNotificationOptions.h"
#include "modules/notifications/Notification.h"
#include "modules/notifications/NotificationData.h"
+#include "modules/notifications/NotificationManager.h"
#include "modules/notifications/NotificationOptions.h"
#include "modules/notifications/NotificationResourcesLoader.h"
#include "modules/serviceworkers/ServiceWorkerRegistration.h"
#include "platform/Histogram.h"
#include "platform/heap/Handle.h"
+#include "platform/mojo/MojoHelper.h"
#include "public/platform/Platform.h"
#include "public/platform/WebSecurityOrigin.h"
-#include "public/platform/modules/notifications/WebNotificationData.h"
+#include "public/platform/modules/notifications/notification_resources.mojom-wtf.h"
+#include "wtf/Functional.h"
#include "wtf/RefPtr.h"
namespace blink {
namespace {
-// Allows using a CallbackPromiseAdapter with a WebVector to resolve the
-// getNotifications() promise with a HeapVector owning Notifications.
-class NotificationArray {
+// Object responsible for handling the result status of showing a persistent
+// notification using the embedder.
+class ShowNotificationResponseHandler {
+ WTF_MAKE_NONCOPYABLE(ShowNotificationResponseHandler);
public:
- using WebType = const WebVector<WebPersistentNotificationInfo>&;
+ explicit ShowNotificationResponseHandler(ScriptPromiseResolver* resolver)
+ : m_resolver(resolver) {}
- static HeapVector<Member<Notification>> take(ScriptPromiseResolver* resolver, const WebVector<WebPersistentNotificationInfo>& notificationInfos)
+ void onResponse(mojom::wtf::NotificationDisplayResult result)
{
- HeapVector<Member<Notification>> notifications;
- for (const WebPersistentNotificationInfo& notificationInfo : notificationInfos)
- notifications.append(Notification::create(resolver->getExecutionContext(), notificationInfo.persistentId, notificationInfo.data, true /* showing */));
-
- return notifications;
+ m_resolver->resolve();
}
private:
- NotificationArray() = delete;
+ Persistent<ScriptPromiseResolver> m_resolver;
};
} // namespace
ServiceWorkerRegistrationNotifications::ServiceWorkerRegistrationNotifications(ExecutionContext* executionContext, ServiceWorkerRegistration* registration)
- : ContextLifecycleObserver(executionContext), m_registration(registration)
+ : ContextLifecycleObserver(executionContext)
+ , m_registration(registration)
{
}
@@ -62,12 +64,15 @@ ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta
if (!registration.active())
return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(scriptState->isolate(), "No active registration available on the ServiceWorkerRegistration."));
+ NotificationManager* notificationManager = NotificationManager::from(executionContext);
+ DCHECK(notificationManager);
+
// If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps.
- if (Notification::checkPermission(executionContext) != mojom::PermissionStatus::GRANTED)
+ if (notificationManager->permissionStatus() != mojom::PermissionStatus::GRANTED)
return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(scriptState->isolate(), "No notification permission has been granted for this origin."));
- // Validate the developer-provided values to get a WebNotificationData object.
- WebNotificationData data = createWebNotificationData(executionContext, title, options, exceptionState);
+ // Validate the developer-provided values to get a Mojo Notification object.
+ mojom::wtf::NotificationPtr data = createNotificationData(executionContext, title, options, exceptionState);
if (exceptionState.hadException())
return exceptionState.reject(scriptState);
@@ -78,8 +83,12 @@ ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
- OwnPtr<WebNotificationShowCallbacks> callbacks = adoptPtr(new CallbackPromiseAdapter<void, void>(resolver));
- ServiceWorkerRegistrationNotifications::from(executionContext, registration).prepareShow(data, callbacks.release());
+ OwnPtr<ShowNotificationResponseHandler> responseHandler = adoptPtr(new ShowNotificationResponseHandler(resolver));
+ mojom::wtf::NotificationService::ShowPersistentCallback callback =
+ createBaseCallback(bind<mojom::wtf::NotificationDisplayResult>(&ShowNotificationResponseHandler::onResponse, responseHandler.release()));
+
+ // TODO(peter): Make the NotificationManager responsible for loading resources.
+ ServiceWorkerRegistrationNotifications::from(executionContext, registration).prepareShow(std::move(data), callback);
return promise;
}
@@ -89,12 +98,12 @@ ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
- WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<NotificationArray, void>(resolver);
+ //WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<NotificationArray, void>(resolver);
- WebNotificationManager* notificationManager = Platform::current()->notificationManager();
- ASSERT(notificationManager);
+ //WebNotificationManager* notificationManager = Platform::current()->notificationManager();
+ //ASSERT(notificationManager);
- notificationManager->getNotifications(options.tag(), registration.webRegistration(), callbacks);
+ //notificationManager->getNotifications(options.tag(), registration.webRegistration(), callbacks);
return promise;
}
@@ -127,22 +136,20 @@ ServiceWorkerRegistrationNotifications& ServiceWorkerRegistrationNotifications::
return *supplement;
}
-void ServiceWorkerRegistrationNotifications::prepareShow(const WebNotificationData& data, PassOwnPtr<WebNotificationShowCallbacks> callbacks)
+void ServiceWorkerRegistrationNotifications::prepareShow(mojom::wtf::NotificationPtr notification, const mojom::wtf::NotificationService::ShowPersistentCallback& callback)
{
- RefPtr<SecurityOrigin> origin = getExecutionContext()->getSecurityOrigin();
- NotificationResourcesLoader* loader = new NotificationResourcesLoader(bind<NotificationResourcesLoader*>(&ServiceWorkerRegistrationNotifications::didLoadResources, WeakPersistentThisPointer<ServiceWorkerRegistrationNotifications>(this), origin.release(), data, callbacks));
+ NotificationResourcesLoader* loader = new NotificationResourcesLoader(bind<NotificationResourcesLoader*, mojom::wtf::NotificationPtr>(&ServiceWorkerRegistrationNotifications::didLoadResources, WeakPersistentThisPointer<ServiceWorkerRegistrationNotifications>(this), callback));
m_loaders.add(loader);
- loader->start(getExecutionContext(), data);
+
+ loader->start(getExecutionContext(), std::move(notification));
}
-void ServiceWorkerRegistrationNotifications::didLoadResources(PassRefPtr<SecurityOrigin> origin, const WebNotificationData& data, PassOwnPtr<WebNotificationShowCallbacks> callbacks, NotificationResourcesLoader* loader)
+void ServiceWorkerRegistrationNotifications::didLoadResources(const mojom::wtf::NotificationService::ShowPersistentCallback& callback, NotificationResourcesLoader* loader, mojom::wtf::NotificationPtr notification)
{
DCHECK(m_loaders.contains(loader));
- WebNotificationManager* notificationManager = Platform::current()->notificationManager();
- DCHECK(notificationManager);
+ NotificationManager::from(getExecutionContext())->showPersistent(std::move(notification), loader->getResources(), callback);
- notificationManager->showPersistent(WebSecurityOrigin(origin.get()), data, loader->getResources(), m_registration->webRegistration(), callbacks.leakPtr());
m_loaders.remove(loader);
}

Powered by Google App Engine
This is Rietveld 408576698