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 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 int favicon_path_len = arraysize(favicon_path) - 1; | 1105 int favicon_path_len = arraysize(favicon_path) - 1; |
1106 | 1106 |
1107 rep.SetPath(favicon_path, url::Component(0, favicon_path_len)); | 1107 rep.SetPath(favicon_path, url::Component(0, favicon_path_len)); |
1108 rep.ClearUsername(); | 1108 rep.ClearUsername(); |
1109 rep.ClearPassword(); | 1109 rep.ClearPassword(); |
1110 rep.ClearQuery(); | 1110 rep.ClearQuery(); |
1111 rep.ClearRef(); | 1111 rep.ClearRef(); |
1112 return url.ReplaceComponents(rep); | 1112 return url.ReplaceComponents(rep); |
1113 } | 1113 } |
1114 | 1114 |
1115 // static | |
1116 bool TemplateURL::MatchesData(const TemplateURL* t_url, | |
1117 const TemplateURLData* data) { | |
1118 if (!t_url || !data) | |
1119 return !t_url && !data; | |
1120 | |
1121 return (t_url->short_name() == data->short_name) && | |
1122 t_url->HasSameKeywordAs(*data) && | |
1123 (t_url->url() == data->url()) && | |
1124 (t_url->suggestions_url() == data->suggestions_url) && | |
1125 (t_url->instant_url() == data->instant_url) && | |
1126 (t_url->image_url() == data->image_url) && | |
1127 (t_url->new_tab_url() == data->new_tab_url) && | |
1128 (t_url->search_url_post_params() == data->search_url_post_params) && | |
1129 (t_url->suggestions_url_post_params() == | |
1130 data->suggestions_url_post_params) && | |
1131 (t_url->instant_url_post_params() == data->instant_url_post_params) && | |
1132 (t_url->image_url_post_params() == data->image_url_post_params) && | |
1133 (t_url->favicon_url() == data->favicon_url) && | |
1134 (t_url->safe_for_autoreplace() == data->safe_for_autoreplace) && | |
1135 (t_url->show_in_default_list() == data->show_in_default_list) && | |
1136 (t_url->input_encodings() == data->input_encodings) && | |
1137 (t_url->alternate_urls() == data->alternate_urls) && | |
1138 (t_url->search_terms_replacement_key() == | |
1139 data->search_terms_replacement_key); | |
1140 } | |
1141 | |
1142 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { | 1115 base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { |
1143 base::string16 bidi_safe_short_name = data_.short_name; | 1116 base::string16 bidi_safe_short_name = data_.short_name; |
1144 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); | 1117 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); |
1145 return bidi_safe_short_name; | 1118 return bidi_safe_short_name; |
1146 } | 1119 } |
1147 | 1120 |
1148 bool TemplateURL::ShowInDefaultList() const { | 1121 bool TemplateURL::ShowInDefaultList() const { |
1149 return data_.show_in_default_list && url_ref_.SupportsReplacement(); | 1122 return data_.show_in_default_list && url_ref_.SupportsReplacement(); |
1150 } | 1123 } |
1151 | 1124 |
1152 bool TemplateURL::SupportsReplacement() const { | 1125 bool TemplateURL::SupportsReplacement() const { |
1153 UIThreadSearchTermsData search_terms_data(profile_); | 1126 UIThreadSearchTermsData search_terms_data(profile_); |
1154 return SupportsReplacementUsingTermsData(search_terms_data); | 1127 return SupportsReplacementUsingTermsData(search_terms_data); |
1155 } | 1128 } |
1156 | 1129 |
1157 bool TemplateURL::SupportsReplacementUsingTermsData( | 1130 bool TemplateURL::SupportsReplacementUsingTermsData( |
1158 const SearchTermsData& search_terms_data) const { | 1131 const SearchTermsData& search_terms_data) const { |
1159 return url_ref_.SupportsReplacementUsingTermsData(search_terms_data); | 1132 return url_ref_.SupportsReplacementUsingTermsData(search_terms_data); |
1160 } | 1133 } |
1161 | 1134 |
1162 bool TemplateURL::HasGoogleBaseURLs() const { | |
1163 return url_ref_.HasGoogleBaseURLs() || | |
1164 suggestions_url_ref_.HasGoogleBaseURLs() || | |
1165 instant_url_ref_.HasGoogleBaseURLs() || | |
1166 image_url_ref_.HasGoogleBaseURLs() || | |
1167 new_tab_url_ref_.HasGoogleBaseURLs(); | |
1168 } | |
1169 | |
1170 bool TemplateURL::IsGoogleSearchURLWithReplaceableKeyword() const { | 1135 bool TemplateURL::IsGoogleSearchURLWithReplaceableKeyword() const { |
1171 return (GetType() == NORMAL) && url_ref_.HasGoogleBaseURLs() && | 1136 return (GetType() == NORMAL) && url_ref_.HasGoogleBaseURLs() && |
1172 google_util::IsGoogleHostname(base::UTF16ToUTF8(data_.keyword()), | 1137 google_util::IsGoogleHostname(base::UTF16ToUTF8(data_.keyword()), |
1173 google_util::DISALLOW_SUBDOMAIN); | 1138 google_util::DISALLOW_SUBDOMAIN); |
1174 } | 1139 } |
1175 | 1140 |
1176 bool TemplateURL::HasSameKeywordAs(const TemplateURLData& other) const { | 1141 bool TemplateURL::HasSameKeywordAs(const TemplateURLData& other) const { |
1177 return (data_.keyword() == other.keyword()) || | 1142 return (data_.keyword() == other.keyword()) || |
1178 (IsGoogleSearchURLWithReplaceableKeyword() && | 1143 (IsGoogleSearchURLWithReplaceableKeyword() && |
1179 TemplateURL(NULL, other).IsGoogleSearchURLWithReplaceableKeyword()); | 1144 TemplateURL(NULL, other).IsGoogleSearchURLWithReplaceableKeyword()); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 // patterns. This means that given patterns | 1330 // patterns. This means that given patterns |
1366 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1331 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1367 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1332 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1368 // return false. This is important for at least Google, where such URLs | 1333 // return false. This is important for at least Google, where such URLs |
1369 // are invalid. | 1334 // are invalid. |
1370 return !search_terms->empty(); | 1335 return !search_terms->empty(); |
1371 } | 1336 } |
1372 } | 1337 } |
1373 return false; | 1338 return false; |
1374 } | 1339 } |
OLD | NEW |