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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/mojo/CommonCustomTypesStructTraits.h"
6
7 #include "mojo/public/cpp/bindings/array_traits_wtf_vector.h"
8 #include <cstring>
9
10 namespace mojo {
11
12 // static
13 mojo::ConstCArray<uint16_t>
14 StructTraits<mojo::common::mojom::String16DataView, ::WTF::String>::data(
15 const ::WTF::String& str) {
16 DCHECK(!str.isNull())
17 << "mojo::common::mojom::String16 only accepts non-null blink::WebString";
18 DCHECK(!str.is8Bit());
19
20 return mojo::ConstCArray<uint16_t>(str.length(), str.characters16());
21 }
22
23 // static
24 bool StructTraits<mojo::common::mojom::String16DataView, ::WTF::String>::Read(
25 mojo::common::mojom::String16DataView data,
26 ::WTF::String* out) {
27 mojo::ArrayDataView<uint16_t> view;
28 data.GetDataDataView(&view);
29 if (view.is_null())
30 return false;
31 *out =
32 ::WTF::String(reinterpret_cast<const UChar*>(view.data()), view.size());
33 // WTF::String is constructed as 8-bit if the string is empty.
34 out->ensure16Bit();
Zhiqiang Zhang (Slow) 2016/10/04 20:06:22 esprehn@, should this be fixed in WTF::String? I
35 return true;
36 }
37
38 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698