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

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: Using ConstCArray to avoid copying Created 4 years, 2 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..f685a7770b0f72165afced24a37c31c416eadf39
--- /dev/null
+++ b/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.cpp
@@ -0,0 +1,38 @@
+// 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 <cstring>
+
+namespace mojo {
+
+// static
+mojo::ConstCArray<uint16_t>
+StructTraits<mojo::common::mojom::String16DataView, ::WTF::String>::data(
+ const ::WTF::String& str) {
+ DCHECK(!str.isNull())
+ << "mojo::common::mojom::String16 only accepts non-null blink::WebString";
+ DCHECK(!str.is8Bit());
+
+ return mojo::ConstCArray<uint16_t>(str.length(), str.characters16());
+}
+
+// static
+bool StructTraits<mojo::common::mojom::String16DataView, ::WTF::String>::Read(
+ mojo::common::mojom::String16DataView data,
+ ::WTF::String* out) {
+ mojo::ArrayDataView<uint16_t> view;
+ data.GetDataDataView(&view);
+ if (view.is_null())
+ return false;
+ *out =
+ ::WTF::String(reinterpret_cast<const UChar*>(view.data()), view.size());
+ // WTF::String is constructed as 8-bit if the string is empty.
+ out->ensure16Bit();
Zhiqiang Zhang (Slow) 2016/10/04 20:06:22 esprehn@, should this be fixed in WTF::String? I
+ return true;
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698