Index: Source/modules/notifications/Notification.cpp |
diff --git a/Source/modules/notifications/Notification.cpp b/Source/modules/notifications/Notification.cpp |
index 1dd3a947ddb0548d6fcab6eca34bee9fbbf68786..6968e5f0d8b32f875dd63f373f69ff4c402256bf 100644 |
--- a/Source/modules/notifications/Notification.cpp |
+++ b/Source/modules/notifications/Notification.cpp |
@@ -51,6 +51,7 @@ |
#include "public/platform/WebString.h" |
#include "public/platform/modules/notifications/WebNotificationData.h" |
#include "public/platform/modules/notifications/WebNotificationManager.h" |
+#include "public/platform/modules/notifications/WebNotificationVibrationData.h" |
namespace blink { |
namespace { |
@@ -77,6 +78,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("If options's silent is true, options's vibrate should not be presented"); |
+ return nullptr; |
+ } |
+ |
RefPtr<SerializedScriptValue> data; |
if (options.hasData()) { |
data = SerializedScriptValueFactory::instance().create(options.data(), nullptr, exceptionState, options.data().isolate()); |
@@ -90,6 +97,7 @@ Notification* Notification::create(ExecutionContext* context, const String& titl |
notification->setTag(options.tag()); |
notification->setLang(options.lang()); |
notification->setDir(options.dir()); |
+ notification->setVibrate(options.vibrate()); |
notification->setSilent(options.silent()); |
notification->setSerializedData(data.release()); |
if (options.hasIcon()) { |
@@ -119,6 +127,14 @@ Notification* Notification::create(ExecutionContext* context, const String& pers |
notification->setTag(data.tag); |
notification->setSilent(data.silent); |
+ if (data.vibrate.type == WebNotificationVibrationData::TypeUnsignedLong) { |
+ notification->setVibrate(UnsignedLongOrUnsignedLongSequence::fromUnsignedLong(data.vibrate.pattern[0])); |
+ } else if (data.vibrate.type == WebNotificationVibrationData::TypeUnsignedLongSequence) { |
+ Vector<unsigned> pattern; |
+ pattern.appendRange(data.vibrate.pattern.begin(), data.vibrate.pattern.end()); |
+ notification->setVibrate(UnsignedLongOrUnsignedLongSequence::fromUnsignedLongSequence(pattern)); |
+ } |
+ |
if (!data.icon.isEmpty()) |
notification->setIconUrl(data.icon); |
@@ -147,6 +163,17 @@ Notification::~Notification() |
{ |
} |
+void Notification::vibrate(UnsignedLongOrUnsignedLongSequence& returnValue) |
+{ |
+ if (m_vibrate.isNull()) |
+ return; |
+ |
+ if (m_vibrate.isUnsignedLong()) |
+ returnValue.setUnsignedLong(m_vibrate.getAsUnsignedLong()); |
+ else |
+ returnValue.setUnsignedLongSequence(m_vibrate.getAsUnsignedLongSequence()); |
+} |
+ |
void Notification::scheduleShow() |
{ |
ASSERT(m_state == NotificationStateIdle); |
@@ -172,7 +199,7 @@ void Notification::show() |
// The lifetime and availability of non-persistent notifications is tied to the page |
// they were created by, and thus the data doesn't have to be known to the embedder. |
String emptyDataAsWireString; |
- WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_iconUrl, m_silent, emptyDataAsWireString); |
+ WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_iconUrl, convertFromVibrationData(m_vibrate), m_silent, emptyDataAsWireString); |
notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); |
m_state = NotificationStateShowing; |
@@ -302,6 +329,23 @@ ScriptValue Notification::data(ScriptState* scriptState) const |
return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->isolate())); |
} |
+WebNotificationVibrationData Notification::convertFromVibrationData(const UnsignedLongOrUnsignedLongSequence& vibrate) |
+{ |
+ WebNotificationVibrationData::Type vibrateType = WebNotificationVibrationData::TypeNone; |
+ Vector<unsigned> vibratePattern; |
+ |
+ if (vibrate.isUnsignedLong()) { |
+ vibrateType = WebNotificationVibrationData::TypeUnsignedLong; |
+ vibratePattern.append(vibrate.getAsUnsignedLong()); |
+ } else if (vibrate.isUnsignedLongSequence()) { |
+ vibrateType = WebNotificationVibrationData::TypeUnsignedLongSequence; |
+ vibratePattern = vibrate.getAsUnsignedLongSequence(); |
+ } |
+ |
+ return WebNotificationVibrationData(vibrateType, vibratePattern); |
+} |
+ |
+ |
DEFINE_TRACE(Notification) |
{ |
RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(visitor); |