| 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/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "components/google/core/browser/google_util.h" | 23 #include "components/google/core/browser/google_util.h" |
| 24 #include "components/metrics/proto/omnibox_input_type.pb.h" | 24 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 25 #include "components/search_engines/search_engines_switches.h" | 25 #include "components/search_engines/search_engines_switches.h" |
| 26 #include "components/search_engines/search_terms_data.h" | 26 #include "components/search_engines/search_terms_data.h" |
| 27 #include "google_apis/google_api_keys.h" | 27 #include "google_apis/google_api_keys.h" |
| 28 #include "net/base/escape.h" | 28 #include "net/base/escape.h" |
| 29 #include "net/base/mime_util.h" | 29 #include "net/base/mime_util.h" |
| 30 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
| 31 #include "url/gurl.h" |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 // The TemplateURLRef has any number of terms that need to be replaced. Each of | 35 // The TemplateURLRef has any number of terms that need to be replaced. Each of |
| 35 // the terms is enclosed in braces. If the character preceeding the final | 36 // the terms is enclosed in braces. If the character preceeding the final |
| 36 // brace is a ?, it indicates the term is optional and can be replaced with | 37 // brace is a ?, it indicates the term is optional and can be replaced with |
| 37 // an empty string. | 38 // an empty string. |
| 38 const char kStartParameter = '{'; | 39 const char kStartParameter = '{'; |
| 39 const char kEndParameter = '}'; | 40 const char kEndParameter = '}'; |
| 40 const char kOptional = '?'; | 41 const char kOptional = '?'; |
| (...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1352 base::string16 encoded_terms; | 1353 base::string16 encoded_terms; |
| 1353 base::string16 encoded_original_query; | 1354 base::string16 encoded_original_query; |
| 1354 EncodeSearchTerms(search_terms_args, true, &input_encoding, | 1355 EncodeSearchTerms(search_terms_args, true, &input_encoding, |
| 1355 &encoded_terms, &encoded_original_query); | 1356 &encoded_terms, &encoded_original_query); |
| 1356 | 1357 |
| 1357 std::string old_params( | 1358 std::string old_params( |
| 1358 (search_term_component == url::Parsed::REF) ? url.ref() : url.query()); | 1359 (search_term_component == url::Parsed::REF) ? url.ref() : url.query()); |
| 1359 std::string new_params(old_params, 0, search_terms_position.begin); | 1360 std::string new_params(old_params, 0, search_terms_position.begin); |
| 1360 new_params += base::UTF16ToUTF8(search_terms_args.search_terms); | 1361 new_params += base::UTF16ToUTF8(search_terms_args.search_terms); |
| 1361 new_params += old_params.substr(search_terms_position.end()); | 1362 new_params += old_params.substr(search_terms_position.end()); |
| 1362 url::StdStringReplacements<std::string> replacements; | 1363 GURL::Replacements replacements; |
| 1363 if (search_term_component == url::Parsed::REF) | 1364 if (search_term_component == url::Parsed::REF) |
| 1364 replacements.SetRefStr(new_params); | 1365 replacements.SetRefStr(new_params); |
| 1365 else | 1366 else |
| 1366 replacements.SetQueryStr(new_params); | 1367 replacements.SetQueryStr(new_params); |
| 1367 *result = url.ReplaceComponents(replacements); | 1368 *result = url.ReplaceComponents(replacements); |
| 1368 return true; | 1369 return true; |
| 1369 } | 1370 } |
| 1370 | 1371 |
| 1371 void TemplateURL::EncodeSearchTerms( | 1372 void TemplateURL::EncodeSearchTerms( |
| 1372 const TemplateURLRef::SearchTermsArgs& search_terms_args, | 1373 const TemplateURLRef::SearchTermsArgs& search_terms_args, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 // patterns. This means that given patterns | 1465 // patterns. This means that given patterns |
| 1465 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1466 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
| 1466 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1467 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
| 1467 // return false. This is important for at least Google, where such URLs | 1468 // return false. This is important for at least Google, where such URLs |
| 1468 // are invalid. | 1469 // are invalid. |
| 1469 return !search_terms->empty(); | 1470 return !search_terms->empty(); |
| 1470 } | 1471 } |
| 1471 } | 1472 } |
| 1472 return false; | 1473 return false; |
| 1473 } | 1474 } |
| OLD | NEW |