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

Unified Diff: components/html_viewer/blink_basic_type_converters.cc

Issue 1270313006: Connects PostMessage() for OOPIFs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: components/html_viewer/blink_basic_type_converters.cc
diff --git a/components/html_viewer/blink_basic_type_converters.cc b/components/html_viewer/blink_basic_type_converters.cc
index f7a5ff470b36c1f311cc43c502fc9cd27cd360e5..70a9b8a04bac21a61d5eaf39b2afc005574e4191 100644
--- a/components/html_viewer/blink_basic_type_converters.cc
+++ b/components/html_viewer/blink_basic_type_converters.cc
@@ -24,6 +24,17 @@ WebString TypeConverter<WebString, String>::Convert(const String& str) {
}
// static
+WebString TypeConverter<WebString, Array<uint8_t>>::Convert(
+ const Array<uint8_t>& input) {
+ COMPILE_ASSERT(sizeof(uint8_t) == sizeof(char),
+ uint8_t_same_size_as_unsigned_char);
+ return input.is_null()
+ ? WebString()
+ : WebString::fromUTF8(
+ reinterpret_cast<const char*>(&input.front()), input.size());
+}
+
+// static
RectPtr TypeConverter<RectPtr, WebRect>::Convert(const WebRect& input) {
RectPtr result(Rect::New());
result->x = input.x;
@@ -34,12 +45,15 @@ RectPtr TypeConverter<RectPtr, WebRect>::Convert(const WebRect& input) {
};
// static
-Array<uint8_t> TypeConverter<Array<uint8_t>, blink::WebString>::Convert(
- const blink::WebString& input) {
- std::string utf8 = input.utf8();
+Array<uint8_t> TypeConverter<Array<uint8_t>, WebString>::Convert(
+ const WebString& input) {
+ if (input.isNull())
+ return Array<uint8_t>();
+ const std::string utf8 = input.utf8();
Array<uint8_t> result(utf8.size());
- for (size_t i = 0; i < utf8.size(); ++i)
- result[i] = utf8[i];
+ COMPILE_ASSERT(sizeof(uint8_t) == sizeof(char),
+ uint8_t_same_size_as_unsigned_char);
+ memcpy(&result.front(), utf8.data(), utf8.size());
return result.Pass();
}

Powered by Google App Engine
This is Rietveld 408576698