| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/doodle/doodle_types.h" | 5 #include "components/doodle/doodle_types.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 | 9 |
| 10 namespace doodle { | 10 namespace doodle { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 const char kKeyUrl[] = "url"; | 24 const char kKeyUrl[] = "url"; |
| 25 const char kKeyHeight[] = "height"; | 25 const char kKeyHeight[] = "height"; |
| 26 const char kKeyWidth[] = "width"; | 26 const char kKeyWidth[] = "width"; |
| 27 const char kKeyIsAnimatedGif[] = "is_animated_gif"; | 27 const char kKeyIsAnimatedGif[] = "is_animated_gif"; |
| 28 const char kKeyIsCta[] = "is_cta"; | 28 const char kKeyIsCta[] = "is_cta"; |
| 29 | 29 |
| 30 // JSON keys for DoodleConfig fields. | 30 // JSON keys for DoodleConfig fields. |
| 31 const char kKeyDoodleType[] = "doodle_type"; | 31 const char kKeyDoodleType[] = "doodle_type"; |
| 32 const char kKeyAltText[] = "alt_text"; | 32 const char kKeyAltText[] = "alt_text"; |
| 33 const char kKeyInteractiveHtml[] = "interactive_html"; | 33 const char kKeyInteractiveHtml[] = "interactive_html"; |
| 34 const char kKeySearchUrl[] = "search_url"; | |
| 35 const char kKeyTargetUrl[] = "target_url"; | 34 const char kKeyTargetUrl[] = "target_url"; |
| 36 const char kKeyFullpageInteractiveUrl[] = "fullpage_interactive_url"; | |
| 37 const char kKeyLargeImage[] = "large_image"; | 35 const char kKeyLargeImage[] = "large_image"; |
| 38 const char kKeyLargeCtaImage[] = "large_cta_image"; | 36 const char kKeyLargeCtaImage[] = "large_cta_image"; |
| 39 const char kKeyTransparentLargeImage[] = "transparent_large_image"; | 37 const char kKeyTransparentLargeImage[] = "transparent_large_image"; |
| 40 | 38 |
| 41 std::string DoodleTypeToString(DoodleType type) { | 39 std::string DoodleTypeToString(DoodleType type) { |
| 42 switch (type) { | 40 switch (type) { |
| 43 case DoodleType::UNKNOWN: | 41 case DoodleType::UNKNOWN: |
| 44 return kDoodleTypeUnknown; | 42 return kDoodleTypeUnknown; |
| 45 case DoodleType::SIMPLE: | 43 case DoodleType::SIMPLE: |
| 46 return kDoodleTypeSimple; | 44 return kDoodleTypeSimple; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 175 |
| 178 std::string type_str; | 176 std::string type_str; |
| 179 dict.GetString(kKeyDoodleType, &type_str); | 177 dict.GetString(kKeyDoodleType, &type_str); |
| 180 | 178 |
| 181 DoodleConfig doodle(DoodleTypeFromString(type_str), large_image.value()); | 179 DoodleConfig doodle(DoodleTypeFromString(type_str), large_image.value()); |
| 182 | 180 |
| 183 dict.GetString(kKeyAltText, &doodle.alt_text); | 181 dict.GetString(kKeyAltText, &doodle.alt_text); |
| 184 | 182 |
| 185 dict.GetString(kKeyInteractiveHtml, &doodle.interactive_html); | 183 dict.GetString(kKeyInteractiveHtml, &doodle.interactive_html); |
| 186 | 184 |
| 187 doodle.search_url = ParseUrl(dict, kKeySearchUrl, base_url); | |
| 188 doodle.target_url = ParseUrl(dict, kKeyTargetUrl, base_url); | 185 doodle.target_url = ParseUrl(dict, kKeyTargetUrl, base_url); |
| 189 doodle.fullpage_interactive_url = | |
| 190 ParseUrl(dict, kKeyFullpageInteractiveUrl, base_url); | |
| 191 | 186 |
| 192 doodle.large_cta_image = ParseImage(dict, kKeyLargeCtaImage, base_url); | 187 doodle.large_cta_image = ParseImage(dict, kKeyLargeCtaImage, base_url); |
| 193 doodle.transparent_large_image = | 188 doodle.transparent_large_image = |
| 194 ParseImage(dict, kKeyTransparentLargeImage, base_url); | 189 ParseImage(dict, kKeyTransparentLargeImage, base_url); |
| 195 | 190 |
| 196 return doodle; | 191 return doodle; |
| 197 } | 192 } |
| 198 | 193 |
| 199 std::unique_ptr<base::DictionaryValue> DoodleConfig::ToDictionary() const { | 194 std::unique_ptr<base::DictionaryValue> DoodleConfig::ToDictionary() const { |
| 200 auto dict = base::MakeUnique<base::DictionaryValue>(); | 195 auto dict = base::MakeUnique<base::DictionaryValue>(); |
| 201 dict->SetString(kKeyDoodleType, DoodleTypeToString(doodle_type)); | 196 dict->SetString(kKeyDoodleType, DoodleTypeToString(doodle_type)); |
| 202 dict->SetString(kKeyAltText, alt_text); | 197 dict->SetString(kKeyAltText, alt_text); |
| 203 dict->SetString(kKeyInteractiveHtml, interactive_html); | 198 dict->SetString(kKeyInteractiveHtml, interactive_html); |
| 204 dict->SetString(kKeySearchUrl, search_url.spec()); | |
| 205 dict->SetString(kKeyTargetUrl, target_url.spec()); | 199 dict->SetString(kKeyTargetUrl, target_url.spec()); |
| 206 dict->SetString(kKeyFullpageInteractiveUrl, fullpage_interactive_url.spec()); | |
| 207 dict->Set(kKeyLargeImage, large_image.ToDictionary()); | 200 dict->Set(kKeyLargeImage, large_image.ToDictionary()); |
| 208 if (large_cta_image.has_value()) { | 201 if (large_cta_image.has_value()) { |
| 209 dict->Set(kKeyLargeCtaImage, large_cta_image->ToDictionary()); | 202 dict->Set(kKeyLargeCtaImage, large_cta_image->ToDictionary()); |
| 210 } | 203 } |
| 211 if (transparent_large_image.has_value()) { | 204 if (transparent_large_image.has_value()) { |
| 212 dict->Set(kKeyTransparentLargeImage, | 205 dict->Set(kKeyTransparentLargeImage, |
| 213 transparent_large_image->ToDictionary()); | 206 transparent_large_image->ToDictionary()); |
| 214 } | 207 } |
| 215 return dict; | 208 return dict; |
| 216 } | 209 } |
| 217 | 210 |
| 218 bool DoodleConfig::operator==(const DoodleConfig& other) const { | 211 bool DoodleConfig::operator==(const DoodleConfig& other) const { |
| 219 return doodle_type == other.doodle_type && alt_text == other.alt_text && | 212 return doodle_type == other.doodle_type && alt_text == other.alt_text && |
| 220 interactive_html == other.interactive_html && | 213 interactive_html == other.interactive_html && |
| 221 search_url == other.search_url && target_url == other.target_url && | |
| 222 fullpage_interactive_url == other.fullpage_interactive_url && | |
| 223 large_image == other.large_image && | 214 large_image == other.large_image && |
| 224 large_cta_image == other.large_cta_image && | 215 large_cta_image == other.large_cta_image && |
| 225 transparent_large_image == other.transparent_large_image; | 216 transparent_large_image == other.transparent_large_image; |
| 226 } | 217 } |
| 227 | 218 |
| 228 bool DoodleConfig::operator!=(const DoodleConfig& other) const { | 219 bool DoodleConfig::operator!=(const DoodleConfig& other) const { |
| 229 return !(*this == other); | 220 return !(*this == other); |
| 230 } | 221 } |
| 231 | 222 |
| 232 } // namespace doodle | 223 } // namespace doodle |
| OLD | NEW |