| 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
|
| index a66290f23b8a3af2cf5e8e3bd448a5e6933a75c2..4a7c088d84e648e6e53fcad1a2473c41197abbec 100644
|
| --- a/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.cpp
|
| +++ b/third_party/WebKit/Source/platform/mojo/CommonCustomTypesStructTraits.cpp
|
| @@ -4,37 +4,48 @@
|
|
|
| #include "platform/mojo/CommonCustomTypesStructTraits.h"
|
|
|
| -#include "base/strings/latin1_string_conversions.h"
|
| #include <cstring>
|
|
|
| namespace mojo {
|
|
|
| // static
|
| -WTF::Vector<uint16_t>
|
| -StructTraits<mojo::common::mojom::String16DataView, ::WTF::String>::data(
|
| - const ::WTF::String& str) {
|
| - // TODO(zqzhang): Need to find a way to avoid another memory copy here. A
|
| - // broader is question is that should sending String16 over mojo be avoided?
|
| - // See https://crbug.com/653209
|
| -
|
| - base::string16 str16 = base::Latin1OrUTF16ToUTF16(
|
| - str.length(), str.is8Bit() ? str.characters8() : nullptr /* latin1 */,
|
| - str.is8Bit() ? nullptr : str.characters16() /* utf16 */);
|
| - WTF::Vector<uint16_t> rawData(str16.size());
|
| - memcpy(rawData.data(), str16.data(), str16.size() * sizeof(uint16_t));
|
| - return rawData;
|
| +void* StructTraits<common::mojom::String16DataView, WTF::String>::SetUpContext(
|
| + const WTF::String& input) {
|
| + // If it is null (i.e., StructTraits<>::IsNull() returns true), this method is
|
| + // guaranteed not to be called.
|
| + DCHECK(!input.isNull());
|
| +
|
| + if (!input.is8Bit())
|
| + return nullptr;
|
| +
|
| + return new base::string16(input.characters8(),
|
| + input.characters8() + input.length());
|
| +}
|
| +
|
| +// static
|
| +ConstCArray<uint16_t> StructTraits<common::mojom::String16DataView,
|
| + WTF::String>::data(const WTF::String& input,
|
| + void* context) {
|
| + auto contextObject = static_cast<base::string16*>(context);
|
| + DCHECK_EQ(input.is8Bit(), !!contextObject);
|
| +
|
| + if (contextObject) {
|
| + return ConstCArray<uint16_t>(
|
| + contextObject->size(),
|
| + reinterpret_cast<const uint16_t*>(contextObject->data()));
|
| + }
|
| +
|
| + return ConstCArray<uint16_t>(
|
| + input.length(), reinterpret_cast<const uint16_t*>(input.characters16()));
|
| }
|
|
|
| // static
|
| -bool StructTraits<mojo::common::mojom::String16DataView, ::WTF::String>::Read(
|
| - mojo::common::mojom::String16DataView data,
|
| - ::WTF::String* out) {
|
| - mojo::ArrayDataView<uint16_t> view;
|
| +bool StructTraits<common::mojom::String16DataView, WTF::String>::Read(
|
| + common::mojom::String16DataView data,
|
| + WTF::String* out) {
|
| + ArrayDataView<uint16_t> view;
|
| data.GetDataDataView(&view);
|
| - if (view.is_null())
|
| - return false;
|
| - *out =
|
| - ::WTF::String(reinterpret_cast<const UChar*>(view.data()), view.size());
|
| + *out = WTF::String(reinterpret_cast<const UChar*>(view.data()), view.size());
|
| return true;
|
| }
|
|
|
|
|