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

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

Powered by Google App Engine
This is Rietveld 408576698