| 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" |
| 23 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 24 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 24 | 25 |
| 25 #if defined(OS_MACOSX) | 26 #if defined(OS_MACOSX) |
| 26 #include "chrome/browser/mac/keystone_glue.h" | 27 #include "chrome/browser/mac/keystone_glue.h" |
| 27 #endif | 28 #endif |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 const char* brand_for_testing = NULL; | 32 const char* brand_for_testing = NULL; |
| 32 | 33 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 return true; | 131 return true; |
| 131 } | 132 } |
| 132 | 133 |
| 133 bool GetReactivationBrand(std::string* brand) { | 134 bool GetReactivationBrand(std::string* brand) { |
| 134 brand->clear(); | 135 brand->clear(); |
| 135 return true; | 136 return true; |
| 136 } | 137 } |
| 137 | 138 |
| 138 #endif | 139 #endif |
| 139 | 140 |
| 141 string16 GetSearchTermsFromGoogleSearchURL(const std::string& url) { |
| 142 if (!IsInstantExtendedAPIGoogleSearchUrl(url)) |
| 143 return string16(); |
| 144 |
| 145 const std::string query_key = "q"; |
| 146 |
| 147 url_parse::Parsed parsed_url; |
| 148 url_parse::ParseStandardURL(url.c_str(), url.length(), &parsed_url); |
| 149 url_parse::Component key, value; |
| 150 while (url_parse::ExtractQueryKeyValue( |
| 151 url.c_str(), &parsed_url.query, &key, &value)) { |
| 152 // If the parameter key is |query_key| and the value is not empty, those are |
| 153 // the search terms. |
| 154 if (!url.compare(key.begin, key.len, query_key)) { |
| 155 if (value.is_nonempty()) { |
| 156 std::string value_str = url.substr(value.begin, value.len); |
| 157 return net::UnescapeAndDecodeUTF8URLComponent( |
| 158 value_str, |
| 159 net::UnescapeRule::SPACES | |
| 160 net::UnescapeRule::URL_SPECIAL_CHARS | |
| 161 net::UnescapeRule::REPLACE_PLUS_WITH_SPACE, |
| 162 NULL); |
| 163 } |
| 164 break; |
| 165 } |
| 166 } |
| 167 return string16(); |
| 168 } |
| 169 |
| 140 bool IsGoogleDomainUrl(const std::string& url, SubdomainPermission permission) { | 170 bool IsGoogleDomainUrl(const std::string& url, SubdomainPermission permission) { |
| 141 GURL original_url(url); | 171 GURL original_url(url); |
| 142 return original_url.is_valid() && original_url.port().empty() && | 172 return original_url.is_valid() && original_url.port().empty() && |
| 143 (original_url.SchemeIs("http") || original_url.SchemeIs("https")) && | 173 (original_url.SchemeIs("http") || original_url.SchemeIs("https")) && |
| 144 google_util::IsGoogleHostname(original_url.host(), permission); | 174 google_util::IsGoogleHostname(original_url.host(), permission); |
| 145 } | 175 } |
| 146 | 176 |
| 147 bool IsGoogleHostname(const std::string& host, | 177 bool IsGoogleHostname(const std::string& host, |
| 148 SubdomainPermission permission) { | 178 SubdomainPermission permission) { |
| 149 size_t tld_length = | 179 size_t tld_length = |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 const char* const kBrands[] = { | 313 const char* const kBrands[] = { |
| 284 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", | 314 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", |
| 285 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", | 315 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", |
| 286 }; | 316 }; |
| 287 const char* const* end = &kBrands[arraysize(kBrands)]; | 317 const char* const* end = &kBrands[arraysize(kBrands)]; |
| 288 const char* const* found = std::find(&kBrands[0], end, brand); | 318 const char* const* found = std::find(&kBrands[0], end, brand); |
| 289 return found != end; | 319 return found != end; |
| 290 } | 320 } |
| 291 | 321 |
| 292 } // namespace google_util | 322 } // namespace google_util |
| OLD | NEW |