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

Unified Diff: third_party/WebKit/Source/platform/PlatformNotificationConverters.cpp

Issue 1808513006: Introduce PlatformNotification structures and converters (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-mojo-hacks
Patch Set: Created 4 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: third_party/WebKit/Source/platform/PlatformNotificationConverters.cpp
diff --git a/third_party/WebKit/Source/platform/PlatformNotificationConverters.cpp b/third_party/WebKit/Source/platform/PlatformNotificationConverters.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d7f40df21e36533006a94b30a33d07dac0b240cc
--- /dev/null
+++ b/third_party/WebKit/Source/platform/PlatformNotificationConverters.cpp
@@ -0,0 +1,117 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/PlatformNotificationConverters.h"
+
+#include "base/time/time.h"
+#include "platform/weborigin/KURL.h"
+#include "wtf/Assertions.h"
+
+using blink::PlatformNotification;
+using blink::PlatformNotificationAction;
+using blink::mojom::wtf::NotificationDirection;
+
+namespace mojo {
+
+// static
+PlatformNotification
+TypeConverter<PlatformNotification, blink::mojom::wtf::NotificationPtr>::Convert(const blink::mojom::wtf::NotificationPtr& mojoNotification)
+{
+ PlatformNotification notification;
+ notification.title = mojoNotification->title;
+
+ switch (mojoNotification->direction) {
+ case NotificationDirection::LEFT_TO_RIGHT:
+ notification.direction = PlatformNotification::Direction::LEFT_TO_RIGHT;
+ break;
+ case NotificationDirection::RIGHT_TO_LEFT:
+ notification.direction = PlatformNotification::Direction::RIGHT_TO_LEFT;
+ break;
+ case NotificationDirection::AUTO:
+ notification.direction = PlatformNotification::Direction::AUTO;
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ notification.lang = mojoNotification->lang;
+ notification.body = mojoNotification->body;
+ notification.tag = mojoNotification->tag;
+
+ if (!mojoNotification->icon.isEmpty())
+ notification.icon = blink::KURL(blink::ParsedURLString, mojoNotification->icon);
+
+ notification.vibrationPattern = mojoNotification->vibration_pattern.Clone().PassStorage();
+ notification.timestamp = base::Time::FromInternalValue(mojoNotification->timestamp).ToJsTime();
+ notification.renotify = mojoNotification->renotify;
+ notification.silent = mojoNotification->silent;
+ notification.requireInteraction = mojoNotification->require_interaction;
+ notification.data = mojoNotification->data.Clone().PassStorage();
+
+ notification.actions.resize(mojoNotification->actions.size());
+ for (size_t i = 0; i < mojoNotification->actions.size(); i++) {
+ PlatformNotificationAction action;
+ action.action = mojoNotification->actions[i]->action;
+ action.title = mojoNotification->actions[i]->title;
+
+ if (!mojoNotification->actions[i]->icon.isEmpty())
+ action.icon = blink::KURL(blink::ParsedURLString, mojoNotification->actions[i]->icon);
+
+ notification.actions[i] = action;
+ }
+
+ return notification;
+}
+
+// static
+blink::mojom::wtf::NotificationPtr
+TypeConverter<blink::mojom::wtf::NotificationPtr, PlatformNotification>::Convert(const PlatformNotification& notification)
+{
+ blink::mojom::wtf::NotificationPtr mojoNotification = blink::mojom::wtf::Notification::New();
+ mojoNotification->title = notification.title;
+
+ switch (notification.direction) {
+ case PlatformNotification::Direction::LEFT_TO_RIGHT:
+ mojoNotification->direction = NotificationDirection::LEFT_TO_RIGHT;
+ break;
+ case PlatformNotification::Direction::RIGHT_TO_LEFT:
+ mojoNotification->direction = NotificationDirection::RIGHT_TO_LEFT;
+ break;
+ case PlatformNotification::Direction::AUTO:
+ mojoNotification->direction = NotificationDirection::AUTO;
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ mojoNotification->lang = notification.lang;
+ mojoNotification->body = notification.body;
+ mojoNotification->tag = notification.tag;
+ mojoNotification->icon = notification.icon.getString();
+
+ Vector<int> vibrationPatternCopy = notification.vibrationPattern;
+ mojoNotification->vibration_pattern.Swap(&vibrationPatternCopy);
+
+ mojoNotification->timestamp = base::Time::FromJsTime(notification.timestamp).ToInternalValue();
+ mojoNotification->renotify = notification.renotify;
+ mojoNotification->silent = notification.silent;
+ mojoNotification->require_interaction = notification.requireInteraction;
+
+ Vector<unsigned char> dataCopy = notification.data;
+ mojoNotification->data.Swap(&dataCopy);
+
+ mojoNotification->actions.resize(notification.actions.size());
+ for (size_t i = 0; i < notification.actions.size(); i++) {
+ blink::mojom::wtf::NotificationActionPtr mojoAction = blink::mojom::wtf::NotificationAction::New();
+ mojoAction->action = notification.actions[i].action;
+ mojoAction->title = notification.actions[i].title;
+ mojoAction->icon = notification.actions[i].icon.getString();
+
+ mojoNotification->actions[i] = std::move(mojoAction);
+ }
+
+ return mojoNotification;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698