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/StringImpl.h" | |
| 9 #include "wtf/text/WTFString.h" | |
| 10 #include <cstring> | |
| 11 | |
| 12 namespace mojo { | |
| 13 | |
| 14 // static | |
| 15 WTF::Vector<uint16_t> | |
| 16 StructTraits<mojo::common::mojom::String16DataView, ::blink::WebString>::data( | |
|
Ken Rockot(use gerrit already)
2016/10/04 18:20:29
This is called twice during serialization. You sho
Zhiqiang Zhang (Slow)
2016/10/04 20:06:22
Thanks! Done.
BTW, I saw your other comment, and t
| |
| 17 const ::blink::WebString& str) { | |
| 18 DCHECK(!str.isNull()) | |
| 19 << "mojo::common::mojom::String16 only accepts non-null blink::WebString"; | |
| 20 WTF::Vector<uint16_t> rawData(str.length()); | |
| 21 WTF::StringView strView = str; | |
| 22 if (strView.is8Bit()) { | |
| 23 WTF::StringImpl::copyChars(reinterpret_cast<UChar*>(rawData.data()), | |
| 24 strView.characters8(), strView.length()); | |
| 25 } else { | |
| 26 memcpy(rawData.data(), strView.characters16(), strView.length()); | |
| 27 } | |
| 28 return rawData; | |
| 29 } | |
| 30 | |
| 31 // static | |
| 32 bool StructTraits<mojo::common::mojom::String16DataView, ::blink::WebString>:: | |
| 33 Read(mojo::common::mojom::String16DataView data, ::blink::WebString* out) { | |
| 34 mojo::ArrayDataView<uint16_t> view; | |
| 35 data.GetDataDataView(&view); | |
| 36 if (view.is_null()) | |
| 37 return false; | |
| 38 *out = ::blink::WebString( | |
| 39 reinterpret_cast<const ::blink::WebUChar*>(view.data()), view.size()); | |
| 40 return true; | |
| 41 } | |
| 42 | |
| 43 } // namespace mojo | |
| OLD | NEW |