Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/common/instant_types.h" | 5 #include "chrome/common/instant_types.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "net/base/escape.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 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(); | |
| 16 } | |
| 17 | |
| 18 } // namespace | |
| 19 | |
| 7 InstantSuggestion::InstantSuggestion() { | 20 InstantSuggestion::InstantSuggestion() { |
| 8 } | 21 } |
| 9 | 22 |
| 10 InstantSuggestion::InstantSuggestion(const base::string16& in_text, | 23 InstantSuggestion::InstantSuggestion(const base::string16& in_text, |
| 11 const std::string& in_metadata) | 24 const std::string& in_metadata) |
| 12 : text(in_text), | 25 : text(in_text), |
| 13 metadata(in_metadata) { | 26 metadata(in_metadata) { |
| 14 } | 27 } |
| 15 | 28 |
| 16 InstantSuggestion::~InstantSuggestion() { | 29 InstantSuggestion::~InstantSuggestion() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 header_color == rhs.header_color && | 74 header_color == rhs.header_color && |
| 62 section_border_color == rhs.section_border_color && | 75 section_border_color == rhs.section_border_color && |
| 63 theme_id == rhs.theme_id && | 76 theme_id == rhs.theme_id && |
| 64 image_horizontal_alignment == rhs.image_horizontal_alignment && | 77 image_horizontal_alignment == rhs.image_horizontal_alignment && |
| 65 image_vertical_alignment == rhs.image_vertical_alignment && | 78 image_vertical_alignment == rhs.image_vertical_alignment && |
| 66 image_tiling == rhs.image_tiling && | 79 image_tiling == rhs.image_tiling && |
| 67 image_height == rhs.image_height && | 80 image_height == rhs.image_height && |
| 68 has_attribution == rhs.has_attribution && | 81 has_attribution == rhs.has_attribution && |
| 69 logo_alternate == rhs.logo_alternate; | 82 logo_alternate == rhs.logo_alternate; |
| 70 } | 83 } |
| 84 | |
| 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"; | |
| 90 | |
| 91 EmbeddedSearchRequestParams::EmbeddedSearchRequestParams() { | |
| 92 } | |
| 93 | |
| 94 EmbeddedSearchRequestParams::EmbeddedSearchRequestParams(const GURL& url) { | |
|
Mark P
2014/11/17 19:15:59
Can you add a simple test for this that show it ex
kmadhusu
2014/11/17 22:52:05
Done.
| |
| 95 const std::string& url_params(url.query()); | |
| 96 url::Component query, key, value; | |
| 97 query.len = static_cast<int>(url_params.size()); | |
| 98 | |
| 99 net::UnescapeRule::Type unescape_rules = | |
|
Mark P
2014/11/17 19:15:59
nit: might as well be const
kmadhusu
2014/11/17 22:52:05
Done.
| |
| 100 net::UnescapeRule::CONTROL_CHARS | net::UnescapeRule::SPACES | | |
| 101 net::UnescapeRule::URL_SPECIAL_CHARS | net::UnescapeRule::NORMAL | | |
| 102 net::UnescapeRule::REPLACE_PLUS_WITH_SPACE; | |
| 103 | |
| 104 while (url::ExtractQueryKeyValue(url_params.c_str(), &query, &key, &value)) { | |
| 105 if (!key.is_nonempty()) | |
| 106 continue; | |
| 107 | |
| 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( | |
|
Mark P
2014/11/17 19:15:59
nit: "=n" -> "= n"
kmadhusu
2014/11/17 22:52:05
Done.
| |
| 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); | |
| 125 } | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 EmbeddedSearchRequestParams::~EmbeddedSearchRequestParams() { | |
| 130 } | |
| OLD | NEW |