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"
12 std::string
GetComponent(const std::string
& url
,
13 const url::Component component
) {
14 return (component
.len
> 0) ? url
.substr(component
.begin
, component
.len
) :
20 InstantSuggestion::InstantSuggestion() {
23 InstantSuggestion::InstantSuggestion(const base::string16
& in_text
,
24 const std::string
& in_metadata
)
26 metadata(in_metadata
) {
29 InstantSuggestion::~InstantSuggestion() {
32 RGBAColor::RGBAColor()
39 RGBAColor::~RGBAColor() {
42 bool RGBAColor::operator==(const RGBAColor
& rhs
) const {
49 ThemeBackgroundInfo::ThemeBackgroundInfo()
50 : using_default_theme(true),
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
),
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 EmbeddedSearchRequestParams::EmbeddedSearchRequestParams() {
94 EmbeddedSearchRequestParams::EmbeddedSearchRequestParams(const GURL
& url
) {
95 const std::string
& url_params(url
.ref().empty()? url
.query() : url
.ref());
96 url::Component query
, key
, value
;
97 query
.len
= static_cast<int>(url_params
.size());
99 const net::UnescapeRule::Type unescape_rules
=
100 net::UnescapeRule::SPOOFING_AND_CONTROL_CHARS
|
101 net::UnescapeRule::SPACES
| net::UnescapeRule::URL_SPECIAL_CHARS
|
102 net::UnescapeRule::NORMAL
| net::UnescapeRule::REPLACE_PLUS_WITH_SPACE
;
104 while (url::ExtractQueryKeyValue(url_params
.c_str(), &query
, &key
, &value
)) {
105 if (!key
.is_nonempty())
108 std::string
key_param(GetComponent(url_params
, key
));
109 std::string
value_param(GetComponent(url_params
, value
));
110 if (key_param
== kSearchQueryKey
) {
111 search_query
= base::UTF8ToUTF16(net::UnescapeURLComponent(
112 value_param
, unescape_rules
));
113 } else if (key_param
== kOriginalQueryKey
) {
114 original_query
= base::UTF8ToUTF16(net::UnescapeURLComponent(
115 value_param
, unescape_rules
));
116 } else if (key_param
== kRLZParameterKey
) {
117 rlz_parameter_value
= net::UnescapeAndDecodeUTF8URLComponent(
118 value_param
, net::UnescapeRule::NORMAL
);
119 } else if (key_param
== kInputEncodingKey
) {
120 input_encoding
= net::UnescapeAndDecodeUTF8URLComponent(
121 value_param
, net::UnescapeRule::NORMAL
);
122 } else if (key_param
== kAssistedQueryStatsKey
) {
123 assisted_query_stats
= net::UnescapeAndDecodeUTF8URLComponent(
124 value_param
, net::UnescapeRule::NORMAL
);
129 EmbeddedSearchRequestParams::~EmbeddedSearchRequestParams() {