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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg
istration.showNotification() instead."); | 72 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg
istration.showNotification() instead."); |
73 return nullptr; | 73 return nullptr; |
74 } | 74 } |
75 | 75 |
76 // The Web Notification constructor may not be used in Service Worker contex
ts. | 76 // The Web Notification constructor may not be used in Service Worker contex
ts. |
77 if (context->isServiceWorkerGlobalScope()) { | 77 if (context->isServiceWorkerGlobalScope()) { |
78 exceptionState.throwTypeError("Illegal constructor."); | 78 exceptionState.throwTypeError("Illegal constructor."); |
79 return nullptr; | 79 return nullptr; |
80 } | 80 } |
81 | 81 |
82 // If options's silent is true, and options's vibrate is present, throw a Ty
peError exception. | 82 // If options's silent is true, and options's vibrate or sound is present, t
hrow a TypeError exception. |
83 if (options.hasVibrate() && options.silent()) { | 83 if ((options.hasSound() || options.hasVibrate()) && options.silent()) { |
84 exceptionState.throwTypeError("Silent notifications must not specify vib
ration patterns."); | 84 exceptionState.throwTypeError("Silent notifications must not specify sou
nd or vibration patterns."); |
85 return nullptr; | 85 return nullptr; |
86 } | 86 } |
87 | 87 |
88 RefPtr<SerializedScriptValue> data; | 88 RefPtr<SerializedScriptValue> data; |
89 if (options.hasData()) { | 89 if (options.hasData()) { |
90 data = SerializedScriptValueFactory::instance().create(options.data().is
olate(), options.data(), nullptr, exceptionState); | 90 data = SerializedScriptValueFactory::instance().create(options.data().is
olate(), options.data(), nullptr, exceptionState); |
91 if (exceptionState.hadException()) | 91 if (exceptionState.hadException()) |
92 return nullptr; | 92 return nullptr; |
93 } | 93 } |
94 | 94 |
95 Notification* notification = new Notification(title, context); | 95 Notification* notification = new Notification(title, context); |
96 | 96 |
97 notification->setBody(options.body()); | 97 notification->setBody(options.body()); |
98 notification->setTag(options.tag()); | 98 notification->setTag(options.tag()); |
99 notification->setLang(options.lang()); | 99 notification->setLang(options.lang()); |
100 notification->setDir(options.dir()); | 100 notification->setDir(options.dir()); |
101 notification->setVibrate(NavigatorVibration::sanitizeVibrationPattern(option
s.vibrate())); | 101 notification->setVibrate(NavigatorVibration::sanitizeVibrationPattern(option
s.vibrate())); |
102 notification->setSilent(options.silent()); | 102 notification->setSilent(options.silent()); |
103 notification->setSerializedData(data.release()); | 103 notification->setSerializedData(data.release()); |
104 if (options.hasIcon()) { | 104 if (options.hasIcon()) { |
105 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL(
options.icon()); | 105 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL(
options.icon()); |
106 if (!iconUrl.isEmpty() && iconUrl.isValid()) | 106 if (!iconUrl.isEmpty() && iconUrl.isValid()) |
107 notification->setIconUrl(iconUrl); | 107 notification->setIconUrl(iconUrl); |
108 } | 108 } |
109 | 109 |
| 110 if (options.hasSound()) { |
| 111 KURL soundUrl = options.sound().isEmpty() ? KURL() : context->completeUR
L(options.sound()); |
| 112 if (!soundUrl.isEmpty() && soundUrl.isValid()) |
| 113 notification->setSoundUrl(soundUrl); |
| 114 } |
| 115 |
110 String insecureOriginMessage; | 116 String insecureOriginMessage; |
111 UseCounter::Feature feature = context->isPrivilegedContext(insecureOriginMes
sage) | 117 UseCounter::Feature feature = context->isPrivilegedContext(insecureOriginMes
sage) |
112 ? UseCounter::NotificationSecureOrigin | 118 ? UseCounter::NotificationSecureOrigin |
113 : UseCounter::NotificationInsecureOrigin; | 119 : UseCounter::NotificationInsecureOrigin; |
114 UseCounter::count(context, feature); | 120 UseCounter::count(context, feature); |
115 | 121 |
116 notification->scheduleShow(); | 122 notification->scheduleShow(); |
117 notification->suspendIfNeeded(); | 123 notification->suspendIfNeeded(); |
118 return notification; | 124 return notification; |
119 } | 125 } |
120 | 126 |
121 Notification* Notification::create(ExecutionContext* context, int64_t persistent
Id, const WebNotificationData& data) | 127 Notification* Notification::create(ExecutionContext* context, int64_t persistent
Id, const WebNotificationData& data) |
122 { | 128 { |
123 Notification* notification = new Notification(data.title, context); | 129 Notification* notification = new Notification(data.title, context); |
124 | 130 |
125 notification->setPersistentId(persistentId); | 131 notification->setPersistentId(persistentId); |
126 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR
ight ? "ltr" : "rtl"); | 132 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR
ight ? "ltr" : "rtl"); |
127 notification->setLang(data.lang); | 133 notification->setLang(data.lang); |
128 notification->setBody(data.body); | 134 notification->setBody(data.body); |
129 notification->setTag(data.tag); | 135 notification->setTag(data.tag); |
130 notification->setSilent(data.silent); | 136 notification->setSilent(data.silent); |
131 | 137 |
132 if (!data.icon.isEmpty()) | 138 if (!data.icon.isEmpty()) |
133 notification->setIconUrl(data.icon); | 139 notification->setIconUrl(data.icon); |
134 | 140 |
| 141 if (!data.sound.isEmpty()) |
| 142 notification->setSoundUrl(data.sound); |
| 143 |
135 if (!data.vibrate.isEmpty()) { | 144 if (!data.vibrate.isEmpty()) { |
136 NavigatorVibration::VibrationPattern pattern; | 145 NavigatorVibration::VibrationPattern pattern; |
137 pattern.appendRange(data.vibrate.begin(), data.vibrate.end()); | 146 pattern.appendRange(data.vibrate.begin(), data.vibrate.end()); |
138 notification->setVibrate(pattern); | 147 notification->setVibrate(pattern); |
139 } | 148 } |
140 | 149 |
141 const WebVector<char>& dataBytes = data.data; | 150 const WebVector<char>& dataBytes = data.data; |
142 if (!dataBytes.isEmpty()) { | 151 if (!dataBytes.isEmpty()) { |
143 notification->setSerializedData(SerializedScriptValueFactory::instance()
.createFromWireBytes(dataBytes.data(), dataBytes.size())); | 152 notification->setSerializedData(SerializedScriptValueFactory::instance()
.createFromWireBytes(dataBytes.data(), dataBytes.size())); |
144 notification->serializedData()->registerMemoryAllocatedWithCurrentScript
Context(); | 153 notification->serializedData()->registerMemoryAllocatedWithCurrentScript
Context(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 SecurityOrigin* origin = executionContext()->securityOrigin(); | 193 SecurityOrigin* origin = executionContext()->securityOrigin(); |
185 ASSERT(origin); | 194 ASSERT(origin); |
186 | 195 |
187 // FIXME: Do CSP checks on the associated notification icon. | 196 // FIXME: Do CSP checks on the associated notification icon. |
188 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D
irectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 197 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D
irectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
189 | 198 |
190 // The lifetime and availability of non-persistent notifications is tied to
the page | 199 // The lifetime and availability of non-persistent notifications is tied to
the page |
191 // they were created by, and thus the data doesn't have to be known to the e
mbedder. | 200 // they were created by, and thus the data doesn't have to be known to the e
mbedder. |
192 Vector<char> emptyDataWireBytes; | 201 Vector<char> emptyDataWireBytes; |
193 | 202 |
194 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_
iconUrl, m_vibrate, m_silent, emptyDataWireBytes); | 203 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_
iconUrl, m_soundUrl, m_vibrate, m_silent, emptyDataWireBytes); |
195 notificationManager()->show(WebSerializedOrigin(*origin), notificationData,
this); | 204 notificationManager()->show(WebSerializedOrigin(*origin), notificationData,
this); |
196 | 205 |
197 m_state = NotificationStateShowing; | 206 m_state = NotificationStateShowing; |
198 } | 207 } |
199 | 208 |
200 void Notification::close() | 209 void Notification::close() |
201 { | 210 { |
202 if (m_state != NotificationStateShowing) | 211 if (m_state != NotificationStateShowing) |
203 return; | 212 return; |
204 | 213 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i
solate())); | 336 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i
solate())); |
328 } | 337 } |
329 | 338 |
330 DEFINE_TRACE(Notification) | 339 DEFINE_TRACE(Notification) |
331 { | 340 { |
332 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); | 341 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); |
333 ActiveDOMObject::trace(visitor); | 342 ActiveDOMObject::trace(visitor); |
334 } | 343 } |
335 | 344 |
336 } // namespace blink | 345 } // namespace blink |
OLD | NEW |