| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 "content/common/manifest_type_converters.h" |
| 6 |
| 7 #include <limits> |
| 8 #include <string> |
| 9 |
| 10 #include "mojo/common/common_type_converters.h" |
| 11 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 12 #include "third_party/WebKit/public/platform/WebDisplayMode.h" |
| 13 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" |
| 14 #include "ui/gfx/geometry/size.h" |
| 15 #include "url/gurl.h" |
| 16 |
| 17 namespace mojo { |
| 18 |
| 19 mojo::String TypeConverter<mojo::String, base::NullableString16>::Convert( |
| 20 const base::NullableString16& input) { |
| 21 if (input.is_null()) |
| 22 return mojo::String(nullptr); |
| 23 |
| 24 return mojo::String::From( |
| 25 input.string().substr(0, content::Manifest::kMaxIPCStringLength)); |
| 26 } |
| 27 |
| 28 base::NullableString16 |
| 29 TypeConverter<base::NullableString16, mojo::String>::Convert( |
| 30 mojo::String input) { |
| 31 if (input.is_null()) |
| 32 return base::NullableString16(); |
| 33 |
| 34 return base::NullableString16(input.To<base::string16>().substr( |
| 35 0, content::Manifest::kMaxIPCStringLength), |
| 36 false); |
| 37 } |
| 38 |
| 39 blink::mojom::ManifestPtr |
| 40 TypeConverter<blink::mojom::ManifestPtr, content::Manifest>::Convert( |
| 41 const content::Manifest& input) { |
| 42 if (input.IsEmpty()) |
| 43 return nullptr; |
| 44 |
| 45 blink::mojom::ManifestPtr output = blink::mojom::Manifest::New(); |
| 46 output->name = mojo::String::From(input.name); |
| 47 output->short_name = mojo::String::From(input.short_name); |
| 48 output->start_url = input.start_url; |
| 49 output->display = static_cast<blink::mojom::DisplayMode>(input.display); |
| 50 output->orientation = |
| 51 static_cast<blink::mojom::ScreenOrientationLockType>(input.orientation); |
| 52 output->icons = decltype(output->icons)::From(input.icons); |
| 53 output->related_applications = |
| 54 decltype(output->related_applications)::From(input.related_applications); |
| 55 output->prefer_related_applications = input.prefer_related_applications; |
| 56 output->theme_color = input.theme_color; |
| 57 output->background_color = input.background_color; |
| 58 output->gcm_sender_id = mojo::String::From(input.gcm_sender_id); |
| 59 return output; |
| 60 } |
| 61 |
| 62 content::Manifest |
| 63 TypeConverter<content::Manifest, blink::mojom::ManifestPtr>::Convert( |
| 64 const blink::mojom::ManifestPtr& input) { |
| 65 content::Manifest output; |
| 66 if (!input) |
| 67 return output; |
| 68 |
| 69 output.name = input->name.To<base::NullableString16>(); |
| 70 output.short_name = input->short_name.To<base::NullableString16>(); |
| 71 output.start_url = input->start_url.is_valid() ? input->start_url : GURL(); |
| 72 output.display = static_cast<blink::WebDisplayMode>(input->display); |
| 73 output.orientation = |
| 74 static_cast<blink::WebScreenOrientationLockType>(input->orientation); |
| 75 output.icons = input->icons.To<decltype(output.icons)>(); |
| 76 output.related_applications = |
| 77 input->related_applications.To<decltype(output.related_applications)>(); |
| 78 output.prefer_related_applications = input->prefer_related_applications; |
| 79 output.theme_color = input->theme_color; |
| 80 output.background_color = input->background_color; |
| 81 // theme_color and background_color are 32 bit unsigned integers with 64 bit |
| 82 // integers simply being used to encode the occurence of an error. Therefore, |
| 83 // any value outside the range of a 32 bit integer is invalid. |
| 84 if (output.theme_color < std::numeric_limits<int32_t>::min() || |
| 85 output.theme_color > std::numeric_limits<int32_t>::max()) |
| 86 output.theme_color = content::Manifest::kInvalidOrMissingColor; |
| 87 if (output.background_color < std::numeric_limits<int32_t>::min() || |
| 88 output.background_color > std::numeric_limits<int32_t>::max()) |
| 89 output.background_color = content::Manifest::kInvalidOrMissingColor; |
| 90 |
| 91 output.gcm_sender_id = input->gcm_sender_id.To<base::NullableString16>(); |
| 92 return output; |
| 93 } |
| 94 |
| 95 blink::mojom::ManifestIconPtr |
| 96 TypeConverter<blink::mojom::ManifestIconPtr, content::Manifest::Icon>::Convert( |
| 97 const content::Manifest::Icon& input) { |
| 98 blink::mojom::ManifestIconPtr output = blink::mojom::ManifestIcon::New(); |
| 99 output->src = input.src; |
| 100 output->type = mojo::String::From(input.type); |
| 101 output->sizes = decltype(output->sizes)::From(input.sizes); |
| 102 return output; |
| 103 } |
| 104 |
| 105 content::Manifest::Icon |
| 106 TypeConverter<content::Manifest::Icon, blink::mojom::ManifestIconPtr>::Convert( |
| 107 const blink::mojom::ManifestIconPtr& input) { |
| 108 content::Manifest::Icon output; |
| 109 output.src = input->src.is_valid() ? input->src : GURL(); |
| 110 output.type = input->type.To<base::NullableString16>(); |
| 111 output.sizes = input->sizes.To<decltype(output.sizes)>(); |
| 112 return output; |
| 113 } |
| 114 |
| 115 blink::mojom::RelatedApplicationPtr |
| 116 TypeConverter<blink::mojom::RelatedApplicationPtr, |
| 117 content::Manifest::RelatedApplication>:: |
| 118 Convert(const content::Manifest::RelatedApplication& input) { |
| 119 blink::mojom::RelatedApplicationPtr output = |
| 120 blink::mojom::RelatedApplication::New(); |
| 121 output->platform = mojo::String::From(input.platform); |
| 122 output->url = input.url; |
| 123 output->id = mojo::String::From(input.id); |
| 124 return output; |
| 125 } |
| 126 |
| 127 content::Manifest::RelatedApplication |
| 128 TypeConverter<content::Manifest::RelatedApplication, |
| 129 blink::mojom::RelatedApplicationPtr>:: |
| 130 Convert(const blink::mojom::RelatedApplicationPtr& input) { |
| 131 content::Manifest::RelatedApplication output; |
| 132 output.platform = input->platform.To<base::NullableString16>(); |
| 133 output.url = input->url.is_valid() ? input->url : GURL(); |
| 134 output.id = input->id.To<base::NullableString16>(); |
| 135 return output; |
| 136 } |
| 137 |
| 138 } // namespace mojo |
| OLD | NEW |