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

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: trying to fix Windows build 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());
esprehn 2016/10/05 17:38:52 What makes sure the string is 16bit here? I think
Ken Rockot(use gerrit already) 2016/10/05 17:47:55 What do you mean by writing directly into the outp
19
20 return mojo::ConstCArray<uint16_t>(
21 str.length(), reinterpret_cast<const uint16_t*>(str.characters16()));
22 }
23
24 // static
25 bool StructTraits<mojo::common::mojom::String16DataView, ::WTF::String>::Read(
26 mojo::common::mojom::String16DataView data,
27 ::WTF::String* out) {
28 mojo::ArrayDataView<uint16_t> view;
29 data.GetDataDataView(&view);
30 if (view.is_null())
31 return false;
32 *out =
33 ::WTF::String(reinterpret_cast<const UChar*>(view.data()), view.size());
34 // WTF::String is constructed as 8-bit if the string is empty.
35 out->ensure16Bit();
36 return true;
37 }
38
39 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698