Chromium Code Reviews| Index: third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.cpp |
| diff --git a/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.cpp b/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ca401e8a47f572383982fd65885b6e042de3c664 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.cpp |
| @@ -0,0 +1,43 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "platform/mojo/CommonCustomTypesStructTraits.h" |
| + |
| +#include "mojo/public/cpp/bindings/array_traits_wtf_vector.h" |
| +#include "wtf/text/StringImpl.h" |
| +#include "wtf/text/WTFString.h" |
| +#include <cstring> |
| + |
| +namespace mojo { |
| + |
| +// static |
| +WTF::Vector<uint16_t> |
| +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
|
| + const ::blink::WebString& str) { |
| + DCHECK(!str.isNull()) |
| + << "mojo::common::mojom::String16 only accepts non-null blink::WebString"; |
| + WTF::Vector<uint16_t> rawData(str.length()); |
| + WTF::StringView strView = str; |
| + if (strView.is8Bit()) { |
| + WTF::StringImpl::copyChars(reinterpret_cast<UChar*>(rawData.data()), |
| + strView.characters8(), strView.length()); |
| + } else { |
| + memcpy(rawData.data(), strView.characters16(), strView.length()); |
| + } |
| + return rawData; |
| +} |
| + |
| +// static |
| +bool StructTraits<mojo::common::mojom::String16DataView, ::blink::WebString>:: |
| + Read(mojo::common::mojom::String16DataView data, ::blink::WebString* out) { |
| + mojo::ArrayDataView<uint16_t> view; |
| + data.GetDataDataView(&view); |
| + if (view.is_null()) |
| + return false; |
| + *out = ::blink::WebString( |
| + reinterpret_cast<const ::blink::WebUChar*>(view.data()), view.size()); |
| + return true; |
| +} |
| + |
| +} // namespace mojo |