Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: chrome/browser/google/google_util.cc

Issue 17022004: Replace --google-base-suggest-url and --instant-url with --google-base-url. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 return true; 145 return true;
146 } 146 }
147 147
148 bool GetReactivationBrand(std::string* brand) { 148 bool GetReactivationBrand(std::string* brand) {
149 brand->clear(); 149 brand->clear();
150 return true; 150 return true;
151 } 151 }
152 152
153 #endif 153 #endif
154 154
155 bool IsGoogleDomainUrl(const std::string& url, 155 bool StartsWithCommandLineGoogleBaseURL(const GURL& url) {
156 SubdomainPermission subdomain_permission, 156 const std::string base_url(CommandLine::ForCurrentProcess()->
157 PortPermission port_permission) { 157 GetSwitchValueASCII(switches::kGoogleBaseURL));
158 GURL original_url(url); 158 return !base_url.empty() &&
159 if (!original_url.is_valid() || 159 StartsWithASCII(url.possibly_invalid_spec(), base_url, true);
160 !(original_url.SchemeIs("http") || original_url.SchemeIs("https")))
161 return false;
162
163 // If we have the Instant URL overridden with a command line flag, accept
164 // its domain/port combination as well.
165 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
166 if (command_line.HasSwitch(switches::kInstantURL)) {
167 GURL custom_instant_url(
168 command_line.GetSwitchValueASCII(switches::kInstantURL));
169 if (original_url.host() == custom_instant_url.host() &&
170 original_url.port() == custom_instant_url.port())
171 return true;
172 }
173
174 return (original_url.port().empty() ||
175 port_permission == ALLOW_NON_STANDARD_PORTS) &&
176 google_util::IsGoogleHostname(original_url.host(), subdomain_permission);
177 } 160 }
178 161
179 bool IsGoogleHostname(const std::string& host, 162 bool IsGoogleHostname(const std::string& host,
180 SubdomainPermission subdomain_permission) { 163 SubdomainPermission subdomain_permission) {
164 const std::string base_url(CommandLine::ForCurrentProcess()->
165 GetSwitchValueASCII(switches::kGoogleBaseURL));
166 if (!base_url.empty()) {
167 GURL base_gurl(base_url);
168 if (base_gurl.is_valid() && (host == base_gurl.host()))
169 return true;
170 }
171
181 size_t tld_length = net::registry_controlled_domains::GetRegistryLength( 172 size_t tld_length = net::registry_controlled_domains::GetRegistryLength(
182 host, 173 host,
183 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, 174 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
184 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); 175 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
185 if ((tld_length == 0) || (tld_length == std::string::npos)) 176 if ((tld_length == 0) || (tld_length == std::string::npos))
186 return false; 177 return false;
187 std::string host_minus_tld(host, 0, host.length() - tld_length); 178 std::string host_minus_tld(host, 0, host.length() - tld_length);
188 if (LowerCaseEqualsASCII(host_minus_tld, "google.")) 179 if (LowerCaseEqualsASCII(host_minus_tld, "google."))
189 return true; 180 return true;
190 if (subdomain_permission == ALLOW_SUBDOMAIN) 181 if (subdomain_permission == ALLOW_SUBDOMAIN)
191 return EndsWith(host_minus_tld, ".google.", false); 182 return EndsWith(host_minus_tld, ".google.", false);
192 return LowerCaseEqualsASCII(host_minus_tld, "www.google."); 183 return LowerCaseEqualsASCII(host_minus_tld, "www.google.");
193 } 184 }
194 185
195 bool IsGoogleHomePageUrl(const std::string& url) { 186 bool IsGoogleDomainUrl(const GURL& url,
196 GURL original_url(url); 187 SubdomainPermission subdomain_permission,
188 PortPermission port_permission) {
189 return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) &&
190 (url.port().empty() || (port_permission == ALLOW_NON_STANDARD_PORTS)) &&
191 google_util::IsGoogleHostname(url.host(), subdomain_permission);
192 }
197 193
194 bool IsGoogleHomePageUrl(const GURL& url) {
198 // First check to see if this has a Google domain. 195 // First check to see if this has a Google domain.
199 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS)) 196 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS))
200 return false; 197 return false;
201 198
202 // Make sure the path is a known home page path. 199 // Make sure the path is a known home page path.
203 std::string path(original_url.path()); 200 std::string path(url.path());
204 if (path != "/" && path != "/webhp" && 201 return (path == "/") || (path == "/webhp") ||
205 !StartsWithASCII(path, "/ig", false)) { 202 StartsWithASCII(path, "/ig", false);
206 return false;
207 }
208
209 return true;
210 } 203 }
211 204
212 bool IsGoogleSearchUrl(const std::string& url) { 205 bool IsGoogleSearchUrl(const GURL& url) {
213 GURL original_url(url);
214
215 // First check to see if this has a Google domain. 206 // First check to see if this has a Google domain.
216 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS)) 207 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS))
217 return false; 208 return false;
218 209
219 // Make sure the path is a known search path. 210 // Make sure the path is a known search path.
220 std::string path(original_url.path()); 211 std::string path(url.path());
221 bool has_valid_path = false;
222 bool is_home_page_base = false; 212 bool is_home_page_base = false;
Jered 2013/06/26 00:32:16 bool is_home_page_base = path == "/webhp" || path
Peter Kasting 2013/06/26 00:40:27 Nice :)
223 if (path == "/search") { 213 if (path != "/search") {
224 has_valid_path = true; 214 if ((path != "/webhp") && (path != "/"))
225 } else if (path == "/webhp" || path == "/") { 215 return false;
226 // Note that we allow both "/" and "" paths, but GURL spits them
227 // both out as just "/".
228 has_valid_path = true;
229 is_home_page_base = true; 216 is_home_page_base = true;
230 } 217 }
231 if (!has_valid_path)
232 return false;
233 218
234 // Check for query parameter in URL parameter and hash fragment, depending on 219 // Check for query parameter in URL parameter and hash fragment, depending on
235 // the path type. 220 // the path type.
236 std::string query(original_url.query()); 221 return HasGoogleSearchQueryParam(url.ref()) ||
237 std::string ref(original_url.ref()); 222 (!is_home_page_base && HasGoogleSearchQueryParam(url.query()));
238 return HasGoogleSearchQueryParam(ref) ||
239 (!is_home_page_base && HasGoogleSearchQueryParam(query));
240 } 223 }
241 224
242 bool IsOrganic(const std::string& brand) { 225 bool IsOrganic(const std::string& brand) {
243 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 226 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
244 if (command_line.HasSwitch(switches::kOrganicInstall)) 227 if (command_line.HasSwitch(switches::kOrganicInstall))
245 return true; 228 return true;
246 229
247 #if defined(OS_MACOSX) 230 #if defined(OS_MACOSX)
248 if (brand.empty()) { 231 if (brand.empty()) {
249 // An empty brand string on Mac is used for channels other than stable, 232 // An empty brand string on Mac is used for channels other than stable,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 const char* const kBrands[] = { 277 const char* const kBrands[] = {
295 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", 278 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE",
296 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", 279 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM",
297 }; 280 };
298 const char* const* end = &kBrands[arraysize(kBrands)]; 281 const char* const* end = &kBrands[arraysize(kBrands)];
299 const char* const* found = std::find(&kBrands[0], end, brand); 282 const char* const* found = std::find(&kBrands[0], end, brand);
300 return found != end; 283 return found != end;
301 } 284 }
302 285
303 } // namespace google_util 286 } // namespace google_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698