Index: chrome/browser/google/google_util.cc |
diff --git a/chrome/browser/google/google_util.cc b/chrome/browser/google/google_util.cc |
index 1e5945984b18014f8518b5fbef89f64b43489b5e..c54980dd55380aa29c74e9694b75c1cb5796363a 100644 |
--- a/chrome/browser/google/google_util.cc |
+++ b/chrome/browser/google/google_util.cc |
@@ -20,6 +20,7 @@ |
#include "chrome/installer/util/google_update_settings.h" |
#include "googleurl/src/gurl.h" |
#include "googleurl/src/url_parse.h" |
+#include "net/base/escape.h" |
#include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
#if defined(OS_MACOSX) |
@@ -137,6 +138,35 @@ bool GetReactivationBrand(std::string* brand) { |
#endif |
+string16 GetSearchTermsFromGoogleSearchURL(const std::string& url) { |
+ if (!IsInstantExtendedAPIGoogleSearchUrl(url)) |
+ return string16(); |
+ |
+ const std::string query_key = "q"; |
+ |
+ url_parse::Parsed parsed_url; |
+ url_parse::ParseStandardURL(url.c_str(), url.length(), &parsed_url); |
+ url_parse::Component key, value; |
+ while (url_parse::ExtractQueryKeyValue( |
+ url.c_str(), &parsed_url.query, &key, &value)) { |
+ // If the parameter key is |query_key| and the value is not empty, those are |
+ // the search terms. |
+ if (!url.compare(key.begin, key.len, query_key)) { |
+ if (value.is_nonempty()) { |
+ std::string value_str = url.substr(value.begin, value.len); |
+ return net::UnescapeAndDecodeUTF8URLComponent( |
+ value_str, |
+ net::UnescapeRule::SPACES | |
+ net::UnescapeRule::URL_SPECIAL_CHARS | |
+ net::UnescapeRule::REPLACE_PLUS_WITH_SPACE, |
+ NULL); |
+ } |
+ break; |
+ } |
+ } |
+ return string16(); |
+} |
+ |
bool IsGoogleDomainUrl(const std::string& url, SubdomainPermission permission) { |
GURL original_url(url); |
return original_url.is_valid() && original_url.port().empty() && |