Commit 08d43079 authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Make net::DataProtocolHandler a test-only class.

It was only being used on iOS, but the system handles
wkWebView-initiated data URL requests there, and they aren't needed for
internal requests, so this CL also removes all of iOS's uses of the
class.

I'll remove DataProtocolHander and URLRequestDataJob in followup CLs
that make sure we don't lose test coverage of the data URL parsing code,
which is still in use.

Change-Id: I5e6789b36c457a7ab06f7a8e0c1cf1dcee2929b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1868837
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707574}
parent 060e8b40
......@@ -22,6 +22,7 @@ namespace net {
class CookieStore;
class HttpNetworkSession;
class HttpTransactionFactory;
class URLRequestJobFactoryImpl;
} // namespace net
class ChromeBrowserStateImplIOData : public ChromeBrowserStateIOData {
......@@ -129,7 +130,7 @@ class ChromeBrowserStateImplIOData : public ChromeBrowserStateIOData {
mutable std::unique_ptr<net::CookieStore> main_cookie_store_;
mutable std::unique_ptr<net::URLRequestJobFactory> main_job_factory_;
mutable std::unique_ptr<net::URLRequestJobFactoryImpl> main_job_factory_;
// Parameters needed for isolated apps.
base::FilePath profile_path_;
......
......@@ -226,12 +226,9 @@ void ChromeBrowserStateImplIOData::InitializeInternal(
std::move(main_backend));
main_context->set_http_transaction_factory(main_http_factory_.get());
std::unique_ptr<net::URLRequestJobFactoryImpl> main_job_factory(
new net::URLRequestJobFactoryImpl());
InstallProtocolHandlers(main_job_factory.get(), protocol_handlers);
main_job_factory_ = std::make_unique<net::URLRequestJobFactoryImpl>();
InstallProtocolHandlers(main_job_factory_.get(), protocol_handlers);
main_job_factory_ = SetUpJobFactoryDefaults(std::move(main_job_factory),
main_context->network_delegate());
main_context->set_job_factory(main_job_factory_.get());
lazy_params_.reset();
......
......@@ -166,10 +166,6 @@ class ChromeBrowserStateIOData {
void InitializeOnUIThread(ios::ChromeBrowserState* browser_state);
void ApplyProfileParamsToContext(net::URLRequestContext* context) const;
std::unique_ptr<net::URLRequestJobFactory> SetUpJobFactoryDefaults(
std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory,
net::NetworkDelegate* network_delegate) const;
// Called when the ChromeBrowserState is destroyed. |context_getters| must
// include all URLRequestContextGetters that refer to the
// ChromeBrowserStateIOData's URLRequestContexts. Triggers destruction of the
......
......@@ -57,7 +57,6 @@
#include "net/proxy_resolution/proxy_config_service_fixed.h"
#include "net/proxy_resolution/proxy_resolution_service.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/data_protocol_handler.h"
#include "net/url_request/report_sender.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
......@@ -374,17 +373,6 @@ void ChromeBrowserStateIOData::ApplyProfileParamsToContext(
context->set_http_user_agent_settings(chrome_http_user_agent_settings_.get());
}
std::unique_ptr<net::URLRequestJobFactory>
ChromeBrowserStateIOData::SetUpJobFactoryDefaults(
std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory,
net::NetworkDelegate* network_delegate) const {
bool set_protocol = job_factory->SetProtocolHandler(
url::kDataScheme, std::make_unique<net::DataProtocolHandler>());
DCHECK(set_protocol);
return job_factory;
}
void ChromeBrowserStateIOData::ShutdownOnUIThread(
std::unique_ptr<IOSChromeURLRequestContextGetterVector> context_getters) {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
......
......@@ -24,6 +24,7 @@ namespace net {
class CookieStore;
class HttpNetworkSession;
class HttpTransactionFactory;
class URLRequestJobFactoryImpl;
} // namespace net
// OffTheRecordChromeBrowserState owns a
......@@ -101,7 +102,7 @@ class OffTheRecordChromeBrowserStateIOData : public ChromeBrowserStateIOData {
mutable std::unique_ptr<net::CookieStore> main_cookie_store_;
mutable std::unique_ptr<net::URLRequestJobFactory> main_job_factory_;
mutable std::unique_ptr<net::URLRequestJobFactoryImpl> main_job_factory_;
// Server bound certificates and cookies are persisted to the disk on iOS.
base::FilePath cookie_path_;
......
......@@ -186,11 +186,8 @@ void OffTheRecordChromeBrowserStateIOData::InitializeInternal(
main_context->set_http_transaction_factory(main_http_factory_.get());
std::unique_ptr<net::URLRequestJobFactoryImpl> main_job_factory(
new net::URLRequestJobFactoryImpl());
main_job_factory_ = std::make_unique<net::URLRequestJobFactoryImpl>();
InstallProtocolHandlers(main_job_factory.get(), protocol_handlers);
main_job_factory_ = SetUpJobFactoryDefaults(std::move(main_job_factory),
main_context->network_delegate());
InstallProtocolHandlers(main_job_factory_.get(), protocol_handlers);
main_context->set_job_factory(main_job_factory_.get());
}
......@@ -60,7 +60,6 @@
#include "net/socket/tcp_client_socket.h"
#include "net/spdy/spdy_session.h"
#include "net/ssl/ssl_config_service_defaults.h"
#include "net/url_request/data_protocol_handler.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
......@@ -360,11 +359,6 @@ net::URLRequestContext* IOSIOThread::ConstructSystemRequestContext(
net::URLRequestJobFactoryImpl* system_job_factory =
new net::URLRequestJobFactoryImpl();
// Data URLs are always loaded through the system request context on iOS
// (due to UIWebView limitations).
bool set_protocol = system_job_factory->SetProtocolHandler(
url::kDataScheme, std::make_unique<net::DataProtocolHandler>());
DCHECK(set_protocol);
globals->system_url_request_job_factory.reset(system_job_factory);
context->set_job_factory(globals->system_url_request_job_factory.get());
......
......@@ -73,25 +73,6 @@ NSURLResponse* GetNSURLResponseForRequest(URLRequest* request) {
NSURL* url = NSURLWithGURL(request->url());
DCHECK(url);
// The default iOS stack returns a NSURLResponse when the request has a data
// scheme, and a NSHTTPURLResponse otherwise.
if (request->url().SchemeIs("data")) {
std::string mt;
request->GetMimeType(&mt);
NSString* mime_type = base::SysUTF8ToNSString(mt);
DCHECK(mime_type);
std::string cs;
request->GetCharset(&cs);
NSString* charset = base::SysUTF8ToNSString(cs);
DCHECK(charset);
// The default iOS stack computes the length of the decoded string. If we
// wanted to do that we would have to decode the string now. However, using
// the unknown length (-1) seems to be working.
return [[NSURLResponse alloc] initWithURL:url
MIMEType:mime_type
expectedContentLength:-1
textEncodingName:charset];
} else {
// Iterate over all the headers and copy them.
bool has_content_type_header = false;
NSMutableDictionary* header_fields = [NSMutableDictionary dictionary];
......@@ -180,7 +161,6 @@ NSURLResponse* GetNSURLResponseForRequest(URLRequest* request) {
statusCode:request->GetResponseCode()
HTTPVersion:version_string
headerFields:header_fields];
}
}
void CopyHttpHeaders(NSURLRequest* in_request, URLRequest* out_request) {
......
......@@ -16,7 +16,6 @@
#include "net/base/upload_bytes_element_reader.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/data_protocol_handler.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_job_factory.h"
......@@ -44,8 +43,6 @@ namespace net {
namespace {
const char* kTextHtml = "text/html";
const char* kTextPlain = "text/plain";
const char* kAscii = "US-ASCII";
class HeadersURLRequestJob : public URLRequestJob {
public:
......@@ -116,40 +113,9 @@ class ProtocolHandlerUtilTest : public PlatformTest,
// Ownership of the protocol handlers is transferred to the factory.
job_factory_.SetProtocolHandler("http",
base::WrapUnique(new NetProtocolHandler));
job_factory_.SetProtocolHandler("data",
base::WrapUnique(new DataProtocolHandler));
request_context_->set_job_factory(&job_factory_);
}
NSURLResponse* BuildDataURLResponse(const std::string& mime_type,
const std::string& encoding,
const std::string& content) {
// Build an URL in the form "data:<mime_type>;charset=<encoding>,<content>"
// The ';' is removed if mime_type or charset is empty.
std::string url_string = std::string("data:") + mime_type;
if (!encoding.empty())
url_string += ";charset=" + encoding;
url_string += ",";
GURL url(url_string);
std::unique_ptr<URLRequest> request(
request_context_->CreateRequest(url, DEFAULT_PRIORITY, this));
request->Start();
base::RunLoop loop;
loop.RunUntilIdle();
return GetNSURLResponseForRequest(request.get());
}
void CheckDataResponse(NSURLResponse* response,
const std::string& mime_type,
const std::string& encoding) {
EXPECT_NSEQ(base::SysUTF8ToNSString(mime_type), [response MIMEType]);
EXPECT_NSEQ(base::SysUTF8ToNSString(encoding), [response textEncodingName]);
// The response class must be NSURLResponse (and not NSHTTPURLResponse) when
// the scheme is "data".
EXPECT_TRUE([response isMemberOfClass:[NSURLResponse class]]);
}
void OnResponseStarted(URLRequest* request, int net_error) override {}
void OnReadCompleted(URLRequest* request, int bytes_read) override {}
......@@ -161,16 +127,6 @@ class ProtocolHandlerUtilTest : public PlatformTest,
} // namespace
TEST_F(ProtocolHandlerUtilTest, GetResponseDataSchemeTest) {
NSURLResponse* response;
// MIME type and charset are correctly carried over.
response = BuildDataURLResponse("?mime=type'", "$(charset-*", "content");
CheckDataResponse(response, "?mime=type'", "$(charset-*");
// Missing values are treated as default values.
response = BuildDataURLResponse("", "", "content");
CheckDataResponse(response, kTextPlain, kAscii);
}
TEST_F(ProtocolHandlerUtilTest, GetResponseHttpTest) {
// Create a request.
GURL url(std::string("http://url"));
......
......@@ -33,7 +33,6 @@
#include "net/proxy_resolution/proxy_resolution_service.h"
#include "net/ssl/ssl_config_service_defaults.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/data_protocol_handler.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_storage.h"
......@@ -145,10 +144,6 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory(
new net::URLRequestJobFactoryImpl());
bool set_protocol = job_factory->SetProtocolHandler(
"data", base::WrapUnique(new net::DataProtocolHandler));
DCHECK(set_protocol);
storage_->set_job_factory(std::move(job_factory));
}
......
......@@ -32,7 +32,6 @@
#include "net/proxy_resolution/proxy_resolution_service.h"
#include "net/ssl/ssl_config_service_defaults.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/data_protocol_handler.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_storage.h"
......@@ -155,9 +154,6 @@ net::URLRequestContext* WebViewURLRequestContextGetter::GetURLRequestContext() {
std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory(
new net::URLRequestJobFactoryImpl());
bool set_protocol = job_factory->SetProtocolHandler(
"data", std::make_unique<net::DataProtocolHandler>());
DCHECK(set_protocol);
storage_->set_job_factory(std::move(job_factory));
}
......
......@@ -1791,8 +1791,6 @@ component("net") {
"third_party/quiche/src/spdy/platform/api/spdy_string_piece.h",
"third_party/quiche/src/spdy/platform/api/spdy_string_utils.h",
"third_party/quiche/src/spdy/platform/api/spdy_unsafe_arena.h",
"url_request/data_protocol_handler.cc",
"url_request/data_protocol_handler.h",
"url_request/redirect_info.cc",
"url_request/redirect_info.h",
"url_request/redirect_util.cc",
......@@ -2853,6 +2851,8 @@ static_library("test_support") {
"test/url_request/url_request_mock_data_job.h",
"test/url_request/url_request_slow_download_job.cc",
"test/url_request/url_request_slow_download_job.h",
"url_request/data_protocol_handler.cc",
"url_request/data_protocol_handler.h",
"url_request/test_url_fetcher_factory.cc",
"url_request/test_url_fetcher_factory.h",
"url_request/url_request_test_util.cc",
......
......@@ -15,8 +15,8 @@ namespace net {
class URLRequestJob;
// Implements a ProtocolHandler for Data jobs.
class NET_EXPORT DataProtocolHandler
: public URLRequestJobFactory::ProtocolHandler {
// TODO(mmenke): This class is now only used in tests. Remove it.
class DataProtocolHandler : public URLRequestJobFactory::ProtocolHandler {
public:
DataProtocolHandler();
URLRequestJob* MaybeCreateJob(
......
......@@ -38,7 +38,6 @@
#include "net/nqe/network_quality_estimator.h"
#include "net/quic/quic_stream_factory.h"
#include "net/ssl/ssl_config_service_defaults.h"
#include "net/url_request/data_protocol_handler.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_storage.h"
......@@ -610,17 +609,13 @@ std::unique_ptr<URLRequestContext> URLRequestContextBuilder::Build() {
URLRequestJobFactoryImpl* job_factory = new URLRequestJobFactoryImpl;
// Adds caller-provided protocol handlers first so that these handlers are
// used over data/file/ftp handlers below.
// used over the ftp handler below.
for (auto& scheme_handler : protocol_handlers_) {
job_factory->SetProtocolHandler(scheme_handler.first,
std::move(scheme_handler.second));
}
protocol_handlers_.clear();
if (data_enabled_)
job_factory->SetProtocolHandler(url::kDataScheme,
std::make_unique<DataProtocolHandler>());
#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
if (ftp_enabled_) {
storage->set_ftp_auth_cache(std::make_unique<FtpAuthCache>());
......
......@@ -195,9 +195,6 @@ class NET_EXPORT URLRequestContextBuilder {
void set_http_user_agent_settings(
std::unique_ptr<HttpUserAgentSettings> http_user_agent_settings);
// Control support for data:// requests. By default it's disabled.
void set_data_enabled(bool enable) { data_enabled_ = enable; }
#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
// Control support for ftp:// requests. By default it's disabled.
void set_ftp_enabled(bool enable) { ftp_enabled_ = enable; }
......@@ -357,8 +354,6 @@ class NET_EXPORT URLRequestContextBuilder {
std::string user_agent_;
std::unique_ptr<HttpUserAgentSettings> http_user_agent_settings_;
// Include support for data:// requests.
bool data_enabled_ = false;
#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
// Include support for ftp:// requests.
bool ftp_enabled_ = false;
......
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