blob: ef2ea24a05ce5434ba3347eef5c78bcf9e1f17a4 [file] [log] [blame]
[email protected]9045b8822012-01-13 20:35:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ac039522010-06-15 16:39:442// 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
avi6846aef2015-12-26 01:09:387#include <stddef.h>
[email protected]eac11e12013-03-19 22:04:328#include <stdlib.h>
9
[email protected]d1208ba32012-11-08 11:10:3310#include <vector>
11
[email protected]d8e4f132012-09-06 04:28:0512#include "base/base_paths.h"
mkwst0513c9d2015-04-01 05:53:1513#include "base/command_line.h"
jochenb93dba3c2014-11-11 05:28:4114#include "base/debug/alias.h"
jochenb5680e62014-10-13 08:43:4115#include "base/debug/dump_without_crashing.h"
jochenb93dba3c2014-11-11 05:28:4116#include "base/debug/stack_trace.h"
[email protected]7a299a92012-10-24 23:54:5017#include "base/logging.h"
avi6846aef2015-12-26 01:09:3818#include "base/macros.h"
jochen0e3b3a62014-09-16 18:31:2319#include "base/metrics/user_metrics.h"
[email protected]d8e4f132012-09-06 04:28:0520#include "base/path_service.h"
[email protected]3ea1b182013-02-08 22:38:4121#include "base/strings/string_number_conversions.h"
ellyjonesd84033d2015-02-12 19:20:3422#include "base/strings/string_util.h"
[email protected]069c49162013-09-11 20:46:3523#include "base/time/time.h"
avi6846aef2015-12-26 01:09:3824#include "build/build_config.h"
[email protected]6baff0b52012-03-06 01:30:1825#include "chrome/browser/browser_process.h"
drogerb1716972015-06-30 09:04:0926#include "chrome/browser/content_settings/cookie_settings_factory.h"
[email protected]9c8ae8c2012-03-09 13:13:3527#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]8523ba52011-05-22 19:00:5828#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]4a2b6232014-06-19 08:44:1429#include "chrome/browser/net/chrome_extensions_network_delegate.h"
[email protected]6baff0b52012-03-06 01:30:1830#include "chrome/browser/profiles/profile_manager.h"
avi24d693f2016-08-06 18:03:5231#include "chrome/browser/task_manager/task_manager_interface.h"
Scott Violet6200d332018-02-23 21:29:2332#include "chrome/common/buildflags.h"
[email protected]0a8db0d2011-04-13 15:15:4033#include "chrome/common/pref_names.h"
drogerb1716972015-06-30 09:04:0934#include "components/content_settings/core/browser/cookie_settings.h"
sclittleae932be2015-10-08 20:53:5035#include "components/data_usage/core/data_use_aggregator.h"
[email protected]45de676a2014-03-18 23:52:0236#include "components/domain_reliability/monitor.h"
brettwb1fc1b82016-02-02 00:19:0837#include "components/prefs/pref_member.h"
38#include "components/prefs/pref_service.h"
Dominic Battre5e8a1cd2018-01-02 16:16:5839#include "components/variations/net/variations_http_headers.h"
[email protected]c38831a12011-10-28 12:44:4940#include "content/public/browser/browser_thread.h"
[email protected]9dfed872013-12-30 23:08:5641#include "content/public/browser/render_frame_host.h"
[email protected]9c1662b2012-03-06 15:44:3342#include "content/public/browser/render_view_host.h"
[email protected]9c8ae8c2012-03-09 13:13:3543#include "content/public/browser/resource_request_info.h"
mkwst0513c9d2015-04-01 05:53:1544#include "content/public/common/content_switches.h"
ellyjonesd84033d2015-02-12 19:20:3445#include "content/public/common/process_type.h"
tyoshino430d2f42016-12-15 09:30:0046#include "content/public/common/resource_type.h"
Scott Violetc8240b02018-03-08 22:03:5947#include "extensions/buildflags/buildflags.h"
[email protected]82b42302011-04-20 16:28:1648#include "net/base/host_port_pair.h"
[email protected]8202d0c2011-02-23 08:31:1449#include "net/base/net_errors.h"
[email protected]5b9bc352012-07-18 13:13:3450#include "net/cookies/canonical_cookie.h"
51#include "net/cookies/cookie_options.h"
[email protected]ac039522010-06-15 16:39:4452#include "net/http/http_request_headers.h"
[email protected]48944382011-04-23 13:28:1653#include "net/http/http_response_headers.h"
ellyjonesd84033d2015-02-12 19:20:3454#include "net/http/http_status_code.h"
eroman87c53d62015-04-02 06:51:0755#include "net/log/net_log.h"
mikecirone8b85c432016-09-08 19:11:0056#include "net/log/net_log_event_type.h"
mikecironef22f9812016-10-04 03:40:1957#include "net/log/net_log_with_source.h"
[email protected]d05ef99c2011-02-01 21:38:1658#include "net/url_request/url_request.h"
59
zpengdb4a58e2017-01-10 17:40:3260#if defined(OS_ANDROID)
Xing Liub9456c12018-05-11 01:46:1761#include "base/android/path_utils.h"
[email protected]4a2b6232014-06-19 08:44:1462#include "chrome/browser/io_thread.h"
[email protected]4a2b6232014-06-19 08:44:1463#endif
64
[email protected]4c219e22012-05-05 19:41:0465#if defined(OS_CHROMEOS)
[email protected]49c4cf852013-09-27 19:28:2466#include "base/sys_info.h"
[email protected]288538482012-09-06 21:09:3567#include "chrome/common/chrome_switches.h"
[email protected]4c219e22012-05-05 19:41:0468#endif
69
brettw00899e62016-11-12 02:10:1770#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]84b7a552014-07-19 04:52:0671#include "extensions/common/constants.h"
72#endif
73
[email protected]631bb742011-11-02 11:29:3974using content::BrowserThread;
[email protected]eaabba22012-03-07 15:02:1175using content::RenderViewHost;
[email protected]ea114722012-03-12 01:11:2576using content::ResourceRequestInfo;
[email protected]631bb742011-11-02 11:29:3977
[email protected]d05ef99c2011-02-01 21:38:1678namespace {
79
satoruxd18e61a2017-06-08 06:38:4680bool g_access_to_all_files_enabled = false;
81
[email protected]d1208ba32012-11-08 11:10:3382// Gets called when the extensions finish work on the URL. If the extensions
83// did not do a redirect (so |new_url| is empty) then we enforce the
84// SafeSearch parameters. Otherwise we will get called again after the
85// redirect and we enforce SafeSearch then.
David Benjamind1f287bf2018-06-12 01:57:2086void ForceGoogleSafeSearchCallbackWrapper(net::CompletionOnceCallback callback,
87 net::URLRequest* request,
88 GURL* new_url,
89 int rv) {
[email protected]d1208ba32012-11-08 11:10:3390 if (rv == net::OK && new_url->is_empty())
[email protected]184799df2014-07-22 16:03:2491 safe_search_util::ForceGoogleSafeSearch(request, new_url);
David Benjamind1f287bf2018-06-12 01:57:2092 std::move(callback).Run(rv);
[email protected]d1208ba32012-11-08 11:10:3393}
94
Ken Rockot314714c2017-11-05 23:36:2495bool IsAccessAllowedInternal(const base::FilePath& path,
96 const base::FilePath& profile_path) {
97#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
98 return true;
99#else
100
101 std::vector<base::FilePath> whitelist;
102#if defined(OS_CHROMEOS)
103 // Use a whitelist to only allow access to files residing in the list of
104 // directories below.
105 static const base::FilePath::CharType* const kLocalAccessWhiteList[] = {
106 "/home/chronos/user/Downloads",
107 "/home/chronos/user/log",
108 "/home/chronos/user/WebRTC Logs",
109 "/media",
110 "/opt/oem",
111 "/usr/share/chromeos-assets",
112 "/var/log",
113 };
114
115 base::FilePath temp_dir;
Avi Drissmanea15ea02018-05-07 18:55:12116 if (base::PathService::Get(base::DIR_TEMP, &temp_dir))
Ken Rockot314714c2017-11-05 23:36:24117 whitelist.push_back(temp_dir);
118
119 // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under
120 // the profile path ("/home/chronos/user' is a hard link to current primary
121 // logged in profile.) For the support of multi-profile sessions, we are
122 // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such
123 // access.
124 if (!profile_path.empty()) {
125 const base::FilePath downloads = profile_path.AppendASCII("Downloads");
126 whitelist.push_back(downloads);
127 const base::FilePath webrtc_logs = profile_path.AppendASCII("WebRTC Logs");
128 whitelist.push_back(webrtc_logs);
129 }
130#elif defined(OS_ANDROID)
131 // Access to files in external storage is allowed.
132 base::FilePath external_storage_path;
Avi Drissman9098f9002018-05-04 00:11:52133 base::PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE,
134 &external_storage_path);
Ken Rockot314714c2017-11-05 23:36:24135 if (external_storage_path.IsParent(path))
136 return true;
137
Xing Liub9456c12018-05-11 01:46:17138 auto all_download_dirs = base::android::GetAllPrivateDownloadsDirectories();
139 for (const auto& dir : all_download_dirs)
140 whitelist.push_back(dir);
141
Ken Rockot314714c2017-11-05 23:36:24142 // Whitelist of other allowed directories.
143 static const base::FilePath::CharType* const kLocalAccessWhiteList[] = {
144 "/sdcard", "/mnt/sdcard",
145 };
146#endif
147
148 for (const auto* whitelisted_path : kLocalAccessWhiteList)
149 whitelist.push_back(base::FilePath(whitelisted_path));
150
151 for (const auto& whitelisted_path : whitelist) {
152 // base::FilePath::operator== should probably handle trailing separators.
153 if (whitelisted_path == path.StripTrailingSeparators() ||
154 whitelisted_path.IsParent(path)) {
155 return true;
156 }
157 }
158
159 DVLOG(1) << "File access denied - " << path.value().c_str();
160 return false;
161#endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
162}
163
[email protected]d05ef99c2011-02-01 21:38:16164} // namespace
[email protected]ac039522010-06-15 16:39:44165
[email protected]0651b812011-02-24 00:22:50166ChromeNetworkDelegate::ChromeNetworkDelegate(
Matt Menkeb63ff0d92018-06-18 21:40:16167 extensions::EventRouterForwarder* event_router)
Chris Mumfordeee253372018-05-29 21:12:38168 : extensions_delegate_(
169 ChromeExtensionsNetworkDelegate::Create(event_router)),
170 profile_(nullptr),
ljusten98684cb72016-10-11 13:26:18171 force_google_safe_search_(nullptr),
172 force_youtube_restrict_(nullptr),
igorcov193d8ad32016-05-27 11:03:21173 allowed_domains_for_apps_(nullptr),
mkwst0513c9d2015-04-01 05:53:15174 experimental_web_platform_features_enabled_(
gayane0b46091c2016-04-07 21:01:05175 base::CommandLine::ForCurrentProcess()->HasSwitch(
176 switches::kEnableExperimentalWebPlatformFeatures)),
sclittleae932be2015-10-08 20:53:50177 data_use_aggregator_(nullptr),
Matt Menkeb63ff0d92018-06-18 21:40:16178 is_data_usage_off_the_record_(true) {}
[email protected]0651b812011-02-24 00:22:50179
[email protected]ac039522010-06-15 16:39:44180ChromeNetworkDelegate::~ChromeNetworkDelegate() {}
181
[email protected]a09159a2012-11-29 12:51:48182void ChromeNetworkDelegate::set_extension_info_map(
[email protected]38427a12013-11-09 17:34:20183 extensions::InfoMap* extension_info_map) {
[email protected]4a2b6232014-06-19 08:44:14184 extensions_delegate_->set_extension_info_map(extension_info_map);
185}
186
187void ChromeNetworkDelegate::set_profile(void* profile) {
188 profile_ = profile;
189 extensions_delegate_->set_profile(profile);
[email protected]a09159a2012-11-29 12:51:48190}
191
192void ChromeNetworkDelegate::set_cookie_settings(
drogerb1716972015-06-30 09:04:09193 content_settings::CookieSettings* cookie_settings) {
[email protected]a09159a2012-11-29 12:51:48194 cookie_settings_ = cookie_settings;
195}
196
sclittleae932be2015-10-08 20:53:50197void ChromeNetworkDelegate::set_data_use_aggregator(
198 data_usage::DataUseAggregator* data_use_aggregator,
199 bool is_data_usage_off_the_record) {
200 data_use_aggregator_ = data_use_aggregator;
201 is_data_usage_off_the_record_ = is_data_usage_off_the_record;
202}
203
[email protected]c4a7df82012-08-09 22:48:46204// static
[email protected]9d8cfb682012-09-13 16:48:04205void ChromeNetworkDelegate::InitializePrefsOnUIThread(
[email protected]d1208ba32012-11-08 11:10:33206 BooleanPrefMember* force_google_safe_search,
ljusten98684cb72016-10-11 13:26:18207 IntegerPrefMember* force_youtube_restrict,
igorcov193d8ad32016-05-27 11:03:21208 StringPrefMember* allowed_domains_for_apps,
[email protected]0a8db0d2011-04-13 15:15:40209 PrefService* pref_service) {
anujk.sharma2e02ce162015-04-29 23:10:02210 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]d1208ba32012-11-08 11:10:33211 if (force_google_safe_search) {
treib4e26f6652014-12-01 14:34:18212 force_google_safe_search->Init(prefs::kForceGoogleSafeSearch, pref_service);
[email protected]d1208ba32012-11-08 11:10:33213 force_google_safe_search->MoveToThread(
thestig529ad8a2016-07-08 20:30:12214 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO));
[email protected]d1208ba32012-11-08 11:10:33215 }
ljusten98684cb72016-10-11 13:26:18216 if (force_youtube_restrict) {
217 force_youtube_restrict->Init(prefs::kForceYouTubeRestrict, pref_service);
218 force_youtube_restrict->MoveToThread(
thestig529ad8a2016-07-08 20:30:12219 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO));
treib4e26f6652014-12-01 14:34:18220 }
igorcov193d8ad32016-05-27 11:03:21221 if (allowed_domains_for_apps) {
222 allowed_domains_for_apps->Init(prefs::kAllowedDomainsForApps, pref_service);
223 allowed_domains_for_apps->MoveToThread(
thestig529ad8a2016-07-08 20:30:12224 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO));
igorcov193d8ad32016-05-27 11:03:21225 }
[email protected]0a8db0d2011-04-13 15:15:40226}
227
[email protected]4875ba12011-03-30 22:31:51228int ChromeNetworkDelegate::OnBeforeURLRequest(
[email protected]4c76d7c2011-04-15 19:14:12229 net::URLRequest* request,
David Benjamind1f287bf2018-06-12 01:57:20230 net::CompletionOnceCallback callback,
[email protected]4c76d7c2011-04-15 19:14:12231 GURL* new_url) {
[email protected]4a2b6232014-06-19 08:44:14232 extensions_delegate_->ForwardStartRequestStatus(request);
[email protected]6baff0b52012-03-06 01:30:18233
treib4e26f6652014-12-01 14:34:18234 bool force_safe_search =
treib4e26f6652014-12-01 14:34:18235 (force_google_safe_search_ && force_google_safe_search_->GetValue());
[email protected]d1208ba32012-11-08 11:10:33236
David Benjamind1f287bf2018-06-12 01:57:20237 net::CompletionOnceCallback wrapped_callback = std::move(callback);
[email protected]d1208ba32012-11-08 11:10:33238 if (force_safe_search) {
David Benjamind1f287bf2018-06-12 01:57:20239 wrapped_callback = base::BindOnce(
240 &ForceGoogleSafeSearchCallbackWrapper, std::move(wrapped_callback),
241 base::Unretained(request), base::Unretained(new_url));
[email protected]d1208ba32012-11-08 11:10:33242 }
243
David Benjamind1f287bf2018-06-12 01:57:20244 int rv = extensions_delegate_->NotifyBeforeURLRequest(
245 request, std::move(wrapped_callback), new_url);
[email protected]d1208ba32012-11-08 11:10:33246
247 if (force_safe_search && rv == net::OK && new_url->is_empty())
[email protected]184799df2014-07-22 16:03:24248 safe_search_util::ForceGoogleSafeSearch(request, new_url);
[email protected]d1208ba32012-11-08 11:10:33249
igorcov193d8ad32016-05-27 11:03:21250 if (allowed_domains_for_apps_ &&
251 !allowed_domains_for_apps_->GetValue().empty() &&
252 request->url().DomainIs("google.com")) {
253 request->SetExtraRequestHeaderByName("X-GoogApps-Allowed-Domains",
254 allowed_domains_for_apps_->GetValue(),
255 true);
256 }
257
[email protected]d1208ba32012-11-08 11:10:33258 return rv;
[email protected]d05ef99c2011-02-01 21:38:16259}
260
ryansturm2343cb62016-06-15 01:09:00261int ChromeNetworkDelegate::OnBeforeStartTransaction(
[email protected]636eccd2011-06-28 12:28:01262 net::URLRequest* request,
David Benjamind1f287bf2018-06-12 01:57:20263 net::CompletionOnceCallback callback,
[email protected]4c76d7c2011-04-15 19:14:12264 net::HttpRequestHeaders* headers) {
ljusten98684cb72016-10-11 13:26:18265 if (force_youtube_restrict_) {
266 int value = force_youtube_restrict_->GetValue();
267 static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0,
268 "OFF must be first");
269 if (value > safe_search_util::YOUTUBE_RESTRICT_OFF &&
270 value < safe_search_util::YOUTUBE_RESTRICT_COUNT) {
271 safe_search_util::ForceYouTubeRestrict(request, headers,
272 static_cast<safe_search_util::YouTubeRestrictMode>(value));
273 }
274 }
[email protected]184799df2014-07-22 16:03:24275
David Benjamind1f287bf2018-06-12 01:57:20276 return extensions_delegate_->NotifyBeforeStartTransaction(
277 request, std::move(callback), headers);
[email protected]ac039522010-06-15 16:39:44278}
[email protected]8202d0c2011-02-23 08:31:14279
ryansturm2343cb62016-06-15 01:09:00280void ChromeNetworkDelegate::OnStartTransaction(
[email protected]5796dc942011-07-14 19:26:10281 net::URLRequest* request,
[email protected]783573b2011-05-13 11:05:15282 const net::HttpRequestHeaders& headers) {
David Benjamind1f287bf2018-06-12 01:57:20283 extensions_delegate_->NotifyStartTransaction(request, headers);
[email protected]82b42302011-04-20 16:28:16284}
285
[email protected]ea8141e2011-10-05 13:12:51286int ChromeNetworkDelegate::OnHeadersReceived(
287 net::URLRequest* request,
David Benjamind1f287bf2018-06-12 01:57:20288 net::CompletionOnceCallback callback,
[email protected]507af8f2012-10-20 00:42:32289 const net::HttpResponseHeaders* original_response_headers,
[email protected]5f714132014-03-26 10:41:16290 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
291 GURL* allowed_unsafe_redirect_url) {
David Benjamind1f287bf2018-06-12 01:57:20292 return extensions_delegate_->NotifyHeadersReceived(
293 request, std::move(callback), original_response_headers,
294 override_response_headers, allowed_unsafe_redirect_url);
[email protected]ea8141e2011-10-05 13:12:51295}
296
[email protected]31b2e5f2011-04-20 16:58:32297void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
298 const GURL& new_location) {
[email protected]45de676a2014-03-18 23:52:02299 if (domain_reliability_monitor_)
300 domain_reliability_monitor_->OnBeforeRedirect(request);
David Benjamind1f287bf2018-06-12 01:57:20301 extensions_delegate_->NotifyBeforeRedirect(request, new_location);
Dominic Battre5e8a1cd2018-01-02 16:16:58302 variations::StripVariationHeaderIfNeeded(new_location, request);
[email protected]31b2e5f2011-04-20 16:58:32303}
304
maksim.sisov1b83bb72016-10-07 06:07:23305void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request,
306 int net_error) {
David Benjamind1f287bf2018-06-12 01:57:20307 extensions_delegate_->NotifyResponseStarted(request, net_error);
[email protected]8202d0c2011-02-23 08:31:14308}
309
sclittlea133de02015-11-10 23:54:21310void ChromeNetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request,
311 int64_t bytes_received) {
brettwee486bb2016-12-08 17:56:34312#if !defined(OS_ANDROID)
sclittlece72c482015-08-24 20:20:59313 // Note: Currently, OnNetworkBytesReceived is only implemented for HTTP jobs,
314 // not FTP or other types, so those kinds of bytes will not be reported here.
avi24d693f2016-08-06 18:03:52315 task_manager::TaskManagerInterface::OnRawBytesRead(*request, bytes_received);
brettwee486bb2016-12-08 17:56:34316#endif // !defined(OS_ANDROID)
sclittleae932be2015-10-08 20:53:50317
sclittlea133de02015-11-10 23:54:21318 ReportDataUsageStats(request, 0 /* tx_bytes */, bytes_received);
sclittleae932be2015-10-08 20:53:50319}
320
sclittlea133de02015-11-10 23:54:21321void ChromeNetworkDelegate::OnNetworkBytesSent(net::URLRequest* request,
sclittleae932be2015-10-08 20:53:50322 int64_t bytes_sent) {
cburne9d2f3612017-06-20 22:15:03323#if !defined(OS_ANDROID)
324 // Note: Currently, OnNetworkBytesSent is only implemented for HTTP jobs,
325 // not FTP or other types, so those kinds of bytes will not be reported here.
326 task_manager::TaskManagerInterface::OnRawBytesSent(*request, bytes_sent);
327#endif // !defined(OS_ANDROID)
328
sclittlea133de02015-11-10 23:54:21329 ReportDataUsageStats(request, bytes_sent, 0 /* rx_bytes */);
[email protected]8523ba52011-05-22 19:00:58330}
331
[email protected]9045b8822012-01-13 20:35:35332void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request,
maksim.sisov1b83bb72016-10-07 06:07:23333 bool started,
334 int net_error) {
David Benjamind1f287bf2018-06-12 01:57:20335 extensions_delegate_->NotifyCompleted(request, started, net_error);
[email protected]45de676a2014-03-18 23:52:02336 if (domain_reliability_monitor_)
337 domain_reliability_monitor_->OnCompleted(request, started);
maksim.sisov1b83bb72016-10-07 06:07:23338 extensions_delegate_->ForwardProxyErrors(request, net_error);
[email protected]4a2b6232014-06-19 08:44:14339 extensions_delegate_->ForwardDoneRequestStatus(request);
[email protected]8202d0c2011-02-23 08:31:14340}
[email protected]4b50cb52011-03-10 00:29:37341
[email protected]4875ba12011-03-30 22:31:51342void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
David Benjamind1f287bf2018-06-12 01:57:20343 extensions_delegate_->NotifyURLRequestDestroyed(request);
[email protected]4875ba12011-03-30 22:31:51344}
345
[email protected]82a37672011-05-03 12:02:41346void ChromeNetworkDelegate::OnPACScriptError(int line_number,
[email protected]439f1e32013-12-09 20:09:09347 const base::string16& error) {
David Benjamind1f287bf2018-06-12 01:57:20348 extensions_delegate_->NotifyPACScriptError(line_number, error);
[email protected]82a37672011-05-03 12:02:41349}
[email protected]7efc582d2011-08-03 20:46:35350
[email protected]c2911d72011-10-03 22:16:36351net::NetworkDelegate::AuthRequiredResponse
David Benjamind1f287bf2018-06-12 01:57:20352ChromeNetworkDelegate::OnAuthRequired(net::URLRequest* request,
353 const net::AuthChallengeInfo& auth_info,
354 AuthCallback callback,
355 net::AuthCredentials* credentials) {
356 return extensions_delegate_->NotifyAuthRequired(
357 request, auth_info, std::move(callback), credentials);
[email protected]7efc582d2011-08-03 20:46:35358}
[email protected]9c8ae8c2012-03-09 13:13:35359
Clark DuVall8420d582018-06-27 20:05:01360bool ChromeNetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
361 const net::CookieList& cookie_list,
362 bool allowed_from_caller) {
jam092d3be2016-09-27 15:56:36363 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
364 if (info) {
[email protected]9c8ae8c2012-03-09 13:13:35365 BrowserThread::PostTask(
366 BrowserThread::UI, FROM_HERE,
tzik53a7b9022017-04-24 11:14:48367 base::BindOnce(&TabSpecificContentSettings::CookiesRead,
368 info->GetWebContentsGetterForRequest(), request.url(),
Clark DuVall8420d582018-06-27 20:05:01369 request.site_for_cookies(), cookie_list,
370 !allowed_from_caller));
[email protected]9c8ae8c2012-03-09 13:13:35371 }
Clark DuVall8420d582018-06-27 20:05:01372 return allowed_from_caller;
[email protected]9c8ae8c2012-03-09 13:13:35373}
374
[email protected]4c219e22012-05-05 19:41:04375bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
Victor Costan70f85512017-11-20 16:14:46376 const net::CanonicalCookie& cookie,
Clark DuVall8420d582018-06-27 20:05:01377 net::CookieOptions* options,
378 bool allowed_from_caller) {
jam092d3be2016-09-27 15:56:36379 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
380 if (info) {
[email protected]9c8ae8c2012-03-09 13:13:35381 BrowserThread::PostTask(
382 BrowserThread::UI, FROM_HERE,
tzik53a7b9022017-04-24 11:14:48383 base::BindOnce(&TabSpecificContentSettings::CookieChanged,
384 info->GetWebContentsGetterForRequest(), request.url(),
Clark DuVall8420d582018-06-27 20:05:01385 request.site_for_cookies(), cookie,
386 !allowed_from_caller));
[email protected]9c8ae8c2012-03-09 13:13:35387 }
Clark DuVall8420d582018-06-27 20:05:01388 return allowed_from_caller;
[email protected]9c8ae8c2012-03-09 13:13:35389}
[email protected]4c219e22012-05-05 19:41:04390
satoruxddac0442017-05-29 06:06:18391bool ChromeNetworkDelegate::OnCanAccessFile(
392 const net::URLRequest& request,
393 const base::FilePath& original_path,
394 const base::FilePath& absolute_path) const {
satoruxd18e61a2017-06-08 06:38:46395 if (g_access_to_all_files_enabled)
[email protected]d8e4f132012-09-06 04:28:05396 return true;
Ken Rockot314714c2017-11-05 23:36:24397 return IsAccessAllowed(original_path, absolute_path, profile_path_);
satorux7c5360582017-01-27 07:24:29398}
399
400// static
401bool ChromeNetworkDelegate::IsAccessAllowed(
402 const base::FilePath& path,
403 const base::FilePath& profile_path) {
Ken Rockot314714c2017-11-05 23:36:24404 return IsAccessAllowedInternal(path, profile_path);
405}
406
407// static
408bool ChromeNetworkDelegate::IsAccessAllowed(
409 const base::FilePath& path,
410 const base::FilePath& absolute_path,
411 const base::FilePath& profile_path) {
412#if defined(OS_ANDROID)
413 // Android's whitelist relies on symbolic links (ex. /sdcard is whitelisted
414 // and commonly a symbolic link), thus do not check absolute paths.
415 return IsAccessAllowedInternal(path, profile_path);
satorux7c5360582017-01-27 07:24:29416#else
Ken Rockot314714c2017-11-05 23:36:24417 return (IsAccessAllowedInternal(path, profile_path) &&
418 IsAccessAllowedInternal(absolute_path, profile_path));
[email protected]d8e4f132012-09-06 04:28:05419#endif
[email protected]4c219e22012-05-05 19:41:04420}
[email protected]a1d4ab072012-06-07 13:21:15421
satoruxd18e61a2017-06-08 06:38:46422// static
423void ChromeNetworkDelegate::EnableAccessToAllFilesForTesting(bool enabled) {
424 g_access_to_all_files_enabled = enabled;
425}
426
estark7625d812015-10-12 20:10:41427bool ChromeNetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const {
mkwst0513c9d2015-04-01 05:53:15428 return experimental_web_platform_features_enabled_;
429}
430
jochen0e3b3a62014-09-16 18:31:23431bool ChromeNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
432 const net::URLRequest& request,
433 const GURL& target_url,
434 const GURL& referrer_url) const {
Matt Menke10e6cade2018-06-20 12:54:20435 // These errors should be handled by the NetworkDelegate wrapper created by
436 // the owning NetworkContext.
437 NOTREACHED();
jochen0e3b3a62014-09-16 18:31:23438 return true;
439}
sclittlea133de02015-11-10 23:54:21440
juliatuttlefcf47202017-05-23 15:53:02441bool ChromeNetworkDelegate::OnCanQueueReportingReport(
442 const url::Origin& origin) const {
443 if (!cookie_settings_)
Douglas Creager81cad472018-05-17 14:34:09444 return false;
juliatuttlefcf47202017-05-23 15:53:02445
446 return cookie_settings_->IsCookieAccessAllowed(origin.GetURL(),
447 origin.GetURL());
448}
449
Douglas Creager7b07ea42018-02-27 21:08:08450void ChromeNetworkDelegate::OnCanSendReportingReports(
451 std::set<url::Origin> origins,
452 base::OnceCallback<void(std::set<url::Origin>)> result_callback) const {
Douglas Creager81cad472018-05-17 14:34:09453 if (!reporting_permissions_checker_) {
454 origins.clear();
Douglas Creager7b07ea42018-02-27 21:08:08455 std::move(result_callback).Run(std::move(origins));
456 return;
457 }
juliatuttlefcf47202017-05-23 15:53:02458
Douglas Creager81cad472018-05-17 14:34:09459 reporting_permissions_checker_->FilterReportingOrigins(
460 std::move(origins), std::move(result_callback));
juliatuttlefcf47202017-05-23 15:53:02461}
462
463bool ChromeNetworkDelegate::OnCanSetReportingClient(
464 const url::Origin& origin,
465 const GURL& endpoint) const {
466 if (!cookie_settings_)
Douglas Creager81cad472018-05-17 14:34:09467 return false;
juliatuttlefcf47202017-05-23 15:53:02468
469 return cookie_settings_->IsCookieAccessAllowed(endpoint, origin.GetURL());
470}
471
472bool ChromeNetworkDelegate::OnCanUseReportingClient(
473 const url::Origin& origin,
474 const GURL& endpoint) const {
475 if (!cookie_settings_)
Douglas Creager81cad472018-05-17 14:34:09476 return false;
juliatuttlefcf47202017-05-23 15:53:02477
478 return cookie_settings_->IsCookieAccessAllowed(endpoint, origin.GetURL());
479}
480
sclittlea133de02015-11-10 23:54:21481void ChromeNetworkDelegate::ReportDataUsageStats(net::URLRequest* request,
482 int64_t tx_bytes,
483 int64_t rx_bytes) {
484 if (!data_use_aggregator_)
485 return;
486
487 if (is_data_usage_off_the_record_) {
488 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes);
489 return;
490 }
491
492 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes);
493}