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

Unified Diff: third_party/WebKit/Source/modules/notifications/NotificationData.cpp

Issue 1904163002: Move Web Notifications to use Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@skbitmap-blink
Patch Set: it works \o/ Created 4 years, 8 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: 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..fe357e0cc688f367ed66e132c22519699085492d 100644
--- a/third_party/WebKit/Source/modules/notifications/NotificationData.cpp
+++ b/third_party/WebKit/Source/modules/notifications/NotificationData.cpp
@@ -17,105 +17,114 @@
namespace blink {
namespace {
-WebNotificationData::Direction toDirectionEnumValue(const String& direction)
+mojom::blink::NotificationDirection toDirectionEnumValue(const String& direction)
{
if (direction == "ltr")
- return WebNotificationData::DirectionLeftToRight;
+ return mojom::blink::NotificationDirection::LEFT_TO_RIGHT;
if (direction == "rtl")
- return WebNotificationData::DirectionRightToLeft;
+ return mojom::blink::NotificationDirection::RIGHT_TO_LEFT;
- return WebNotificationData::DirectionAuto;
+ return mojom::blink::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::blink::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::blink::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::blink::NotificationPtr();
}
- WebNotificationData webData;
+ mojom::blink::NotificationPtr notification = mojom::blink::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::blink::NotificationPtr();
Vector<char> serializedData;
serializedScriptValue->toWireBytes(serializedData);
- webData.data = serializedData;
+ // Bail out if the developer provides more data than we allow them to provide.
+ if (serializedData.size() > mojom::blink::Notification::kMaximumDeveloperDataBytes) {
+ exceptionState.throwTypeError("Notifications only support up to 1MB of developer-provided payload.");
+ return mojom::blink::NotificationPtr();
+ }
+
+ // 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::blink::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::blink::NotificationActionPtr mojoAction = mojom::blink::NotificationAction::New();
if (action.type() == "button")
- webAction.type = WebNotificationAction::Button;
+ mojoAction->type = mojom::blink::NotificationActionType::BUTTON;
else if (action.type() == "text")
- webAction.type = WebNotificationAction::Text;
+ mojoAction->type = mojom::blink::NotificationActionType::TEXT;
else
NOTREACHED() << "Unknown action type: " << action.type();
- if (action.hasPlaceholder() && webAction.type == WebNotificationAction::Button) {
+ if (action.hasPlaceholder() && mojoAction->type == mojom::blink::NotificationActionType::BUTTON) {
exceptionState.throwTypeError("Notifications of type \"button\" cannot specify a placeholder.");
- return WebNotificationData();
+ return mojom::blink::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

Powered by Google App Engine
This is Rietveld 408576698