| 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 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/browser/search_engines/search_terms_data.h" | 27 #include "chrome/browser/search_engines/search_terms_data.h" |
| 28 #include "chrome/browser/search_engines/template_url_service.h" | 28 #include "chrome/browser/search_engines/template_url_service.h" |
| 29 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/chrome_version_info.h" | 30 #include "chrome/common/chrome_version_info.h" |
| 31 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 32 #include "extensions/common/constants.h" | 32 #include "extensions/common/constants.h" |
| 33 #include "google_apis/google_api_keys.h" | 33 #include "google_apis/google_api_keys.h" |
| 34 #include "net/base/escape.h" | 34 #include "net/base/escape.h" |
| 35 #include "net/base/mime_util.h" | 35 #include "net/base/mime_util.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 37 #include "url/url_constants.h" |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 // The TemplateURLRef has any number of terms that need to be replaced. Each of | 41 // The TemplateURLRef has any number of terms that need to be replaced. Each of |
| 41 // the terms is enclosed in braces. If the character preceeding the final | 42 // the terms is enclosed in braces. If the character preceeding the final |
| 42 // brace is a ?, it indicates the term is optional and can be replaced with | 43 // brace is a ?, it indicates the term is optional and can be replaced with |
| 43 // an empty string. | 44 // an empty string. |
| 44 const char kStartParameter = '{'; | 45 const char kStartParameter = '{'; |
| 45 const char kEndParameter = '}'; | 46 const char kEndParameter = '}'; |
| 46 const char kOptional = '?'; | 47 const char kOptional = '?'; |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 DCHECK(!i->is_post_param); | 831 DCHECK(!i->is_post_param); |
| 831 if (!search_terms_args.assisted_query_stats.empty()) { | 832 if (!search_terms_args.assisted_query_stats.empty()) { |
| 832 // Get the base URL without substituting AQS to avoid infinite | 833 // Get the base URL without substituting AQS to avoid infinite |
| 833 // recursion. We need the URL to find out if it meets all | 834 // recursion. We need the URL to find out if it meets all |
| 834 // AQS requirements (e.g. HTTPS protocol check). | 835 // AQS requirements (e.g. HTTPS protocol check). |
| 835 // See TemplateURLRef::SearchTermsArgs for more details. | 836 // See TemplateURLRef::SearchTermsArgs for more details. |
| 836 SearchTermsArgs search_terms_args_without_aqs(search_terms_args); | 837 SearchTermsArgs search_terms_args_without_aqs(search_terms_args); |
| 837 search_terms_args_without_aqs.assisted_query_stats.clear(); | 838 search_terms_args_without_aqs.assisted_query_stats.clear(); |
| 838 GURL base_url(ReplaceSearchTermsUsingTermsData( | 839 GURL base_url(ReplaceSearchTermsUsingTermsData( |
| 839 search_terms_args_without_aqs, search_terms_data, NULL)); | 840 search_terms_args_without_aqs, search_terms_data, NULL)); |
| 840 if (base_url.SchemeIs(content::kHttpsScheme)) { | 841 if (base_url.SchemeIs(url::kHttpsScheme)) { |
| 841 HandleReplacement( | 842 HandleReplacement( |
| 842 "aqs", search_terms_args.assisted_query_stats, *i, &url); | 843 "aqs", search_terms_args.assisted_query_stats, *i, &url); |
| 843 } | 844 } |
| 844 } | 845 } |
| 845 break; | 846 break; |
| 846 | 847 |
| 847 case GOOGLE_BASE_URL: | 848 case GOOGLE_BASE_URL: |
| 848 DCHECK(!i->is_post_param); | 849 DCHECK(!i->is_post_param); |
| 849 HandleReplacement( | 850 HandleReplacement( |
| 850 std::string(), search_terms_data.GoogleBaseURLValue(), *i, &url); | 851 std::string(), search_terms_data.GoogleBaseURLValue(), *i, &url); |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 // patterns. This means that given patterns | 1334 // patterns. This means that given patterns |
| 1334 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1335 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
| 1335 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1336 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
| 1336 // return false. This is important for at least Google, where such URLs | 1337 // return false. This is important for at least Google, where such URLs |
| 1337 // are invalid. | 1338 // are invalid. |
| 1338 return !search_terms->empty(); | 1339 return !search_terms->empty(); |
| 1339 } | 1340 } |
| 1340 } | 1341 } |
| 1341 return false; | 1342 return false; |
| 1342 } | 1343 } |
| OLD | NEW |