Chromium Code Reviews| Index: Source/modules/notifications/Notification.h |
| diff --git a/Source/modules/notifications/Notification.h b/Source/modules/notifications/Notification.h |
| index e922eb9227fbdd6c7178da3884fdc23287de9b70..938c5ad6a1779638b670f8ef2d4cfe6e5c8e4714 100644 |
| --- a/Source/modules/notifications/Notification.h |
| +++ b/Source/modules/notifications/Notification.h |
| @@ -35,11 +35,14 @@ |
| #include "core/dom/ActiveDOMObject.h" |
| #include "modules/EventTargetModules.h" |
| #include "modules/ModulesExport.h" |
| +#include "modules/notifications/NotificationAction.h" |
| #include "modules/vibration/NavigatorVibration.h" |
| #include "platform/AsyncMethodRunner.h" |
| #include "platform/heap/Handle.h" |
| #include "platform/text/TextDirection.h" |
| #include "platform/weborigin/KURL.h" |
| +#include "public/platform/WebVector.h" |
| +#include "public/platform/modules/notifications/WebNotificationAction.h" |
| #include "public/platform/modules/notifications/WebNotificationDelegate.h" |
| #include "public/platform/modules/notifications/WebNotificationPermission.h" |
| #include "wtf/PassOwnPtr.h" |
| @@ -90,9 +93,10 @@ public: |
| String body() const { return m_body; } |
| String tag() const { return m_tag; } |
| String icon() const { return m_iconUrl; } |
| - NavigatorVibration::VibrationPattern vibrate(bool& isNull) const; |
| + const NavigatorVibration::VibrationPattern& vibrate(bool& isNull) const; |
| bool silent() const { return m_silent; } |
| ScriptValue data(ScriptState*) const; |
| + const Vector<NotificationAction>& actions() const { return m_actions; } |
| TextDirection direction() const; |
| KURL iconURL() const { return m_iconUrl; } |
| @@ -103,6 +107,10 @@ public: |
| static WebNotificationPermission checkPermission(ExecutionContext*); |
| static void requestPermission(ExecutionContext*, NotificationPermissionCallback* = nullptr); |
| + template<size_t C, typename A> |
| + static void actionsToWebActions(const Vector<NotificationAction, C, A>& actions, WebVector<WebNotificationAction>& webActions); |
| + static void webActionsToActions(const WebVector<WebNotificationAction>& webActions, Vector<NotificationAction>& actions); |
|
Peter Beverloo
2015/07/30 16:24:07
This can be private.
johnme
2015/07/31 15:10:10
Done.
|
| + |
| // EventTarget interface. |
| ExecutionContext* executionContext() const final { return ActiveDOMObject::executionContext(); } |
| const AtomicString& interfaceName() const override; |
| @@ -118,6 +126,9 @@ protected: |
| bool dispatchEventInternal(PassRefPtrWillBeRawPtr<Event>) final; |
| private: |
| + // Conveniently, all Blink platforms that support notifications currently support 2 actions. |
| + static const size_t maxActions = 2; |
|
Peter Beverloo
2015/07/30 16:24:08
This is an embedder concern, not a Blink one. Perh
johnme
2015/07/31 15:10:10
Done.
|
| + |
| Notification(const String& title, ExecutionContext*); |
| void scheduleShow(); |
| @@ -137,10 +148,10 @@ private: |
| void setVibrate(const NavigatorVibration::VibrationPattern& vibrate) { m_vibrate = vibrate; } |
| void setSilent(bool silent) { m_silent = silent; } |
| void setSerializedData(PassRefPtr<SerializedScriptValue> data) { m_serializedData = data; } |
| + void setActions(const Vector<NotificationAction>& actions) { m_actions = actions; } |
| void setPersistentId(int64_t persistentId) { m_persistentId = persistentId; } |
| -private: |
| String m_title; |
| String m_dir; |
| String m_lang; |
| @@ -149,6 +160,7 @@ private: |
| NavigatorVibration::VibrationPattern m_vibrate; |
| bool m_silent; |
| RefPtr<SerializedScriptValue> m_serializedData; |
| + Vector<NotificationAction> m_actions; |
| KURL m_iconUrl; |
| @@ -173,6 +185,17 @@ private: |
| AsyncMethodRunner<Notification> m_asyncRunner; |
| }; |
| +template<size_t C, typename A> |
| +void Notification::actionsToWebActions(const Vector<NotificationAction, C, A>& actions, WebVector<WebNotificationAction>& webActions) |
|
Peter Beverloo
2015/07/30 16:24:07
nit: While the Blink style allows it, I'd prefer i
Peter Beverloo
2015/07/30 16:24:08
Why do we need template<>? This should be defined
johnme
2015/07/31 15:10:10
Done.
johnme
2015/07/31 15:10:10
Done (without the template, we need an extra copy
|
| +{ |
| + size_t count = std::min(+maxActions, actions.size()); |
| + WebVector<WebNotificationAction> clearedAndResized(count); |
| + webActions.swap(clearedAndResized); |
| + for (size_t i = 0; i < count; ++i) { |
| + webActions[i].title = actions[i].title(); |
| + } |
| +} |
| + |
| } // namespace blink |
| #endif // Notification_h |