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

Unified Diff: Source/modules/notifications/Notification.cpp

Issue 584023002: [WIP] Implement Notifications through Platform instead of WebFrame. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 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
« no previous file with comments | « Source/modules/notifications/Notification.h ('k') | Source/modules/notifications/Notification.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/notifications/Notification.cpp
diff --git a/Source/modules/notifications/Notification.cpp b/Source/modules/notifications/Notification.cpp
index f0964c3a66a09ebc1a3393f1c2061024cd9fcf24..ca4049269b8f7207535b8d7832e928592d64bf43 100644
--- a/Source/modules/notifications/Notification.cpp
+++ b/Source/modules/notifications/Notification.cpp
@@ -35,17 +35,27 @@
#include "core/dom/Document.h"
#include "core/events/Event.h"
#include "core/page/WindowFocusAllowedIndicator.h"
-#include "modules/notifications/NotificationClient.h"
-#include "modules/notifications/NotificationController.h"
#include "modules/notifications/NotificationOptions.h"
#include "modules/notifications/NotificationPermissionClient.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebNotificationData.h"
+#include "public/platform/WebNotificationManager.h"
+#include "public/platform/WebSerializedOrigin.h"
namespace blink {
+namespace {
+
+WebNotificationManager* notificationManager()
+{
+ return Platform::current()->notificationManager();
+}
+
+} // namespace
+
Notification* Notification::create(ExecutionContext* context, const String& title, const NotificationOptions& options)
{
- NotificationClient& client = NotificationController::clientFrom(context);
- Notification* notification = adoptRefCountedGarbageCollectedWillBeNoop(new Notification(title, context, &client));
+ Notification* notification = adoptRefCountedGarbageCollectedWillBeNoop(new Notification(title, context));
notification->setBody(options.body());
notification->setTag(options.tag());
@@ -61,15 +71,14 @@ Notification* Notification::create(ExecutionContext* context, const String& titl
return notification;
}
-Notification::Notification(const String& title, ExecutionContext* context, NotificationClient* client)
+Notification::Notification(const String& title, ExecutionContext* context)
: ActiveDOMObject(context)
, m_title(title)
, m_dir("auto")
, m_state(NotificationStateIdle)
- , m_client(client)
, m_asyncRunner(this, &Notification::show)
{
- ASSERT(m_client);
+ ASSERT(notificationManager());
m_asyncRunner.runAsync();
}
@@ -81,15 +90,17 @@ Notification::~Notification()
void Notification::show()
{
ASSERT(m_state == NotificationStateIdle);
- if (!toDocument(executionContext())->page())
- return;
-
- if (m_client->checkPermission(executionContext()) != NotificationClient::PermissionAllowed) {
+ if (Notification::checkPermission(executionContext()) != WebNotificationPermissionAllowed) {
dispatchErrorEvent();
return;
}
- if (m_client->show(this))
+ SecurityOrigin* origin = executionContext()->securityOrigin();
+ ASSERT(origin);
+
+ // TODO(peter): We should set the correct direction as part of this call.
+ WebNotificationData notificationData(m_title, WebNotificationData::DirectionLeftToRight, m_lang, m_body, m_tag, m_iconUrl);
+ if (notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this))
m_state = NotificationStateShowing;
}
@@ -99,7 +110,7 @@ void Notification::close()
case NotificationStateIdle:
break;
case NotificationStateShowing:
- m_client->close(this);
+ notificationManager()->close(this);
break;
case NotificationStateClosed:
break;
@@ -115,6 +126,7 @@ void Notification::dispatchClickEvent()
{
UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
WindowFocusAllowedIndicator windowFocusAllowed;
+
dispatchEvent(Event::create(EventTypeNames::click));
}
@@ -135,18 +147,18 @@ TextDirection Notification::direction() const
return dir() == "rtl" ? RTL : LTR;
}
-const String& Notification::permissionString(NotificationClient::Permission permission)
+const String& Notification::permissionString(WebNotificationPermission permission)
{
DEFINE_STATIC_LOCAL(const String, allowedPermission, ("granted"));
DEFINE_STATIC_LOCAL(const String, deniedPermission, ("denied"));
DEFINE_STATIC_LOCAL(const String, defaultPermission, ("default"));
switch (permission) {
- case NotificationClient::PermissionAllowed:
+ case WebNotificationPermissionAllowed:
return allowedPermission;
- case NotificationClient::PermissionDenied:
+ case WebNotificationPermissionDenied:
return deniedPermission;
- case NotificationClient::PermissionNotAllowed:
+ case WebNotificationPermissionDefault:
return defaultPermission;
}
@@ -156,17 +168,22 @@ const String& Notification::permissionString(NotificationClient::Permission perm
const String& Notification::permission(ExecutionContext* context)
{
- return permissionString(NotificationController::clientFrom(context).checkPermission(context));
+ return permissionString(checkPermission(context));
+}
+
+WebNotificationPermission Notification::checkPermission(ExecutionContext* context)
+{
+ SecurityOrigin* origin = context->securityOrigin();
+ ASSERT(origin);
+
+ return notificationManager()->checkPermission(WebSerializedOrigin(*origin));
}
void Notification::requestPermission(ExecutionContext* context, PassOwnPtrWillBeRawPtr<NotificationPermissionCallback> callback)
{
- // FIXME: Assert that this code-path will only be reached for Document environments
- // when Blink supports [Exposed] annotations on class members in IDL definitions.
- if (NotificationPermissionClient* permissionClient = NotificationPermissionClient::from(context)) {
+ ASSERT(context->isDocument());
+ if (NotificationPermissionClient* permissionClient = NotificationPermissionClient::from(context))
permissionClient->requestPermission(context, callback);
- return;
- }
}
bool Notification::dispatchEvent(PassRefPtrWillBeRawPtr<Event> event)
@@ -183,13 +200,9 @@ const AtomicString& Notification::interfaceName() const
void Notification::stop()
{
- m_state = NotificationStateClosed;
-
- if (m_client) {
- m_client->notificationObjectDestroyed(this);
- m_client = 0;
- }
+ notificationManager()->notifyDelegateDestroyed(this);
+ m_state = NotificationStateClosed;
m_asyncRunner.stop();
}
« no previous file with comments | « Source/modules/notifications/Notification.h ('k') | Source/modules/notifications/Notification.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698