diff options
author | cdn@chromium.org <cdn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-22 01:43:33 +0000 |
---|---|---|
committer | cdn@chromium.org <cdn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-22 01:43:33 +0000 |
commit | 91f568903f5d067e7a82b2543434ba13b9dee9ef (patch) | |
tree | be24ab4ddd5fbc657bef13e3b5cf7ad83a82fcce | |
parent | 31268815420a038ad43ba7808862f97a8a129801 (diff) | |
download | chromium_src-91f568903f5d067e7a82b2543434ba13b9dee9ef.zip chromium_src-91f568903f5d067e7a82b2543434ba13b9dee9ef.tar.gz chromium_src-91f568903f5d067e7a82b2543434ba13b9dee9ef.tar.bz2 |
Introduce GURL::SchemeIsHttpFamily(), which returns true for http and 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
25 files changed, 34 insertions, 40 deletions
diff --git a/chrome/browser/android/intercept_download_resource_throttle.cc b/chrome/browser/android/intercept_download_resource_throttle.cc index c901a3a..5700ff9 100644 --- a/chrome/browser/android/intercept_download_resource_throttle.cc +++ b/chrome/browser/android/intercept_download_resource_throttle.cc @@ -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( diff --git a/chrome/browser/extensions/api/dial/dial_device_data.cc b/chrome/browser/extensions/api/dial/dial_device_data.cc index 125317d..f8f5540 100644 --- a/chrome/browser/extensions/api/dial/dial_device_data.cc +++ b/chrome/browser/extensions/api/dial/dial_device_data.cc @@ -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) { diff --git a/chrome/browser/google/google_util.cc b/chrome/browser/google/google_util.cc index d14ec5a..99e4b7a 100644 --- a/chrome/browser/google/google_util.cc +++ b/chrome/browser/google/google_util.cc @@ -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); } diff --git a/chrome/browser/metrics/variations/variations_http_header_provider.cc b/chrome/browser/metrics/variations/variations_http_header_provider.cc index f4ed100..7be3775 100644 --- a/chrome/browser/metrics/variations/variations_http_header_provider.cc +++ b/chrome/browser/metrics/variations/variations_http_header_provider.cc @@ -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(); diff --git a/chrome/browser/net/predictor.cc b/chrome/browser/net/predictor.cc index 90644fd..a31f0cf 100644 --- a/chrome/browser/net/predictor.cc +++ b/chrome/browser/net/predictor.cc @@ -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()); } } @@ -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(); diff --git a/chrome/browser/net/predictor_tab_helper.cc b/chrome/browser/net/predictor_tab_helper.cc index 752bb7a..0b8be8f 100644 --- a/chrome/browser/net/predictor_tab_helper.cc +++ b/chrome/browser/net/predictor_tab_helper.cc @@ -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( diff --git a/chrome/browser/prerender/prerender_histograms.cc b/chrome/browser/prerender/prerender_histograms.cc index fba4c52..7e7fd42 100644 --- a/chrome/browser/prerender/prerender_histograms.cc +++ b/chrome/browser/prerender/prerender_histograms.cc @@ -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); @@ -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); } diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc index 14aaa3b..f704d407 100644 --- a/chrome/browser/prerender/prerender_manager.cc +++ b/chrome/browser/prerender/prerender_manager.cc @@ -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")); } @@ -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( diff --git a/chrome/browser/prerender/prerender_util.cc b/chrome/browser/prerender/prerender_util.cc index ca25418..1c4ab6f 100644 --- a/chrome/browser/prerender/prerender_util.cc +++ b/chrome/browser/prerender/prerender_util.cc @@ -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; @@ -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)) { diff --git a/chrome/browser/prerender/prerender_util.h b/chrome/browser/prerender/prerender_util.h index 1c0626e..fd93887 100644 --- a/chrome/browser/prerender/prerender_util.h +++ b/chrome/browser/prerender/prerender_util.h @@ -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. diff --git a/chrome/common/extensions/manifest_url_handler.cc b/chrome/common/extensions/manifest_url_handler.cc index 9605af4..31dc519 100644 --- a/chrome/common/extensions/manifest_url_handler.cc +++ b/chrome/common/extensions/manifest_url_handler.cc @@ -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; @@ -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; } diff --git a/chrome_frame/test/net/test_automation_provider.cc b/chrome_frame/test/net/test_automation_provider.cc index 496e943..9acec9a 100644 --- a/chrome_frame/test/net/test_automation_provider.cc +++ b/chrome_frame/test/net/test_automation_provider.cc @@ -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. diff --git a/content/browser/download/file_metadata_mac.mm b/content/browser/download/file_metadata_mac.mm index fc0556e..9dc504f 100644 --- a/content/browser/download/file_metadata_mac.mm +++ b/content/browser/download/file_metadata_mac.mm @@ -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 diff --git a/content/browser/loader/resource_dispatcher_host_impl.cc b/content/browser/loader/resource_dispatcher_host_impl.cc index c37137d..d4f6e53 100644 --- a/content/browser/loader/resource_dispatcher_host_impl.cc +++ b/content/browser/loader/resource_dispatcher_host_impl.cc @@ -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()-> diff --git a/content/renderer/media/webmediaplayer_impl.cc b/content/renderer/media/webmediaplayer_impl.cc index adea375..935faec 100644 --- a/content/renderer/media/webmediaplayer_impl.cc +++ b/content/renderer/media/webmediaplayer_impl.cc @@ -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() { diff --git a/content/renderer/npapi/webplugin_impl.cc b/content/renderer/npapi/webplugin_impl.cc index 21e80b6..d898011 100644 --- a/content/renderer/npapi/webplugin_impl.cc +++ b/content/renderer/npapi/webplugin_impl.cc @@ -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; } diff --git a/content/renderer/savable_resources.cc b/content/renderer/savable_resources.cc index d21da17..f1b2fde 100644 --- a/content/renderer/savable_resources.cc +++ b/content/renderer/savable_resources.cc @@ -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) diff --git a/net/base/mime_sniffer.cc b/net/base/mime_sniffer.cc index cc83c7c..06034cb 100644 --- a/net/base/mime_sniffer.cc +++ b/net/base/mime_sniffer.cc @@ -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") || diff --git a/net/base/network_change_notifier.cc b/net/base/network_change_notifier.cc index a6335d0..fad9440 100644 --- a/net/base/network_change_notifier.cc +++ b/net/base/network_change_notifier.cc @@ -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; } diff --git a/net/http/http_auth_cache.cc b/net/http/http_auth_cache.cc index 79ea7fd..1c8c03f 100644 --- a/net/http/http_auth_cache.cc +++ b/net/http/http_auth_cache.cc @@ -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); } diff --git a/net/http/http_util_icu.cc b/net/http/http_util_icu.cc index 64e7424..4f38f84 100644 --- a/net/http/http_util_icu.cc +++ b/net/http/http_util_icu.cc @@ -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(); @@ -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(); } diff --git a/net/proxy/proxy_script_fetcher_impl.cc b/net/proxy/proxy_script_fetcher_impl.cc index 2bf9e66..f8925fa 100644 --- a/net/proxy/proxy_script_fetcher_impl.cc +++ b/net/proxy/proxy_script_fetcher_impl.cc @@ -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) { diff --git a/url/gurl.cc b/url/gurl.cc index 09b8abb..229df5d 100644 --- a/url/gurl.cc +++ b/url/gurl.cc @@ -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); @@ -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 { diff --git a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc index 0a6034e..bfd7fd8 100644 --- a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc +++ b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc @@ -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()); |