OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/template_url.h" | 5 #include "components/search_engines/template_url.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 wants_to_be_default_engine(false) { | 1192 wants_to_be_default_engine(false) { |
1193 DCHECK_NE(NORMAL, type); | 1193 DCHECK_NE(NORMAL, type); |
1194 } | 1194 } |
1195 | 1195 |
1196 TemplateURL::AssociatedExtensionInfo::~AssociatedExtensionInfo() { | 1196 TemplateURL::AssociatedExtensionInfo::~AssociatedExtensionInfo() { |
1197 } | 1197 } |
1198 | 1198 |
1199 TemplateURL::TemplateURL(const TemplateURLData& data) | 1199 TemplateURL::TemplateURL(const TemplateURLData& data) |
1200 : data_(data), | 1200 : data_(data), |
1201 url_ref_(nullptr), | 1201 url_ref_(nullptr), |
1202 suggestions_url_ref_(this, | 1202 suggestions_url_ref_(this, TemplateURLRef::SUGGEST), |
1203 TemplateURLRef::SUGGEST), | 1203 instant_url_ref_(this, TemplateURLRef::INSTANT), |
1204 instant_url_ref_(this, | |
1205 TemplateURLRef::INSTANT), | |
1206 image_url_ref_(this, TemplateURLRef::IMAGE), | 1204 image_url_ref_(this, TemplateURLRef::IMAGE), |
1207 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), | 1205 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), |
1208 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH), | 1206 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH), |
1209 engine_type_(SEARCH_ENGINE_UNKNOWN) { | 1207 engine_type_(SEARCH_ENGINE_UNKNOWN), |
| 1208 type_(NORMAL) { |
1210 ResizeURLRefVector(); | 1209 ResizeURLRefVector(); |
1211 SetPrepopulateId(data_.prepopulate_id); | 1210 SetPrepopulateId(data_.prepopulate_id); |
1212 | 1211 |
1213 if (data_.search_terms_replacement_key == | 1212 if (data_.search_terms_replacement_key == |
1214 "{google:instantExtendedEnabledKey}") { | 1213 "{google:instantExtendedEnabledKey}") { |
1215 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; | 1214 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; |
1216 } | 1215 } |
1217 } | 1216 } |
1218 | 1217 |
1219 TemplateURL::~TemplateURL() { | 1218 TemplateURL::~TemplateURL() { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 bool TemplateURL::HasSameKeywordAs( | 1318 bool TemplateURL::HasSameKeywordAs( |
1320 const TemplateURLData& other, | 1319 const TemplateURLData& other, |
1321 const SearchTermsData& search_terms_data) const { | 1320 const SearchTermsData& search_terms_data) const { |
1322 return (data_.keyword() == other.keyword()) || | 1321 return (data_.keyword() == other.keyword()) || |
1323 (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) && | 1322 (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) && |
1324 TemplateURL(other).IsGoogleSearchURLWithReplaceableKeyword( | 1323 TemplateURL(other).IsGoogleSearchURLWithReplaceableKeyword( |
1325 search_terms_data)); | 1324 search_terms_data)); |
1326 } | 1325 } |
1327 | 1326 |
1328 TemplateURL::Type TemplateURL::GetType() const { | 1327 TemplateURL::Type TemplateURL::GetType() const { |
1329 return extension_info_ ? extension_info_->type : NORMAL; | 1328 return extension_info_ ? extension_info_->type : type_; |
| 1329 } |
| 1330 |
| 1331 void TemplateURL::SetType(Type type) { |
| 1332 type_ = type; |
1330 } | 1333 } |
1331 | 1334 |
1332 std::string TemplateURL::GetExtensionId() const { | 1335 std::string TemplateURL::GetExtensionId() const { |
1333 DCHECK(extension_info_); | 1336 DCHECK(extension_info_); |
1334 return extension_info_->extension_id; | 1337 return extension_info_->extension_id; |
1335 } | 1338 } |
1336 | 1339 |
1337 SearchEngineType TemplateURL::GetEngineType( | 1340 SearchEngineType TemplateURL::GetEngineType( |
1338 const SearchTermsData& search_terms_data) const { | 1341 const SearchTermsData& search_terms_data) const { |
1339 if (engine_type_ == SEARCH_ENGINE_UNKNOWN) { | 1342 if (engine_type_ == SEARCH_ENGINE_UNKNOWN) { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 // patterns. This means that given patterns | 1556 // patterns. This means that given patterns |
1554 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1557 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1555 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1558 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1556 // return false. This is important for at least Google, where such URLs | 1559 // return false. This is important for at least Google, where such URLs |
1557 // are invalid. | 1560 // are invalid. |
1558 return !search_terms->empty(); | 1561 return !search_terms->empty(); |
1559 } | 1562 } |
1560 } | 1563 } |
1561 return false; | 1564 return false; |
1562 } | 1565 } |
OLD | NEW |