OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/browser/search_engines/template_url.h" | 5 #include "chrome/browser/search_engines/template_url.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 int favicon_path_len = arraysize(favicon_path) - 1; | 1115 int favicon_path_len = arraysize(favicon_path) - 1; |
1116 | 1116 |
1117 rep.SetPath(favicon_path, url::Component(0, favicon_path_len)); | 1117 rep.SetPath(favicon_path, url::Component(0, favicon_path_len)); |
1118 rep.ClearUsername(); | 1118 rep.ClearUsername(); |
1119 rep.ClearPassword(); | 1119 rep.ClearPassword(); |
1120 rep.ClearQuery(); | 1120 rep.ClearQuery(); |
1121 rep.ClearRef(); | 1121 rep.ClearRef(); |
1122 return url.ReplaceComponents(rep); | 1122 return url.ReplaceComponents(rep); |
1123 } | 1123 } |
1124 | 1124 |
| 1125 // static |
| 1126 bool TemplateURL::MatchesData(const TemplateURL* t_url, |
| 1127 const TemplateURLData* data) { |
| 1128 if (!t_url || !data) |
| 1129 return !t_url && !data; |
| 1130 |
| 1131 return (t_url->short_name() == data->short_name) && |
| 1132 t_url->HasSameKeywordAs(*data) && |
| 1133 (t_url->url() == data->url()) && |
| 1134 (t_url->suggestions_url() == data->suggestions_url) && |
| 1135 (t_url->instant_url() == data->instant_url) && |
| 1136 (t_url->image_url() == data->image_url) && |
| 1137 (t_url->new_tab_url() == data->new_tab_url) && |
| 1138 (t_url->search_url_post_params() == data->search_url_post_params) && |
| 1139 (t_url->suggestions_url_post_params() == |
| 1140 data->suggestions_url_post_params) && |
| 1141 (t_url->instant_url_post_params() == data->instant_url_post_params) && |
| 1142 (t_url->image_url_post_params() == data->image_url_post_params) && |
| 1143 (t_url->favicon_url() == data->favicon_url) && |
| 1144 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && |
| 1145 (t_url->show_in_default_list() == data->show_in_default_list) && |
| 1146 (t_url->input_encodings() == data->input_encodings) && |
| 1147 (t_url->alternate_urls() == data->alternate_urls) && |
| 1148 (t_url->search_terms_replacement_key() == |
| 1149 data->search_terms_replacement_key); |
| 1150 } |
| 1151 |
1125 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { | 1152 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { |
1126 base::string16 bidi_safe_short_name = data_.short_name; | 1153 base::string16 bidi_safe_short_name = data_.short_name; |
1127 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); | 1154 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); |
1128 return bidi_safe_short_name; | 1155 return bidi_safe_short_name; |
1129 } | 1156 } |
1130 | 1157 |
1131 bool TemplateURL::ShowInDefaultList() const { | 1158 bool TemplateURL::ShowInDefaultList() const { |
1132 return data_.show_in_default_list && url_ref_.SupportsReplacement(); | 1159 return data_.show_in_default_list && url_ref_.SupportsReplacement(); |
1133 } | 1160 } |
1134 | 1161 |
1135 bool TemplateURL::SupportsReplacement() const { | 1162 bool TemplateURL::SupportsReplacement() const { |
1136 UIThreadSearchTermsData search_terms_data(profile_); | 1163 UIThreadSearchTermsData search_terms_data(profile_); |
1137 return SupportsReplacementUsingTermsData(search_terms_data); | 1164 return SupportsReplacementUsingTermsData(search_terms_data); |
1138 } | 1165 } |
1139 | 1166 |
1140 bool TemplateURL::SupportsReplacementUsingTermsData( | 1167 bool TemplateURL::SupportsReplacementUsingTermsData( |
1141 const SearchTermsData& search_terms_data) const { | 1168 const SearchTermsData& search_terms_data) const { |
1142 return url_ref_.SupportsReplacementUsingTermsData(search_terms_data); | 1169 return url_ref_.SupportsReplacementUsingTermsData(search_terms_data); |
1143 } | 1170 } |
1144 | 1171 |
| 1172 bool TemplateURL::HasGoogleBaseURLs() const { |
| 1173 return url_ref_.HasGoogleBaseURLs() || |
| 1174 suggestions_url_ref_.HasGoogleBaseURLs() || |
| 1175 instant_url_ref_.HasGoogleBaseURLs() || |
| 1176 image_url_ref_.HasGoogleBaseURLs() || |
| 1177 new_tab_url_ref_.HasGoogleBaseURLs(); |
| 1178 } |
| 1179 |
1145 bool TemplateURL::IsGoogleSearchURLWithReplaceableKeyword() const { | 1180 bool TemplateURL::IsGoogleSearchURLWithReplaceableKeyword() const { |
1146 return (GetType() == NORMAL) && url_ref_.HasGoogleBaseURLs() && | 1181 return (GetType() == NORMAL) && url_ref_.HasGoogleBaseURLs() && |
1147 google_util::IsGoogleHostname(base::UTF16ToUTF8(data_.keyword()), | 1182 google_util::IsGoogleHostname(base::UTF16ToUTF8(data_.keyword()), |
1148 google_util::DISALLOW_SUBDOMAIN); | 1183 google_util::DISALLOW_SUBDOMAIN); |
1149 } | 1184 } |
1150 | 1185 |
1151 bool TemplateURL::HasSameKeywordAs(const TemplateURLData& other) const { | 1186 bool TemplateURL::HasSameKeywordAs(const TemplateURLData& other) const { |
1152 return (data_.keyword() == other.keyword()) || | 1187 return (data_.keyword() == other.keyword()) || |
1153 (IsGoogleSearchURLWithReplaceableKeyword() && | 1188 (IsGoogleSearchURLWithReplaceableKeyword() && |
1154 TemplateURL(NULL, other).IsGoogleSearchURLWithReplaceableKeyword()); | 1189 TemplateURL(NULL, other).IsGoogleSearchURLWithReplaceableKeyword()); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 // patterns. This means that given patterns | 1375 // patterns. This means that given patterns |
1341 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1376 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1342 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1377 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1343 // return false. This is important for at least Google, where such URLs | 1378 // return false. This is important for at least Google, where such URLs |
1344 // are invalid. | 1379 // are invalid. |
1345 return !search_terms->empty(); | 1380 return !search_terms->empty(); |
1346 } | 1381 } |
1347 } | 1382 } |
1348 return false; | 1383 return false; |
1349 } | 1384 } |
OLD | NEW |