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

Unified Diff: Source/modules/notifications/Notification.cpp

Issue 1042513002: Add the vibrate attribute to the Notification object (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/notifications/Notification.h ('k') | Source/modules/notifications/Notification.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/notifications/Notification.cpp
diff --git a/Source/modules/notifications/Notification.cpp b/Source/modules/notifications/Notification.cpp
index 4e1fe5877522c2d834806a77040bf152c02655a1..1810112b23a218ccdb9ddef34f1a9cf0e2698888 100644
--- a/Source/modules/notifications/Notification.cpp
+++ b/Source/modules/notifications/Notification.cpp
@@ -79,6 +79,12 @@ Notification* Notification::create(ExecutionContext* context, const String& titl
return nullptr;
}
+ // If options's silent is true, and options's vibrate is present, throw a TypeError exception.
+ if (options.hasVibrate() && options.silent()) {
+ exceptionState.throwTypeError("Silent notifications must not specify vibration patterns.");
+ return nullptr;
+ }
+
RefPtr<SerializedScriptValue> data;
if (options.hasData()) {
data = SerializedScriptValueFactory::instance().create(options.data(), nullptr, exceptionState, options.data().isolate());
@@ -92,6 +98,7 @@ Notification* Notification::create(ExecutionContext* context, const String& titl
notification->setTag(options.tag());
notification->setLang(options.lang());
notification->setDir(options.dir());
+ notification->setVibrate(NavigatorVibration::sanitizeVibrationPattern(options.vibrate()));
notification->setSilent(options.silent());
notification->setSerializedData(data.release());
if (options.hasIcon()) {
@@ -125,6 +132,12 @@ Notification* Notification::create(ExecutionContext* context, int64_t persistent
if (!data.icon.isEmpty())
notification->setIconUrl(data.icon);
+ if (!data.vibrate.isEmpty()) {
+ NavigatorVibration::VibrationPattern pattern;
+ pattern.appendRange(data.vibrate.begin(), data.vibrate.end());
+ notification->setVibrate(pattern);
+ }
+
const WebVector<char>& dataBytes = data.data;
if (!dataBytes.isEmpty()) {
notification->setSerializedData(SerializedScriptValueFactory::instance().createFromWireBytes(dataBytes.data(), dataBytes.size()));
@@ -203,7 +216,7 @@ void Notification::show()
// they were created by, and thus the data doesn't have to be known to the embedder.
Vector<char> emptyDataWireBytes;
- WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_iconUrl, m_silent, emptyDataWireBytes);
+ WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_iconUrl, m_vibrate, m_silent, emptyDataWireBytes);
notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this);
m_state = NotificationStateShowing;
@@ -261,6 +274,12 @@ void Notification::dispatchCloseEvent()
dispatchEvent(Event::create(EventTypeNames::close));
}
+NavigatorVibration::VibrationPattern Notification::vibrate(bool& isNull) const
+{
+ isNull = m_vibrate.isEmpty();
+ return m_vibrate;
+}
+
TextDirection Notification::direction() const
{
// FIXME: Resolve dir()=="auto" against the document.
« no previous file with comments | « Source/modules/notifications/Notification.h ('k') | Source/modules/notifications/Notification.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698