Commit 42749713 authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Remove URLRequest::SupportsScheme and URLRequest::IsHandledURL.

These used to query a global set of factories reflecting all schemes
that Chrome supported, which have mostly long since gone away. The
only remaining global factories it queries against are for http(s)
and ws(s).

I want to clean up those remaining two global factories, so this CL
removes those functions and inlines the schemes into the pre-existing
lists of all other supported schemes.

Bug: 488166
Change-Id: I2ff34752a91a1c4eede18e271a90b6ed922314c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869398Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Matt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709203}
parent 6844dad7
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "build/build_config.h"
#include "components/autofill/content/browser/content_autofill_driver_factory.h" #include "components/autofill/content/browser/content_autofill_driver_factory.h"
#include "components/cdm/browser/cdm_message_filter_android.h" #include "components/cdm/browser/cdm_message_filter_android.h"
#include "components/cdm/browser/media_drm_storage_impl.h" #include "components/cdm/browser/media_drm_storage_impl.h"
...@@ -91,6 +92,7 @@ ...@@ -91,6 +92,7 @@
#include "mojo/public/cpp/bindings/pending_associated_receiver.h" #include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "net/android/network_library.h" #include "net/android/network_library.h"
#include "net/http/http_util.h" #include "net/http/http_util.h"
#include "net/net_buildflags.h"
#include "net/ssl/ssl_cert_request_info.h" #include "net/ssl/ssl_cert_request_info.h"
#include "net/ssl/ssl_info.h" #include "net/ssl/ssl_info.h"
#include "services/network/network_service.h" #include "services/network/network_service.h"
...@@ -413,10 +415,13 @@ bool AwContentBrowserClient::IsHandledURL(const GURL& url) { ...@@ -413,10 +415,13 @@ bool AwContentBrowserClient::IsHandledURL(const GURL& url) {
const std::string scheme = url.scheme(); const std::string scheme = url.scheme();
DCHECK_EQ(scheme, base::ToLowerASCII(scheme)); DCHECK_EQ(scheme, base::ToLowerASCII(scheme));
// See CreateJobFactory in aw_url_request_context_getter.cc for the
// list of protocols that are handled.
// TODO(mnaganov): Make this automatic.
static const char* const kProtocolList[] = { static const char* const kProtocolList[] = {
url::kHttpScheme,
url::kHttpsScheme,
#if BUILDFLAG(ENABLE_WEBSOCKETS)
url::kWsScheme,
url::kWssScheme,
#endif // BUILDFLAG(ENABLE_WEBSOCKETS)
url::kDataScheme, url::kDataScheme,
url::kBlobScheme, url::kBlobScheme,
url::kFileSystemScheme, url::kFileSystemScheme,
...@@ -428,11 +433,11 @@ bool AwContentBrowserClient::IsHandledURL(const GURL& url) { ...@@ -428,11 +433,11 @@ bool AwContentBrowserClient::IsHandledURL(const GURL& url) {
// even if access to file: scheme is not granted to the child process. // even if access to file: scheme is not granted to the child process.
return !IsAndroidSpecialFileUrl(url); return !IsAndroidSpecialFileUrl(url);
} }
for (size_t i = 0; i < base::size(kProtocolList); ++i) { for (const char* supported_protocol : kProtocolList) {
if (scheme == kProtocolList[i]) if (scheme == supported_protocol)
return true; return true;
} }
return net::URLRequest::IsHandledProtocol(scheme); return false;
} }
bool AwContentBrowserClient::ForceSniffingFileUrlsForHtml() { bool AwContentBrowserClient::ForceSniffingFileUrlsForHtml() {
......
...@@ -63,7 +63,6 @@ ...@@ -63,7 +63,6 @@
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "extensions/buildflags/buildflags.h" #include "extensions/buildflags/buildflags.h"
#include "net/ssl/client_cert_store.h" #include "net/ssl/client_cert_store.h"
#include "net/url_request/url_request.h"
#include "services/network/ignore_errors_cert_verifier.h" #include "services/network/ignore_errors_cert_verifier.h"
#include "services/network/network_service.h" #include "services/network/network_service.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
...@@ -340,6 +339,12 @@ ProfileIOData* ProfileIOData::FromResourceContext( ...@@ -340,6 +339,12 @@ ProfileIOData* ProfileIOData::FromResourceContext(
bool ProfileIOData::IsHandledProtocol(const std::string& scheme) { bool ProfileIOData::IsHandledProtocol(const std::string& scheme) {
DCHECK_EQ(scheme, base::ToLowerASCII(scheme)); DCHECK_EQ(scheme, base::ToLowerASCII(scheme));
static const char* const kProtocolList[] = { static const char* const kProtocolList[] = {
url::kHttpScheme,
url::kHttpsScheme,
#if BUILDFLAG(ENABLE_WEBSOCKETS)
url::kWsScheme,
url::kWssScheme,
#endif // BUILDFLAG(ENABLE_WEBSOCKETS)
url::kFileScheme, url::kFileScheme,
content::kChromeDevToolsScheme, content::kChromeDevToolsScheme,
dom_distiller::kDomDistillerScheme, dom_distiller::kDomDistillerScheme,
...@@ -362,11 +367,11 @@ bool ProfileIOData::IsHandledProtocol(const std::string& scheme) { ...@@ -362,11 +367,11 @@ bool ProfileIOData::IsHandledProtocol(const std::string& scheme) {
url::kFileSystemScheme, url::kFileSystemScheme,
chrome::kChromeSearchScheme, chrome::kChromeSearchScheme,
}; };
for (size_t i = 0; i < base::size(kProtocolList); ++i) { for (const char* supported_protocol : kProtocolList) {
if (scheme == kProtocolList[i]) if (scheme == supported_protocol)
return true; return true;
} }
return net::URLRequest::IsHandledProtocol(scheme); return false;
} }
// static // static
......
...@@ -33,11 +33,11 @@ ...@@ -33,11 +33,11 @@
#include "components/search_engines/template_url.h" #include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_client.h" #include "components/search_engines/template_url_service_client.h"
#include "net/url_request/url_request.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/omnibox_event.pb.h" #include "third_party/metrics_proto/omnibox_event.pb.h"
#include "ui/gfx/image/image_unittest_util.h" #include "ui/gfx/image/image_unittest_util.h"
#include "ui/gfx/image/image_util.h" #include "ui/gfx/image/image_util.h"
#include "url/url_constants.h"
static std::ostream& operator<<(std::ostream& os, static std::ostream& operator<<(std::ostream& os,
const AutocompleteResult::const_iterator& it) { const AutocompleteResult::const_iterator& it) {
...@@ -55,7 +55,8 @@ class TestingSchemeClassifier : public AutocompleteSchemeClassifier { ...@@ -55,7 +55,8 @@ class TestingSchemeClassifier : public AutocompleteSchemeClassifier {
metrics::OmniboxInputType GetInputTypeForScheme( metrics::OmniboxInputType GetInputTypeForScheme(
const std::string& scheme) const override { const std::string& scheme) const override {
return net::URLRequest::IsHandledProtocol(scheme) DCHECK_EQ(scheme, base::ToLowerASCII(scheme));
return (scheme == url::kHttpScheme || scheme == url::kHttpsScheme)
? metrics::OmniboxInputType::URL ? metrics::OmniboxInputType::URL
: metrics::OmniboxInputType::EMPTY; : metrics::OmniboxInputType::EMPTY;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "components/omnibox/browser/autocomplete_match.h" #include "components/omnibox/browser/autocomplete_match.h"
...@@ -24,11 +25,11 @@ ...@@ -24,11 +25,11 @@
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/variations/entropy_provider.h" #include "components/variations/entropy_provider.h"
#include "components/variations/variations_associated_data.h" #include "components/variations/variations_associated_data.h"
#include "net/url_request/url_request.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/omnibox_event.pb.h" #include "third_party/metrics_proto/omnibox_event.pb.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "url/url_constants.h"
using base::ASCIIToUTF16; using base::ASCIIToUTF16;
...@@ -38,7 +39,8 @@ class TestingSchemeClassifier : public AutocompleteSchemeClassifier { ...@@ -38,7 +39,8 @@ class TestingSchemeClassifier : public AutocompleteSchemeClassifier {
public: public:
metrics::OmniboxInputType GetInputTypeForScheme( metrics::OmniboxInputType GetInputTypeForScheme(
const std::string& scheme) const override { const std::string& scheme) const override {
if (net::URLRequest::IsHandledProtocol(scheme)) DCHECK_EQ(scheme, base::ToLowerASCII(scheme));
if (scheme == url::kHttpScheme || scheme == url::kHttpsScheme)
return metrics::OmniboxInputType::URL; return metrics::OmniboxInputType::URL;
return metrics::OmniboxInputType::EMPTY; return metrics::OmniboxInputType::EMPTY;
} }
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include <string> #include <string>
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "components/omnibox/browser/test_scheme_classifier.h" #include "components/omnibox/browser/test_scheme_classifier.h"
#include "net/url_request/url_request.h"
#include "third_party/metrics_proto/omnibox_input_type.pb.h" #include "third_party/metrics_proto/omnibox_input_type.pb.h"
#include "url/url_constants.h" #include "url/url_constants.h"
...@@ -18,17 +18,20 @@ TestSchemeClassifier::~TestSchemeClassifier() {} ...@@ -18,17 +18,20 @@ TestSchemeClassifier::~TestSchemeClassifier() {}
metrics::OmniboxInputType TestSchemeClassifier::GetInputTypeForScheme( metrics::OmniboxInputType TestSchemeClassifier::GetInputTypeForScheme(
const std::string& scheme) const { const std::string& scheme) const {
DCHECK_EQ(scheme, base::ToLowerASCII(scheme));
// This doesn't check the preference but check some chrome-ish schemes. // This doesn't check the preference but check some chrome-ish schemes.
const char* kKnownURLSchemes[] = { const char* kKnownURLSchemes[] = {
url::kFileScheme, url::kAboutScheme, url::kFtpScheme, url::kBlobScheme, url::kHttpScheme, url::kHttpsScheme, url::kWsScheme,
url::kFileSystemScheme, "view-source", "javascript", "chrome", "chrome-ui", url::kWssScheme, url::kFileScheme, url::kAboutScheme,
url::kFtpScheme, url::kBlobScheme, url::kFileSystemScheme,
"view-source", "javascript", "chrome",
"chrome-ui",
}; };
for (size_t i = 0; i < base::size(kKnownURLSchemes); ++i) { for (const char* known_scheme : kKnownURLSchemes) {
if (scheme == kKnownURLSchemes[i]) if (scheme == known_scheme)
return metrics::OmniboxInputType::URL; return metrics::OmniboxInputType::URL;
} }
if (net::URLRequest::IsHandledProtocol(scheme))
return metrics::OmniboxInputType::URL;
return metrics::OmniboxInputType::EMPTY; return metrics::OmniboxInputType::EMPTY;
} }
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "net/base/filename_util.h" #include "net/base/filename_util.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
#include "net/url_request/url_request.h" #include "net/net_buildflags.h"
#include "services/network/public/cpp/resource_request_body.h" #include "services/network/public/cpp/resource_request_body.h"
#include "storage/browser/file_system/file_permission_policy.h" #include "storage/browser/file_system/file_permission_policy.h"
#include "storage/browser/file_system/file_system_context.h" #include "storage/browser/file_system/file_system_context.h"
...@@ -525,6 +525,10 @@ ChildProcessSecurityPolicyImpl::ChildProcessSecurityPolicyImpl() { ...@@ -525,6 +525,10 @@ ChildProcessSecurityPolicyImpl::ChildProcessSecurityPolicyImpl() {
// We know about these schemes and believe them to be safe. // We know about these schemes and believe them to be safe.
RegisterWebSafeScheme(url::kHttpScheme); RegisterWebSafeScheme(url::kHttpScheme);
RegisterWebSafeScheme(url::kHttpsScheme); RegisterWebSafeScheme(url::kHttpsScheme);
#if BUILDFLAG(ENABLE_WEBSOCKETS)
RegisterWebSafeScheme(url::kWsScheme);
RegisterWebSafeScheme(url::kWssScheme);
#endif // BUILDFLAG(ENABLE_WEBSOCKETS)
RegisterWebSafeScheme(url::kFtpScheme); RegisterWebSafeScheme(url::kFtpScheme);
RegisterWebSafeScheme(url::kDataScheme); RegisterWebSafeScheme(url::kDataScheme);
RegisterWebSafeScheme("feed"); RegisterWebSafeScheme("feed");
...@@ -930,8 +934,7 @@ bool ChildProcessSecurityPolicyImpl::CanRequestURL( ...@@ -930,8 +934,7 @@ bool ChildProcessSecurityPolicyImpl::CanRequestURL(
} }
// Also allow URLs destined for ShellExecute and not the browser itself. // Also allow URLs destined for ShellExecute and not the browser itself.
return !GetContentClient()->browser()->IsHandledURL(url) && return !GetContentClient()->browser()->IsHandledURL(url);
!net::URLRequest::IsHandledURL(url);
} }
bool ChildProcessSecurityPolicyImpl::CanRedirectToURL(const GURL& url) { bool ChildProcessSecurityPolicyImpl::CanRedirectToURL(const GURL& url) {
......
...@@ -48,8 +48,6 @@ ...@@ -48,8 +48,6 @@
#include "device/bluetooth/public/mojom/test/fake_bluetooth.mojom.h" #include "device/bluetooth/public/mojom/test/fake_bluetooth.mojom.h"
#include "media/mojo/buildflags.h" #include "media/mojo/buildflags.h"
#include "net/ssl/client_cert_identity.h" #include "net/ssl/client_cert_identity.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context_getter.h"
#include "services/network/public/mojom/network_service.mojom.h" #include "services/network/public/mojom/network_service.mojom.h"
#include "services/service_manager/public/cpp/manifest.h" #include "services/service_manager/public/cpp/manifest.h"
#include "services/service_manager/public/cpp/manifest_builder.h" #include "services/service_manager/public/cpp/manifest_builder.h"
...@@ -256,21 +254,17 @@ ShellContentBrowserClient::CreateBrowserMainParts( ...@@ -256,21 +254,17 @@ ShellContentBrowserClient::CreateBrowserMainParts(
bool ShellContentBrowserClient::IsHandledURL(const GURL& url) { bool ShellContentBrowserClient::IsHandledURL(const GURL& url) {
if (!url.is_valid()) if (!url.is_valid())
return false; return false;
// Keep in sync with ProtocolHandlers added by
// ShellURLRequestContextGetter::GetURLRequestContext().
static const char* const kProtocolList[] = { static const char* const kProtocolList[] = {
url::kBlobScheme, url::kHttpScheme, url::kHttpsScheme, url::kWsScheme,
url::kFileSystemScheme, url::kWssScheme, url::kBlobScheme, url::kFileSystemScheme,
kChromeUIScheme, kChromeUIScheme, kChromeDevToolsScheme, url::kDataScheme,
kChromeDevToolsScheme,
url::kDataScheme,
url::kFileScheme, url::kFileScheme,
}; };
for (size_t i = 0; i < base::size(kProtocolList); ++i) { for (const char* supported_protocol : kProtocolList) {
if (url.scheme() == kProtocolList[i]) if (url.scheme_piece() == supported_protocol)
return true; return true;
} }
return net::URLRequest::IsHandledProtocol(url.scheme()); return false;
} }
void ShellContentBrowserClient::BindInterfaceRequestFromFrame( void ShellContentBrowserClient::BindInterfaceRequestFromFrame(
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
#import "ios/net/url_scheme_util.h" #import "ios/net/url_scheme_util.h"
#include "net/url_request/url_request.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "url/url_constants.h" #include "url/url_constants.h"
...@@ -40,13 +39,9 @@ bool IsURLNtp(const GURL& url) { ...@@ -40,13 +39,9 @@ bool IsURLNtp(const GURL& url) {
bool IsHandledProtocol(const std::string& scheme) { bool IsHandledProtocol(const std::string& scheme) {
DCHECK_EQ(scheme, base::ToLowerASCII(scheme)); DCHECK_EQ(scheme, base::ToLowerASCII(scheme));
if (scheme == url::kAboutScheme) return (scheme == url::kHttpScheme || scheme == url::kHttpsScheme ||
return true; scheme == url::kAboutScheme || scheme == url::kDataScheme ||
if (scheme == url::kDataScheme) scheme == kChromeUIScheme);
return true;
if (scheme == kChromeUIScheme)
return true;
return net::URLRequest::IsHandledProtocol(scheme);
} }
@implementation ChromeAppConstants { @implementation ChromeAppConstants {
......
...@@ -442,21 +442,6 @@ void URLRequest::SetDefaultCookiePolicyToBlock() { ...@@ -442,21 +442,6 @@ void URLRequest::SetDefaultCookiePolicyToBlock() {
g_default_can_use_cookies = false; g_default_can_use_cookies = false;
} }
// static
bool URLRequest::IsHandledProtocol(const std::string& scheme) {
return URLRequestJobManager::SupportsScheme(scheme);
}
// static
bool URLRequest::IsHandledURL(const GURL& url) {
if (!url.is_valid()) {
// We handle error cases.
return true;
}
return IsHandledProtocol(url.scheme());
}
void URLRequest::set_site_for_cookies(const GURL& site_for_cookies) { void URLRequest::set_site_for_cookies(const GURL& site_for_cookies) {
DCHECK(!is_pending_); DCHECK(!is_pending_);
site_for_cookies_ = site_for_cookies; site_for_cookies_ = site_for_cookies;
......
...@@ -247,17 +247,6 @@ class NET_EXPORT URLRequest : public base::SupportsUserData { ...@@ -247,17 +247,6 @@ class NET_EXPORT URLRequest : public base::SupportsUserData {
// started. Once it was set to block all cookies, it cannot be changed back. // started. Once it was set to block all cookies, it cannot be changed back.
static void SetDefaultCookiePolicyToBlock(); static void SetDefaultCookiePolicyToBlock();
// Returns true if the scheme can be handled by URLRequest. False otherwise.
static bool IsHandledProtocol(const std::string& scheme);
// Returns true if the url can be handled by URLRequest. False otherwise.
// The function returns true for invalid urls because URLRequest knows how
// to handle those.
// NOTE: This will also return true for URLs that are handled by
// ProtocolFactories that only work for requests that are scoped to a
// Profile.
static bool IsHandledURL(const GURL& url);
// The original url is the url used to initialize the request, and it may // The original url is the url used to initialize the request, and it may
// differ from the url if the request was redirected. // differ from the url if the request was redirected.
const GURL& original_url() const { return url_chain_.front(); } const GURL& original_url() const { return url_chain_.front(); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment