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

Unified Diff: third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.h

Issue 2367393002: Migrating MediaSession messages to mojo (Closed)
Patch Set: better type mapping (experimental, should move to a separate CL) Created 4 years, 3 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/mojo/CommonCustomTypesStructTraits.h
diff --git a/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.h b/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.h
new file mode 100644
index 0000000000000000000000000000000000000000..46512182b3df1003b3ab03a5094603d0c4d16ee4
--- /dev/null
+++ b/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.h
@@ -0,0 +1,34 @@
+// 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.
+
+#ifndef CommonCustomTypesBlinkStructTraits_h
+#define CommonCustomTypesBlinkStructTraits_h
+
+#include "public/platform/WebString.h"
+#include "mojo/common/common_custom_types.mojom-blink.h"
+#include "base/strings/string16.h"
+#include <cstring>
+
+namespace mojo {
+
+template <>
+struct StructTraits<mojo::common::mojom::String16DataView, blink::WebString> {
+ static WTF::Vector<uint16_t> data(const blink::WebString& str) {
+ base::string16 str16 = str;
+ WTF::Vector<uint16_t> raw_data(str16.size());
+ memcpy(raw_data.data(), str16.data(), str16.size() * sizeof(uint16_t));
+ return raw_data;
+ }
+ static bool Read(mojo::common::mojom::String16DataView data, blink::WebString* out) {
+ WTF::Vector<uint16_t> raw_data;
+ if (!data.ReadData(&raw_data))
+ return false;
+ out->assign(raw_data.begin(), raw_data.size());
+ return true;
+ }
+};
+
+} // namespace mojo
+
+#endif // CommonCustomTypesBlinkStructTraits_h

Powered by Google App Engine
This is Rietveld 408576698