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

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: 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 "wtf/text/WTFString.h"
9 #include <cstring>
10
11 namespace mojo {
12
13 // static
14 WTF::Vector<uint16_t> StructTraits<mojo::common::mojom::String16DataView, blink: :WebString>::data(const blink::WebString& str)
15 {
16 DCHECK(!str.isNull()) << "mojo::common::mojom::String16 only accepts non-nul l blink::WebString";
17 WTF::String str16 = str;
18 str16.ensure16Bit();
19 WTF::Vector<uint16_t> rawData(str16.length());
20 memcpy(rawData.data(), str16.characters16(), str16.length() * sizeof(uint16_ t));
21 return rawData;
22 }
23
24 // static
25 bool StructTraits<mojo::common::mojom::String16DataView, blink::WebString>::Read (mojo::common::mojom::String16DataView data, blink::WebString* out)
26 {
27 WTF::Vector<uint16_t> rawData;
28 if (!data.ReadData(&rawData))
29 return false;
30 *out = blink::WebString(static_cast<blink::WebUChar*>(rawData.begin()), rawD ata.size());
31 return true;
32 }
33
34 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698