| 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_split.h" | 12 #include "base/string_split.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/google/google_url_tracker.h" | 16 #include "chrome/browser/google/google_url_tracker.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/net/url_util.h" | 18 #include "chrome/common/net/url_util.h" |
| 19 #include "chrome/installer/util/google_update_settings.h" | 19 #include "chrome/installer/util/google_update_settings.h" |
| 20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 21 #include "googleurl/src/url_parse.h" |
| 21 #include "net/base/registry_controlled_domain.h" | 22 #include "net/base/registry_controlled_domain.h" |
| 22 | 23 |
| 23 #if defined(OS_MACOSX) | 24 #if defined(OS_MACOSX) |
| 24 #include "chrome/browser/mac/keystone_glue.h" | 25 #include "chrome/browser/mac/keystone_glue.h" |
| 25 #endif | 26 #endif |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 const char* brand_for_testing = NULL; | 30 const char* brand_for_testing = NULL; |
| 30 | 31 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return false; | 197 return false; |
| 197 | 198 |
| 198 // Check for query parameter in URL parameter and hash fragment, depending on | 199 // Check for query parameter in URL parameter and hash fragment, depending on |
| 199 // the path type. | 200 // the path type. |
| 200 std::string query(original_url.query()); | 201 std::string query(original_url.query()); |
| 201 std::string ref(original_url.ref()); | 202 std::string ref(original_url.ref()); |
| 202 return HasQueryParameter(ref) || | 203 return HasQueryParameter(ref) || |
| 203 (!is_home_page_base && HasQueryParameter(query)); | 204 (!is_home_page_base && HasQueryParameter(query)); |
| 204 } | 205 } |
| 205 | 206 |
| 207 bool IsInstantExtendedAPIGoogleSearchUrl(const std::string& url) { |
| 208 if (!IsGoogleSearchUrl(url)) |
| 209 return false; |
| 210 |
| 211 const std::string embedded_search_key = "espv"; |
| 212 |
| 213 url_parse::Parsed parsed_url; |
| 214 url_parse::ParseStandardURL(url.c_str(), url.length(), &parsed_url); |
| 215 url_parse::Component key, value; |
| 216 while (url_parse::ExtractQueryKeyValue( |
| 217 url.c_str(), &parsed_url.query, &key, &value)) { |
| 218 // If the parameter key is |embedded_search_key| and the value is not 0 this |
| 219 // is an Instant Extended API Google search URL. |
| 220 if (url.substr(key.begin, key.len) == embedded_search_key) { |
| 221 return value.is_nonempty() && url.substr(value.begin, value.len) != "0"; |
| 222 } |
| 223 } |
| 224 return false; |
| 225 } |
| 226 |
| 206 bool IsOrganic(const std::string& brand) { | 227 bool IsOrganic(const std::string& brand) { |
| 207 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 228 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 208 if (command_line.HasSwitch(switches::kOrganicInstall)) | 229 if (command_line.HasSwitch(switches::kOrganicInstall)) |
| 209 return true; | 230 return true; |
| 210 | 231 |
| 211 #if defined(OS_MACOSX) | 232 #if defined(OS_MACOSX) |
| 212 if (brand.empty()) { | 233 if (brand.empty()) { |
| 213 // An empty brand string on Mac is used for channels other than stable, | 234 // An empty brand string on Mac is used for channels other than stable, |
| 214 // which are always organic. | 235 // which are always organic. |
| 215 return true; | 236 return true; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 const char* const kBrands[] = { | 279 const char* const kBrands[] = { |
| 259 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", | 280 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", |
| 260 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", | 281 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", |
| 261 }; | 282 }; |
| 262 const char* const* end = &kBrands[arraysize(kBrands)]; | 283 const char* const* end = &kBrands[arraysize(kBrands)]; |
| 263 const char* const* found = std::find(&kBrands[0], end, brand); | 284 const char* const* found = std::find(&kBrands[0], end, brand); |
| 264 return found != end; | 285 return found != end; |
| 265 } | 286 } |
| 266 | 287 |
| 267 } // namespace google_util | 288 } // namespace google_util |
| OLD | NEW |