| Index: third_party/WebKit/Source/modules/notifications/NotificationData.cpp
|
| diff --git a/third_party/WebKit/Source/modules/notifications/NotificationData.cpp b/third_party/WebKit/Source/modules/notifications/NotificationData.cpp
|
| index 60a86876e6e384665d18932fe54e34e4a7943190..0554da3b41d4c3e77d99d9c9cb52d8f9c6a5f33c 100644
|
| --- a/third_party/WebKit/Source/modules/notifications/NotificationData.cpp
|
| +++ b/third_party/WebKit/Source/modules/notifications/NotificationData.cpp
|
| @@ -17,105 +17,108 @@
|
| namespace blink {
|
| namespace {
|
|
|
| -WebNotificationData::Direction toDirectionEnumValue(const String& direction)
|
| +mojom::wtf::NotificationDirection toDirectionEnumValue(const String& direction)
|
| {
|
| if (direction == "ltr")
|
| - return WebNotificationData::DirectionLeftToRight;
|
| + return mojom::wtf::NotificationDirection::LEFT_TO_RIGHT;
|
| if (direction == "rtl")
|
| - return WebNotificationData::DirectionRightToLeft;
|
| + return mojom::wtf::NotificationDirection::RIGHT_TO_LEFT;
|
|
|
| - return WebNotificationData::DirectionAuto;
|
| + return mojom::wtf::NotificationDirection::AUTO;
|
| }
|
|
|
| -WebURL completeURL(ExecutionContext* executionContext, const String& stringUrl)
|
| +String completeURL(ExecutionContext* executionContext, const String& stringUrl)
|
| {
|
| - WebURL url = executionContext->completeURL(stringUrl);
|
| + KURL url = executionContext->completeURL(stringUrl);
|
| if (url.isValid())
|
| - return url;
|
| - return WebURL();
|
| + return url.getString();
|
| +
|
| + return String();
|
| }
|
|
|
| } // namespace
|
|
|
| -WebNotificationData createWebNotificationData(ExecutionContext* executionContext, const String& title, const NotificationOptions& options, ExceptionState& exceptionState)
|
| +mojom::wtf::NotificationPtr createNotificationData(ExecutionContext* executionContext, const String& title, const NotificationOptions& options, ExceptionState& exceptionState)
|
| {
|
| // If silent is true, the notification must not have a vibration pattern.
|
| if (options.hasVibrate() && options.silent()) {
|
| exceptionState.throwTypeError("Silent notifications must not specify vibration patterns.");
|
| - return WebNotificationData();
|
| + return mojom::wtf::NotificationPtr();
|
| }
|
|
|
| // If renotify is true, the notification must have a tag.
|
| if (options.renotify() && options.tag().isEmpty()) {
|
| exceptionState.throwTypeError("Notifications which set the renotify flag must specify a non-empty tag.");
|
| - return WebNotificationData();
|
| + return mojom::wtf::NotificationPtr();
|
| }
|
|
|
| - WebNotificationData webData;
|
| + mojom::wtf::NotificationPtr notification = mojom::wtf::Notification::New();
|
|
|
| - webData.title = title;
|
| - webData.direction = toDirectionEnumValue(options.dir());
|
| - webData.lang = options.lang();
|
| - webData.body = options.body();
|
| - webData.tag = options.tag();
|
| + notification->title = title;
|
| + notification->direction = toDirectionEnumValue(options.dir());
|
| + notification->lang = options.lang();
|
| + notification->body = options.body();
|
| + notification->tag = options.tag();
|
|
|
| if (options.hasIcon() && !options.icon().isEmpty())
|
| - webData.icon = completeURL(executionContext, options.icon());
|
| + notification->icon = completeURL(executionContext, options.icon());
|
|
|
| if (options.hasBadge() && !options.badge().isEmpty())
|
| - webData.badge = completeURL(executionContext, options.badge());
|
| + notification->badge = completeURL(executionContext, options.badge());
|
|
|
| - webData.vibrate = NavigatorVibration::sanitizeVibrationPattern(options.vibrate());
|
| - webData.timestamp = options.hasTimestamp() ? static_cast<double>(options.timestamp()) : WTF::currentTimeMS();
|
| - webData.renotify = options.renotify();
|
| - webData.silent = options.silent();
|
| - webData.requireInteraction = options.requireInteraction();
|
| + notification->vibration_pattern = NavigatorVibration::sanitizeVibrationPattern(options.vibrate());
|
| + notification->timestamp = options.hasTimestamp() ? static_cast<double>(options.timestamp()) : WTF::currentTimeMS();
|
| + notification->renotify = options.renotify();
|
| + notification->silent = options.silent();
|
| + notification->require_interaction = options.requireInteraction();
|
|
|
| if (options.hasData()) {
|
| RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptValueFactory::instance().create(options.data().isolate(), options.data(), nullptr, exceptionState);
|
| if (exceptionState.hadException())
|
| - return WebNotificationData();
|
| + return mojom::wtf::NotificationPtr();
|
|
|
| Vector<char> serializedData;
|
| serializedScriptValue->toWireBytes(serializedData);
|
|
|
| - webData.data = serializedData;
|
| + // Mojo defines int8 as 'signed char', where signedness of 'char' is usually left up
|
| + // to the implementation. The sizes are identical, so this cast is ugly but safe.
|
| + notification->data.Swap(reinterpret_cast<Vector<signed char>*>(&serializedData));
|
| }
|
|
|
| - Vector<WebNotificationAction> actions;
|
| + Vector<mojom::wtf::NotificationActionPtr> actions;
|
|
|
| const size_t maxActions = Notification::maxActions();
|
| for (const NotificationAction& action : options.actions()) {
|
| if (actions.size() >= maxActions)
|
| break;
|
|
|
| - WebNotificationAction webAction;
|
| - webAction.action = action.action();
|
| - webAction.title = action.title();
|
| + mojom::wtf::NotificationActionPtr mojoAction = mojom::wtf::NotificationAction::New();
|
|
|
| if (action.type() == "button")
|
| - webAction.type = WebNotificationAction::Button;
|
| + mojoAction->type = mojom::wtf::NotificationActionType::BUTTON;
|
| else if (action.type() == "text")
|
| - webAction.type = WebNotificationAction::Text;
|
| + mojoAction->type = mojom::wtf::NotificationActionType::TEXT;
|
| else
|
| NOTREACHED() << "Unknown action type: " << action.type();
|
|
|
| - if (action.hasPlaceholder() && webAction.type == WebNotificationAction::Button) {
|
| + if (action.hasPlaceholder() && mojoAction->type == mojom::wtf::NotificationActionType::BUTTON) {
|
| exceptionState.throwTypeError("Notifications of type \"button\" cannot specify a placeholder.");
|
| - return WebNotificationData();
|
| + return mojom::wtf::NotificationPtr();
|
| }
|
|
|
| - webAction.placeholder = action.placeholder();
|
| + mojoAction->action = action.action();
|
| + mojoAction->title = action.title();
|
| + mojoAction->placeholder = action.placeholder();
|
|
|
| if (action.hasIcon() && !action.icon().isEmpty())
|
| - webAction.icon = completeURL(executionContext, action.icon());
|
| + mojoAction->icon = completeURL(executionContext, action.icon());
|
|
|
| - actions.append(webAction);
|
| + actions.append(std::move(mojoAction));
|
| }
|
|
|
| - webData.actions = actions;
|
| + notification->actions = std::move(actions);
|
|
|
| - return webData;
|
| + return notification;
|
| }
|
|
|
| } // namespace blink
|
|
|