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

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

Issue 2344983003: Merge the code paths for closing different kinds of notifications. (Closed)
Patch Set: rebase Created 4 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
Index: third_party/WebKit/Source/modules/notifications/Notification.cpp
diff --git a/third_party/WebKit/Source/modules/notifications/Notification.cpp b/third_party/WebKit/Source/modules/notifications/Notification.cpp
index af9ad5b05de815721b36bc7ea43af3bf48a5b67a..eea467bd9b203d395bc38da3b5069f346412e0af 100644
--- a/third_party/WebKit/Source/modules/notifications/Notification.cpp
+++ b/third_party/WebKit/Source/modules/notifications/Notification.cpp
@@ -137,7 +137,8 @@ Notification::Notification(ExecutionContext* context,
ActiveDOMObject(context),
m_type(type),
m_state(State::Loading),
- m_data(data) {
+ m_data(data),
+ m_requestedClose(false) {
DCHECK(notificationManager());
}
@@ -156,7 +157,7 @@ void Notification::prepareShow() {
DCHECK_EQ(m_state, State::Loading);
if (NotificationManager::from(getExecutionContext())->permissionStatus() !=
mojom::blink::PermissionStatus::GRANTED) {
- dispatchErrorEvent();
+ dispatchEvent(Event::create(EventTypeNames::error));
return;
}
@@ -179,48 +180,55 @@ void Notification::didLoadResources(NotificationResourcesLoader* loader) {
}
void Notification::close() {
- if (m_state != State::Showing)
+ if (m_state != State::Showing) {
+ // TODO(peter): Abort the load instead of closing the notification after
+ // it's completed.
+ if (m_state == State::Loading || m_notificationId.isEmpty())
+ m_requestedClose = true;
+
return;
+ }
// Schedule the "close" event to be fired for non-persistent notifications.
// Persistent notifications won't get such events for programmatic closes.
if (m_type == Type::NonPersistent) {
getExecutionContext()->postTask(
- BLINK_FROM_HERE, createSameThreadTask(&Notification::dispatchCloseEvent,
- wrapPersistent(this)));
+ BLINK_FROM_HERE,
+ createSameThreadTask(&Notification::didCloseNotification,
+ wrapPersistent(this)));
m_state = State::Closing;
-
- notificationManager()->close(this);
- return;
+ } else {
+ m_state = State::Closed;
}
- m_state = State::Closed;
-
SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin();
DCHECK(origin);
- notificationManager()->closePersistent(WebSecurityOrigin(origin), m_data.tag,
- m_notificationId);
+ notificationManager()->close(WebSecurityOrigin(origin), m_data.tag,
+ m_notificationId);
}
-void Notification::dispatchShowEvent() {
+void Notification::didShowNotification(const WebString& notificationId) {
+ DCHECK(m_notificationId.isEmpty());
+ m_notificationId = notificationId;
+
dispatchEvent(Event::create(EventTypeNames::show));
+
+ if (m_requestedClose)
+ close();
}
-void Notification::dispatchClickEvent() {
+void Notification::didClickNotification() {
UserGestureIndicator gestureIndicator(
UserGestureToken::create(UserGestureToken::NewGesture));
+
ScopedWindowFocusAllowedIndicator windowFocusAllowed(getExecutionContext());
dispatchEvent(Event::create(EventTypeNames::click));
}
-void Notification::dispatchErrorEvent() {
- dispatchEvent(Event::create(EventTypeNames::error));
-}
-
-void Notification::dispatchCloseEvent() {
- // The notification should be Showing if the user initiated the close, or it
- // should be Closing if the developer initiated the close.
+void Notification::didCloseNotification() {
+ // The notification will be showing when the user initiated the close, or it
+ // will be closing if the developer initiated the close.
if (m_state != State::Showing && m_state != State::Closing)
return;

Powered by Google App Engine
This is Rietveld 408576698