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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 return nullptr; | 99 return nullptr; |
100 } | 100 } |
101 if (action.title().isEmpty()) { | 101 if (action.title().isEmpty()) { |
102 exceptionState.throwTypeError("NotificationAction title must not be
empty."); | 102 exceptionState.throwTypeError("NotificationAction title must not be
empty."); |
103 return nullptr; | 103 return nullptr; |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 Notification* notification = new Notification(title, context); | 107 Notification* notification = new Notification(title, context); |
108 | 108 |
| 109 notification->setDir(options.dir()); |
| 110 notification->setLang(options.lang()); |
109 notification->setBody(options.body()); | 111 notification->setBody(options.body()); |
110 notification->setTag(options.tag()); | 112 notification->setTag(options.tag()); |
111 notification->setLang(options.lang()); | 113 notification->setPriority(options.priority()); |
112 notification->setDir(options.dir()); | |
113 notification->setVibrate(NavigatorVibration::sanitizeVibrationPattern(option
s.vibrate())); | 114 notification->setVibrate(NavigatorVibration::sanitizeVibrationPattern(option
s.vibrate())); |
114 notification->setSilent(options.silent()); | 115 notification->setSilent(options.silent()); |
115 notification->setSerializedData(data.release()); | 116 notification->setSerializedData(data.release()); |
116 if (options.hasIcon()) { | 117 if (options.hasIcon()) { |
117 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL(
options.icon()); | 118 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL(
options.icon()); |
118 if (!iconUrl.isEmpty() && iconUrl.isValid()) | 119 if (!iconUrl.isEmpty() && iconUrl.isValid()) |
119 notification->setIconUrl(iconUrl); | 120 notification->setIconUrl(iconUrl); |
120 } | 121 } |
121 HeapVector<NotificationAction> actions; | 122 HeapVector<NotificationAction> actions; |
122 actions.appendRange(options.actions().begin(), options.actions().begin() + s
td::min(maxActions(), options.actions().size())); | 123 actions.appendRange(options.actions().begin(), options.actions().begin() + s
td::min(maxActions(), options.actions().size())); |
(...skipping 12 matching lines...) Expand all Loading... |
135 | 136 |
136 Notification* Notification::create(ExecutionContext* context, int64_t persistent
Id, const WebNotificationData& data) | 137 Notification* Notification::create(ExecutionContext* context, int64_t persistent
Id, const WebNotificationData& data) |
137 { | 138 { |
138 Notification* notification = new Notification(data.title, context); | 139 Notification* notification = new Notification(data.title, context); |
139 | 140 |
140 notification->setPersistentId(persistentId); | 141 notification->setPersistentId(persistentId); |
141 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR
ight ? "ltr" : "rtl"); | 142 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR
ight ? "ltr" : "rtl"); |
142 notification->setLang(data.lang); | 143 notification->setLang(data.lang); |
143 notification->setBody(data.body); | 144 notification->setBody(data.body); |
144 notification->setTag(data.tag); | 145 notification->setTag(data.tag); |
| 146 notification->setPriority(priorityString(data.priority)); |
145 notification->setSilent(data.silent); | 147 notification->setSilent(data.silent); |
146 | 148 |
147 if (!data.icon.isEmpty()) | 149 if (!data.icon.isEmpty()) |
148 notification->setIconUrl(data.icon); | 150 notification->setIconUrl(data.icon); |
149 | 151 |
150 if (!data.vibrate.isEmpty()) { | 152 if (!data.vibrate.isEmpty()) { |
151 NavigatorVibration::VibrationPattern pattern; | 153 NavigatorVibration::VibrationPattern pattern; |
152 pattern.appendRange(data.vibrate.begin(), data.vibrate.end()); | 154 pattern.appendRange(data.vibrate.begin(), data.vibrate.end()); |
153 notification->setVibrate(pattern); | 155 notification->setVibrate(pattern); |
154 } | 156 } |
(...skipping 10 matching lines...) Expand all Loading... |
165 | 167 |
166 notification->setState(NotificationStateShowing); | 168 notification->setState(NotificationStateShowing); |
167 notification->suspendIfNeeded(); | 169 notification->suspendIfNeeded(); |
168 return notification; | 170 return notification; |
169 } | 171 } |
170 | 172 |
171 Notification::Notification(const String& title, ExecutionContext* context) | 173 Notification::Notification(const String& title, ExecutionContext* context) |
172 : ActiveDOMObject(context) | 174 : ActiveDOMObject(context) |
173 , m_title(title) | 175 , m_title(title) |
174 , m_dir("auto") | 176 , m_dir("auto") |
| 177 , m_priority("normal") |
175 , m_silent(false) | 178 , m_silent(false) |
176 , m_persistentId(kInvalidPersistentId) | 179 , m_persistentId(kInvalidPersistentId) |
177 , m_state(NotificationStateIdle) | 180 , m_state(NotificationStateIdle) |
178 , m_asyncRunner(this, &Notification::show) | 181 , m_asyncRunner(this, &Notification::show) |
179 { | 182 { |
180 ASSERT(notificationManager()); | 183 ASSERT(notificationManager()); |
181 } | 184 } |
182 | 185 |
183 Notification::~Notification() | 186 Notification::~Notification() |
184 { | 187 { |
(...skipping 13 matching lines...) Expand all Loading... |
198 if (Notification::checkPermission(executionContext()) != WebNotificationPerm
issionAllowed) { | 201 if (Notification::checkPermission(executionContext()) != WebNotificationPerm
issionAllowed) { |
199 dispatchErrorEvent(); | 202 dispatchErrorEvent(); |
200 return; | 203 return; |
201 } | 204 } |
202 | 205 |
203 SecurityOrigin* origin = executionContext()->securityOrigin(); | 206 SecurityOrigin* origin = executionContext()->securityOrigin(); |
204 ASSERT(origin); | 207 ASSERT(origin); |
205 | 208 |
206 // FIXME: Do CSP checks on the associated notification icon. | 209 // FIXME: Do CSP checks on the associated notification icon. |
207 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D
irectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 210 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D
irectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
| 211 WebNotificationData::Priority priority = priorityEnum(m_priority); |
208 | 212 |
209 // The lifetime and availability of non-persistent notifications is tied to
the page | 213 // The lifetime and availability of non-persistent notifications is tied to
the page |
210 // they were created by, and thus the data doesn't have to be known to the e
mbedder. | 214 // they were created by, and thus the data doesn't have to be known to the e
mbedder. |
211 Vector<char> emptyDataWireBytes; | 215 Vector<char> emptyDataWireBytes; |
212 | 216 |
213 WebVector<WebNotificationAction> webActions; | 217 WebVector<WebNotificationAction> webActions; |
214 actionsToWebActions(m_actions, &webActions); | 218 actionsToWebActions(m_actions, &webActions); |
215 | 219 |
216 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_
iconUrl, m_vibrate, m_silent, emptyDataWireBytes, webActions); | 220 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, pr
iority, m_iconUrl, m_vibrate, m_silent, emptyDataWireBytes, webActions); |
217 notificationManager()->show(WebSecurityOrigin(origin), notificationData, thi
s); | 221 notificationManager()->show(WebSecurityOrigin(origin), notificationData, thi
s); |
218 | 222 |
219 m_state = NotificationStateShowing; | 223 m_state = NotificationStateShowing; |
220 } | 224 } |
221 | 225 |
222 void Notification::close() | 226 void Notification::close() |
223 { | 227 { |
224 if (m_state != NotificationStateShowing) | 228 if (m_state != NotificationStateShowing) |
225 return; | 229 return; |
226 | 230 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 NotificationPermissionClient* permissionClient = NotificationPermissionClien
t::from(context); | 318 NotificationPermissionClient* permissionClient = NotificationPermissionClien
t::from(context); |
315 if (!permissionClient) { | 319 if (!permissionClient) { |
316 // TODO(peter): Assert that this code-path will only be reached for Docu
ment environments when Blink | 320 // TODO(peter): Assert that this code-path will only be reached for Docu
ment environments when Blink |
317 // supports [Exposed] annotations on class members in IDL definitions. S
ee https://crbug.com/442139. | 321 // supports [Exposed] annotations on class members in IDL definitions. S
ee https://crbug.com/442139. |
318 return ScriptPromise::cast(scriptState, v8String(scriptState->isolate(),
permission(context))); | 322 return ScriptPromise::cast(scriptState, v8String(scriptState->isolate(),
permission(context))); |
319 } | 323 } |
320 | 324 |
321 return permissionClient->requestPermission(scriptState, deprecatedCallback); | 325 return permissionClient->requestPermission(scriptState, deprecatedCallback); |
322 } | 326 } |
323 | 327 |
| 328 WebNotificationData::Priority Notification::priorityEnum(const String& priority) |
| 329 { |
| 330 if (priority == "lowest") |
| 331 return WebNotificationData::PriorityLowest; |
| 332 if (priority == "low") |
| 333 return WebNotificationData::PriorityLow; |
| 334 if (priority == "normal") |
| 335 return WebNotificationData::PriorityNormal; |
| 336 if (priority == "high") |
| 337 return WebNotificationData::PriorityHigh; |
| 338 if (priority == "highest") |
| 339 return WebNotificationData::PriorityHighest; |
| 340 |
| 341 ASSERT_NOT_REACHED(); |
| 342 return WebNotificationData::PriorityNormal; |
| 343 } |
| 344 |
| 345 String Notification::priorityString(WebNotificationData::Priority priority) |
| 346 { |
| 347 switch (priority) { |
| 348 case WebNotificationData::PriorityLowest: |
| 349 return "lowest"; |
| 350 case WebNotificationData::PriorityLow: |
| 351 return "low"; |
| 352 case WebNotificationData::PriorityNormal: |
| 353 return "normal"; |
| 354 case WebNotificationData::PriorityHigh: |
| 355 return "high"; |
| 356 case WebNotificationData::PriorityHighest: |
| 357 return "highest"; |
| 358 } |
| 359 |
| 360 ASSERT_NOT_REACHED(); |
| 361 return "normal"; |
| 362 } |
| 363 |
324 size_t Notification::maxActions() | 364 size_t Notification::maxActions() |
325 { | 365 { |
326 return notificationManager()->maxActions(); | 366 return notificationManager()->maxActions(); |
327 } | 367 } |
328 | 368 |
329 void Notification::actionsToWebActions(const HeapVector<NotificationAction>& act
ions, WebVector<WebNotificationAction>* webActions) | 369 void Notification::actionsToWebActions(const HeapVector<NotificationAction>& act
ions, WebVector<WebNotificationAction>* webActions) |
330 { | 370 { |
331 size_t count = std::min(maxActions(), actions.size()); | 371 size_t count = std::min(maxActions(), actions.size()); |
332 WebVector<WebNotificationAction> clearedAndResized(count); | 372 WebVector<WebNotificationAction> clearedAndResized(count); |
333 webActions->swap(clearedAndResized); | 373 webActions->swap(clearedAndResized); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 } | 421 } |
382 | 422 |
383 DEFINE_TRACE(Notification) | 423 DEFINE_TRACE(Notification) |
384 { | 424 { |
385 visitor->trace(m_actions); | 425 visitor->trace(m_actions); |
386 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); | 426 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); |
387 ActiveDOMObject::trace(visitor); | 427 ActiveDOMObject::trace(visitor); |
388 } | 428 } |
389 | 429 |
390 } // namespace blink | 430 } // namespace blink |
OLD | NEW |