[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/net/chrome_network_delegate.h" |
| 6 | |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 7 | #include <stddef.h> |
[email protected] | eac11e1 | 2013-03-19 22:04:32 | [diff] [blame] | 8 | #include <stdlib.h> |
| 9 | |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 12 | #include "base/base_paths.h" |
mkwst | 0513c9d | 2015-04-01 05:53:15 | [diff] [blame] | 13 | #include "base/command_line.h" |
jochen | b93dba3c | 2014-11-11 05:28:41 | [diff] [blame] | 14 | #include "base/debug/alias.h" |
jochen | b5680e6 | 2014-10-13 08:43:41 | [diff] [blame] | 15 | #include "base/debug/dump_without_crashing.h" |
jochen | b93dba3c | 2014-11-11 05:28:41 | [diff] [blame] | 16 | #include "base/debug/stack_trace.h" |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 17 | #include "base/logging.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 18 | #include "base/macros.h" |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 19 | #include "base/metrics/user_metrics.h" |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 20 | #include "base/path_service.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 21 | #include "base/strings/string_number_conversions.h" |
ellyjones | d84033d | 2015-02-12 19:20:34 | [diff] [blame] | 22 | #include "base/strings/string_util.h" |
[email protected] | 069c4916 | 2013-09-11 20:46:35 | [diff] [blame] | 23 | #include "base/time/time.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 24 | #include "build/build_config.h" |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 25 | #include "chrome/browser/browser_process.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 26 | #include "chrome/browser/content_settings/cookie_settings_factory.h" |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 27 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | 8523ba5 | 2011-05-22 19:00:58 | [diff] [blame] | 28 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 29 | #include "chrome/browser/net/chrome_extensions_network_delegate.h" |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 30 | #include "chrome/browser/profiles/profile_manager.h" |
avi | 24d693f | 2016-08-06 18:03:52 | [diff] [blame] | 31 | #include "chrome/browser/task_manager/task_manager_interface.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 32 | #include "chrome/common/buildflags.h" |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 33 | #include "chrome/common/pref_names.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 34 | #include "components/content_settings/core/browser/cookie_settings.h" |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 35 | #include "components/domain_reliability/monitor.h" |
Dominic Battre | 5e8a1cd | 2018-01-02 16:16:58 | [diff] [blame] | 36 | #include "components/variations/net/variations_http_headers.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 37 | #include "content/public/browser/browser_thread.h" |
[email protected] | 9dfed87 | 2013-12-30 23:08:56 | [diff] [blame] | 38 | #include "content/public/browser/render_frame_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 39 | #include "content/public/browser/render_view_host.h" |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 40 | #include "content/public/browser/resource_request_info.h" |
mkwst | 0513c9d | 2015-04-01 05:53:15 | [diff] [blame] | 41 | #include "content/public/common/content_switches.h" |
ellyjones | d84033d | 2015-02-12 19:20:34 | [diff] [blame] | 42 | #include "content/public/common/process_type.h" |
tyoshino | 430d2f4 | 2016-12-15 09:30:00 | [diff] [blame] | 43 | #include "content/public/common/resource_type.h" |
Scott Violet | c8240b0 | 2018-03-08 22:03:59 | [diff] [blame] | 44 | #include "extensions/buildflags/buildflags.h" |
[email protected] | 82b4230 | 2011-04-20 16:28:16 | [diff] [blame] | 45 | #include "net/base/host_port_pair.h" |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 46 | #include "net/base/net_errors.h" |
[email protected] | 5b9bc35 | 2012-07-18 13:13:34 | [diff] [blame] | 47 | #include "net/cookies/canonical_cookie.h" |
| 48 | #include "net/cookies/cookie_options.h" |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 49 | #include "net/http/http_request_headers.h" |
[email protected] | 4894438 | 2011-04-23 13:28:16 | [diff] [blame] | 50 | #include "net/http/http_response_headers.h" |
ellyjones | d84033d | 2015-02-12 19:20:34 | [diff] [blame] | 51 | #include "net/http/http_status_code.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 52 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 53 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 54 | #include "net/log/net_log_with_source.h" |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 55 | #include "net/url_request/url_request.h" |
| 56 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 57 | #if defined(OS_ANDROID) |
Xing Liu | b9456c1 | 2018-05-11 01:46:17 | [diff] [blame] | 58 | #include "base/android/path_utils.h" |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 59 | #include "chrome/browser/io_thread.h" |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 60 | #endif |
| 61 | |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 62 | #if defined(OS_CHROMEOS) |
[email protected] | 49c4cf85 | 2013-09-27 19:28:24 | [diff] [blame] | 63 | #include "base/sys_info.h" |
[email protected] | 28853848 | 2012-09-06 21:09:35 | [diff] [blame] | 64 | #include "chrome/common/chrome_switches.h" |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 65 | #endif |
| 66 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 67 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 68 | #include "extensions/common/constants.h" |
| 69 | #endif |
| 70 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 71 | using content::BrowserThread; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 72 | using content::RenderViewHost; |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 73 | using content::ResourceRequestInfo; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 74 | |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 75 | namespace { |
| 76 | |
satorux | d18e61a | 2017-06-08 06:38:46 | [diff] [blame] | 77 | bool g_access_to_all_files_enabled = false; |
| 78 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 79 | bool IsAccessAllowedInternal(const base::FilePath& path, |
| 80 | const base::FilePath& profile_path) { |
| 81 | #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 82 | return true; |
| 83 | #else |
| 84 | |
| 85 | std::vector<base::FilePath> whitelist; |
| 86 | #if defined(OS_CHROMEOS) |
| 87 | // Use a whitelist to only allow access to files residing in the list of |
| 88 | // directories below. |
| 89 | static const base::FilePath::CharType* const kLocalAccessWhiteList[] = { |
| 90 | "/home/chronos/user/Downloads", |
| 91 | "/home/chronos/user/log", |
| 92 | "/home/chronos/user/WebRTC Logs", |
| 93 | "/media", |
| 94 | "/opt/oem", |
| 95 | "/usr/share/chromeos-assets", |
| 96 | "/var/log", |
| 97 | }; |
| 98 | |
| 99 | base::FilePath temp_dir; |
Avi Drissman | ea15ea0 | 2018-05-07 18:55:12 | [diff] [blame] | 100 | if (base::PathService::Get(base::DIR_TEMP, &temp_dir)) |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 101 | whitelist.push_back(temp_dir); |
| 102 | |
| 103 | // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under |
| 104 | // the profile path ("/home/chronos/user' is a hard link to current primary |
| 105 | // logged in profile.) For the support of multi-profile sessions, we are |
| 106 | // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such |
| 107 | // access. |
| 108 | if (!profile_path.empty()) { |
| 109 | const base::FilePath downloads = profile_path.AppendASCII("Downloads"); |
| 110 | whitelist.push_back(downloads); |
| 111 | const base::FilePath webrtc_logs = profile_path.AppendASCII("WebRTC Logs"); |
| 112 | whitelist.push_back(webrtc_logs); |
| 113 | } |
| 114 | #elif defined(OS_ANDROID) |
| 115 | // Access to files in external storage is allowed. |
| 116 | base::FilePath external_storage_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 117 | base::PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, |
| 118 | &external_storage_path); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 119 | if (external_storage_path.IsParent(path)) |
| 120 | return true; |
| 121 | |
Xing Liu | b9456c1 | 2018-05-11 01:46:17 | [diff] [blame] | 122 | auto all_download_dirs = base::android::GetAllPrivateDownloadsDirectories(); |
| 123 | for (const auto& dir : all_download_dirs) |
| 124 | whitelist.push_back(dir); |
| 125 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 126 | // Whitelist of other allowed directories. |
| 127 | static const base::FilePath::CharType* const kLocalAccessWhiteList[] = { |
| 128 | "/sdcard", "/mnt/sdcard", |
| 129 | }; |
| 130 | #endif |
| 131 | |
| 132 | for (const auto* whitelisted_path : kLocalAccessWhiteList) |
| 133 | whitelist.push_back(base::FilePath(whitelisted_path)); |
| 134 | |
| 135 | for (const auto& whitelisted_path : whitelist) { |
| 136 | // base::FilePath::operator== should probably handle trailing separators. |
| 137 | if (whitelisted_path == path.StripTrailingSeparators() || |
| 138 | whitelisted_path.IsParent(path)) { |
| 139 | return true; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | DVLOG(1) << "File access denied - " << path.value().c_str(); |
| 144 | return false; |
| 145 | #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 146 | } |
| 147 | |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 148 | } // namespace |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 149 | |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 150 | ChromeNetworkDelegate::ChromeNetworkDelegate( |
Matt Menke | b63ff0d9 | 2018-06-18 21:40:16 | [diff] [blame] | 151 | extensions::EventRouterForwarder* event_router) |
Chris Mumford | eee25337 | 2018-05-29 21:12:38 | [diff] [blame] | 152 | : extensions_delegate_( |
| 153 | ChromeExtensionsNetworkDelegate::Create(event_router)), |
| 154 | profile_(nullptr), |
mkwst | 0513c9d | 2015-04-01 05:53:15 | [diff] [blame] | 155 | experimental_web_platform_features_enabled_( |
gayane | 0b46091c | 2016-04-07 21:01:05 | [diff] [blame] | 156 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
rajendrant | 3980635 | 2018-07-19 23:23:35 | [diff] [blame] | 157 | switches::kEnableExperimentalWebPlatformFeatures)) {} |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 158 | |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 159 | ChromeNetworkDelegate::~ChromeNetworkDelegate() {} |
| 160 | |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 161 | void ChromeNetworkDelegate::set_extension_info_map( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 162 | extensions::InfoMap* extension_info_map) { |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 163 | extensions_delegate_->set_extension_info_map(extension_info_map); |
| 164 | } |
| 165 | |
| 166 | void ChromeNetworkDelegate::set_profile(void* profile) { |
| 167 | profile_ = profile; |
| 168 | extensions_delegate_->set_profile(profile); |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void ChromeNetworkDelegate::set_cookie_settings( |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 172 | content_settings::CookieSettings* cookie_settings) { |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 173 | cookie_settings_ = cookie_settings; |
| 174 | } |
| 175 | |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 176 | int ChromeNetworkDelegate::OnBeforeURLRequest( |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 177 | net::URLRequest* request, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 178 | net::CompletionOnceCallback callback, |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 179 | GURL* new_url) { |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 180 | extensions_delegate_->ForwardStartRequestStatus(request); |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame^] | 181 | return extensions_delegate_->NotifyBeforeURLRequest( |
| 182 | request, std::move(callback), new_url); |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 183 | } |
| 184 | |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 185 | int ChromeNetworkDelegate::OnBeforeStartTransaction( |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 186 | net::URLRequest* request, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 187 | net::CompletionOnceCallback callback, |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 188 | net::HttpRequestHeaders* headers) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 189 | return extensions_delegate_->NotifyBeforeStartTransaction( |
| 190 | request, std::move(callback), headers); |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 191 | } |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 192 | |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 193 | void ChromeNetworkDelegate::OnStartTransaction( |
[email protected] | 5796dc94 | 2011-07-14 19:26:10 | [diff] [blame] | 194 | net::URLRequest* request, |
[email protected] | 783573b | 2011-05-13 11:05:15 | [diff] [blame] | 195 | const net::HttpRequestHeaders& headers) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 196 | extensions_delegate_->NotifyStartTransaction(request, headers); |
[email protected] | 82b4230 | 2011-04-20 16:28:16 | [diff] [blame] | 197 | } |
| 198 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 199 | int ChromeNetworkDelegate::OnHeadersReceived( |
| 200 | net::URLRequest* request, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 201 | net::CompletionOnceCallback callback, |
[email protected] | 507af8f | 2012-10-20 00:42:32 | [diff] [blame] | 202 | const net::HttpResponseHeaders* original_response_headers, |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 203 | scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
| 204 | GURL* allowed_unsafe_redirect_url) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 205 | return extensions_delegate_->NotifyHeadersReceived( |
| 206 | request, std::move(callback), original_response_headers, |
| 207 | override_response_headers, allowed_unsafe_redirect_url); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 208 | } |
| 209 | |
[email protected] | 31b2e5f | 2011-04-20 16:58:32 | [diff] [blame] | 210 | void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request, |
| 211 | const GURL& new_location) { |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 212 | if (domain_reliability_monitor_) |
| 213 | domain_reliability_monitor_->OnBeforeRedirect(request); |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 214 | extensions_delegate_->NotifyBeforeRedirect(request, new_location); |
Dominic Battre | 5e8a1cd | 2018-01-02 16:16:58 | [diff] [blame] | 215 | variations::StripVariationHeaderIfNeeded(new_location, request); |
[email protected] | 31b2e5f | 2011-04-20 16:58:32 | [diff] [blame] | 216 | } |
| 217 | |
maksim.sisov | 1b83bb7 | 2016-10-07 06:07:23 | [diff] [blame] | 218 | void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request, |
| 219 | int net_error) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 220 | extensions_delegate_->NotifyResponseStarted(request, net_error); |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 221 | } |
| 222 | |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 223 | void ChromeNetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request, |
| 224 | int64_t bytes_received) { |
brettw | ee486bb | 2016-12-08 17:56:34 | [diff] [blame] | 225 | #if !defined(OS_ANDROID) |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 226 | // Note: Currently, OnNetworkBytesReceived is only implemented for HTTP jobs, |
| 227 | // not FTP or other types, so those kinds of bytes will not be reported here. |
avi | 24d693f | 2016-08-06 18:03:52 | [diff] [blame] | 228 | task_manager::TaskManagerInterface::OnRawBytesRead(*request, bytes_received); |
brettw | ee486bb | 2016-12-08 17:56:34 | [diff] [blame] | 229 | #endif // !defined(OS_ANDROID) |
sclittle | ae932be | 2015-10-08 20:53:50 | [diff] [blame] | 230 | } |
| 231 | |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 232 | void ChromeNetworkDelegate::OnNetworkBytesSent(net::URLRequest* request, |
sclittle | ae932be | 2015-10-08 20:53:50 | [diff] [blame] | 233 | int64_t bytes_sent) { |
cburn | e9d2f361 | 2017-06-20 22:15:03 | [diff] [blame] | 234 | #if !defined(OS_ANDROID) |
| 235 | // Note: Currently, OnNetworkBytesSent is only implemented for HTTP jobs, |
| 236 | // not FTP or other types, so those kinds of bytes will not be reported here. |
| 237 | task_manager::TaskManagerInterface::OnRawBytesSent(*request, bytes_sent); |
| 238 | #endif // !defined(OS_ANDROID) |
[email protected] | 8523ba5 | 2011-05-22 19:00:58 | [diff] [blame] | 239 | } |
| 240 | |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 241 | void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, |
maksim.sisov | 1b83bb7 | 2016-10-07 06:07:23 | [diff] [blame] | 242 | bool started, |
| 243 | int net_error) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 244 | extensions_delegate_->NotifyCompleted(request, started, net_error); |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 245 | if (domain_reliability_monitor_) |
| 246 | domain_reliability_monitor_->OnCompleted(request, started); |
maksim.sisov | 1b83bb7 | 2016-10-07 06:07:23 | [diff] [blame] | 247 | extensions_delegate_->ForwardProxyErrors(request, net_error); |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 248 | extensions_delegate_->ForwardDoneRequestStatus(request); |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 249 | } |
[email protected] | 4b50cb5 | 2011-03-10 00:29:37 | [diff] [blame] | 250 | |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 251 | void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 252 | extensions_delegate_->NotifyURLRequestDestroyed(request); |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 253 | } |
| 254 | |
[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 255 | void ChromeNetworkDelegate::OnPACScriptError(int line_number, |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 256 | const base::string16& error) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 257 | extensions_delegate_->NotifyPACScriptError(line_number, error); |
[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 258 | } |
[email protected] | 7efc582d | 2011-08-03 20:46:35 | [diff] [blame] | 259 | |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 260 | net::NetworkDelegate::AuthRequiredResponse |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 261 | ChromeNetworkDelegate::OnAuthRequired(net::URLRequest* request, |
| 262 | const net::AuthChallengeInfo& auth_info, |
| 263 | AuthCallback callback, |
| 264 | net::AuthCredentials* credentials) { |
| 265 | return extensions_delegate_->NotifyAuthRequired( |
| 266 | request, auth_info, std::move(callback), credentials); |
[email protected] | 7efc582d | 2011-08-03 20:46:35 | [diff] [blame] | 267 | } |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 268 | |
Clark DuVall | 8420d58 | 2018-06-27 20:05:01 | [diff] [blame] | 269 | bool ChromeNetworkDelegate::OnCanGetCookies(const net::URLRequest& request, |
| 270 | const net::CookieList& cookie_list, |
| 271 | bool allowed_from_caller) { |
jam | 092d3be | 2016-09-27 15:56:36 | [diff] [blame] | 272 | const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); |
| 273 | if (info) { |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 274 | BrowserThread::PostTask( |
| 275 | BrowserThread::UI, FROM_HERE, |
tzik | 53a7b902 | 2017-04-24 11:14:48 | [diff] [blame] | 276 | base::BindOnce(&TabSpecificContentSettings::CookiesRead, |
| 277 | info->GetWebContentsGetterForRequest(), request.url(), |
Clark DuVall | 8420d58 | 2018-06-27 20:05:01 | [diff] [blame] | 278 | request.site_for_cookies(), cookie_list, |
| 279 | !allowed_from_caller)); |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 280 | } |
Clark DuVall | 8420d58 | 2018-06-27 20:05:01 | [diff] [blame] | 281 | return allowed_from_caller; |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 282 | } |
| 283 | |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 284 | bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, |
Victor Costan | 70f8551 | 2017-11-20 16:14:46 | [diff] [blame] | 285 | const net::CanonicalCookie& cookie, |
Clark DuVall | 8420d58 | 2018-06-27 20:05:01 | [diff] [blame] | 286 | net::CookieOptions* options, |
| 287 | bool allowed_from_caller) { |
jam | 092d3be | 2016-09-27 15:56:36 | [diff] [blame] | 288 | const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); |
| 289 | if (info) { |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 290 | BrowserThread::PostTask( |
| 291 | BrowserThread::UI, FROM_HERE, |
tzik | 53a7b902 | 2017-04-24 11:14:48 | [diff] [blame] | 292 | base::BindOnce(&TabSpecificContentSettings::CookieChanged, |
| 293 | info->GetWebContentsGetterForRequest(), request.url(), |
Clark DuVall | 8420d58 | 2018-06-27 20:05:01 | [diff] [blame] | 294 | request.site_for_cookies(), cookie, |
| 295 | !allowed_from_caller)); |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 296 | } |
Clark DuVall | 8420d58 | 2018-06-27 20:05:01 | [diff] [blame] | 297 | return allowed_from_caller; |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 298 | } |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 299 | |
satorux | ddac044 | 2017-05-29 06:06:18 | [diff] [blame] | 300 | bool ChromeNetworkDelegate::OnCanAccessFile( |
| 301 | const net::URLRequest& request, |
| 302 | const base::FilePath& original_path, |
| 303 | const base::FilePath& absolute_path) const { |
satorux | d18e61a | 2017-06-08 06:38:46 | [diff] [blame] | 304 | if (g_access_to_all_files_enabled) |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 305 | return true; |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 306 | return IsAccessAllowed(original_path, absolute_path, profile_path_); |
satorux | 7c536058 | 2017-01-27 07:24:29 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | // static |
| 310 | bool ChromeNetworkDelegate::IsAccessAllowed( |
| 311 | const base::FilePath& path, |
| 312 | const base::FilePath& profile_path) { |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 313 | return IsAccessAllowedInternal(path, profile_path); |
| 314 | } |
| 315 | |
| 316 | // static |
| 317 | bool ChromeNetworkDelegate::IsAccessAllowed( |
| 318 | const base::FilePath& path, |
| 319 | const base::FilePath& absolute_path, |
| 320 | const base::FilePath& profile_path) { |
| 321 | #if defined(OS_ANDROID) |
| 322 | // Android's whitelist relies on symbolic links (ex. /sdcard is whitelisted |
| 323 | // and commonly a symbolic link), thus do not check absolute paths. |
| 324 | return IsAccessAllowedInternal(path, profile_path); |
satorux | 7c536058 | 2017-01-27 07:24:29 | [diff] [blame] | 325 | #else |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 326 | return (IsAccessAllowedInternal(path, profile_path) && |
| 327 | IsAccessAllowedInternal(absolute_path, profile_path)); |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 328 | #endif |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 329 | } |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 330 | |
satorux | d18e61a | 2017-06-08 06:38:46 | [diff] [blame] | 331 | // static |
| 332 | void ChromeNetworkDelegate::EnableAccessToAllFilesForTesting(bool enabled) { |
| 333 | g_access_to_all_files_enabled = enabled; |
| 334 | } |
| 335 | |
estark | 7625d81 | 2015-10-12 20:10:41 | [diff] [blame] | 336 | bool ChromeNetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const { |
mkwst | 0513c9d | 2015-04-01 05:53:15 | [diff] [blame] | 337 | return experimental_web_platform_features_enabled_; |
| 338 | } |
| 339 | |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 340 | bool ChromeNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader( |
| 341 | const net::URLRequest& request, |
| 342 | const GURL& target_url, |
| 343 | const GURL& referrer_url) const { |
Matt Menke | 10e6cade | 2018-06-20 12:54:20 | [diff] [blame] | 344 | // These errors should be handled by the NetworkDelegate wrapper created by |
| 345 | // the owning NetworkContext. |
| 346 | NOTREACHED(); |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 347 | return true; |
| 348 | } |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 349 | |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 350 | bool ChromeNetworkDelegate::OnCanQueueReportingReport( |
| 351 | const url::Origin& origin) const { |
| 352 | if (!cookie_settings_) |
Douglas Creager | 81cad47 | 2018-05-17 14:34:09 | [diff] [blame] | 353 | return false; |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 354 | |
| 355 | return cookie_settings_->IsCookieAccessAllowed(origin.GetURL(), |
| 356 | origin.GetURL()); |
| 357 | } |
| 358 | |
Douglas Creager | 7b07ea4 | 2018-02-27 21:08:08 | [diff] [blame] | 359 | void ChromeNetworkDelegate::OnCanSendReportingReports( |
| 360 | std::set<url::Origin> origins, |
| 361 | base::OnceCallback<void(std::set<url::Origin>)> result_callback) const { |
Douglas Creager | 81cad47 | 2018-05-17 14:34:09 | [diff] [blame] | 362 | if (!reporting_permissions_checker_) { |
| 363 | origins.clear(); |
Douglas Creager | 7b07ea4 | 2018-02-27 21:08:08 | [diff] [blame] | 364 | std::move(result_callback).Run(std::move(origins)); |
| 365 | return; |
| 366 | } |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 367 | |
Douglas Creager | 81cad47 | 2018-05-17 14:34:09 | [diff] [blame] | 368 | reporting_permissions_checker_->FilterReportingOrigins( |
| 369 | std::move(origins), std::move(result_callback)); |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | bool ChromeNetworkDelegate::OnCanSetReportingClient( |
| 373 | const url::Origin& origin, |
| 374 | const GURL& endpoint) const { |
| 375 | if (!cookie_settings_) |
Douglas Creager | 81cad47 | 2018-05-17 14:34:09 | [diff] [blame] | 376 | return false; |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 377 | |
| 378 | return cookie_settings_->IsCookieAccessAllowed(endpoint, origin.GetURL()); |
| 379 | } |
| 380 | |
| 381 | bool ChromeNetworkDelegate::OnCanUseReportingClient( |
| 382 | const url::Origin& origin, |
| 383 | const GURL& endpoint) const { |
| 384 | if (!cookie_settings_) |
Douglas Creager | 81cad47 | 2018-05-17 14:34:09 | [diff] [blame] | 385 | return false; |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 386 | |
| 387 | return cookie_settings_->IsCookieAccessAllowed(endpoint, origin.GetURL()); |
| 388 | } |