Skip to content

Commit

Permalink
Remove file URL support from net/.
Browse files Browse the repository at this point in the history
This CL deletes FileProtocolHandler from net/, makes URLRequestFileJob
a test-only class (HTTP request mocks subclass it), and deletes
URLRequestFileDirJob and NetworkDelegate::CanAccessFile. File URLs are
now handled outside of the network service, so this code is no longer
being used.

This CL leaves in place net/directory_* files, which are used by the
new code (And should probably be moved somewhere more appropriate for
their new use, in another CL), and the network build option
disable_file_support, which should also be cleaned up when moving
those files.

TBR=seantopping@chromium.org

Bug: 934009
Change-Id: I2ef493849847adbb340a364de12ea41e91870b6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1787187
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Eugene But <eugenebut@chromium.org>
Reviewed-by: Eric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695192}
  • Loading branch information
Matt Menke authored and Commit Bot committed Sep 10, 2019
1 parent 9d0e995 commit 27e91ae
Show file tree
Hide file tree
Showing 47 changed files with 159 additions and 1,913 deletions.
1 change: 0 additions & 1 deletion chrome/browser/extensions/extension_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
#include "extensions/common/file_util.h"
#include "extensions/common/switches.h"
#include "extensions/common/value_builder.h"
#include "net/url_request/url_request_file_job.h"

#if defined(OS_CHROMEOS)
#include "chromeos/constants/chromeos_switches.h"
Expand Down
14 changes: 0 additions & 14 deletions chromecast/browser/cast_network_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,6 @@ bool CastNetworkDelegate::IsWhitelisted(const GURL& gurl,
gurl, session_id, render_process_id, render_frame_id, for_device_auth);
}

bool CastNetworkDelegate::OnCanAccessFile(
const net::URLRequest& request,
const base::FilePath& original_path,
const base::FilePath& absolute_path) const {
if (base::CommandLine::ForCurrentProcess()->
HasSwitch(switches::kEnableLocalFileAccesses)) {
return true;
}

LOG(WARNING) << "Could not access file " << original_path.value()
<< ". All file accesses are forbidden.";
return false;
}

int CastNetworkDelegate::OnBeforeURLRequest(
net::URLRequest* request,
net::CompletionOnceCallback callback,
Expand Down
3 changes: 0 additions & 3 deletions chromecast/browser/cast_network_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ class CastNetworkDelegate : public net::NetworkDelegateImpl {

private:
// net::NetworkDelegate implementation:
bool OnCanAccessFile(const net::URLRequest& request,
const base::FilePath& original_path,
const base::FilePath& absolute_path) const override;
int OnBeforeURLRequest(net::URLRequest* request,
net::CompletionOnceCallback callback,
GURL* new_url) override;
Expand Down
6 changes: 0 additions & 6 deletions components/cronet/cronet_url_request_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@ class BasicNetworkDelegate : public net::NetworkDelegateImpl {
return false;
}

bool OnCanAccessFile(const net::URLRequest& request,
const base::FilePath& original_path,
const base::FilePath& absolute_path) const override {
return false;
}

DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate);
};

Expand Down
7 changes: 0 additions & 7 deletions ios/chrome/browser/net/ios_chrome_network_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,6 @@ bool IOSChromeNetworkDelegate::OnCanSetCookie(
request.url(), request.site_for_cookies());
}

bool IOSChromeNetworkDelegate::OnCanAccessFile(
const net::URLRequest& request,
const base::FilePath& original_path,
const base::FilePath& absolute_path) const {
return true;
}

