Skip to content

Commit

Permalink
Introduce GURL::SchemeIsHttpFamily(), which returns true for http and…
Browse files Browse the repository at this point in the history
… https.

BUG=274679
TEST=N/A
TBR=cbentzel, jamesr, simonjam, tzik, stevet, mpcomplete

Review URL: https://chromiumcodereview.appspot.com/23064011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218893 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
cdn@chromium.org committed Aug 22, 2013
1 parent 3126881 commit 91f5689
Show file tree
Hide file tree
Showing 25 changed files with 34 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void InterceptDownloadResourceThrottle::ProcessDownloadRequest() {
return;

GURL url = request_->url_chain().back();
if (!url.SchemeIs("http") && !url.SchemeIs("https"))
if (!url.SchemeIsHTTPOrHTTPS())
return;

content::DownloadControllerAndroid::Get()->CreateGETDownload(
Expand Down
3 changes: 1 addition & 2 deletions chrome/browser/extensions/api/dial/dial_device_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ void DialDeviceData::set_device_description_url(const GURL& url) {

// static
bool DialDeviceData::IsDeviceDescriptionUrl(const GURL& url) {
return url.is_valid() && !url.is_empty() &&
(url.SchemeIs("http") || url.SchemeIs("https"));
return url.is_valid() && !url.is_empty() && url.SchemeIsHTTPOrHTTPS();
}

bool DialDeviceData::UpdateFrom(const DialDeviceData& new_data) {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/google/google_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ bool IsGoogleHostname(const std::string& host,
bool IsGoogleDomainUrl(const GURL& url,
SubdomainPermission subdomain_permission,
PortPermission port_permission) {
return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) &&
return url.is_valid() && url.SchemeIsHTTPOrHTTPS() &&
(url.port().empty() || (port_permission == ALLOW_NON_STANDARD_PORTS)) &&
google_util::IsGoogleHostname(url.host(), subdomain_permission);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ bool VariationsHttpHeaderProvider::ShouldAppendHeaders(const GURL& url) {
}

// The below mirrors logic in IsGoogleDomainUrl(), but for youtube.<TLD>.
if (!url.is_valid() || !(url.SchemeIs("http") || url.SchemeIs("https")))
if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS())
return false;

const std::string host = url.host();
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/net/predictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ UrlList Predictor::GetPredictedUrlListAtStartup(
GURL gurl = tab_start_pref.urls[i];
if (!gurl.is_valid() || gurl.SchemeIsFile() || gurl.host().empty())
continue;
if (gurl.SchemeIs("http") || gurl.SchemeIs("https"))
if (gurl.SchemeIsHTTPOrHTTPS())
urls.push_back(gurl.GetWithEmptyPath());
}
}
Expand Down Expand Up @@ -1302,7 +1302,7 @@ void Predictor::InitialObserver::Append(const GURL& url,
if (kStartupResolutionCount <= first_navigations_.size())
return;

DCHECK(url.SchemeIs("http") || url.SchemeIs("https"));
DCHECK(url.SchemeIsHTTPOrHTTPS());
DCHECK_EQ(url, Predictor::CanonicalizeUrl(url));
if (first_navigations_.find(url) == first_navigations_.end())
first_navigations_[url] = base::TimeTicks::Now();
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/net/predictor_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void PredictorTabHelper::DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) {
if (!IsUserLinkNavigationRequest(params.transition) ||
!(params.url.SchemeIs("http") || params.url.SchemeIs("https")))
!(params.url.SchemeIsHTTPOrHTTPS()))
return;

Profile* profile = Profile::FromBrowserContext(
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/prerender/prerender_histograms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void PrerenderHistograms::RecordPerceivedPageLoadTime(
base::TimeDelta perceived_page_load_time,
bool was_prerender,
bool was_complete_prerender, const GURL& url) {
if (!IsWebURL(url))
if (!url.SchemeIsHTTPOrHTTPS())
return;
bool within_window = WithinWindow();
bool is_google_url = IsGoogleDomain(url);
Expand Down Expand Up @@ -303,7 +303,7 @@ void PrerenderHistograms::RecordPageLoadTimeNotSwappedIn(
const GURL& url) const {
// If the URL to be prerendered is not a http[s] URL, or is a Google URL,
// do not record.
if (!IsWebURL(url) || IsGoogleDomain(url))
if (!url.SchemeIsHTTPOrHTTPS() || IsGoogleDomain(url))
return;
RECORD_PLT("PrerenderNotSwappedInPLT", page_load_time);
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/prerender/prerender_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ bool PrerenderManager::IsValidHttpMethod(const std::string& method) {

// static
bool PrerenderManager::DoesURLHaveValidScheme(const GURL& url) {
return (IsWebURL(url) ||
return (url.SchemeIsHTTPOrHTTPS() ||
url.SchemeIs(extensions::kExtensionScheme) ||
url.SchemeIs("data"));
}
Expand Down Expand Up @@ -1471,7 +1471,7 @@ void PrerenderManager::OnCreatingAudioStream(int render_process_id,

void PrerenderManager::RecordLikelyLoginOnURL(const GURL& url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!IsWebURL(url))
if (!url.SchemeIsHTTPOrHTTPS())
return;
if (logged_in_predictor_table_.get()) {
BrowserThread::PostTask(
Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/prerender/prerender_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ bool IsGoogleSearchResultURL(const GURL& url) {
StartsWithASCII(url.path(), std::string("/webhp"), true));
}

bool IsWebURL(const GURL& url) {
return url.SchemeIs("http") || url.SchemeIs("https");
}

bool IsNoSwapInExperiment(uint8 experiment_id) {
// Currently, experiments 5 and 6 fall in this category.
return experiment_id == 5 || experiment_id == 6;
Expand All @@ -100,7 +96,7 @@ void URLRequestResponseStarted(net::URLRequest* request) {
content::ResourceRequestInfo::ForRequest(request);
// Gather histogram information about the X-Mod-Pagespeed header.
if (info->GetResourceType() == ResourceType::MAIN_FRAME &&
IsWebURL(request->url())) {
request->url().SchemeIsHTTPOrHTTPS()) {
UMA_HISTOGRAM_SPARSE_SLOWLY(kModPagespeedHistogram, 0);
if (request->response_headers() &&
request->response_headers()->HasHeader(kModPagespeedHeader)) {
Expand Down
4 changes: 0 additions & 4 deletions chrome/browser/prerender/prerender_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ bool IsGoogleDomain(const GURL& url);
// Indicates whether the URL provided could be a Google search result page.
bool IsGoogleSearchResultURL(const GURL& url);

// Returns true iff the URL provided is Web URL, using the scheme http
// or https.
bool IsWebURL(const GURL& url);

// The prerender contents of some experiments should never be swapped in
// by pretending to never match on the URL. This function will return true
// iff this is the case for the experiment_id specified.
Expand Down
5 changes: 2 additions & 3 deletions chrome/common/extensions/manifest_url_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ bool HomepageURLHandler::Parse(Extension* extension, string16* error) {
}
manifest_url->url_ = GURL(homepage_url_str);
if (!manifest_url->url_.is_valid() ||
(!manifest_url->url_.SchemeIs("http") &&
!manifest_url->url_.SchemeIs("https"))) {
!manifest_url->url_.SchemeIsHTTPOrHTTPS()) {
*error = ErrorUtils::FormatErrorMessageUTF16(
errors::kInvalidHomepageURL, homepage_url_str);
return false;
Expand Down Expand Up @@ -206,7 +205,7 @@ bool OptionsPageHandler::Parse(Extension* extension, string16* error) {
// hosted apps require an absolute URL.
GURL options_url(options_str);
if (!options_url.is_valid() ||
!(options_url.SchemeIs("http") || options_url.SchemeIs("https"))) {
!options_url.SchemeIsHTTPOrHTTPS()) {
*error = ASCIIToUTF16(errors::kInvalidOptionsPageInHostedApp);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion chrome_frame/test/net/test_automation_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ net::URLRequestJob* TestAutomationProvider::Factory(
if (CFTestsDisabled())
return NULL;

if (request->url().SchemeIs("http") || request->url().SchemeIs("https")) {
if (request->url().SchemeIsHTTPOrHTTPS()) {
// Only look at requests that don't have any user data.
// ResourceDispatcherHost uses the user data for requests that it manages.
// We don't want to mess with those.
Expand Down
2 changes: 1 addition & 1 deletion content/browser/download/file_metadata_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void AddQuarantineMetadataToFile(const base::FilePath& file, const GURL& source,
// need to set the values that the OS can't infer.

if (![quarantine_properties valueForKey:(NSString*)kLSQuarantineTypeKey]) {
CFStringRef type = (source.SchemeIs("http") || source.SchemeIs("https"))
CFStringRef type = source.SchemeIsHTTPOrHTTPS()
? kLSQuarantineTypeWebDownload
: kLSQuarantineTypeOtherDownload;
[quarantine_properties setValue:(NSString*)type
Expand Down
2 changes: 1 addition & 1 deletion content/browser/loader/resource_dispatcher_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ void ResourceDispatcherHostImpl::OnDidLoadResourceFromMemoryCache(
const std::string& http_method,
const std::string& mime_type,
ResourceType::Type resource_type) {
if (!url.is_valid() || !(url.SchemeIs("http") || url.SchemeIs("https")))
if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS())
return;

filter_->GetURLRequestContext(resource_type)->http_transaction_factory()->
Expand Down
2 changes: 1 addition & 1 deletion content/renderer/media/webmediaplayer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void WebMediaPlayerImpl::DoLoad(LoadType load_type,
&WebMediaPlayerImpl::DataSourceInitialized,
AsWeakPtr(), gurl));

is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https");
is_local_source_ = !gurl.SchemeIsHTTPOrHTTPS();
}

void WebMediaPlayerImpl::play() {
Expand Down
2 changes: 1 addition & 1 deletion content/renderer/npapi/webplugin_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ WebPluginImpl::RoutingStatus WebPluginImpl::RouteToFrame(

if (strcmp(method, "GET") != 0) {
// We're only going to route HTTP/HTTPS requests
if (!(complete_url.SchemeIs("http") || complete_url.SchemeIs("https")))
if (!complete_url.SchemeIsHTTPOrHTTPS())
return INVALID_URL;
}

Expand Down
2 changes: 1 addition & 1 deletion content/renderer/savable_resources.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void GetSavableResourceLinkForElement(
// Ignore those URLs which are not standard protocols. Because FTP
// protocol does no have cache mechanism, we will skip all
// sub-resources if they use FTP protocol.
if (!u.SchemeIs("http") && !u.SchemeIs("https") && !u.SchemeIs("file"))
if (!u.SchemeIsHTTPOrHTTPS() && !u.SchemeIs("file"))
return;
// Ignore duplicated resource link.
if (!unique_check->resources_set->insert(u).second)
Expand Down
3 changes: 1 addition & 2 deletions net/base/mime_sniffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,7 @@ bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type) {
UMASnifferHistogramGet("mime_sniffer.ShouldSniffMimeType2", 3);
}
bool sniffable_scheme = url.is_empty() ||
url.SchemeIs("http") ||
url.SchemeIs("https") ||
url.SchemeIsHTTPOrHTTPS() ||
url.SchemeIs("ftp") ||
#if defined(OS_ANDROID)
url.SchemeIs("content") ||
Expand Down
2 changes: 1 addition & 1 deletion net/base/network_change_notifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class HistogramWatcher
// from the network thread.
void NotifyDataReceived(const URLRequest& request, int bytes_read) {
if (IsLocalhost(request.url().host()) ||
!(request.url().SchemeIs("http") || request.url().SchemeIs("https"))) {
!request.url().SchemeIsHTTPOrHTTPS()) {
return;
}

Expand Down
3 changes: 1 addition & 2 deletions net/http/http_auth_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ bool IsEnclosingPath(const std::string& container, const std::string& path) {
void CheckOriginIsValid(const GURL& origin) {
DCHECK(origin.is_valid());
// Note that the scheme may be FTP when we're using a HTTP proxy.
DCHECK(origin.SchemeIs("http") || origin.SchemeIs("https") ||
origin.SchemeIs("ftp"));
DCHECK(origin.SchemeIsHTTPOrHTTPS() || origin.SchemeIs("ftp"));
DCHECK(origin.GetOrigin() == origin);
}

Expand Down
5 changes: 2 additions & 3 deletions net/http/http_util_icu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace net {

// static
std::string HttpUtil::PathForRequest(const GURL& url) {
DCHECK(url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")));
DCHECK(url.is_valid() && url.SchemeIsHTTPOrHTTPS());
if (url.has_query())
return url.path() + "?" + url.query();
return url.path();
Expand All @@ -23,8 +23,7 @@ std::string HttpUtil::PathForRequest(const GURL& url) {
// static
std::string HttpUtil::SpecForRequest(const GURL& url) {
// We may get ftp scheme when fetching ftp resources through proxy.
DCHECK(url.is_valid() && (url.SchemeIs("http") ||
url.SchemeIs("https") ||
DCHECK(url.is_valid() && (url.SchemeIsHTTPOrHTTPS() ||
url.SchemeIs("ftp")));
return SimplifyUrlForRequest(url).spec();
}
Expand Down
2 changes: 1 addition & 1 deletion net/proxy/proxy_script_fetcher_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void ProxyScriptFetcherImpl::OnResponseStarted(URLRequest* request) {
}

// Require HTTP responses to have a success status code.
if (request->url().SchemeIs("http") || request->url().SchemeIs("https")) {
if (request->url().SchemeIsHTTPOrHTTPS()) {
// NOTE about status codes: We are like Firefox 3 in this respect.
// {IE 7, Safari 3, Opera 9.5} do not care about the status code.
if (request->GetResponseCode() != 200) {
Expand Down
4 changes: 4 additions & 0 deletions url/gurl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ bool GURL::SchemeIs(const char* lower_ascii_scheme) const {
lower_ascii_scheme);
}

bool GURL::SchemeIsHTTPOrHTTPS() const {
return SchemeIs("http") || SchemeIs("https");
}

int GURL::IntPort() const {
if (parsed_.port.is_nonempty())
return url_parse::ParsePort(spec_.data(), parsed_.port);
Expand Down
3 changes: 3 additions & 0 deletions url/gurl.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ class URL_EXPORT GURL {
// object constructions are done.
bool SchemeIs(const char* lower_ascii_scheme) const;

// Returns true if the scheme is "http" or "https".
bool SchemeIsHTTPOrHTTPS() const;

// We often need to know if this is a file URL. File URLs are "standard", but
// are often treated separately by some programs.
bool SchemeIsFile() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ bool SandboxFileSystemBackendDelegate::IsAccessValid(
bool SandboxFileSystemBackendDelegate::IsAllowedScheme(const GURL& url) const {
// Basically we only accept http or https. We allow file:// URLs
// only if --allow-file-access-from-files flag is given.
if (url.SchemeIs("http") || url.SchemeIs("https"))
if (url.SchemeIsHTTPOrHTTPS())
return true;
if (url.SchemeIsFileSystem())
return url.inner_url() && IsAllowedScheme(*url.inner_url());
Expand Down

0 comments on commit 91f5689

Please sign in to comment.