| 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/public/common/manifest_struct_traits.h" |
| 6 |
| 7 namespace mojo { |
| 8 namespace { |
| 9 |
| 10 bool ValidateColor(int64_t color) { |
| 11 if (color < std::numeric_limits<int32_t>::min() && |
| 12 color > std::numeric_limits<int32_t>::max() && |
| 13 color != content::Manifest::kInvalidOrMissingColor) { |
| 14 return false; |
| 15 } |
| 16 return true; |
| 17 } |
| 18 |
| 19 // A wrapper around base::NullableString16 so a custom StringTraits |
| 20 // specialization can enforce maximum string length. |
| 21 struct TruncatedNullableString16 { |
| 22 base::NullableString16 string; |
| 23 }; |
| 24 |
| 25 } // namespace |
| 26 |
| 27 template <> |
| 28 struct StringTraits<TruncatedNullableString16> { |
| 29 static void SetToNull(TruncatedNullableString16* output) { |
| 30 output->string = base::NullableString16(); |
| 31 } |
| 32 |
| 33 static bool Read(StringDataView input, TruncatedNullableString16* output) { |
| 34 if (!StringTraits<base::NullableString16>::Read(input, &output->string)) |
| 35 return false; |
| 36 |
| 37 return (output->string.is_null() || |
| 38 output->string.string().size() <= |
| 39 content::Manifest::kMaxIPCStringLength); |
| 40 } |
| 41 }; |
| 42 |
| 43 bool StructTraits<blink::mojom::Manifest, content::Manifest>::Read( |
| 44 blink::mojom::ManifestDataView data, |
| 45 content::Manifest* out) { |
| 46 TruncatedNullableString16 string; |
| 47 if (!data.ReadName(&string)) |
| 48 return false; |
| 49 out->name = string.string; |
| 50 |
| 51 if (!data.ReadShortName(&string)) |
| 52 return false; |
| 53 out->short_name = string.string; |
| 54 |
| 55 if (!data.ReadGcmSenderId(&string)) |
| 56 return false; |
| 57 out->gcm_sender_id = string.string; |
| 58 |
| 59 if (!data.ReadStartUrl(&out->start_url)) |
| 60 return false; |
| 61 |
| 62 if (!data.ReadIcons(&out->icons)) |
| 63 return false; |
| 64 |
| 65 if (!data.ReadRelatedApplications(&out->related_applications)) |
| 66 return false; |
| 67 |
| 68 out->prefer_related_applications = data.prefer_related_applications(); |
| 69 out->theme_color = data.theme_color(); |
| 70 if (!ValidateColor(out->theme_color)) |
| 71 return false; |
| 72 |
| 73 out->background_color = data.background_color(); |
| 74 if (!ValidateColor(out->background_color)) |
| 75 return false; |
| 76 |
| 77 out->display = static_cast<blink::WebDisplayMode>(data.display()); |
| 78 out->orientation = |
| 79 static_cast<blink::WebScreenOrientationLockType>(data.orientation()); |
| 80 |
| 81 return true; |
| 82 } |
| 83 |
| 84 bool StructTraits<blink::mojom::ManifestIcon, content::Manifest::Icon>::Read( |
| 85 blink::mojom::ManifestIconDataView data, |
| 86 content::Manifest::Icon* out) { |
| 87 if (!data.ReadSrc(&out->src)) |
| 88 return false; |
| 89 |
| 90 TruncatedNullableString16 string; |
| 91 if (!data.ReadType(&string)) |
| 92 return false; |
| 93 |
| 94 out->type = string.string; |
| 95 |
| 96 if (!data.ReadSizes(&out->sizes)) |
| 97 return false; |
| 98 |
| 99 return true; |
| 100 } |
| 101 |
| 102 bool StructTraits<blink::mojom::RelatedApplication, |
| 103 content::Manifest::RelatedApplication>:: |
| 104 Read(blink::mojom::RelatedApplicationDataView data, |
| 105 content::Manifest::RelatedApplication* out) { |
| 106 TruncatedNullableString16 string; |
| 107 if (!data.ReadPlatform(&string)) |
| 108 return false; |
| 109 out->platform = string.string; |
| 110 |
| 111 if (!data.ReadUrl(&out->url)) |
| 112 return false; |
| 113 |
| 114 if (!data.ReadId(&string)) |
| 115 return false; |
| 116 out->id = string.string; |
| 117 |
| 118 return true; |
| 119 } |
| 120 |
| 121 } // namespace mojo |
| OLD | NEW |