Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / common / instant_types.cc
blob8645f6b82d2a6c0ccafd48d0c1024206a4d3dbaa
1 // Copyright 2012 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.
5 #include "chrome/common/instant_types.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "net/base/escape.h"
10 namespace {
12 std::string GetComponent(const std::string& url,
13 const url::Component component) {
14 return (component.len > 0) ? url.substr(component.begin, component.len) :
15 std::string();
18 } // namespace
20 InstantSuggestion::InstantSuggestion() {
23 InstantSuggestion::InstantSuggestion(const base::string16& in_text,
24 const std::string& in_metadata)
25 : text(in_text),
26 metadata(in_metadata) {
29 InstantSuggestion::~InstantSuggestion() {
32 RGBAColor::RGBAColor()
33 : r(0),
34 g(0),
35 b(0),
36 a(0) {
39 RGBAColor::~RGBAColor() {
42 bool RGBAColor::operator==(const RGBAColor& rhs) const {
43 return r == rhs.r &&
44 g == rhs.g &&
45 b == rhs.b &&
46 a == rhs.a;
49 ThemeBackgroundInfo::ThemeBackgroundInfo()
50 : using_default_theme(true),
51 background_color(),
52 text_color(),
53 link_color(),
54 text_color_light(),
55 header_color(),
56 section_border_color(),
57 image_horizontal_alignment(THEME_BKGRND_IMAGE_ALIGN_CENTER),
58 image_vertical_alignment(THEME_BKGRND_IMAGE_ALIGN_CENTER),
59 image_tiling(THEME_BKGRND_IMAGE_NO_REPEAT),
60 image_height(0),
61 has_attribution(false),
62 logo_alternate(false) {
65 ThemeBackgroundInfo::~ThemeBackgroundInfo() {
68 bool ThemeBackgroundInfo::operator==(const ThemeBackgroundInfo& rhs) const {
69 return using_default_theme == rhs.using_default_theme &&
70 background_color == rhs.background_color &&
71 text_color == rhs.text_color &&
72 link_color == rhs.link_color &&
73 text_color_light == rhs.text_color_light &&
74 header_color == rhs.header_color &&
75 section_border_color == rhs.section_border_color &&
76 theme_id == rhs.theme_id &&
77 image_horizontal_alignment == rhs.image_horizontal_alignment &&
78 image_vertical_alignment == rhs.image_vertical_alignment &&
79 image_tiling == rhs.image_tiling &&
80 image_height == rhs.image_height &&
81 has_attribution == rhs.has_attribution &&
82 logo_alternate == rhs.logo_alternate;
85 const char kSearchQueryKey[] = "q";
86 const char kOriginalQueryKey[] = "oq";
87 const char kRLZParameterKey[] = "rlz";
88 const char kInputEncodingKey[] = "ie";
89 const char kAssistedQueryStatsKey[] = "aqs";
91 InstantMostVisitedItem::InstantMostVisitedItem() {}
93 InstantMostVisitedItem::~InstantMostVisitedItem() {}
95 EmbeddedSearchRequestParams::EmbeddedSearchRequestParams() {
98 EmbeddedSearchRequestParams::EmbeddedSearchRequestParams(const GURL& url) {
99 const std::string& url_params(url.ref().empty()? url.query() : url.ref());
100 url::Component query, key, value;
101 query.len = static_cast<int>(url_params.size());
103 const net::UnescapeRule::Type unescape_rules =
104 net::UnescapeRule::SPOOFING_AND_CONTROL_CHARS |
105 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS |
106 net::UnescapeRule::NORMAL | net::UnescapeRule::REPLACE_PLUS_WITH_SPACE;
108 while (url::ExtractQueryKeyValue(url_params.c_str(), &query, &key, &value)) {
109 if (!key.is_nonempty())
110 continue;
112 std::string key_param(GetComponent(url_params, key));
113 std::string value_param(GetComponent(url_params, value));
114 if (key_param == kSearchQueryKey) {
115 search_query = base::UTF8ToUTF16(net::UnescapeURLComponent(
116 value_param, unescape_rules));
117 } else if (key_param == kOriginalQueryKey) {
118 original_query = base::UTF8ToUTF16(net::UnescapeURLComponent(
119 value_param, unescape_rules));
120 } else if (key_param == kRLZParameterKey) {
121 rlz_parameter_value = net::UnescapeAndDecodeUTF8URLComponent(
122 value_param, net::UnescapeRule::NORMAL);
123 } else if (key_param == kInputEncodingKey) {
124 input_encoding = net::UnescapeAndDecodeUTF8URLComponent(
125 value_param, net::UnescapeRule::NORMAL);
126 } else if (key_param == kAssistedQueryStatsKey) {
127 assisted_query_stats = net::UnescapeAndDecodeUTF8URLComponent(
128 value_param, net::UnescapeRule::NORMAL);
133 EmbeddedSearchRequestParams::~EmbeddedSearchRequestParams() {