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

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

Issue 2379993003: Mojo C++ bindings: make String16 and gfx::Size available in Blink (Closed)
Patch Set: 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.cpp
diff --git a/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.cpp b/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..33311c50d4e572abdafedd183a10947f1cc452fa
--- /dev/null
+++ b/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.cpp
@@ -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.
+
+#include "platform/mojo/CommonCustomTypesStructTraits.h"
+
+#include "mojo/public/cpp/bindings/array_traits_wtf_vector.h"
+#include "wtf/text/WTFString.h"
+#include <cstring>
+
+namespace mojo {
+
+// static
+WTF::Vector<uint16_t> StructTraits<mojo::common::mojom::String16DataView, blink::WebString>::data(const blink::WebString& str)
+{
+ DCHECK(!str.isNull()) << "mojo::common::mojom::String16 only accepts non-null blink::WebString";
+ WTF::String str16 = str;
+ str16.ensure16Bit();
+ WTF::Vector<uint16_t> rawData(str16.length());
+ memcpy(rawData.data(), str16.characters16(), str16.length() * sizeof(uint16_t));
+ return rawData;
+}
+
+// static
+bool StructTraits<mojo::common::mojom::String16DataView, blink::WebString>::Read(mojo::common::mojom::String16DataView data, blink::WebString* out)
+{
+ WTF::Vector<uint16_t> rawData;
+ if (!data.ReadData(&rawData))
+ return false;
+ *out = blink::WebString(static_cast<blink::WebUChar*>(rawData.begin()), rawData.size());
+ return true;
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698