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> 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 |
OLD | NEW |