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 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 | 1121 |
1122 if (!post_params_.empty()) | 1122 if (!post_params_.empty()) |
1123 EncodeFormData(post_params_, post_content); | 1123 EncodeFormData(post_params_, post_content); |
1124 | 1124 |
1125 return url; | 1125 return url; |
1126 } | 1126 } |
1127 | 1127 |
1128 | 1128 |
1129 // TemplateURL ---------------------------------------------------------------- | 1129 // TemplateURL ---------------------------------------------------------------- |
1130 | 1130 |
1131 TemplateURL::TemplateURL(Profile* profile, const TemplateURLData& data) | 1131 TemplateURL::TemplateURL(const TemplateURLData& data) |
1132 : profile_(profile), | 1132 : data_(data), |
1133 data_(data), | |
1134 url_ref_(this, TemplateURLRef::SEARCH), | 1133 url_ref_(this, TemplateURLRef::SEARCH), |
1135 suggestions_url_ref_(this, | 1134 suggestions_url_ref_(this, |
1136 TemplateURLRef::SUGGEST), | 1135 TemplateURLRef::SUGGEST), |
1137 instant_url_ref_(this, | 1136 instant_url_ref_(this, |
1138 TemplateURLRef::INSTANT), | 1137 TemplateURLRef::INSTANT), |
1139 image_url_ref_(this, TemplateURLRef::IMAGE), | 1138 image_url_ref_(this, TemplateURLRef::IMAGE), |
1140 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), | 1139 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), |
1141 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH) { | 1140 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH) { |
1142 SetPrepopulateId(data_.prepopulate_id); | 1141 SetPrepopulateId(data_.prepopulate_id); |
1143 | 1142 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 url_ref_.HasGoogleBaseURLs(search_terms_data) && | 1225 url_ref_.HasGoogleBaseURLs(search_terms_data) && |
1227 google_util::IsGoogleHostname(base::UTF16ToUTF8(data_.keyword()), | 1226 google_util::IsGoogleHostname(base::UTF16ToUTF8(data_.keyword()), |
1228 google_util::DISALLOW_SUBDOMAIN); | 1227 google_util::DISALLOW_SUBDOMAIN); |
1229 } | 1228 } |
1230 | 1229 |
1231 bool TemplateURL::HasSameKeywordAs( | 1230 bool TemplateURL::HasSameKeywordAs( |
1232 const TemplateURLData& other, | 1231 const TemplateURLData& other, |
1233 const SearchTermsData& search_terms_data) const { | 1232 const SearchTermsData& search_terms_data) const { |
1234 return (data_.keyword() == other.keyword()) || | 1233 return (data_.keyword() == other.keyword()) || |
1235 (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) && | 1234 (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) && |
1236 TemplateURL(NULL, other).IsGoogleSearchURLWithReplaceableKeyword( | 1235 TemplateURL(other).IsGoogleSearchURLWithReplaceableKeyword( |
1237 search_terms_data)); | 1236 search_terms_data)); |
1238 } | 1237 } |
1239 | 1238 |
1240 TemplateURL::Type TemplateURL::GetType() const { | 1239 TemplateURL::Type TemplateURL::GetType() const { |
1241 if (extension_info_) | 1240 if (extension_info_) |
1242 return NORMAL_CONTROLLED_BY_EXTENSION; | 1241 return NORMAL_CONTROLLED_BY_EXTENSION; |
1243 return GURL(data_.url()).SchemeIs(extensions::kExtensionScheme) ? | 1242 return GURL(data_.url()).SchemeIs(extensions::kExtensionScheme) ? |
1244 OMNIBOX_API_EXTENSION : NORMAL; | 1243 OMNIBOX_API_EXTENSION : NORMAL; |
1245 } | 1244 } |
1246 | 1245 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 return; | 1351 return; |
1353 } | 1352 } |
1354 } | 1353 } |
1355 NOTREACHED(); | 1354 NOTREACHED(); |
1356 } | 1355 } |
1357 | 1356 |
1358 void TemplateURL::CopyFrom(const TemplateURL& other) { | 1357 void TemplateURL::CopyFrom(const TemplateURL& other) { |
1359 if (this == &other) | 1358 if (this == &other) |
1360 return; | 1359 return; |
1361 | 1360 |
1362 profile_ = other.profile_; | |
1363 data_ = other.data_; | 1361 data_ = other.data_; |
1364 url_ref_.InvalidateCachedValues(); | 1362 url_ref_.InvalidateCachedValues(); |
1365 suggestions_url_ref_.InvalidateCachedValues(); | 1363 suggestions_url_ref_.InvalidateCachedValues(); |
1366 instant_url_ref_.InvalidateCachedValues(); | 1364 instant_url_ref_.InvalidateCachedValues(); |
1367 SetPrepopulateId(other.data_.prepopulate_id); | 1365 SetPrepopulateId(other.data_.prepopulate_id); |
1368 } | 1366 } |
1369 | 1367 |
1370 void TemplateURL::SetURL(const std::string& url) { | 1368 void TemplateURL::SetURL(const std::string& url) { |
1371 data_.SetURL(url); | 1369 data_.SetURL(url); |
1372 url_ref_.InvalidateCachedValues(); | 1370 url_ref_.InvalidateCachedValues(); |
1373 } | 1371 } |
1374 | 1372 |
1375 void TemplateURL::SetPrepopulateId(int id) { | 1373 void TemplateURL::SetPrepopulateId(int id) { |
1376 data_.prepopulate_id = id; | 1374 data_.prepopulate_id = id; |
1377 const bool prepopulated = id > 0; | 1375 const bool prepopulated = id > 0; |
1378 url_ref_.prepopulated_ = prepopulated; | 1376 url_ref_.prepopulated_ = prepopulated; |
1379 suggestions_url_ref_.prepopulated_ = prepopulated; | 1377 suggestions_url_ref_.prepopulated_ = prepopulated; |
1380 instant_url_ref_.prepopulated_ = prepopulated; | 1378 instant_url_ref_.prepopulated_ = prepopulated; |
1381 } | 1379 } |
1382 | 1380 |
1383 void TemplateURL::ResetKeywordIfNecessary( | 1381 void TemplateURL::ResetKeywordIfNecessary( |
1384 const SearchTermsData& search_terms_data, | 1382 const SearchTermsData& search_terms_data, |
1385 bool force) { | 1383 bool force) { |
1386 if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) { | 1384 if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) { |
1387 DCHECK(GetType() != OMNIBOX_API_EXTENSION); | 1385 DCHECK(GetType() != OMNIBOX_API_EXTENSION); |
1388 GURL url(TemplateURLService::GenerateSearchURL(this)); | 1386 GURL url(TemplateURLService::GenerateSearchURL(this, search_terms_data)); |
1389 if (url.is_valid()) | 1387 if (url.is_valid()) |
1390 data_.SetKeyword(TemplateURLService::GenerateKeyword(url)); | 1388 data_.SetKeyword(TemplateURLService::GenerateKeyword(url)); |
1391 } | 1389 } |
1392 } | 1390 } |
1393 | 1391 |
1394 bool TemplateURL::FindSearchTermsInURL( | 1392 bool TemplateURL::FindSearchTermsInURL( |
1395 const GURL& url, | 1393 const GURL& url, |
1396 const SearchTermsData& search_terms_data, | 1394 const SearchTermsData& search_terms_data, |
1397 base::string16* search_terms, | 1395 base::string16* search_terms, |
1398 url::Parsed::ComponentType* search_term_component, | 1396 url::Parsed::ComponentType* search_term_component, |
(...skipping 12 matching lines...) Expand all Loading... |
1411 // patterns. This means that given patterns | 1409 // patterns. This means that given patterns |
1412 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1410 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1413 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1411 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1414 // return false. This is important for at least Google, where such URLs | 1412 // return false. This is important for at least Google, where such URLs |
1415 // are invalid. | 1413 // are invalid. |
1416 return !search_terms->empty(); | 1414 return !search_terms->empty(); |
1417 } | 1415 } |
1418 } | 1416 } |
1419 return false; | 1417 return false; |
1420 } | 1418 } |
OLD | NEW |