Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: components/html_viewer/blink_basic_type_converters.cc

Issue 1677293002: Bye bye Mandoline (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moar Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/html_viewer/blink_basic_type_converters.h"
6
7 #include "mojo/public/cpp/bindings/string.h"
8 #include "third_party/WebKit/public/platform/WebRect.h"
9 #include "third_party/WebKit/public/platform/WebString.h"
10
11 using blink::WebRect;
12 using blink::WebString;
13
14 namespace mojo {
15
16 // static
17 String TypeConverter<String, WebString>::Convert(const WebString& str) {
18 return String(str.utf8());
19 }
20
21 // static
22 WebString TypeConverter<WebString, String>::Convert(const String& str) {
23 return WebString::fromUTF8(str.get());
24 }
25
26 // static
27 WebString TypeConverter<WebString, Array<uint8_t>>::Convert(
28 const Array<uint8_t>& input) {
29 static_assert(sizeof(uint8_t) == sizeof(char),
30 "uint8_t must be the same size as a char");
31 return input.is_null()
32 ? WebString()
33 : WebString::fromUTF8(
34 reinterpret_cast<const char*>(&input.front()), input.size());
35 }
36
37 // static
38 RectPtr TypeConverter<RectPtr, WebRect>::Convert(const WebRect& input) {
39 RectPtr result(Rect::New());
40 result->x = input.x;
41 result->y = input.y;
42 result->width = input.width;
43 result->height = input.height;
44 return result;
45 };
46
47 // static
48 Array<uint8_t> TypeConverter<Array<uint8_t>, WebString>::Convert(
49 const WebString& input) {
50 if (input.isNull())
51 return Array<uint8_t>();
52 const std::string utf8 = input.utf8();
53 Array<uint8_t> result(utf8.size());
54 static_assert(sizeof(uint8_t) == sizeof(char),
55 "uint8_t must be the same size as an unsigned char");
56 memcpy(&result.front(), utf8.data(), utf8.size());
57 return result;
58 }
59
60 } // namespace mojo
OLDNEW
« no previous file with comments | « components/html_viewer/blink_basic_type_converters.h ('k') | components/html_viewer/blink_find_type_converters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698