Chromium Code Reviews| Index: Source/modules/notifications/Notification.cpp |
| diff --git a/Source/modules/notifications/Notification.cpp b/Source/modules/notifications/Notification.cpp |
| index a6b1ca2576922a88ae369b9608557a0f178104e5..36c205960348f93e751a55097f410b99809c53c3 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,9 @@ Notification* Notification::create(ExecutionContext* context, const String& titl |
| if (!iconUrl.isEmpty() && iconUrl.isValid()) |
| notification->setIconUrl(iconUrl); |
| } |
| + HeapVector<NotificationAction> actions; |
| + actions.appendRange(options.actions().begin(), options.actions().begin() + std::min(notificationManager()->maxActions(), options.actions().size())); |
|
Peter Beverloo
2015/07/31 15:38:49
nit: you can just write |maxActions()| rather than
johnme
2015/07/31 16:08:52
Done.
|
| + notification->setActions(actions); |
| String insecureOriginMessage; |
| UseCounter::Feature feature = context->isPrivilegedContext(insecureOriginMessage) |
| @@ -144,6 +154,10 @@ Notification* Notification::create(ExecutionContext* context, int64_t persistent |
| notification->serializedData()->registerMemoryAllocatedWithCurrentScriptContext(); |
| } |
| + HeapVector<NotificationAction> actions; |
| + webActionsToActions(data.actions, &actions); |
| + notification->setActions(actions); |
| + |
| notification->setState(NotificationStateShowing); |
| notification->suspendIfNeeded(); |
| return notification; |
| @@ -191,7 +205,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 +263,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; |
| @@ -299,6 +316,25 @@ unsigned Notification::maxActions() |
| return notificationManager()->maxActions(); |
| } |
| +void Notification::actionsToWebActions(const HeapVector<NotificationAction>& actions, WebVector<WebNotificationAction>* webActions) |
| +{ |
| + size_t count = std::min(notificationManager()->maxActions(), actions.size()); |
|
Peter Beverloo
2015/07/31 15:38:49
dito
johnme
2015/07/31 16:08:52
Done.
|
| + WebVector<WebNotificationAction> clearedAndResized(count); |
| + webActions->swap(clearedAndResized); |
| + for (size_t i = 0; i < count; ++i) { |
|
Peter Beverloo
2015/07/31 15:38:49
nit: no need for {} in one-line if statements
johnme
2015/07/31 16:08:52
Done (but this becomes 2-line in https://coderevie
|
| + (*webActions)[i].title = actions[i].title(); |
| + } |
| +} |
| + |
| +void Notification::webActionsToActions(const WebVector<WebNotificationAction>& webActions, HeapVector<NotificationAction>* actions) |
| +{ |
| + actions->clear(); |
| + actions->grow(webActions.size()); |
| + for (size_t i = 0; i < webActions.size(); ++i) { |
| + (*actions)[i].setTitle(webActions[i].title); |
|
Peter Beverloo
2015/07/31 15:38:49
dito
johnme
2015/07/31 16:08:52
Done (but this becomes 2-line in https://coderevie
|
| + } |
| +} |
| + |
| bool Notification::dispatchEventInternal(PassRefPtrWillBeRawPtr<Event> event) |
| { |
| ASSERT(executionContext()->isContextThread()); |
| @@ -334,6 +370,7 @@ ScriptValue Notification::data(ScriptState* scriptState) const |
| DEFINE_TRACE(Notification) |
| { |
| + visitor->trace(m_actions); |
| RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(visitor); |
| ActiveDOMObject::trace(visitor); |
| } |