| 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/google/google_util.h" | 5 #include "chrome/browser/google/google_util.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" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/string_split.h" | 13 #include "base/string_split.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/google/google_url_tracker.h" | 17 #include "chrome/browser/google/google_url_tracker.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/net/url_util.h" | 19 #include "chrome/common/net/url_util.h" |
| 20 #include "chrome/installer/util/google_update_settings.h" | 20 #include "chrome/installer/util/google_update_settings.h" |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 #include "googleurl/src/url_parse.h" | 22 #include "googleurl/src/url_parse.h" |
| 23 #include "net/base/escape.h" | |
| 24 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 23 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 25 | 24 |
| 26 #if defined(OS_MACOSX) | 25 #if defined(OS_MACOSX) |
| 27 #include "chrome/browser/mac/keystone_glue.h" | 26 #include "chrome/browser/mac/keystone_glue.h" |
| 28 #endif | 27 #endif |
| 29 | 28 |
| 30 #if defined(GOOGLE_CHROME_BUILD) | 29 #if defined(GOOGLE_CHROME_BUILD) |
| 31 #include "chrome/browser/google/linkdoctor_internal/linkdoctor_internal.h" | 30 #include "chrome/browser/google/linkdoctor_internal/linkdoctor_internal.h" |
| 32 #endif | 31 #endif |
| 33 | 32 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 itr != parameters.end(); | 49 itr != parameters.end(); |
| 51 ++itr) { | 50 ++itr) { |
| 52 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2) | 51 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2) |
| 53 return true; | 52 return true; |
| 54 } | 53 } |
| 55 return false; | 54 return false; |
| 56 } | 55 } |
| 57 | 56 |
| 58 bool gUseMockLinkDoctorBaseURLForTesting = false; | 57 bool gUseMockLinkDoctorBaseURLForTesting = false; |
| 59 | 58 |
| 60 // Finds the first key-value pair where the key matches |query_key|. Returns | |
| 61 // true if a match is found and sets |search_terms| to the value. | |
| 62 bool ExtractSearchTermsFromComponent(const std::string& url, | |
| 63 url_parse::Component* component, | |
| 64 string16* search_terms) { | |
| 65 const std::string query_key = "q"; | |
| 66 url_parse::Component key, value; | |
| 67 | |
| 68 while (url_parse::ExtractQueryKeyValue(url.c_str(), component, | |
| 69 &key, &value)) { | |
| 70 if (url.compare(key.begin, key.len, query_key) != 0) | |
| 71 continue; | |
| 72 std::string value_str = url.substr(value.begin, value.len); | |
| 73 *search_terms = net::UnescapeAndDecodeUTF8URLComponent( | |
| 74 value_str, | |
| 75 net::UnescapeRule::SPACES | | |
| 76 net::UnescapeRule::URL_SPECIAL_CHARS | | |
| 77 net::UnescapeRule::REPLACE_PLUS_WITH_SPACE, | |
| 78 NULL); | |
| 79 return true; | |
| 80 } | |
| 81 return false; | |
| 82 } | |
| 83 | |
| 84 } // anonymous namespace | 59 } // anonymous namespace |
| 85 | 60 |
| 86 namespace google_util { | 61 namespace google_util { |
| 87 | 62 |
| 88 GURL LinkDoctorBaseURL() { | 63 GURL LinkDoctorBaseURL() { |
| 89 if (gUseMockLinkDoctorBaseURLForTesting) | 64 if (gUseMockLinkDoctorBaseURLForTesting) |
| 90 return GURL("http://mock.linkdoctor.url/for?testing"); | 65 return GURL("http://mock.linkdoctor.url/for?testing"); |
| 91 return GURL(LINKDOCTOR_SERVER_REQUEST_URL); | 66 return GURL(LINKDOCTOR_SERVER_REQUEST_URL); |
| 92 } | 67 } |
| 93 | 68 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 return true; | 147 return true; |
| 173 } | 148 } |
| 174 | 149 |
| 175 bool GetReactivationBrand(std::string* brand) { | 150 bool GetReactivationBrand(std::string* brand) { |
| 176 brand->clear(); | 151 brand->clear(); |
| 177 return true; | 152 return true; |
| 178 } | 153 } |
| 179 | 154 |
| 180 #endif | 155 #endif |
| 181 | 156 |
| 182 string16 GetSearchTermsFromGoogleSearchURL(const std::string& url) { | |
| 183 if (!IsInstantExtendedAPIGoogleSearchUrl(url)) | |
| 184 return string16(); | |
| 185 | |
| 186 url_parse::Parsed parsed_url; | |
| 187 url_parse::ParseStandardURL(url.c_str(), url.length(), &parsed_url); | |
| 188 | |
| 189 string16 search_terms; | |
| 190 // The search terms can be in either the query or ref component - for | |
| 191 // instance, in a regular Google search they'll be in the query but in a | |
| 192 // Google Instant search they can be in both. The ref is the correct one to | |
| 193 // return in this case, so test the ref component first. | |
| 194 if (ExtractSearchTermsFromComponent(url, &parsed_url.ref, &search_terms) || | |
| 195 ExtractSearchTermsFromComponent(url, &parsed_url.query, &search_terms)) { | |
| 196 return search_terms; | |
| 197 } | |
| 198 return string16(); | |
| 199 } | |
| 200 | |
| 201 bool IsGoogleDomainUrl(const std::string& url, | 157 bool IsGoogleDomainUrl(const std::string& url, |
| 202 SubdomainPermission subdomain_permission, | 158 SubdomainPermission subdomain_permission, |
| 203 PortPermission port_permission) { | 159 PortPermission port_permission) { |
| 204 GURL original_url(url); | 160 GURL original_url(url); |
| 205 if (!original_url.is_valid() || | 161 if (!original_url.is_valid() || |
| 206 !(original_url.SchemeIs("http") || original_url.SchemeIs("https"))) | 162 !(original_url.SchemeIs("http") || original_url.SchemeIs("https"))) |
| 207 return false; | 163 return false; |
| 208 | 164 |
| 209 // If we have the Instant URL overridden with a command line flag, accept | 165 // If we have the Instant URL overridden with a command line flag, accept |
| 210 // its domain/port combination as well. | 166 // its domain/port combination as well. |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 const char* const kBrands[] = { | 317 const char* const kBrands[] = { |
| 362 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", | 318 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", |
| 363 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", | 319 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", |
| 364 }; | 320 }; |
| 365 const char* const* end = &kBrands[arraysize(kBrands)]; | 321 const char* const* end = &kBrands[arraysize(kBrands)]; |
| 366 const char* const* found = std::find(&kBrands[0], end, brand); | 322 const char* const* found = std::find(&kBrands[0], end, brand); |
| 367 return found != end; | 323 return found != end; |
| 368 } | 324 } |
| 369 | 325 |
| 370 } // namespace google_util | 326 } // namespace google_util |
| OLD | NEW |