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

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

Issue 624033003: [WIP] Move Web Notifications to a WebFrame-less code path (Blink). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: current state Created 6 years, 2 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 5fb0c9a83b655ebefcf15c67c27edacb511aa673..bb159d2f0ed1bf4ab08701e0ecc1c460ea908633 100644
--- a/Source/modules/notifications/Notification.cpp
+++ b/Source/modules/notifications/Notification.cpp
@@ -36,17 +36,27 @@
#include "core/events/Event.h"
#include "core/frame/UseCounter.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 = new Notification(title, context, &client);
+ Notification* notification = new Notification(title, context);
notification->setBody(options.body());
notification->setTag(options.tag());
@@ -67,15 +77,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();
}
@@ -87,29 +96,27 @@ 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;
}
void Notification::close()
{
- switch (m_state) {
- case NotificationStateIdle:
- break;
- case NotificationStateShowing:
- m_client->close(this);
- break;
- case NotificationStateClosed:
- break;
- }
+ if (m_state != NotificationStateShowing)
+ return;
+
+ m_state = NotificationStateClosed;
+ notificationManager()->close(this);
}
void Notification::dispatchShowEvent()
@@ -121,6 +128,7 @@ void Notification::dispatchClickEvent()
{
UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
WindowFocusAllowedIndicator windowFocusAllowed;
+
dispatchEvent(Event::create(EventTypeNames::click));
}
@@ -132,7 +140,6 @@ void Notification::dispatchErrorEvent()
void Notification::dispatchCloseEvent()
{
dispatchEvent(Event::create(EventTypeNames::close));
- m_state = NotificationStateClosed;
}
TextDirection Notification::direction() const
@@ -141,18 +148,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;
}
@@ -162,23 +169,27 @@ 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, 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)
{
- ASSERT(m_state != NotificationStateClosed);
-
+ ASSERT(executionContext()->isContextThread());
return EventTarget::dispatchEvent(event);
}
@@ -189,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