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 NavigatorVibration::VibrationPattern vibrate; | |
81 if (options.hasVibrate() && !options.vibrate().isNull()) { | |
82 if (options.silent()) { | |
83 exceptionState.throwTypeError("If options's silent is true, options' s vibrate should not be presented"); | |
Peter Beverloo
2015/04/01 14:26:29
What about:
"Notifications must not have a vibrat
Sanghyun Park
2015/04/01 17:46:08
Yes. Following Spec, this is described like below.
| |
84 return nullptr; | |
85 } | |
86 | |
87 NavigatorVibration::VibrationPattern pattern; | |
timvolodine
2015/04/01 16:27:16
How about introducing a method
static VibrationPat
Sanghyun Park
2015/04/01 17:46:08
Thanks for your advice. :)
I agree your opinion.
| |
88 if (options.vibrate().isUnsignedLong()) | |
89 pattern.append(options.vibrate().getAsUnsignedLong()); | |
90 else | |
91 pattern = options.vibrate().getAsUnsignedLongSequence(); | |
92 vibrate = NavigatorVibration::verifyVibrationPattern(pattern); | |
93 } | |
94 | |
80 RefPtr<SerializedScriptValue> data; | 95 RefPtr<SerializedScriptValue> data; |
81 if (options.hasData()) { | 96 if (options.hasData()) { |
82 data = SerializedScriptValueFactory::instance().create(options.data(), n ullptr, exceptionState, options.data().isolate()); | 97 data = SerializedScriptValueFactory::instance().create(options.data(), n ullptr, exceptionState, options.data().isolate()); |
83 if (exceptionState.hadException()) | 98 if (exceptionState.hadException()) |
84 return nullptr; | 99 return nullptr; |
85 } | 100 } |
86 | 101 |
87 Notification* notification = new Notification(title, context); | 102 Notification* notification = new Notification(title, context); |
88 | 103 |
89 notification->setBody(options.body()); | 104 notification->setBody(options.body()); |
90 notification->setTag(options.tag()); | 105 notification->setTag(options.tag()); |
91 notification->setLang(options.lang()); | 106 notification->setLang(options.lang()); |
92 notification->setDir(options.dir()); | 107 notification->setDir(options.dir()); |
108 notification->setVibrate(vibrate); | |
93 notification->setSilent(options.silent()); | 109 notification->setSilent(options.silent()); |
94 notification->setSerializedData(data.release()); | 110 notification->setSerializedData(data.release()); |
95 if (options.hasIcon()) { | 111 if (options.hasIcon()) { |
96 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon()); | 112 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon()); |
97 if (!iconUrl.isEmpty() && iconUrl.isValid()) | 113 if (!iconUrl.isEmpty() && iconUrl.isValid()) |
98 notification->setIconUrl(iconUrl); | 114 notification->setIconUrl(iconUrl); |
99 } | 115 } |
100 | 116 |
101 String insecureOriginMessage; | 117 String insecureOriginMessage; |
102 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq uiringSecureOrigin(insecureOriginMessage) | 118 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq uiringSecureOrigin(insecureOriginMessage) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 | 181 |
166 SecurityOrigin* origin = executionContext()->securityOrigin(); | 182 SecurityOrigin* origin = executionContext()->securityOrigin(); |
167 ASSERT(origin); | 183 ASSERT(origin); |
168 | 184 |
169 // FIXME: Do CSP checks on the associated notification icon. | 185 // FIXME: Do CSP checks on the associated notification icon. |
170 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D irectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 186 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D irectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
171 | 187 |
172 // The lifetime and availability of non-persistent notifications is tied to the page | 188 // The lifetime and availability of non-persistent notifications is tied to the page |
173 // they were created by, and thus the data doesn't have to be known to the e mbedder. | 189 // they were created by, and thus the data doesn't have to be known to the e mbedder. |
174 String emptyDataAsWireString; | 190 String emptyDataAsWireString; |
175 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_ iconUrl, m_silent, emptyDataAsWireString); | 191 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_ iconUrl, m_vibrate, m_silent, emptyDataAsWireString); |
176 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); | 192 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); |
177 | 193 |
178 m_state = NotificationStateShowing; | 194 m_state = NotificationStateShowing; |
179 } | 195 } |
180 | 196 |
181 void Notification::close() | 197 void Notification::close() |
182 { | 198 { |
183 if (m_state != NotificationStateShowing) | 199 if (m_state != NotificationStateShowing) |
184 return; | 200 return; |
185 | 201 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i solate())); | 318 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i solate())); |
303 } | 319 } |
304 | 320 |
305 DEFINE_TRACE(Notification) | 321 DEFINE_TRACE(Notification) |
306 { | 322 { |
307 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); | 323 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); |
308 ActiveDOMObject::trace(visitor); | 324 ActiveDOMObject::trace(visitor); |
309 } | 325 } |
310 | 326 |
311 } // namespace blink | 327 } // namespace blink |
OLD | NEW |