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

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

Issue 9705021: Clean up TemplateURL prepopulate data: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/protector/histograms.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 26 matching lines...) Expand all
37 base::SplitString(str, '&', &parameters); 37 base::SplitString(str, '&', &parameters);
38 for (std::vector<std::string>::const_iterator itr = parameters.begin(); 38 for (std::vector<std::string>::const_iterator itr = parameters.begin();
39 itr != parameters.end(); 39 itr != parameters.end();
40 ++itr) { 40 ++itr) {
41 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2) 41 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2)
42 return true; 42 return true;
43 } 43 }
44 return false; 44 return false;
45 } 45 }
46 46
47 // True if |url| is an HTTP[S] request with host "[www.]google.<TLD>". 47 // True if |url| is an HTTP[S] request with host "[www.]google.<TLD>" and no
48 // explicit port.
48 bool IsGoogleDomainUrl(const GURL& url) { 49 bool IsGoogleDomainUrl(const GURL& url) {
49 if (!url.is_valid()) 50 return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) &&
50 return false; 51 url.port().empty() && google_util::IsGoogleHostname(url.host());
51
52 // Make sure the scheme is valid.
53 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
54 return false;
55
56 // Make sure port is default for the respective scheme.
57 if (!url.port().empty())
58 return false;
59
60 // Accept only valid TLD.
61 size_t tld_length = net::RegistryControlledDomainService::GetRegistryLength(
62 url, false);
63 if (tld_length == 0 || tld_length == std::string::npos)
64 return false;
65
66 // We only accept "[www.]google." in front of the TLD.
67 std::string host = url.host();
68 host = host.substr(0, host.length() - tld_length);
69 if (!LowerCaseEqualsASCII(host, "www.google.") &&
70 !LowerCaseEqualsASCII(host, "google."))
71 return false;
72
73 return true;
74 } 52 }
75 53
76 } // anonymous namespace 54 } // anonymous namespace
77 55
78 namespace google_util { 56 namespace google_util {
79 57
80 const char kLinkDoctorBaseURL[] = 58 const char kLinkDoctorBaseURL[] =
81 "http://linkhelp.clients.google.com/tbproxy/lh/fixurl"; 59 "http://linkhelp.clients.google.com/tbproxy/lh/fixurl";
82 60
83 BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) { 61 BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return true; 135 return true;
158 } 136 }
159 137
160 bool GetReactivationBrand(std::string* brand) { 138 bool GetReactivationBrand(std::string* brand) {
161 brand->clear(); 139 brand->clear();
162 return true; 140 return true;
163 } 141 }
164 142
165 #endif 143 #endif
166 144
145 bool IsGoogleHostname(const std::string& host) {
146 size_t tld_length =
147 net::RegistryControlledDomainService::GetRegistryLength(host, false);
148 if ((tld_length == 0) || (tld_length == std::string::npos))
149 return false;
150 std::string host_minus_tld(host, 0, host.length() - tld_length);
151 return LowerCaseEqualsASCII(host_minus_tld, "www.google.") ||
152 LowerCaseEqualsASCII(host_minus_tld, "google.");
153 }
154
167 bool IsGoogleHomePageUrl(const std::string& url) { 155 bool IsGoogleHomePageUrl(const std::string& url) {
168 GURL original_url(url); 156 GURL original_url(url);
169 157
170 // First check to see if this has a Google domain. 158 // First check to see if this has a Google domain.
171 if (!IsGoogleDomainUrl(original_url)) 159 if (!IsGoogleDomainUrl(original_url))
172 return false; 160 return false;
173 161
174 // Make sure the path is a known home page path. 162 // Make sure the path is a known home page path.
175 std::string path(original_url.path()); 163 std::string path(original_url.path());
176 if (path != "/" && path != "/webhp" && 164 if (path != "/" && path != "/webhp" &&
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 const char* const kBrands[] = { 254 const char* const kBrands[] = {
267 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", 255 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE",
268 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", 256 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM",
269 }; 257 };
270 const char* const* end = &kBrands[arraysize(kBrands)]; 258 const char* const* end = &kBrands[arraysize(kBrands)];
271 const char* const* found = std::find(&kBrands[0], end, brand); 259 const char* const* found = std::find(&kBrands[0], end, brand);
272 return found != end; 260 return found != end;
273 } 261 }
274 262
275 } // namespace google_util 263 } // namespace google_util
OLDNEW
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/protector/histograms.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698