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

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: Add to global-interface-listing*-expected.txt 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
« no previous file with comments | « Source/modules/modules.gypi ('k') | Source/modules/notifications/Notification.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 18 matching lines...) Expand all
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/ScriptPromise.h" 34 #include "bindings/core/v8/ScriptPromise.h"
35 #include "bindings/core/v8/SerializedScriptValue.h" 35 #include "bindings/core/v8/SerializedScriptValue.h"
36 #include "core/dom/ActiveDOMObject.h" 36 #include "core/dom/ActiveDOMObject.h"
37 #include "modules/EventTargetModules.h" 37 #include "modules/EventTargetModules.h"
38 #include "modules/ModulesExport.h" 38 #include "modules/ModulesExport.h"
39 #include "modules/notifications/NotificationAction.h"
39 #include "modules/vibration/NavigatorVibration.h" 40 #include "modules/vibration/NavigatorVibration.h"
40 #include "platform/AsyncMethodRunner.h" 41 #include "platform/AsyncMethodRunner.h"
41 #include "platform/heap/Handle.h" 42 #include "platform/heap/Handle.h"
42 #include "platform/text/TextDirection.h" 43 #include "platform/text/TextDirection.h"
43 #include "platform/weborigin/KURL.h" 44 #include "platform/weborigin/KURL.h"
45 #include "public/platform/WebVector.h"
46 #include "public/platform/modules/notifications/WebNotificationAction.h"
44 #include "public/platform/modules/notifications/WebNotificationDelegate.h" 47 #include "public/platform/modules/notifications/WebNotificationDelegate.h"
45 #include "public/platform/modules/notifications/WebNotificationPermission.h" 48 #include "public/platform/modules/notifications/WebNotificationPermission.h"
46 #include "wtf/PassOwnPtr.h" 49 #include "wtf/PassOwnPtr.h"
47 #include "wtf/PassRefPtr.h" 50 #include "wtf/PassRefPtr.h"
48 #include "wtf/RefCounted.h" 51 #include "wtf/RefCounted.h"
49 #include "wtf/RefPtr.h" 52 #include "wtf/RefPtr.h"
50 53
51 namespace blink { 54 namespace blink {
52 55
53 class ExecutionContext; 56 class ExecutionContext;
(...skipping 30 matching lines...) Expand all
84 void dispatchClickEvent() override; 87 void dispatchClickEvent() override;
85 void dispatchErrorEvent() override; 88 void dispatchErrorEvent() override;
86 void dispatchCloseEvent() override; 89 void dispatchCloseEvent() override;
87 90
88 String title() const { return m_title; } 91 String title() const { return m_title; }
89 String dir() const { return m_dir; } 92 String dir() const { return m_dir; }
90 String lang() const { return m_lang; } 93 String lang() const { return m_lang; }
91 String body() const { return m_body; } 94 String body() const { return m_body; }
92 String tag() const { return m_tag; } 95 String tag() const { return m_tag; }
93 String icon() const { return m_iconUrl; } 96 String icon() const { return m_iconUrl; }
94 NavigatorVibration::VibrationPattern vibrate(bool& isNull) const; 97 const NavigatorVibration::VibrationPattern& vibrate(bool& isNull) const;
95 bool silent() const { return m_silent; } 98 bool silent() const { return m_silent; }
96 ScriptValue data(ScriptState*) const; 99 ScriptValue data(ScriptState*) const;
100 const HeapVector<NotificationAction>& actions() const { return m_actions; }
97 101
98 TextDirection direction() const; 102 TextDirection direction() const;
99 KURL iconURL() const { return m_iconUrl; } 103 KURL iconURL() const { return m_iconUrl; }
100 SerializedScriptValue* serializedData() const { return m_serializedData.get( ); } 104 SerializedScriptValue* serializedData() const { return m_serializedData.get( ); }
101 105
102 static String permissionString(WebNotificationPermission); 106 static String permissionString(WebNotificationPermission);
103 static String permission(ExecutionContext*); 107 static String permission(ExecutionContext*);
104 static WebNotificationPermission checkPermission(ExecutionContext*); 108 static WebNotificationPermission checkPermission(ExecutionContext*);
105 static ScriptPromise requestPermission(ScriptState*, NotificationPermissionC allback*); 109 static ScriptPromise requestPermission(ScriptState*, NotificationPermissionC allback*);
106 110
107 static unsigned maxActions(); 111 static size_t maxActions();
112
113 static void actionsToWebActions(const HeapVector<NotificationAction>& action s, WebVector<WebNotificationAction>* webActions);
108 114
109 // EventTarget interface. 115 // EventTarget interface.
110 ExecutionContext* executionContext() const final { return ActiveDOMObject::e xecutionContext(); } 116 ExecutionContext* executionContext() const final { return ActiveDOMObject::e xecutionContext(); }
111 const AtomicString& interfaceName() const override; 117 const AtomicString& interfaceName() const override;
112 118
113 // ActiveDOMObject interface. 119 // ActiveDOMObject interface.
114 void stop() override; 120 void stop() override;
115 bool hasPendingActivity() const override; 121 bool hasPendingActivity() const override;
116 122
117 DECLARE_VIRTUAL_TRACE(); 123 DECLARE_VIRTUAL_TRACE();
118 124
119 protected: 125 protected:
120 // EventTarget interface. 126 // EventTarget interface.
121 bool dispatchEventInternal(PassRefPtrWillBeRawPtr<Event>) final; 127 bool dispatchEventInternal(PassRefPtrWillBeRawPtr<Event>) final;
122 128
123 private: 129 private:
130 static void webActionsToActions(const WebVector<WebNotificationAction>& webA ctions, HeapVector<NotificationAction>* actions);
131
124 Notification(const String& title, ExecutionContext*); 132 Notification(const String& title, ExecutionContext*);
125 133
126 void scheduleShow(); 134 void scheduleShow();
127 135
128 // Calling show() may start asynchronous operation. If this object has 136 // Calling show() may start asynchronous operation. If this object has
129 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being 137 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being
130 // 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
131 // 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
132 // instance until the operation completes. 140 // instance until the operation completes.
133 void show(); 141 void show();
134 142
135 void setDir(const String& dir) { m_dir = dir; } 143 void setDir(const String& dir) { m_dir = dir; }
136 void setLang(const String& lang) { m_lang = lang; } 144 void setLang(const String& lang) { m_lang = lang; }
137 void setBody(const String& body) { m_body = body; } 145 void setBody(const String& body) { m_body = body; }
138 void setIconUrl(KURL iconUrl) { m_iconUrl = iconUrl; } 146 void setIconUrl(KURL iconUrl) { m_iconUrl = iconUrl; }
139 void setTag(const String& tag) { m_tag = tag; } 147 void setTag(const String& tag) { m_tag = tag; }
140 void setVibrate(const NavigatorVibration::VibrationPattern& vibrate) { m_vib rate = vibrate; } 148 void setVibrate(const NavigatorVibration::VibrationPattern& vibrate) { m_vib rate = vibrate; }
141 void setSilent(bool silent) { m_silent = silent; } 149 void setSilent(bool silent) { m_silent = silent; }
142 void setSerializedData(PassRefPtr<SerializedScriptValue> data) { m_serialize dData = data; } 150 void setSerializedData(PassRefPtr<SerializedScriptValue> data) { m_serialize dData = data; }
151 void setActions(const HeapVector<NotificationAction>& actions) { m_actions = actions; }
143 152
144 void setPersistentId(int64_t persistentId) { m_persistentId = persistentId; } 153 void setPersistentId(int64_t persistentId) { m_persistentId = persistentId; }
145 154
146 private:
147 String m_title; 155 String m_title;
148 String m_dir; 156 String m_dir;
149 String m_lang; 157 String m_lang;
150 String m_body; 158 String m_body;
151 String m_tag; 159 String m_tag;
152 NavigatorVibration::VibrationPattern m_vibrate; 160 NavigatorVibration::VibrationPattern m_vibrate;
153 bool m_silent; 161 bool m_silent;
154 RefPtr<SerializedScriptValue> m_serializedData; 162 RefPtr<SerializedScriptValue> m_serializedData;
163 HeapVector<NotificationAction> m_actions;
155 164
156 KURL m_iconUrl; 165 KURL m_iconUrl;
157 166
158 // 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
159 // 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
160 // 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.
161 int64_t m_persistentId; 170 int64_t m_persistentId;
162 171
163 enum NotificationState { 172 enum NotificationState {
164 NotificationStateIdle, 173 NotificationStateIdle,
165 NotificationStateShowing, 174 NotificationStateShowing,
166 NotificationStateClosing, 175 NotificationStateClosing,
167 NotificationStateClosed 176 NotificationStateClosed
168 }; 177 };
169 178
170 // 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
171 // by the embedder rather than by Blink. 180 // by the embedder rather than by Blink.
172 void setState(NotificationState state) { m_state = state; } 181 void setState(NotificationState state) { m_state = state; }
173 182
174 NotificationState m_state; 183 NotificationState m_state;
175 184
176 AsyncMethodRunner<Notification> m_asyncRunner; 185 AsyncMethodRunner<Notification> m_asyncRunner;
177 }; 186 };
178 187
179 } // namespace blink 188 } // namespace blink
180 189
181 #endif // Notification_h 190 #endif // Notification_h
OLDNEW
« no previous file with comments | « Source/modules/modules.gypi ('k') | Source/modules/notifications/Notification.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698