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

Side by Side Diff: components/google/core/browser/google_util.cc

Issue 1242023005: Remove legacy StartsWithASCII function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: y Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/google/core/browser/google_util.h" 5 #include "components/google/core/browser/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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 base_url = url_fixer::FixupURL(switch_value, std::string()); 156 base_url = url_fixer::FixupURL(switch_value, std::string());
157 if (!base_url.is_valid() || base_url.has_query() || base_url.has_ref()) 157 if (!base_url.is_valid() || base_url.has_query() || base_url.has_ref())
158 base_url = GURL(); 158 base_url = GURL();
159 } 159 }
160 return base_url; 160 return base_url;
161 } 161 }
162 162
163 bool StartsWithCommandLineGoogleBaseURL(const GURL& url) { 163 bool StartsWithCommandLineGoogleBaseURL(const GURL& url) {
164 GURL base_url(CommandLineGoogleBaseURL()); 164 GURL base_url(CommandLineGoogleBaseURL());
165 return base_url.is_valid() && 165 return base_url.is_valid() &&
166 base::StartsWithASCII(url.possibly_invalid_spec(), base_url.spec(), 166 base::StartsWith(url.possibly_invalid_spec(), base_url.spec(),
167 true); 167 base::CompareCase::SENSITIVE);
168 } 168 }
169 169
170 bool IsGoogleHostname(const std::string& host, 170 bool IsGoogleHostname(const std::string& host,
171 SubdomainPermission subdomain_permission) { 171 SubdomainPermission subdomain_permission) {
172 GURL base_url(CommandLineGoogleBaseURL()); 172 GURL base_url(CommandLineGoogleBaseURL());
173 if (base_url.is_valid() && (host == base_url.host())) 173 if (base_url.is_valid() && (host == base_url.host()))
174 return true; 174 return true;
175 175
176 return IsValidHostName(host, "google", subdomain_permission); 176 return IsValidHostName(host, "google", subdomain_permission);
177 } 177 }
178 178
179 bool IsGoogleDomainUrl(const GURL& url, 179 bool IsGoogleDomainUrl(const GURL& url,
180 SubdomainPermission subdomain_permission, 180 SubdomainPermission subdomain_permission,
181 PortPermission port_permission) { 181 PortPermission port_permission) {
182 return IsValidURL(url, port_permission) && 182 return IsValidURL(url, port_permission) &&
183 IsGoogleHostname(url.host(), subdomain_permission); 183 IsGoogleHostname(url.host(), subdomain_permission);
184 } 184 }
185 185
186 bool IsGoogleHomePageUrl(const GURL& url) { 186 bool IsGoogleHomePageUrl(const GURL& url) {
187 // First check to see if this has a Google domain. 187 // First check to see if this has a Google domain.
188 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS)) 188 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS))
189 return false; 189 return false;
190 190
191 // Make sure the path is a known home page path. 191 // Make sure the path is a known home page path.
192 std::string path(url.path()); 192 std::string path(url.path());
193 return IsPathHomePageBase(path) || base::StartsWithASCII(path, "/ig", false); 193 return IsPathHomePageBase(path) ||
194 base::StartsWith(path, "/ig", base::CompareCase::INSENSITIVE_ASCII);
194 } 195 }
195 196
196 bool IsGoogleSearchUrl(const GURL& url) { 197 bool IsGoogleSearchUrl(const GURL& url) {
197 // First check to see if this has a Google domain. 198 // First check to see if this has a Google domain.
198 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS)) 199 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS))
199 return false; 200 return false;
200 201
201 // Make sure the path is a known search path. 202 // Make sure the path is a known search path.
202 std::string path(url.path()); 203 std::string path(url.path());
203 bool is_home_page_base = IsPathHomePageBase(path); 204 bool is_home_page_base = IsPathHomePageBase(path);
204 if (!is_home_page_base && (path != "/search")) 205 if (!is_home_page_base && (path != "/search"))
205 return false; 206 return false;
206 207
207 // Check for query parameter in URL parameter and hash fragment, depending on 208 // Check for query parameter in URL parameter and hash fragment, depending on
208 // the path type. 209 // the path type.
209 return HasGoogleSearchQueryParam(url.ref()) || 210 return HasGoogleSearchQueryParam(url.ref()) ||
210 (!is_home_page_base && HasGoogleSearchQueryParam(url.query())); 211 (!is_home_page_base && HasGoogleSearchQueryParam(url.query()));
211 } 212 }
212 213
213 bool IsYoutubeDomainUrl(const GURL& url, 214 bool IsYoutubeDomainUrl(const GURL& url,
214 SubdomainPermission subdomain_permission, 215 SubdomainPermission subdomain_permission,
215 PortPermission port_permission) { 216 PortPermission port_permission) {
216 return IsValidURL(url, port_permission) && 217 return IsValidURL(url, port_permission) &&
217 IsValidHostName(url.host(), "youtube", subdomain_permission); 218 IsValidHostName(url.host(), "youtube", subdomain_permission);
218 } 219 }
219 220
220 } // namespace google_util 221 } // namespace google_util
OLDNEW
« no previous file with comments | « components/google/core/browser/google_url_tracker.cc ('k') | components/html_viewer/web_mime_registry_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698