bool IOSChromeNetworkDelegate::OnForcePrivacyMode(
const GURL& url,
const GURL& site_for_cookies,
Expand Down
3 changes: 0 additions & 3 deletions ios/chrome/browser/net/ios_chrome_network_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ class IOSChromeNetworkDelegate : public net::NetworkDelegateImpl {
const net::CanonicalCookie& cookie,
net::CookieOptions* options,
bool allowed_from_caller) override;
bool OnCanAccessFile(const net::URLRequest& request,
const base::FilePath& original_path,
const base::FilePath& absolute_path) const override;
bool OnForcePrivacyMode(
const GURL& url,
const GURL& site_for_cookies,
Expand Down
1 change: 0 additions & 1 deletion ios/components/io_thread/ios_io_thread.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
#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/file_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"
Expand Down
2 changes: 0 additions & 2 deletions ios/web/shell/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ source_set("shell") {
"shell_browser_state.mm",
"shell_main_delegate.h",
"shell_main_delegate.mm",
"shell_network_delegate.cc",
"shell_network_delegate.h",
"shell_url_request_context_getter.h",
"shell_url_request_context_getter.mm",
"shell_web_client.h",
Expand Down
24 changes: 0 additions & 24 deletions ios/web/shell/shell_network_delegate.cc

This file was deleted.

30 changes: 0 additions & 30 deletions ios/web/shell/shell_network_delegate.h

This file was deleted.

4 changes: 2 additions & 2 deletions ios/web/shell/shell_url_request_context_getter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "base/task/post_task.h"
#import "ios/net/cookies/cookie_store_ios_persistent.h"
#import "ios/web/public/web_client.h"
#include "ios/web/shell/shell_network_delegate.h"
#include "net/base/cache_type.h"
#include "net/base/network_delegate_impl.h"
#include "net/cert/cert_verifier.h"
#include "net/cert/ct_policy_enforcer.h"
#include "net/cert/multi_log_ct_verifier.h"
Expand Down Expand Up @@ -63,7 +63,7 @@
url_request_context_.reset(new net::URLRequestContext());
url_request_context_->set_net_log(net_log_.get());
DCHECK(!network_delegate_.get());
network_delegate_.reset(new ShellNetworkDelegate);
network_delegate_ = std::make_unique<net::NetworkDelegateImpl>();
url_request_context_->set_network_delegate(network_delegate_.get());

storage_.reset(
Expand Down
2 changes: 0 additions & 2 deletions ios/web_view/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ ios_web_view_sources = [
"internal/web_view_global_state_util.mm",
"internal/web_view_java_script_dialog_presenter.h",
"internal/web_view_java_script_dialog_presenter.mm",
"internal/web_view_network_delegate.h",
"internal/web_view_network_delegate.mm",
"internal/web_view_url_request_context_getter.h",
"internal/web_view_url_request_context_getter.mm",
"internal/web_view_web_client.h",
Expand Down
4 changes: 2 additions & 2 deletions ios/web_view/internal/app/web_view_io_thread.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "ios/web_view/internal/app/web_view_io_thread.h"

#include "ios/web_view/internal/web_view_network_delegate.h"
#include "net/base/network_delegate_impl.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
Expand All @@ -19,7 +19,7 @@

std::unique_ptr<net::NetworkDelegate>
WebViewIOThread::CreateSystemNetworkDelegate() {
return std::make_unique<ios_web_view::WebViewNetworkDelegate>();
return std::make_unique<net::NetworkDelegateImpl>();
}

std::string WebViewIOThread::GetChannelString() const {
Expand Down
30 changes: 0 additions & 30 deletions ios/web_view/internal/web_view_network_delegate.h

This file was deleted.

26 changes: 0 additions & 26 deletions ios/web_view/internal/web_view_network_delegate.mm

This file was deleted.

4 changes: 2 additions & 2 deletions ios/web_view/internal/web_view_url_request_context_getter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include "base/task/post_task.h"
#import "ios/net/cookies/cookie_store_ios_persistent.h"
#import "ios/web/public/web_client.h"
#include "ios/web_view/internal/web_view_network_delegate.h"
#include "net/base/cache_type.h"
#include "net/base/network_delegate_impl.h"
#include "net/cert/cert_verifier.h"
#include "net/cert/ct_policy_enforcer.h"
#include "net/cert/multi_log_ct_verifier.h"
Expand Down Expand Up @@ -68,7 +68,7 @@
url_request_context_.reset(new net::URLRequestContext());
url_request_context_->set_net_log(net_log_);
DCHECK(!network_delegate_.get());
network_delegate_ = std::make_unique<WebViewNetworkDelegate>();
network_delegate_ = std::make_unique<net::NetworkDelegateImpl>();
url_request_context_->set_network_delegate(network_delegate_.get());

storage_.reset(
Expand Down
20 changes: 5 additions & 15 deletions net/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2152,12 +2152,6 @@ component("net") {
"base/directory_lister.h",
"base/directory_listing.cc",
"base/directory_listing.h",
"url_request/file_protocol_handler.cc",
"url_request/file_protocol_handler.h",
"url_request/url_request_file_dir_job.cc",
"url_request/url_request_file_dir_job.h",
"url_request/url_request_file_job.cc",
"url_request/url_request_file_job.h",
]
}

Expand Down Expand Up @@ -2939,6 +2933,8 @@ static_library("test_support") {
sources += [
"test/url_request/url_request_mock_http_job.cc",
"test/url_request/url_request_mock_http_job.h",
"test/url_request/url_request_test_job_backed_by_file.cc",
"test/url_request/url_request_test_job_backed_by_file.h",
"url_request/test_url_request_interceptor.cc",
"url_request/test_url_request_interceptor.h",
]
Expand Down Expand Up @@ -4063,7 +4059,6 @@ bundle_data("net_unittests_bundle_data") {
"data/url_request_unittest/expect-ct-header-preload.html.mock-http-headers",
"data/url_request_unittest/expect-ct-header.html",
"data/url_request_unittest/expect-ct-header.html.mock-http-headers",
"data/url_request_unittest/filedir-sentinel",
"data/url_request_unittest/gzip-encoded",
"data/url_request_unittest/gzip-encoded.mock-http-headers",
"data/url_request_unittest/hsts-headers.html",
Expand Down Expand Up @@ -5063,8 +5058,6 @@ test("net_unittests") {
"base/chunked_upload_data_stream_unittest.cc",
"base/data_url_unittest.cc",
"base/datagram_buffer_unittest.cc",
"base/directory_lister_unittest.cc",
"base/directory_listing_unittest.cc",
"base/elements_upload_data_stream_unittest.cc",
"base/escape_unittest.cc",
"base/expiring_cache_unittest.cc",
Expand Down Expand Up @@ -5677,8 +5670,6 @@ test("net_unittests") {
"url_request/url_request_context_builder_unittest.cc",
"url_request/url_request_context_unittest.cc",
"url_request/url_request_data_job_unittest.cc",
"url_request/url_request_file_dir_job_unittest.cc",
"url_request/url_request_file_job_unittest.cc",
"url_request/url_request_filter_unittest.cc",
"url_request/url_request_ftp_job_unittest.cc",
"url_request/url_request_http_job_unittest.cc",
Expand Down Expand Up @@ -5975,12 +5966,11 @@ test("net_unittests") {
]
}

if (disable_file_support) {
sources -= [
if (!disable_file_support) {
sources += [
"base/directory_lister_unittest.cc",
"base/directory_listing_unittest.cc",
"url_request/url_request_file_dir_job_unittest.cc",
"url_request/url_request_file_job_unittest.cc",
"test/url_request/url_request_test_job_backed_by_file_unittest.cc",
]
}

Expand Down
14 changes: 0 additions & 14 deletions net/base/layered_network_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,6 @@ bool LayeredNetworkDelegate::OnCanSetCookieInternal(
return allowed_from_caller;
}

bool LayeredNetworkDelegate::OnCanAccessFile(
const URLRequest& request,
const base::FilePath& original_path,
const base::FilePath& absolute_path) const {
OnCanAccessFileInternal(request, original_path, absolute_path);
return nested_network_delegate_->CanAccessFile(request, original_path,
absolute_path);
}

void LayeredNetworkDelegate::OnCanAccessFileInternal(
const URLRequest& request,
const base::FilePath& original_path,
const base::FilePath& absolute_path) const {}

bool LayeredNetworkDelegate::OnForcePrivacyMode(
const GURL& url,
const GURL& site_for_cookies,
Expand Down
12 changes: 0 additions & 12 deletions net/base/layered_network_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@

class GURL;

namespace base {
class FilePath;
}

namespace net {

class CookieOptions;
Expand Down Expand Up @@ -86,9 +82,6 @@ class NET_EXPORT LayeredNetworkDelegate : public NetworkDelegate {
const net::CanonicalCookie& cookie,
CookieOptions* options,
bool allowed_from_caller) final;
bool OnCanAccessFile(const URLRequest& request,
const base::FilePath& original_path,
const base::FilePath& absolute_path) const final;
bool OnForcePrivacyMode(
const GURL& url,
const GURL& site_for_cookies,
Expand Down Expand Up @@ -165,11 +158,6 @@ class NET_EXPORT LayeredNetworkDelegate : public NetworkDelegate {
const AuthChallengeInfo& auth_info,
AuthCredentials* credentials);

virtual void OnCanAccessFileInternal(
const URLRequest& request,
const base::FilePath& original_path,
const base::FilePath& absolute_path) const;

// If this returns false, it short circuits the corresponding call in any
// nested NetworkDelegates.
virtual bool OnForcePrivacyModeInternal(
Expand Down
Loading

0 comments on commit 27e91ae

Please sign in to comment.