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

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: WebNotificationVibrationData is renamed WebNotificationVibratePattern Created 5 years, 9 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
Index: Source/modules/notifications/Notification.cpp
diff --git a/Source/modules/notifications/Notification.cpp b/Source/modules/notifications/Notification.cpp
index 1dd3a947ddb0548d6fcab6eca34bee9fbbf68786..22e1c823e1cd1d7d85dd1d43d4f832b4eef3499e 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/WebNotificationVibratePattern.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.
Peter Beverloo 2015/04/07 11:37:31 ’ -> '
Sanghyun Park 2015/04/08 08:00:03 Done.
+ if (options.hasVibrate() && options.silent()) {
+ exceptionState.throwTypeError("If options's silent is true, options's vibrate should not be presented");
Peter Beverloo 2015/04/07 11:37:31 "Silent notifications must not specify vibration p
Sanghyun Park 2015/04/08 08:00:02 Done.
+ 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 == WebNotificationVibratePattern::TypeUnsignedLong) {
+ notification->setVibrate(UnsignedLongOrUnsignedLongSequence::fromUnsignedLong(data.vibrate.pattern[0]));
+ } else if (data.vibrate.type == WebNotificationVibratePattern::TypeUnsignedLongSequence) {
+ Vector<unsigned> pattern;
+ pattern.appendRange(data.vibrate.pattern.begin(), data.vibrate.pattern.end());
+ notification->setVibrate(UnsignedLongOrUnsignedLongSequence::fromUnsignedLongSequence(pattern));
+ }
Peter Beverloo 2015/04/07 11:37:31 This seems overly complicated to me. We should alw
+
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());
Peter Beverloo 2015/04/07 11:37:31 Ah, I see why you're doing this. This is your inte
Sanghyun Park 2015/04/08 08:00:03 Okay, I will fix to only return sequence type.
+}
+
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()));
}
+WebNotificationVibratePattern Notification::convertFromVibrationData(const UnsignedLongOrUnsignedLongSequence& vibrate)
+{
+ WebNotificationVibratePattern::Type vibrateType = WebNotificationVibratePattern::TypeNone;
+ Vector<unsigned> vibratePattern;
+
+ if (vibrate.isUnsignedLong()) {
+ vibrateType = WebNotificationVibratePattern::TypeUnsignedLong;
+ vibratePattern.append(vibrate.getAsUnsignedLong());
+ } else if (vibrate.isUnsignedLongSequence()) {
+ vibrateType = WebNotificationVibratePattern::TypeUnsignedLongSequence;
+ vibratePattern = vibrate.getAsUnsignedLongSequence();
+ }
+
+ return WebNotificationVibratePattern(vibrateType, vibratePattern);
+}
+
+
DEFINE_TRACE(Notification)
{
RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(visitor);

Powered by Google App Engine
This is Rietveld 408576698