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

Side by Side Diff: Source/modules/notifications/Notification.h

Issue 1263043002: Add NotificationOptions.actions so websites can provide buttons (blink) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef Notification_h 31 #ifndef Notification_h
32 #define Notification_h 32 #define Notification_h
33 33
34 #include "bindings/core/v8/SerializedScriptValue.h" 34 #include "bindings/core/v8/SerializedScriptValue.h"
35 #include "core/dom/ActiveDOMObject.h" 35 #include "core/dom/ActiveDOMObject.h"
36 #include "modules/EventTargetModules.h" 36 #include "modules/EventTargetModules.h"
37 #include "modules/ModulesExport.h" 37 #include "modules/ModulesExport.h"
38 #include "modules/notifications/NotificationAction.h"
38 #include "modules/vibration/NavigatorVibration.h" 39 #include "modules/vibration/NavigatorVibration.h"
39 #include "platform/AsyncMethodRunner.h" 40 #include "platform/AsyncMethodRunner.h"
40 #include "platform/heap/Handle.h" 41 #include "platform/heap/Handle.h"
41 #include "platform/text/TextDirection.h" 42 #include "platform/text/TextDirection.h"
42 #include "platform/weborigin/KURL.h" 43 #include "platform/weborigin/KURL.h"
44 #include "public/platform/WebVector.h"
45 #include "public/platform/modules/notifications/WebNotificationAction.h"
43 #include "public/platform/modules/notifications/WebNotificationDelegate.h" 46 #include "public/platform/modules/notifications/WebNotificationDelegate.h"
44 #include "public/platform/modules/notifications/WebNotificationPermission.h" 47 #include "public/platform/modules/notifications/WebNotificationPermission.h"
45 #include "wtf/PassOwnPtr.h" 48 #include "wtf/PassOwnPtr.h"
46 #include "wtf/PassRefPtr.h" 49 #include "wtf/PassRefPtr.h"
47 #include "wtf/RefCounted.h" 50 #include "wtf/RefCounted.h"
48 #include "wtf/RefPtr.h" 51 #include "wtf/RefPtr.h"
49 52
50 namespace blink { 53 namespace blink {
51 54
52 class ExecutionContext; 55 class ExecutionContext;
(...skipping 30 matching lines...) Expand all
83 void dispatchClickEvent() override; 86 void dispatchClickEvent() override;
84 void dispatchErrorEvent() override; 87 void dispatchErrorEvent() override;
85 void dispatchCloseEvent() override; 88 void dispatchCloseEvent() override;
86 89
87 String title() const { return m_title; } 90 String title() const { return m_title; }
88 String dir() const { return m_dir; } 91 String dir() const { return m_dir; }
89 String lang() const { return m_lang; } 92 String lang() const { return m_lang; }
90 String body() const { return m_body; } 93 String body() const { return m_body; }
91 String tag() const { return m_tag; } 94 String tag() const { return m_tag; }
92 String icon() const { return m_iconUrl; } 95 String icon() const { return m_iconUrl; }
93 NavigatorVibration::VibrationPattern vibrate(bool& isNull) const; 96 const NavigatorVibration::VibrationPattern& vibrate(bool& isNull) const;
94 bool silent() const { return m_silent; } 97 bool silent() const { return m_silent; }
95 ScriptValue data(ScriptState*) const; 98 ScriptValue data(ScriptState*) const;
99 const Vector<NotificationAction>& actions() const { return m_actions; }
96 100
97 TextDirection direction() const; 101 TextDirection direction() const;
98 KURL iconURL() const { return m_iconUrl; } 102 KURL iconURL() const { return m_iconUrl; }
99 SerializedScriptValue* serializedData() const { return m_serializedData.get( ); } 103 SerializedScriptValue* serializedData() const { return m_serializedData.get( ); }
100 104
101 static String permissionString(WebNotificationPermission); 105 static String permissionString(WebNotificationPermission);
102 static String permission(ExecutionContext*); 106 static String permission(ExecutionContext*);
103 static WebNotificationPermission checkPermission(ExecutionContext*); 107 static WebNotificationPermission checkPermission(ExecutionContext*);
104 static void requestPermission(ExecutionContext*, NotificationPermissionCallb ack* = nullptr); 108 static void requestPermission(ExecutionContext*, NotificationPermissionCallb ack* = nullptr);
105 109
110 template<size_t C, typename A>
111 static void actionsToWebActions(const Vector<NotificationAction, C, A>& acti ons, WebVector<WebNotificationAction>& webActions);
112 static void webActionsToActions(const WebVector<WebNotificationAction>& webA ctions, Vector<NotificationAction>& actions);
Peter Beverloo 2015/07/30 16:24:07 This can be private.
johnme 2015/07/31 15:10:10 Done.
113
106 // EventTarget interface. 114 // EventTarget interface.
107 ExecutionContext* executionContext() const final { return ActiveDOMObject::e xecutionContext(); } 115 ExecutionContext* executionContext() const final { return ActiveDOMObject::e xecutionContext(); }
108 const AtomicString& interfaceName() const override; 116 const AtomicString& interfaceName() const override;
109 117
110 // ActiveDOMObject interface. 118 // ActiveDOMObject interface.
111 void stop() override; 119 void stop() override;
112 bool hasPendingActivity() const override; 120 bool hasPendingActivity() const override;
113 121
114 DECLARE_VIRTUAL_TRACE(); 122 DECLARE_VIRTUAL_TRACE();
115 123
116 protected: 124 protected:
117 // EventTarget interface. 125 // EventTarget interface.
118 bool dispatchEventInternal(PassRefPtrWillBeRawPtr<Event>) final; 126 bool dispatchEventInternal(PassRefPtrWillBeRawPtr<Event>) final;
119 127
120 private: 128 private:
129 // Conveniently, all Blink platforms that support notifications currently su pport 2 actions.
130 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.
131
121 Notification(const String& title, ExecutionContext*); 132 Notification(const String& title, ExecutionContext*);
122 133
123 void scheduleShow(); 134 void scheduleShow();
124 135
125 // Calling show() may start asynchronous operation. If this object has 136 // Calling show() may start asynchronous operation. If this object has
126 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being 137 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being
127 // collected while m_state is Showing, and so this instance stays alive 138 // collected while m_state is Showing, and so this instance stays alive
128 // until the operation completes. Otherwise, you need to hold a ref on this 139 // until the operation completes. Otherwise, you need to hold a ref on this
129 // instance until the operation completes. 140 // instance until the operation completes.
130 void show(); 141 void show();
131 142
132 void setDir(const String& dir) { m_dir = dir; } 143 void setDir(const String& dir) { m_dir = dir; }
133 void setLang(const String& lang) { m_lang = lang; } 144 void setLang(const String& lang) { m_lang = lang; }
134 void setBody(const String& body) { m_body = body; } 145 void setBody(const String& body) { m_body = body; }
135 void setIconUrl(KURL iconUrl) { m_iconUrl = iconUrl; } 146 void setIconUrl(KURL iconUrl) { m_iconUrl = iconUrl; }
136 void setTag(const String& tag) { m_tag = tag; } 147 void setTag(const String& tag) { m_tag = tag; }
137 void setVibrate(const NavigatorVibration::VibrationPattern& vibrate) { m_vib rate = vibrate; } 148 void setVibrate(const NavigatorVibration::VibrationPattern& vibrate) { m_vib rate = vibrate; }
138 void setSilent(bool silent) { m_silent = silent; } 149 void setSilent(bool silent) { m_silent = silent; }
139 void setSerializedData(PassRefPtr<SerializedScriptValue> data) { m_serialize dData = data; } 150 void setSerializedData(PassRefPtr<SerializedScriptValue> data) { m_serialize dData = data; }
151 void setActions(const Vector<NotificationAction>& actions) { m_actions = act ions; }
140 152
141 void setPersistentId(int64_t persistentId) { m_persistentId = persistentId; } 153 void setPersistentId(int64_t persistentId) { m_persistentId = persistentId; }
142 154
143 private:
144 String m_title; 155 String m_title;
145 String m_dir; 156 String m_dir;
146 String m_lang; 157 String m_lang;
147 String m_body; 158 String m_body;
148 String m_tag; 159 String m_tag;
149 NavigatorVibration::VibrationPattern m_vibrate; 160 NavigatorVibration::VibrationPattern m_vibrate;
150 bool m_silent; 161 bool m_silent;
151 RefPtr<SerializedScriptValue> m_serializedData; 162 RefPtr<SerializedScriptValue> m_serializedData;
163 Vector<NotificationAction> m_actions;
152 164
153 KURL m_iconUrl; 165 KURL m_iconUrl;
154 166
155 // Notifications can either be bound to the page, which means they're identi fied by 167 // Notifications can either be bound to the page, which means they're identi fied by
156 // their delegate, or persistent, which means they're identified by a persis tent Id 168 // their delegate, or persistent, which means they're identified by a persis tent Id
157 // given to us by the embedder. This influences how we close the notificatio n. 169 // given to us by the embedder. This influences how we close the notificatio n.
158 int64_t m_persistentId; 170 int64_t m_persistentId;
159 171
160 enum NotificationState { 172 enum NotificationState {
161 NotificationStateIdle, 173 NotificationStateIdle,
162 NotificationStateShowing, 174 NotificationStateShowing,
163 NotificationStateClosing, 175 NotificationStateClosing,
164 NotificationStateClosed 176 NotificationStateClosed
165 }; 177 };
166 178
167 // Only to be used by the Notification::create() method when notifications w ere created 179 // Only to be used by the Notification::create() method when notifications w ere created
168 // by the embedder rather than by Blink. 180 // by the embedder rather than by Blink.
169 void setState(NotificationState state) { m_state = state; } 181 void setState(NotificationState state) { m_state = state; }
170 182
171 NotificationState m_state; 183 NotificationState m_state;
172 184
173 AsyncMethodRunner<Notification> m_asyncRunner; 185 AsyncMethodRunner<Notification> m_asyncRunner;
174 }; 186 };
175 187
188 template<size_t C, typename A>
189 void Notification::actionsToWebActions(const Vector<NotificationAction, C, A>& a ctions, 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
190 {
191 size_t count = std::min(+maxActions, actions.size());
192 WebVector<WebNotificationAction> clearedAndResized(count);
193 webActions.swap(clearedAndResized);
194 for (size_t i = 0; i < count; ++i) {
195 webActions[i].title = actions[i].title();
196 }
197 }
198
176 } // namespace blink 199 } // namespace blink
177 200
178 #endif // Notification_h 201 #endif // Notification_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698