Chromium Code Reviews| 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 4bc1975fd1a88af47eecdb2456cc8a88e7dc513a..0f9d64e20fbeec8ad232426ad2730c9824b936bd 100644 |
| --- a/third_party/WebKit/Source/modules/notifications/Notification.cpp |
| +++ b/third_party/WebKit/Source/modules/notifications/Notification.cpp |
| @@ -100,29 +100,29 @@ Notification* Notification::create(ExecutionContext* context, const String& titl |
| if (exceptionState.hadException()) |
| return nullptr; |
| - Notification* notification = new Notification(context, data); |
| + Notification* notification = new Notification(context, NotificationType::NonPersistent, data); |
| notification->schedulePrepareShow(); |
| - notification->suspendIfNeeded(); |
| + notification->suspendIfNeeded(); |
| return notification; |
| } |
| Notification* Notification::create(ExecutionContext* context, const String& notificationId, const WebNotificationData& data, bool showing) |
| { |
| - Notification* notification = new Notification(context, data); |
| + Notification* notification = new Notification(context, NotificationType::Persistent, data); |
| + notification->setState(showing ? NotificationState::Showing : NotificationState::Closed); |
| notification->setNotificationId(notificationId); |
| - notification->setState(showing ? NotificationStateShowing : NotificationStateClosed); |
| - notification->suspendIfNeeded(); |
| + notification->suspendIfNeeded(); |
| return notification; |
| } |
| -Notification::Notification(ExecutionContext* context, const WebNotificationData& data) |
| +Notification::Notification(ExecutionContext* context, NotificationType type, const WebNotificationData& data) |
| : ActiveScriptWrappable(this) |
| , ActiveDOMObject(context) |
| + , m_type(type) |
| + , m_state(NotificationState::Loading) |
| , m_data(data) |
| - , m_state(NotificationStateIdle) |
| - , m_prepareShowMethodRunner(AsyncMethodRunner<Notification>::create(this, &Notification::prepareShow)) |
| { |
| DCHECK(notificationManager()); |
| } |
| @@ -133,15 +133,16 @@ Notification::~Notification() |
| void Notification::schedulePrepareShow() |
| { |
| - DCHECK_EQ(m_state, NotificationStateIdle); |
| - DCHECK(!m_prepareShowMethodRunner->isActive()); |
| + DCHECK_EQ(m_state, NotificationState::Loading); |
| + DCHECK(!m_prepareShowMethodRunner); |
| + m_prepareShowMethodRunner = AsyncMethodRunner<Notification>::create(this, &Notification::prepareShow); |
| m_prepareShowMethodRunner->runAsync(); |
| } |
| void Notification::prepareShow() |
| { |
| - DCHECK_EQ(m_state, NotificationStateIdle); |
| + DCHECK_EQ(m_state, NotificationState::Loading); |
| if (NotificationManager::from(getExecutionContext())->permissionStatus() != mojom::blink::PermissionStatus::GRANTED) { |
| dispatchErrorEvent(); |
| return; |
| @@ -161,23 +162,26 @@ void Notification::didLoadResources(NotificationResourcesLoader* loader) |
| notificationManager()->show(WebSecurityOrigin(origin), m_data, loader->getResources(), this); |
| m_loader.clear(); |
| - m_state = NotificationStateShowing; |
| + m_state = NotificationState::Showing; |
| } |
| void Notification::close() |
| { |
| - if (m_state != NotificationStateShowing) |
| + if (m_state != NotificationState::Showing) |
| return; |
| - if (m_notificationId.isNull()) { |
| - // Fire the close event asynchronously. |
| + // Schedule the "close" event to be fired for non-persistent notifications. |
| + // Persistent notifications won't get such events for programmatic closes. |
| + if (m_type == NotificationType::NonPersistent) { |
| getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&Notification::dispatchCloseEvent, wrapPersistent(this))); |
| + m_state = NotificationState::Closing; |
| + } else { |
| + m_state = NotificationState::Closed; |
| + } |
| - m_state = NotificationStateClosing; |
| + if (m_type == NotificationType::NonPersistent) { |
|
johnme
2016/09/16 14:14:35
Nit: I'm not sure splitting this into two if-elses
Peter Beverloo
2016/09/16 14:45:37
Done.
|
| notificationManager()->close(this); |
| } else { |
| - m_state = NotificationStateClosed; |
| - |
| SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); |
| DCHECK(origin); |
| @@ -206,10 +210,10 @@ void Notification::dispatchCloseEvent() |
| { |
| // 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 != NotificationStateShowing && m_state != NotificationStateClosing) |
| + if (m_state != NotificationState::Showing && m_state != NotificationState::Closing) |
| return; |
| - m_state = NotificationStateClosed; |
| + m_state = NotificationState::Closed; |
| dispatchEvent(Event::create(EventTypeNames::close)); |
| } |
| @@ -376,9 +380,10 @@ void Notification::stop() |
| { |
| notificationManager()->notifyDelegateDestroyed(this); |
| - m_state = NotificationStateClosed; |
| + m_state = NotificationState::Closed; |
| - m_prepareShowMethodRunner->stop(); |
| + if (m_prepareShowMethodRunner) |
| + m_prepareShowMethodRunner->stop(); |
| if (m_loader) |
| m_loader->stop(); |
| @@ -386,7 +391,12 @@ void Notification::stop() |
| bool Notification::hasPendingActivity() const |
| { |
| - return m_state == NotificationStateShowing || m_prepareShowMethodRunner->isActive() || m_loader; |
| + // Non-persistent notification can receive events until they've been closed. |
| + // Persistent notifications should be subject to regular garbage collection. |
| + if (m_type == NotificationType::NonPersistent) |
| + return m_state != NotificationState::Closed; |
| + |
| + return false; |
| } |
| DEFINE_TRACE(Notification) |