OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/html_viewer/blink_basic_type_converters.h" | 5 #include "components/html_viewer/blink_basic_type_converters.h" |
6 | 6 |
7 #include "mojo/public/cpp/bindings/string.h" | 7 #include "mojo/public/cpp/bindings/string.h" |
8 #include "third_party/WebKit/public/platform/WebRect.h" | 8 #include "third_party/WebKit/public/platform/WebRect.h" |
9 #include "third_party/WebKit/public/platform/WebString.h" | 9 #include "third_party/WebKit/public/platform/WebString.h" |
10 | 10 |
11 using blink::WebRect; | 11 using blink::WebRect; |
12 using blink::WebString; | 12 using blink::WebString; |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 | 15 |
16 // static | 16 // static |
17 String TypeConverter<String, WebString>::Convert(const WebString& str) { | 17 String TypeConverter<String, WebString>::Convert(const WebString& str) { |
18 return String(str.utf8()); | 18 return String(str.utf8()); |
19 } | 19 } |
20 | 20 |
21 // static | 21 // static |
22 WebString TypeConverter<WebString, String>::Convert(const String& str) { | 22 WebString TypeConverter<WebString, String>::Convert(const String& str) { |
23 return WebString::fromUTF8(str.get()); | 23 return WebString::fromUTF8(str.get()); |
24 } | 24 } |
25 | 25 |
26 // static | 26 // static |
27 WebString TypeConverter<WebString, Array<uint8_t>>::Convert( | 27 WebString TypeConverter<WebString, Array<uint8_t>>::Convert( |
28 const Array<uint8_t>& input) { | 28 const Array<uint8_t>& input) { |
29 COMPILE_ASSERT(sizeof(uint8_t) == sizeof(char), | 29 static_assert(sizeof(uint8_t) == sizeof(char), |
30 uint8_t_same_size_as_unsigned_char); | 30 "uint8_t must be the same size as a char"); |
31 return input.is_null() | 31 return input.is_null() |
32 ? WebString() | 32 ? WebString() |
33 : WebString::fromUTF8( | 33 : WebString::fromUTF8( |
34 reinterpret_cast<const char*>(&input.front()), input.size()); | 34 reinterpret_cast<const char*>(&input.front()), input.size()); |
35 } | 35 } |
36 | 36 |
37 // static | 37 // static |
38 RectPtr TypeConverter<RectPtr, WebRect>::Convert(const WebRect& input) { | 38 RectPtr TypeConverter<RectPtr, WebRect>::Convert(const WebRect& input) { |
39 RectPtr result(Rect::New()); | 39 RectPtr result(Rect::New()); |
40 result->x = input.x; | 40 result->x = input.x; |
41 result->y = input.y; | 41 result->y = input.y; |
42 result->width = input.width; | 42 result->width = input.width; |
43 result->height = input.height; | 43 result->height = input.height; |
44 return result.Pass(); | 44 return result.Pass(); |
45 }; | 45 }; |
46 | 46 |
47 // static | 47 // static |
48 Array<uint8_t> TypeConverter<Array<uint8_t>, WebString>::Convert( | 48 Array<uint8_t> TypeConverter<Array<uint8_t>, WebString>::Convert( |
49 const WebString& input) { | 49 const WebString& input) { |
50 if (input.isNull()) | 50 if (input.isNull()) |
51 return Array<uint8_t>(); | 51 return Array<uint8_t>(); |
52 const std::string utf8 = input.utf8(); | 52 const std::string utf8 = input.utf8(); |
53 Array<uint8_t> result(utf8.size()); | 53 Array<uint8_t> result(utf8.size()); |
54 COMPILE_ASSERT(sizeof(uint8_t) == sizeof(char), | 54 static_assert(sizeof(uint8_t) == sizeof(char), |
55 uint8_t_same_size_as_unsigned_char); | 55 "uint8_t must be the same size as an unsigned char"); |
56 memcpy(&result.front(), utf8.data(), utf8.size()); | 56 memcpy(&result.front(), utf8.data(), utf8.size()); |
57 return result.Pass(); | 57 return result.Pass(); |
58 } | 58 } |
59 | 59 |
60 } // namespace mojo | 60 } // namespace mojo |
OLD | NEW |