| 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..a80a6b6c174a7c5e3c09bd81ca682adc603b8cb8 100644
|
| --- a/third_party/WebKit/Source/modules/notifications/Notification.cpp
|
| +++ b/third_party/WebKit/Source/modules/notifications/Notification.cpp
|
| @@ -41,6 +41,7 @@
|
| #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"
|
| @@ -49,9 +50,8 @@
|
| #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 {
|
| @@ -59,11 +59,6 @@ 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,20 +92,20 @@ Notification* Notification::create(ExecutionContext* context, const String& titl
|
| UseCounter::countCrossOriginIframe(*toDocument(context), UseCounter::NotificationAPIInsecureOriginIframe);
|
| }
|
|
|
| - WebNotificationData data = createWebNotificationData(context, title, options, exceptionState);
|
| + mojom::wtf::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, int64_t persistentId, mojom::wtf::NotificationPtr data, bool showing)
|
| {
|
| - Notification* notification = new Notification(context, data);
|
| + Notification* notification = new Notification(context, std::move(data));
|
| notification->setPersistentId(persistentId);
|
| notification->setState(showing ? NotificationStateShowing : NotificationStateClosed);
|
| notification->suspendIfNeeded();
|
| @@ -118,21 +113,25 @@ Notification* Notification::create(ExecutionContext* context, int64_t persistent
|
| return notification;
|
| }
|
|
|
| -Notification::Notification(ExecutionContext* context, const WebNotificationData& data)
|
| +Notification::Notification(ExecutionContext* context, mojom::wtf::NotificationPtr data)
|
| : ActiveScriptWrappable(this)
|
| , ActiveDOMObject(context)
|
| - , m_data(data)
|
| + , m_data(std::move(data))
|
| , m_persistentId(kInvalidPersistentId)
|
| , m_state(NotificationStateIdle)
|
| , m_prepareShowMethodRunner(AsyncMethodRunner<Notification>::create(this, &Notification::prepareShow))
|
| {
|
| - ASSERT(notificationManager());
|
| }
|
|
|
| Notification::~Notification()
|
| {
|
| }
|
|
|
| +NotificationManager* Notification::manager() const
|
| +{
|
| + return NotificationManager::from(getExecutionContext());
|
| +}
|
| +
|
| void Notification::schedulePrepareShow()
|
| {
|
| ASSERT(m_state == NotificationStateIdle);
|
| @@ -144,23 +143,22 @@ void Notification::schedulePrepareShow()
|
| void Notification::prepareShow()
|
| {
|
| ASSERT(m_state == NotificationStateIdle);
|
| - if (Notification::checkPermission(getExecutionContext()) != mojom::PermissionStatus::GRANTED) {
|
| + if (manager()->permissionStatus() != mojom::PermissionStatus::GRANTED) {
|
| dispatchErrorEvent();
|
| return;
|
| }
|
|
|
| - m_loader = new NotificationResourcesLoader(bind<NotificationResourcesLoader*>(&Notification::didLoadResources, WeakPersistentThisPointer<Notification>(this)));
|
| - m_loader->start(getExecutionContext(), m_data);
|
| + // TODO(peter): Make the NotificationManager responsible for loading resources.
|
| + m_loader = new NotificationResourcesLoader(bind<NotificationResourcesLoader*, mojom::wtf::NotificationPtr>(&Notification::didLoadResources, WeakPersistentThisPointer<Notification>(this)));
|
| + m_loader->start(getExecutionContext(), m_data.Clone());
|
| }
|
|
|
| -void Notification::didLoadResources(NotificationResourcesLoader* loader)
|
| +void Notification::didLoadResources(NotificationResourcesLoader* loader, mojom::wtf::NotificationPtr notification)
|
| {
|
| DCHECK_EQ(loader, m_loader.get());
|
|
|
| - SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin();
|
| - ASSERT(origin);
|
| + manager()->show(std::move(notification), loader->getResources());
|
|
|
| - notificationManager()->show(WebSecurityOrigin(origin), m_data, loader->getResources(), this);
|
| m_loader.clear();
|
|
|
| m_state = NotificationStateShowing;
|
| @@ -176,14 +174,14 @@ void Notification::close()
|
| getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&Notification::dispatchCloseEvent, this));
|
|
|
| m_state = NotificationStateClosing;
|
| - notificationManager()->close(this);
|
| + //notificationManager()->close(this);
|
| } else {
|
| m_state = NotificationStateClosed;
|
|
|
| SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin();
|
| ASSERT(origin);
|
|
|
| - notificationManager()->closePersistent(WebSecurityOrigin(origin), m_persistentId);
|
| + //notificationManager()->closePersistent(WebSecurityOrigin(origin), m_persistentId);
|
| }
|
| }
|
|
|
| @@ -217,17 +215,17 @@ void Notification::dispatchCloseEvent()
|
|
|
| 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::wtf::NotificationDirection::LEFT_TO_RIGHT:
|
| return "ltr";
|
| - case WebNotificationData::DirectionRightToLeft:
|
| + case mojom::wtf::NotificationDirection::RIGHT_TO_LEFT:
|
| return "rtl";
|
| - case WebNotificationData::DirectionAuto:
|
| + case mojom::wtf::NotificationDirection::AUTO:
|
| return "auto";
|
| }
|
|
|
| @@ -237,33 +235,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 +271,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 +294,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 +309,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) {
|
| - switch (m_data.actions[i].type) {
|
| - case WebNotificationAction::Button:
|
| + for (size_t i = 0; i < m_data->actions.size(); ++i) {
|
| + const auto& action = m_data->actions[i];
|
| +
|
| + switch (action->type) {
|
| + case mojom::wtf::NotificationActionType::BUTTON:
|
| actions[i].setType("button");
|
| break;
|
| - case WebNotificationAction::Text:
|
| + case mojom::wtf::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 +351,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,7 +383,7 @@ const AtomicString& Notification::interfaceName() const
|
|
|
| void Notification::stop()
|
| {
|
| - notificationManager()->notifyDelegateDestroyed(this);
|
| + //notificationManager()->notifyDelegateDestroyed(this);
|
|
|
| m_state = NotificationStateClosed;
|
|
|
|
|