| 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 a874cbe0ba0267b670cf4caeeafb4d89d670ea9b..2e2b92f95cd6a1b43a0d46e44847dacb4e3fed64 100644
|
| --- a/third_party/WebKit/Source/modules/notifications/Notification.cpp
|
| +++ b/third_party/WebKit/Source/modules/notifications/Notification.cpp
|
| @@ -41,30 +41,21 @@
|
| #include "core/frame/UseCounter.h"
|
| #include "modules/notifications/NotificationAction.h"
|
| #include "modules/notifications/NotificationData.h"
|
| +#include "modules/notifications/NotificationManager.h"
|
| #include "modules/notifications/NotificationOptions.h"
|
| #include "modules/notifications/NotificationPermissionClient.h"
|
| #include "modules/notifications/NotificationResourcesLoader.h"
|
| #include "platform/RuntimeEnabledFeatures.h"
|
| #include "platform/UserGestureIndicator.h"
|
| +#include "platform/mojo/MojoHelper.h"
|
| #include "public/platform/Platform.h"
|
| #include "public/platform/WebSecurityOrigin.h"
|
| #include "public/platform/WebString.h"
|
| -#include "public/platform/modules/notifications/WebNotificationAction.h"
|
| #include "public/platform/modules/notifications/WebNotificationConstants.h"
|
| -#include "public/platform/modules/notifications/WebNotificationManager.h"
|
| +#include "public/platform/modules/permissions/permission_status.mojom.h"
|
| #include "wtf/Functional.h"
|
|
|
| namespace blink {
|
| -namespace {
|
| -
|
| -const int64_t kInvalidPersistentId = -1;
|
| -
|
| -WebNotificationManager* notificationManager()
|
| -{
|
| - return Platform::current()->notificationManager();
|
| -}
|
| -
|
| -} // namespace
|
|
|
| Notification* Notification::create(ExecutionContext* context, const String& title, const NotificationOptions& options, ExceptionState& exceptionState)
|
| {
|
| @@ -97,73 +88,89 @@ Notification* Notification::create(ExecutionContext* context, const String& titl
|
| UseCounter::countCrossOriginIframe(*toDocument(context), UseCounter::NotificationAPIInsecureOriginIframe);
|
| }
|
|
|
| - WebNotificationData data = createWebNotificationData(context, title, options, exceptionState);
|
| + mojom::blink::NotificationPtr data = createNotificationData(context, title, options, exceptionState);
|
| if (exceptionState.hadException())
|
| return nullptr;
|
|
|
| - Notification* notification = new Notification(context, data);
|
| + Notification* notification = new Notification(context, std::move(data));
|
| notification->schedulePrepareShow();
|
| notification->suspendIfNeeded();
|
|
|
| return notification;
|
| }
|
|
|
| -Notification* Notification::create(ExecutionContext* context, int64_t persistentId, const WebNotificationData& data, bool showing)
|
| +Notification* Notification::create(ExecutionContext* context, mojom::blink::NotificationPtr data, bool showing)
|
| {
|
| - Notification* notification = new Notification(context, data);
|
| - notification->setPersistentId(persistentId);
|
| + Notification* notification = new Notification(context, std::move(data));
|
| notification->setState(showing ? NotificationStateShowing : NotificationStateClosed);
|
| notification->suspendIfNeeded();
|
|
|
| return notification;
|
| }
|
|
|
| -Notification::Notification(ExecutionContext* context, const WebNotificationData& data)
|
| +Notification::Notification(ExecutionContext* context, mojom::blink::NotificationPtr data)
|
| : ActiveScriptWrappable(this)
|
| , ActiveDOMObject(context)
|
| - , m_data(data)
|
| - , m_persistentId(kInvalidPersistentId)
|
| + , m_data(std::move(data))
|
| , m_state(NotificationStateIdle)
|
| , m_prepareShowMethodRunner(AsyncMethodRunner<Notification>::create(this, &Notification::prepareShow))
|
| + , m_binding(this)
|
| {
|
| - ASSERT(notificationManager());
|
| }
|
|
|
| Notification::~Notification()
|
| {
|
| }
|
|
|
| +NotificationManager* Notification::manager() const
|
| +{
|
| + return NotificationManager::from(getExecutionContext());
|
| +}
|
| +
|
| void Notification::schedulePrepareShow()
|
| {
|
| - ASSERT(m_state == NotificationStateIdle);
|
| - ASSERT(!m_prepareShowMethodRunner->isActive());
|
| + DCHECK_EQ(NotificationStateIdle, m_state);
|
| + DCHECK(!m_prepareShowMethodRunner->isActive());
|
|
|
| m_prepareShowMethodRunner->runAsync();
|
| }
|
|
|
| void Notification::prepareShow()
|
| {
|
| - ASSERT(m_state == NotificationStateIdle);
|
| - if (Notification::checkPermission(getExecutionContext()) != mojom::PermissionStatus::GRANTED) {
|
| - dispatchErrorEvent();
|
| + DCHECK_EQ(NotificationStateIdle, m_state);
|
| + if (manager()->permissionStatus() != mojom::PermissionStatus::GRANTED) {
|
| + dispatchEvent(Event::create(EventTypeNames::error));
|
| return;
|
| }
|
|
|
| - m_loader = new NotificationResourcesLoader(bind<NotificationResourcesLoader*>(&Notification::didLoadResources, WeakPersistentThisPointer<Notification>(this)));
|
| - m_loader->start(getExecutionContext(), m_data);
|
| + m_state = NotificationStateLoading;
|
| +
|
| + m_loader = new NotificationResourcesLoader(bind<NotificationResourcesLoader*, mojom::blink::NotificationPtr>(&Notification::didLoadResources, WeakPersistentThisPointer<Notification>(this)));
|
| + m_loader->start(getExecutionContext(), m_data.Clone());
|
| }
|
|
|
| -void Notification::didLoadResources(NotificationResourcesLoader* loader)
|
| +void Notification::didLoadResources(NotificationResourcesLoader* loader, mojom::blink::NotificationPtr notification)
|
| {
|
| DCHECK_EQ(loader, m_loader.get());
|
| + DCHECK(!m_binding.is_bound());
|
|
|
| - SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin();
|
| - ASSERT(origin);
|
| + manager()->display(std::move(notification), loader->getResources(), m_binding.CreateInterfacePtrAndBind(), sameThreadBindForMojo(&Notification::didShowNotification, this));
|
|
|
| - notificationManager()->show(WebSecurityOrigin(origin), m_data, loader->getResources(), this);
|
| m_loader.clear();
|
| +}
|
| +
|
| +void Notification::didShowNotification(mojom::blink::NotificationDisplayResult result, const String& id)
|
| +{
|
| + DCHECK_EQ(NotificationStateLoading, m_state);
|
| +
|
| + // TODO(peter): Fire the error event when |result| is not SUCCESS?
|
| +
|
| + DCHECK(!id.isNull());
|
|
|
| m_state = NotificationStateShowing;
|
| + m_data->id = id;
|
| +
|
| + dispatchEvent(Event::create(EventTypeNames::show));
|
| }
|
|
|
| void Notification::close()
|
| @@ -171,63 +178,51 @@ void Notification::close()
|
| if (m_state != NotificationStateShowing)
|
| return;
|
|
|
| - if (m_persistentId == kInvalidPersistentId) {
|
| - // Fire the close event asynchronously.
|
| - getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&Notification::dispatchCloseEvent, this));
|
| -
|
| - m_state = NotificationStateClosing;
|
| - notificationManager()->close(this);
|
| - } else {
|
| - m_state = NotificationStateClosed;
|
| + DCHECK(!m_data->id.isNull());
|
|
|
| - SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin();
|
| - ASSERT(origin);
|
| + manager()->close(m_data->id, sameThreadBindForMojo(&Notification::OnClose, this));
|
|
|
| - notificationManager()->closePersistent(WebSecurityOrigin(origin), m_persistentId);
|
| - }
|
| + m_state = NotificationStateClosing;
|
| }
|
|
|
| -void Notification::dispatchShowEvent()
|
| +void Notification::OnClick()
|
| {
|
| - dispatchEvent(Event::create(EventTypeNames::show));
|
| -}
|
| + ASSERT(getExecutionContext()->isContextThread());
|
|
|
| -void Notification::dispatchClickEvent()
|
| -{
|
| UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
|
| ScopedWindowFocusAllowedIndicator windowFocusAllowed(getExecutionContext());
|
| dispatchEvent(Event::create(EventTypeNames::click));
|
| }
|
|
|
| -void Notification::dispatchErrorEvent()
|
| +void Notification::OnClose(mojom::blink::NotificationCloseResult reason)
|
| {
|
| - dispatchEvent(Event::create(EventTypeNames::error));
|
| -}
|
| + ASSERT(getExecutionContext()->isContextThread());
|
|
|
| -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)
|
| return;
|
|
|
| m_state = NotificationStateClosed;
|
| - dispatchEvent(Event::create(EventTypeNames::close));
|
| +
|
| + // Only fire the "close" event if the notification was in fact closed.
|
| + if (reason == mojom::blink::NotificationCloseResult::CLOSED)
|
| + dispatchEvent(Event::create(EventTypeNames::close));
|
| }
|
|
|
| String Notification::title() const
|
| {
|
| - return m_data.title;
|
| + return m_data->title;
|
| }
|
|
|
| String Notification::dir() const
|
| {
|
| - switch (m_data.direction) {
|
| - case WebNotificationData::DirectionLeftToRight:
|
| + switch (m_data->direction) {
|
| + case mojom::blink::NotificationDirection::LEFT_TO_RIGHT:
|
| return "ltr";
|
| - case WebNotificationData::DirectionRightToLeft:
|
| + case mojom::blink::NotificationDirection::RIGHT_TO_LEFT:
|
| return "rtl";
|
| - case WebNotificationData::DirectionAuto:
|
| + case mojom::blink::NotificationDirection::AUTO:
|
| return "auto";
|
| }
|
|
|
| @@ -237,33 +232,33 @@ String Notification::dir() const
|
|
|
| String Notification::lang() const
|
| {
|
| - return m_data.lang;
|
| + return m_data->lang;
|
| }
|
|
|
| String Notification::body() const
|
| {
|
| - return m_data.body;
|
| + return m_data->body;
|
| }
|
|
|
| String Notification::tag() const
|
| {
|
| - return m_data.tag;
|
| + return m_data->tag;
|
| }
|
|
|
| String Notification::icon() const
|
| {
|
| - return m_data.icon.string();
|
| + return m_data->icon;
|
| }
|
|
|
| String Notification::badge() const
|
| {
|
| - return m_data.badge.string();
|
| + return m_data->badge;
|
| }
|
|
|
| NavigatorVibration::VibrationPattern Notification::vibrate(bool& isNull) const
|
| {
|
| NavigatorVibration::VibrationPattern pattern;
|
| - pattern.appendRange(m_data.vibrate.begin(), m_data.vibrate.end());
|
| + pattern.appendRange(m_data->vibration_pattern.storage().begin(), m_data->vibration_pattern.storage().end());
|
|
|
| if (!pattern.size())
|
| isNull = true;
|
| @@ -273,22 +268,22 @@ NavigatorVibration::VibrationPattern Notification::vibrate(bool& isNull) const
|
|
|
| DOMTimeStamp Notification::timestamp() const
|
| {
|
| - return m_data.timestamp;
|
| + return m_data->timestamp;
|
| }
|
|
|
| bool Notification::renotify() const
|
| {
|
| - return m_data.renotify;
|
| + return m_data->renotify;
|
| }
|
|
|
| bool Notification::silent() const
|
| {
|
| - return m_data.silent;
|
| + return m_data->silent;
|
| }
|
|
|
| bool Notification::requireInteraction() const
|
| {
|
| - return m_data.requireInteraction;
|
| + return m_data->require_interaction;
|
| }
|
|
|
| ScriptValue Notification::data(ScriptState* scriptState)
|
| @@ -296,7 +291,7 @@ ScriptValue Notification::data(ScriptState* scriptState)
|
| if (m_developerData.isEmpty()) {
|
| RefPtr<SerializedScriptValue> serializedValue;
|
|
|
| - const WebVector<char>& serializedData = m_data.data;
|
| + const WebVector<char>& serializedData = m_data->data.storage();
|
| if (serializedData.size())
|
| serializedValue = SerializedScriptValueFactory::instance().createFromWireBytes(serializedData.data(), serializedData.size());
|
| else
|
| @@ -311,23 +306,26 @@ ScriptValue Notification::data(ScriptState* scriptState)
|
| HeapVector<NotificationAction> Notification::actions() const
|
| {
|
| HeapVector<NotificationAction> actions;
|
| - actions.grow(m_data.actions.size());
|
| + actions.grow(m_data->actions.size());
|
| +
|
| + for (size_t i = 0; i < m_data->actions.size(); ++i) {
|
| + const auto& action = m_data->actions[i];
|
|
|
| - for (size_t i = 0; i < m_data.actions.size(); ++i) {
|
| - switch (m_data.actions[i].type) {
|
| - case WebNotificationAction::Button:
|
| + switch (action->type) {
|
| + case mojom::blink::NotificationActionType::BUTTON:
|
| actions[i].setType("button");
|
| break;
|
| - case WebNotificationAction::Text:
|
| + case mojom::blink::NotificationActionType::TEXT:
|
| actions[i].setType("text");
|
| break;
|
| default:
|
| - NOTREACHED() << "Unknown action type: " << m_data.actions[i].type;
|
| + NOTREACHED() << "Unknown action type: " << action->type;
|
| }
|
| - actions[i].setAction(m_data.actions[i].action);
|
| - actions[i].setTitle(m_data.actions[i].title);
|
| - actions[i].setIcon(m_data.actions[i].icon.string());
|
| - actions[i].setPlaceholder(m_data.actions[i].placeholder);
|
| +
|
| + actions[i].setAction(action->action);
|
| + actions[i].setTitle(action->title);
|
| + actions[i].setIcon(action->icon);
|
| + actions[i].setPlaceholder(action->placeholder);
|
| }
|
|
|
| return actions;
|
| @@ -350,15 +348,7 @@ String Notification::permissionString(mojom::PermissionStatus permission)
|
|
|
| String Notification::permission(ExecutionContext* context)
|
| {
|
| - return permissionString(checkPermission(context));
|
| -}
|
| -
|
| -mojom::PermissionStatus Notification::checkPermission(ExecutionContext* context)
|
| -{
|
| - SecurityOrigin* origin = context->getSecurityOrigin();
|
| - ASSERT(origin);
|
| -
|
| - return notificationManager()->checkPermission(WebSecurityOrigin(origin));
|
| + return permissionString(NotificationManager::from(context)->permissionStatus());
|
| }
|
|
|
| ScriptPromise Notification::requestPermission(ScriptState* scriptState, NotificationPermissionCallback* deprecatedCallback)
|
| @@ -390,8 +380,6 @@ const AtomicString& Notification::interfaceName() const
|
|
|
| void Notification::stop()
|
| {
|
| - notificationManager()->notifyDelegateDestroyed(this);
|
| -
|
| m_state = NotificationStateClosed;
|
|
|
| m_prepareShowMethodRunner->stop();
|
|
|