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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 DCHECK(search_terms); | 455 DCHECK(search_terms); |
456 search_terms->clear(); | 456 search_terms->clear(); |
457 | 457 |
458 ParseIfNecessary(search_terms_data); | 458 ParseIfNecessary(search_terms_data); |
459 | 459 |
460 // We need a search term in the template URL to extract something. | 460 // We need a search term in the template URL to extract something. |
461 if (search_term_key_.empty() && | 461 if (search_term_key_.empty() && |
462 (search_term_key_location_ != url::Parsed::PATH)) | 462 (search_term_key_location_ != url::Parsed::PATH)) |
463 return false; | 463 return false; |
464 | 464 |
465 // Fill-in the replacements. We don't care about search terms in the pattern, | 465 // Host, port, and path must match. |
466 // so we use the empty string. | 466 if ((url.host() != host_) || |
467 // Currently we assume the search term only shows in URL, not in post params. | 467 (url.port() != port_) || |
468 GURL pattern(ReplaceSearchTerms(SearchTermsArgs(base::string16()), | |
469 search_terms_data, NULL)); | |
470 // Host, path and port must match. | |
471 if ((url.port() != pattern.port()) || | |
472 (url.host() != host_) || | |
473 ((url.path() != path_) && | 468 ((url.path() != path_) && |
474 (search_term_key_location_ != url::Parsed::PATH))) { | 469 (search_term_key_location_ != url::Parsed::PATH))) { |
475 return false; | 470 return false; |
476 } | 471 } |
477 | 472 |
478 std::string source; | 473 std::string source; |
479 url::Component position; | 474 url::Component position; |
480 | 475 |
481 if (search_term_key_location_ == url::Parsed::PATH) { | 476 if (search_term_key_location_ == url::Parsed::PATH) { |
482 source = url.path(); | 477 source = url.path(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 if (search_terms_component) | 514 if (search_terms_component) |
520 *search_terms_component = search_term_key_location_; | 515 *search_terms_component = search_term_key_location_; |
521 if (search_terms_position) | 516 if (search_terms_position) |
522 *search_terms_position = position; | 517 *search_terms_position = position; |
523 return true; | 518 return true; |
524 } | 519 } |
525 | 520 |
526 void TemplateURLRef::InvalidateCachedValues() const { | 521 void TemplateURLRef::InvalidateCachedValues() const { |
527 supports_replacements_ = valid_ = parsed_ = false; | 522 supports_replacements_ = valid_ = parsed_ = false; |
528 host_.clear(); | 523 host_.clear(); |
524 port_.clear(); | |
529 path_.clear(); | 525 path_.clear(); |
530 search_term_key_.clear(); | 526 search_term_key_.clear(); |
531 search_term_position_in_path_ = std::string::npos; | 527 search_term_position_in_path_ = std::string::npos; |
532 search_term_key_location_ = url::Parsed::QUERY; | 528 search_term_key_location_ = url::Parsed::QUERY; |
533 replacements_.clear(); | 529 replacements_.clear(); |
534 post_params_.clear(); | 530 post_params_.clear(); |
535 } | 531 } |
536 | 532 |
537 bool TemplateURLRef::ParseParameter(size_t start, | 533 bool TemplateURLRef::ParseParameter(size_t start, |
538 size_t end, | 534 size_t end, |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 base::ReplaceSubstringsAfterOffset( | 766 base::ReplaceSubstringsAfterOffset( |
771 &url_string, 0, "{google:baseURL}", | 767 &url_string, 0, "{google:baseURL}", |
772 search_terms_data.GoogleBaseURLValue()); | 768 search_terms_data.GoogleBaseURLValue()); |
773 base::ReplaceSubstringsAfterOffset( | 769 base::ReplaceSubstringsAfterOffset( |
774 &url_string, 0, "{google:baseSuggestURL}", | 770 &url_string, 0, "{google:baseSuggestURL}", |
775 search_terms_data.GoogleBaseSuggestURLValue()); | 771 search_terms_data.GoogleBaseSuggestURLValue()); |
776 | 772 |
777 search_term_key_.clear(); | 773 search_term_key_.clear(); |
778 search_term_position_in_path_ = std::string::npos; | 774 search_term_position_in_path_ = std::string::npos; |
779 host_.clear(); | 775 host_.clear(); |
776 port_.clear(); | |
780 path_.clear(); | 777 path_.clear(); |
781 search_term_key_location_ = url::Parsed::QUERY; | 778 search_term_key_location_ = url::Parsed::QUERY; |
Peter Kasting
2016/01/20 01:42:56
While you're touching this stuff, I don't think an
Mark P
2016/01/20 05:18:06
I looked closer. ParseURL() cannot be static beca
| |
782 | 779 |
783 GURL url(url_string); | 780 GURL url(url_string); |
784 if (!url.is_valid()) | 781 if (!url.is_valid()) |
785 return; | 782 return; |
786 | 783 |
787 std::string query_key = FindSearchTermsKey(url.query()); | 784 std::string query_key = FindSearchTermsKey(url.query()); |
788 std::string ref_key = FindSearchTermsKey(url.ref()); | 785 std::string ref_key = FindSearchTermsKey(url.ref()); |
789 url::Component parameter_position; | 786 url::Component parameter_position; |
790 const bool in_query = !query_key.empty(); | 787 const bool in_query = !query_key.empty(); |
791 const bool in_ref = !ref_key.empty(); | 788 const bool in_ref = !ref_key.empty(); |
792 const bool in_path = FindSearchTermsInPath(url.path(), ¶meter_position); | 789 const bool in_path = FindSearchTermsInPath(url.path(), ¶meter_position); |
793 if (in_query ? (in_ref || in_path) : (in_ref == in_path)) | 790 if (in_query ? (in_ref || in_path) : (in_ref == in_path)) |
794 return; // No key or multiple keys found. We only handle having one key. | 791 return; // No key or multiple keys found. We only handle having one key. |
795 | 792 |
796 host_ = url.host(); | 793 host_ = url.host(); |
794 port_ = url.port(); | |
797 path_ = url.path(); | 795 path_ = url.path(); |
798 if (in_query) { | 796 if (in_query) { |
799 search_term_key_ = query_key; | 797 search_term_key_ = query_key; |
800 search_term_key_location_ = url::Parsed::QUERY; | 798 search_term_key_location_ = url::Parsed::QUERY; |
801 } else if (in_ref) { | 799 } else if (in_ref) { |
802 search_term_key_ = ref_key; | 800 search_term_key_ = ref_key; |
803 search_term_key_location_ = url::Parsed::REF; | 801 search_term_key_location_ = url::Parsed::REF; |
804 } else { | 802 } else { |
805 DCHECK(in_path); | 803 DCHECK(in_path); |
806 DCHECK_GE(parameter_position.begin, 1); // Path must start with '/'. | 804 DCHECK_GE(parameter_position.begin, 1); // Path must start with '/'. |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1478 // patterns. This means that given patterns | 1476 // patterns. This means that given patterns |
1479 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1477 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1480 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1478 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1481 // return false. This is important for at least Google, where such URLs | 1479 // return false. This is important for at least Google, where such URLs |
1482 // are invalid. | 1480 // are invalid. |
1483 return !search_terms->empty(); | 1481 return !search_terms->empty(); |
1484 } | 1482 } |
1485 } | 1483 } |
1486 return false; | 1484 return false; |
1487 } | 1485 } |
OLD | NEW |