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

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

Issue 1260793007: Generalize validation of developer input for Web Notifications (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix actions 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 | Annotate | Revision Log
« 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"
40 #include "modules/vibration/NavigatorVibration.h" 39 #include "modules/vibration/NavigatorVibration.h"
41 #include "platform/AsyncMethodRunner.h" 40 #include "platform/AsyncMethodRunner.h"
42 #include "platform/heap/Handle.h" 41 #include "platform/heap/Handle.h"
43 #include "platform/text/TextDirection.h"
44 #include "platform/weborigin/KURL.h" 42 #include "platform/weborigin/KURL.h"
45 #include "public/platform/WebVector.h" 43 #include "public/platform/WebVector.h"
46 #include "public/platform/modules/notifications/WebNotificationAction.h" 44 #include "public/platform/modules/notifications/WebNotificationData.h"
47 #include "public/platform/modules/notifications/WebNotificationDelegate.h" 45 #include "public/platform/modules/notifications/WebNotificationDelegate.h"
48 #include "public/platform/modules/notifications/WebNotificationPermission.h" 46 #include "public/platform/modules/notifications/WebNotificationPermission.h"
49 #include "wtf/PassOwnPtr.h" 47 #include "wtf/PassOwnPtr.h"
50 #include "wtf/PassRefPtr.h" 48 #include "wtf/PassRefPtr.h"
51 #include "wtf/RefCounted.h" 49 #include "wtf/RefCounted.h"
52 #include "wtf/RefPtr.h" 50 #include "wtf/RefPtr.h"
53 51
54 namespace blink { 52 namespace blink {
55 53
56 class ExecutionContext; 54 class ExecutionContext;
55 class NotificationAction;
57 class NotificationOptions; 56 class NotificationOptions;
58 class NotificationPermissionCallback; 57 class NotificationPermissionCallback;
59 class ScriptState; 58 class ScriptState;
60 class ScriptValue; 59 class ScriptValue;
61 class UnsignedLongOrUnsignedLongSequence; 60 class UnsignedLongOrUnsignedLongSequence;
62 struct WebNotificationData;
63 61
64 class MODULES_EXPORT Notification final : public RefCountedGarbageCollectedEvent TargetWithInlineData<Notification>, public ActiveDOMObject, public WebNotificati onDelegate { 62 class MODULES_EXPORT Notification final : public RefCountedGarbageCollectedEvent TargetWithInlineData<Notification>, public ActiveDOMObject, public WebNotificati onDelegate {
65 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(Notification); 63 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(Notification);
66 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Notification); 64 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Notification);
67 DEFINE_WRAPPERTYPEINFO(); 65 DEFINE_WRAPPERTYPEINFO();
68 public: 66 public:
69 // Used for JavaScript instantiations of the Notification object. Will autom atically schedule for 67 // Used for JavaScript instantiations of the Notification object. Will autom atically schedule for
70 // the notification to be displayed to the user. 68 // the notification to be displayed to the user when the developer-provided data is valid.
71 static Notification* create(ExecutionContext*, const String& title, const No tificationOptions&, ExceptionState&); 69 static Notification* create(ExecutionContext*, const String& title, const No tificationOptions&, ExceptionState&);
72 70
73 // Used for embedder-created Notification objects. Will initialize the Notif ication's state as showing. 71 // Used for embedder-created Notification objects. Will initialize the Notif ication's state as showing.
74 static Notification* create(ExecutionContext*, int64_t persistentId, const W ebNotificationData&); 72 static Notification* create(ExecutionContext*, int64_t persistentId, const W ebNotificationData&);
75 73
76 ~Notification() override; 74 ~Notification() override;
77 75
78 void close(); 76 void close();
79 77
80 DEFINE_ATTRIBUTE_EVENT_LISTENER(click); 78 DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
81 DEFINE_ATTRIBUTE_EVENT_LISTENER(show); 79 DEFINE_ATTRIBUTE_EVENT_LISTENER(show);
82 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); 80 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
83 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); 81 DEFINE_ATTRIBUTE_EVENT_LISTENER(close);
84 82
85 // WebNotificationDelegate implementation. 83 // WebNotificationDelegate implementation.
86 void dispatchShowEvent() override; 84 void dispatchShowEvent() override;
87 void dispatchClickEvent() override; 85 void dispatchClickEvent() override;
88 void dispatchErrorEvent() override; 86 void dispatchErrorEvent() override;
89 void dispatchCloseEvent() override; 87 void dispatchCloseEvent() override;
90 88
91 String title() const { return m_title; } 89 String title() const;
92 String dir() const { return m_dir; } 90 String dir() const;
93 String lang() const { return m_lang; } 91 String lang() const;
94 String body() const { return m_body; } 92 String body() const;
95 String tag() const { return m_tag; } 93 String tag() const;
96 String icon() const { return m_iconUrl; } 94 String icon() const;
97 const NavigatorVibration::VibrationPattern& vibrate(bool& isNull) const; 95 NavigatorVibration::VibrationPattern vibrate(bool& isNull) const;
98 bool silent() const { return m_silent; } 96 bool silent() const;
99 ScriptValue data(ScriptState*) const; 97 ScriptValue data(ScriptState*);
100 const HeapVector<NotificationAction>& actions() const { return m_actions; } 98 HeapVector<NotificationAction> actions() const;
101
102 TextDirection direction() const;
103 KURL iconURL() const { return m_iconUrl; }
104 SerializedScriptValue* serializedData() const { return m_serializedData.get( ); }
105 99
106 static String permissionString(WebNotificationPermission); 100 static String permissionString(WebNotificationPermission);
107 static String permission(ExecutionContext*); 101 static String permission(ExecutionContext*);
108 static WebNotificationPermission checkPermission(ExecutionContext*); 102 static WebNotificationPermission checkPermission(ExecutionContext*);
109 static ScriptPromise requestPermission(ScriptState*, NotificationPermissionC allback*); 103 static ScriptPromise requestPermission(ScriptState*, NotificationPermissionC allback*);
110 104
111 static size_t maxActions(); 105 static size_t maxActions();
112 106
113 static void actionsToWebActions(const HeapVector<NotificationAction>& action s, WebVector<WebNotificationAction>* webActions);
114
115 // EventTarget interface. 107 // EventTarget interface.
116 ExecutionContext* executionContext() const final { return ActiveDOMObject::e xecutionContext(); } 108 ExecutionContext* executionContext() const final { return ActiveDOMObject::e xecutionContext(); }
117 const AtomicString& interfaceName() const override; 109 const AtomicString& interfaceName() const override;
118 110
119 // ActiveDOMObject interface. 111 // ActiveDOMObject interface.
120 void stop() override; 112 void stop() override;
121 bool hasPendingActivity() const override; 113 bool hasPendingActivity() const override;
122 114
123 DECLARE_VIRTUAL_TRACE(); 115 DECLARE_VIRTUAL_TRACE();
124 116
125 protected: 117 protected:
126 // EventTarget interface. 118 // EventTarget interface.
127 bool dispatchEventInternal(PassRefPtrWillBeRawPtr<Event>) final; 119 bool dispatchEventInternal(PassRefPtrWillBeRawPtr<Event>) final;
128 120
129 private: 121 private:
130 static void webActionsToActions(const WebVector<WebNotificationAction>& webA ctions, HeapVector<NotificationAction>* actions); 122 Notification(ExecutionContext*, const WebNotificationData&);
131
132 Notification(const String& title, ExecutionContext*);
133 123
134 void scheduleShow(); 124 void scheduleShow();
135 125
136 // Calling show() may start asynchronous operation. If this object has 126 // Calling show() may start asynchronous operation. If this object has
137 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being 127 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being
138 // collected while m_state is Showing, and so this instance stays alive 128 // collected while m_state is Showing, and so this instance stays alive
139 // until the operation completes. Otherwise, you need to hold a ref on this 129 // until the operation completes. Otherwise, you need to hold a ref on this
140 // instance until the operation completes. 130 // instance until the operation completes.
141 void show(); 131 void show();
142 132
143 void setDir(const String& dir) { m_dir = dir; }
144 void setLang(const String& lang) { m_lang = lang; }
145 void setBody(const String& body) { m_body = body; }
146 void setIconUrl(KURL iconUrl) { m_iconUrl = iconUrl; }
147 void setTag(const String& tag) { m_tag = tag; }
148 void setVibrate(const NavigatorVibration::VibrationPattern& vibrate) { m_vib rate = vibrate; }
149 void setSilent(bool silent) { m_silent = silent; }
150 void setSerializedData(PassRefPtr<SerializedScriptValue> data) { m_serialize dData = data; }
151 void setActions(const HeapVector<NotificationAction>& actions) { m_actions = actions; }
152
153 void setPersistentId(int64_t persistentId) { m_persistentId = persistentId; } 133 void setPersistentId(int64_t persistentId) { m_persistentId = persistentId; }
154 134
155 String m_title; 135 private:
156 String m_dir; 136 WebNotificationData m_data;
157 String m_lang; 137
158 String m_body;
159 String m_tag;
160 NavigatorVibration::VibrationPattern m_vibrate;
161 bool m_silent;
162 RefPtr<SerializedScriptValue> m_serializedData; 138 RefPtr<SerializedScriptValue> m_serializedData;
163 HeapVector<NotificationAction> m_actions;
164
165 KURL m_iconUrl;
166 139
167 // Notifications can either be bound to the page, which means they're identi fied by 140 // Notifications can either be bound to the page, which means they're identi fied by
168 // their delegate, or persistent, which means they're identified by a persis tent Id 141 // their delegate, or persistent, which means they're identified by a persis tent Id
169 // given to us by the embedder. This influences how we close the notificatio n. 142 // given to us by the embedder. This influences how we close the notificatio n.
170 int64_t m_persistentId; 143 int64_t m_persistentId;
171 144
172 enum NotificationState { 145 enum NotificationState {
173 NotificationStateIdle, 146 NotificationStateIdle,
174 NotificationStateShowing, 147 NotificationStateShowing,
175 NotificationStateClosing, 148 NotificationStateClosing,
176 NotificationStateClosed 149 NotificationStateClosed
177 }; 150 };
178 151
179 // Only to be used by the Notification::create() method when notifications w ere created 152 // Only to be used by the Notification::create() method when notifications w ere created
180 // by the embedder rather than by Blink. 153 // by the embedder rather than by Blink.
181 void setState(NotificationState state) { m_state = state; } 154 void setState(NotificationState state) { m_state = state; }
182 155
183 NotificationState m_state; 156 NotificationState m_state;
184 157
185 AsyncMethodRunner<Notification> m_asyncRunner; 158 AsyncMethodRunner<Notification> m_asyncRunner;
186 }; 159 };
187 160
188 } // namespace blink 161 } // namespace blink
189 162
190 #endif // Notification_h 163 #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