Chromium Code Reviews| OLD | NEW |
|---|---|
| (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> | |
| 15 StructTraits<mojo::common::mojom::String16DataView, ::blink::WebString>::data( | |
| 16 const ::blink::WebString& str) { | |
| 17 DCHECK(!str.isNull()) | |
| 18 << "mojo::common::mojom::String16 only accepts non-null blink::WebString"; | |
| 19 WTF::String str16 = str; | |
| 20 str16.ensure16Bit(); | |
| 21 WTF::Vector<uint16_t> rawData(str16.length()); | |
|
Ken Rockot(use gerrit already)
2016/10/04 06:28:40
And similarly you can use ArrayDataView here as we
Zhiqiang Zhang (Slow)
2016/10/04 13:21:59
Done.
| |
| 22 memcpy(rawData.data(), str16.characters16(), | |
| 23 str16.length() * sizeof(uint16_t)); | |
| 24 return rawData; | |
| 25 } | |
| 26 | |
| 27 // static | |
| 28 bool StructTraits<mojo::common::mojom::String16DataView, ::blink::WebString>:: | |
| 29 Read(mojo::common::mojom::String16DataView data, ::blink::WebString* out) { | |
| 30 WTF::Vector<uint16_t> rawData; | |
| 31 if (!data.ReadData(&rawData)) | |
| 32 return false; | |
| 33 *out = ::blink::WebString( | |
| 34 reinterpret_cast<::blink::WebUChar*>(rawData.begin()), rawData.size()); | |
| 35 return true; | |
| 36 } | |
| 37 | |
| 38 } // namespace mojo | |
| OLD | NEW |