Chromium Code Reviews| Index: Source/modules/notifications/Notification.cpp |
| diff --git a/Source/modules/notifications/Notification.cpp b/Source/modules/notifications/Notification.cpp |
| index 4ac301fe131c9af0bd40d396f9092e1d4da9c867..6b73d6cfee3a64f03201bfc8e1020f79390b4960 100644 |
| --- a/Source/modules/notifications/Notification.cpp |
| +++ b/Source/modules/notifications/Notification.cpp |
| @@ -92,6 +92,13 @@ Notification* Notification::create(ExecutionContext* context, const String& titl |
| return nullptr; |
| } |
| + for (NotificationAction action : options.actions()) { |
| + if (action.title().isEmpty()) { |
| + exceptionState.throwTypeError("Notification action titles must not be empty."); |
| + return nullptr; |
| + } |
| + } |
| + |
| Notification* notification = new Notification(title, context); |
| notification->setBody(options.body()); |
| @@ -106,6 +113,7 @@ Notification* Notification::create(ExecutionContext* context, const String& titl |
| if (!iconUrl.isEmpty() && iconUrl.isValid()) |
| notification->setIconUrl(iconUrl); |
| } |
| + notification->m_actions.appendRange(options.actions().begin(), options.actions().begin() + std::min(+maxActions, options.actions().size())); |
| String insecureOriginMessage; |
| UseCounter::Feature feature = context->isPrivilegedContext(insecureOriginMessage) |
| @@ -132,11 +140,8 @@ 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); |
| - } |
| + if (!data.vibrate.isEmpty()) |
| + notification->m_vibrate.appendRange(data.vibrate.begin(), data.vibrate.end()); |
|
Peter Beverloo
2015/07/30 16:24:07
Please don't do this. Everything uses setters and
johnme
2015/07/31 15:10:10
Done.
|
| const WebVector<char>& dataBytes = data.data; |
| if (!dataBytes.isEmpty()) { |
| @@ -144,6 +149,8 @@ Notification* Notification::create(ExecutionContext* context, int64_t persistent |
| notification->serializedData()->registerMemoryAllocatedWithCurrentScriptContext(); |
| } |
| + webActionsToActions(data.actions, notification->m_actions); |
|
Peter Beverloo
2015/07/30 16:24:07
Dito.
johnme
2015/07/31 15:10:10
Done.
|
| + |
| notification->setState(NotificationStateShowing); |
| notification->suspendIfNeeded(); |
| return notification; |
| @@ -191,7 +198,10 @@ 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_vibrate, m_silent, emptyDataWireBytes); |
| + WebVector<WebNotificationAction> webActions; |
| + actionsToWebActions(m_actions, webActions); |
| + |
| + WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_iconUrl, m_vibrate, m_silent, emptyDataWireBytes, webActions); |
| notificationManager()->show(WebSecurityOrigin(origin), notificationData, this); |
| m_state = NotificationStateShowing; |
| @@ -246,7 +256,7 @@ void Notification::dispatchCloseEvent() |
| dispatchEvent(Event::create(EventTypeNames::close)); |
| } |
| -NavigatorVibration::VibrationPattern Notification::vibrate(bool& isNull) const |
| +const NavigatorVibration::VibrationPattern& Notification::vibrate(bool& isNull) const |
| { |
| isNull = m_vibrate.isEmpty(); |
| return m_vibrate; |
| @@ -294,6 +304,15 @@ void Notification::requestPermission(ExecutionContext* context, NotificationPerm |
| permissionClient->requestPermission(context, callback); |
| } |
| +void Notification::webActionsToActions(const WebVector<WebNotificationAction>& webActions, Vector<NotificationAction>& actions) |
| +{ |
| + actions.clear(); |
| + actions.grow(webActions.size()); |
| + for (size_t i = 0; i < webActions.size(); ++i) { |
| + actions[i].setTitle(webActions[i].title); |
| + } |
| +} |
| + |
| bool Notification::dispatchEventInternal(PassRefPtrWillBeRawPtr<Event> event) |
| { |
| ASSERT(executionContext()->isContextThread()); |