OLD | NEW |
---|---|
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg istration.showNotification() instead."); | 70 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg istration.showNotification() instead."); |
71 return nullptr; | 71 return nullptr; |
72 } | 72 } |
73 | 73 |
74 // The Web Notification constructor may not be used in Service Worker contex ts. | 74 // The Web Notification constructor may not be used in Service Worker contex ts. |
75 if (context->isServiceWorkerGlobalScope()) { | 75 if (context->isServiceWorkerGlobalScope()) { |
76 exceptionState.throwTypeError("Illegal constructor."); | 76 exceptionState.throwTypeError("Illegal constructor."); |
77 return nullptr; | 77 return nullptr; |
78 } | 78 } |
79 | 79 |
80 // If options's silent is true, and options's vibrate is present, throw a Ty peError exception. | |
81 if (options.hasVibrate() && options.silent()) { | |
82 exceptionState.throwTypeError("Silent notification must not specify vibr ation patterns."); | |
Peter Beverloo
2015/04/13 15:05:18
nit: notification -> notifications
Sanghyun Park
2015/04/13 17:27:23
Done.
| |
83 return nullptr; | |
84 } | |
85 | |
80 RefPtr<SerializedScriptValue> data; | 86 RefPtr<SerializedScriptValue> data; |
81 if (options.hasData()) { | 87 if (options.hasData()) { |
82 data = SerializedScriptValueFactory::instance().create(options.data(), n ullptr, exceptionState, options.data().isolate()); | 88 data = SerializedScriptValueFactory::instance().create(options.data(), n ullptr, exceptionState, options.data().isolate()); |
83 if (exceptionState.hadException()) | 89 if (exceptionState.hadException()) |
84 return nullptr; | 90 return nullptr; |
85 } | 91 } |
86 | 92 |
87 Notification* notification = new Notification(title, context); | 93 Notification* notification = new Notification(title, context); |
88 | 94 |
89 notification->setBody(options.body()); | 95 notification->setBody(options.body()); |
90 notification->setTag(options.tag()); | 96 notification->setTag(options.tag()); |
91 notification->setLang(options.lang()); | 97 notification->setLang(options.lang()); |
92 notification->setDir(options.dir()); | 98 notification->setDir(options.dir()); |
99 notification->setVibrate(NavigatorVibration::sanitizeVibrationPattern(option s.vibrate())); | |
93 notification->setSilent(options.silent()); | 100 notification->setSilent(options.silent()); |
94 notification->setSerializedData(data.release()); | 101 notification->setSerializedData(data.release()); |
95 if (options.hasIcon()) { | 102 if (options.hasIcon()) { |
96 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon()); | 103 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon()); |
97 if (!iconUrl.isEmpty() && iconUrl.isValid()) | 104 if (!iconUrl.isEmpty() && iconUrl.isValid()) |
98 notification->setIconUrl(iconUrl); | 105 notification->setIconUrl(iconUrl); |
99 } | 106 } |
100 | 107 |
101 String insecureOriginMessage; | 108 String insecureOriginMessage; |
102 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq uiringSecureOrigin(insecureOriginMessage) | 109 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq uiringSecureOrigin(insecureOriginMessage) |
(...skipping 12 matching lines...) Expand all Loading... | |
115 notification->setPersistentId(persistentId); | 122 notification->setPersistentId(persistentId); |
116 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR ight ? "ltr" : "rtl"); | 123 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR ight ? "ltr" : "rtl"); |
117 notification->setLang(data.lang); | 124 notification->setLang(data.lang); |
118 notification->setBody(data.body); | 125 notification->setBody(data.body); |
119 notification->setTag(data.tag); | 126 notification->setTag(data.tag); |
120 notification->setSilent(data.silent); | 127 notification->setSilent(data.silent); |
121 | 128 |
122 if (!data.icon.isEmpty()) | 129 if (!data.icon.isEmpty()) |
123 notification->setIconUrl(data.icon); | 130 notification->setIconUrl(data.icon); |
124 | 131 |
132 if (!data.vibrate.isEmpty()) { | |
133 NavigatorVibration::VibrationPattern pattern; | |
134 pattern.appendRange(data.vibrate.begin(), data.vibrate.end()); | |
135 notification->setVibrate(pattern); | |
136 } | |
137 | |
125 const WebVector<char>& dataBytes = data.data; | 138 const WebVector<char>& dataBytes = data.data; |
126 if (!dataBytes.isEmpty()) { | 139 if (!dataBytes.isEmpty()) { |
127 notification->setSerializedData(SerializedScriptValueFactory::instance() .createFromWireBytes(dataBytes.data(), dataBytes.size())); | 140 notification->setSerializedData(SerializedScriptValueFactory::instance() .createFromWireBytes(dataBytes.data(), dataBytes.size())); |
128 notification->serializedData()->registerMemoryAllocatedWithCurrentScript Context(); | 141 notification->serializedData()->registerMemoryAllocatedWithCurrentScript Context(); |
129 } | 142 } |
130 | 143 |
131 notification->setState(NotificationStateShowing); | 144 notification->setState(NotificationStateShowing); |
132 notification->suspendIfNeeded(); | 145 notification->suspendIfNeeded(); |
133 return notification; | 146 return notification; |
134 } | 147 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 SecurityOrigin* origin = executionContext()->securityOrigin(); | 180 SecurityOrigin* origin = executionContext()->securityOrigin(); |
168 ASSERT(origin); | 181 ASSERT(origin); |
169 | 182 |
170 // FIXME: Do CSP checks on the associated notification icon. | 183 // FIXME: Do CSP checks on the associated notification icon. |
171 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D irectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 184 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D irectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
172 | 185 |
173 // The lifetime and availability of non-persistent notifications is tied to the page | 186 // The lifetime and availability of non-persistent notifications is tied to the page |
174 // they were created by, and thus the data doesn't have to be known to the e mbedder. | 187 // they were created by, and thus the data doesn't have to be known to the e mbedder. |
175 Vector<char> emptyDataWireBytes; | 188 Vector<char> emptyDataWireBytes; |
176 | 189 |
177 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_ iconUrl, m_silent, emptyDataWireBytes); | 190 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_ iconUrl, m_vibrate, m_silent, emptyDataWireBytes); |
178 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); | 191 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); |
179 | 192 |
180 m_state = NotificationStateShowing; | 193 m_state = NotificationStateShowing; |
181 } | 194 } |
182 | 195 |
183 void Notification::close() | 196 void Notification::close() |
184 { | 197 { |
185 if (m_state != NotificationStateShowing) | 198 if (m_state != NotificationStateShowing) |
186 return; | 199 return; |
187 | 200 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 { | 235 { |
223 // The notification will be showing when the user initiated the close, or it will be | 236 // The notification will be showing when the user initiated the close, or it will be |
224 // closing if the developer initiated the close. | 237 // closing if the developer initiated the close. |
225 if (m_state != NotificationStateShowing && m_state != NotificationStateClosi ng) | 238 if (m_state != NotificationStateShowing && m_state != NotificationStateClosi ng) |
226 return; | 239 return; |
227 | 240 |
228 m_state = NotificationStateClosed; | 241 m_state = NotificationStateClosed; |
229 dispatchEvent(Event::create(EventTypeNames::close)); | 242 dispatchEvent(Event::create(EventTypeNames::close)); |
230 } | 243 } |
231 | 244 |
245 NavigatorVibration::VibrationPattern Notification::vibrate(bool& isNull) const | |
246 { | |
247 isNull = m_vibrate.isEmpty(); | |
248 return m_vibrate; | |
249 } | |
250 | |
232 TextDirection Notification::direction() const | 251 TextDirection Notification::direction() const |
233 { | 252 { |
234 // FIXME: Resolve dir()=="auto" against the document. | 253 // FIXME: Resolve dir()=="auto" against the document. |
235 return dir() == "rtl" ? RTL : LTR; | 254 return dir() == "rtl" ? RTL : LTR; |
236 } | 255 } |
237 | 256 |
238 String Notification::permissionString(WebNotificationPermission permission) | 257 String Notification::permissionString(WebNotificationPermission permission) |
239 { | 258 { |
240 switch (permission) { | 259 switch (permission) { |
241 case WebNotificationPermissionAllowed: | 260 case WebNotificationPermissionAllowed: |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i solate())); | 323 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i solate())); |
305 } | 324 } |
306 | 325 |
307 DEFINE_TRACE(Notification) | 326 DEFINE_TRACE(Notification) |
308 { | 327 { |
309 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); | 328 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); |
310 ActiveDOMObject::trace(visitor); | 329 ActiveDOMObject::trace(visitor); |
311 } | 330 } |
312 | 331 |
313 } // namespace blink | 332 } // namespace blink |
OLD | NEW |