[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" |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 19 | #include "base/metrics/histogram_functions.h" |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 20 | #include "base/metrics/user_metrics.h" |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 21 | #include "base/path_service.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 22 | #include "base/strings/string_number_conversions.h" |
ellyjones | d84033d | 2015-02-12 19:20:34 | [diff] [blame] | 23 | #include "base/strings/string_util.h" |
[email protected] | 069c4916 | 2013-09-11 20:46:35 | [diff] [blame] | 24 | #include "base/time/time.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 25 | #include "build/build_config.h" |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 26 | #include "chrome/browser/browser_process.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 27 | #include "chrome/browser/content_settings/cookie_settings_factory.h" |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 28 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | 8523ba5 | 2011-05-22 19:00:58 | [diff] [blame] | 29 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 30 | #include "chrome/browser/net/chrome_extensions_network_delegate.h" |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 31 | #include "chrome/browser/profiles/profile_manager.h" |
avi | 24d693f | 2016-08-06 18:03:52 | [diff] [blame] | 32 | #include "chrome/browser/task_manager/task_manager_interface.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 33 | #include "chrome/common/buildflags.h" |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 34 | #include "chrome/common/pref_names.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 35 | #include "components/content_settings/core/browser/cookie_settings.h" |
sclittle | ae932be | 2015-10-08 20:53:50 | [diff] [blame] | 36 | #include "components/data_usage/core/data_use_aggregator.h" |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 37 | #include "components/domain_reliability/monitor.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 38 | #include "components/prefs/pref_member.h" |
| 39 | #include "components/prefs/pref_service.h" |
Dominic Battre | 5e8a1cd | 2018-01-02 16:16:58 | [diff] [blame] | 40 | #include "components/variations/net/variations_http_headers.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 41 | #include "content/public/browser/browser_thread.h" |
[email protected] | 9dfed87 | 2013-12-30 23:08:56 | [diff] [blame] | 42 | #include "content/public/browser/render_frame_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 43 | #include "content/public/browser/render_view_host.h" |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 44 | #include "content/public/browser/resource_request_info.h" |
mkwst | 0513c9d | 2015-04-01 05:53:15 | [diff] [blame] | 45 | #include "content/public/common/content_switches.h" |
ellyjones | d84033d | 2015-02-12 19:20:34 | [diff] [blame] | 46 | #include "content/public/common/process_type.h" |
tyoshino | 430d2f4 | 2016-12-15 09:30:00 | [diff] [blame] | 47 | #include "content/public/common/resource_type.h" |
Scott Violet | c8240b0 | 2018-03-08 22:03:59 | [diff] [blame] | 48 | #include "extensions/buildflags/buildflags.h" |
[email protected] | 82b4230 | 2011-04-20 16:28:16 | [diff] [blame] | 49 | #include "net/base/host_port_pair.h" |
sclittle | 3c16159e | 2014-12-15 19:53:17 | [diff] [blame] | 50 | #include "net/base/load_flags.h" |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 51 | #include "net/base/net_errors.h" |
[email protected] | 5b9bc35 | 2012-07-18 13:13:34 | [diff] [blame] | 52 | #include "net/cookies/canonical_cookie.h" |
| 53 | #include "net/cookies/cookie_options.h" |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 54 | #include "net/http/http_request_headers.h" |
[email protected] | 4894438 | 2011-04-23 13:28:16 | [diff] [blame] | 55 | #include "net/http/http_response_headers.h" |
ellyjones | d84033d | 2015-02-12 19:20:34 | [diff] [blame] | 56 | #include "net/http/http_status_code.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 57 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 58 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 59 | #include "net/log/net_log_with_source.h" |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 60 | #include "net/url_request/url_request.h" |
| 61 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 62 | #if defined(OS_ANDROID) |
Xing Liu | b9456c1 | 2018-05-11 01:46:17 | [diff] [blame] | 63 | #include "base/android/path_utils.h" |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 64 | #include "chrome/browser/io_thread.h" |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 65 | #endif |
| 66 | |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 67 | #if defined(OS_CHROMEOS) |
[email protected] | 49c4cf85 | 2013-09-27 19:28:24 | [diff] [blame] | 68 | #include "base/sys_info.h" |
[email protected] | 28853848 | 2012-09-06 21:09:35 | [diff] [blame] | 69 | #include "chrome/common/chrome_switches.h" |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 70 | #endif |
| 71 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 72 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 73 | #include "extensions/common/constants.h" |
| 74 | #endif |
| 75 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 76 | using content::BrowserThread; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 77 | using content::RenderViewHost; |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 78 | using content::ResourceRequestInfo; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 79 | |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 80 | namespace { |
| 81 | |
satorux | d18e61a | 2017-06-08 06:38:46 | [diff] [blame] | 82 | bool g_access_to_all_files_enabled = false; |
| 83 | |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 84 | // Gets called when the extensions finish work on the URL. If the extensions |
| 85 | // did not do a redirect (so |new_url| is empty) then we enforce the |
| 86 | // SafeSearch parameters. Otherwise we will get called again after the |
| 87 | // redirect and we enforce SafeSearch then. |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 88 | void ForceGoogleSafeSearchCallbackWrapper(net::CompletionOnceCallback callback, |
| 89 | net::URLRequest* request, |
| 90 | GURL* new_url, |
| 91 | int rv) { |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 92 | if (rv == net::OK && new_url->is_empty()) |
[email protected] | 184799df | 2014-07-22 16:03:24 | [diff] [blame] | 93 | safe_search_util::ForceGoogleSafeSearch(request, new_url); |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 94 | std::move(callback).Run(rv); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 95 | } |
| 96 | |
jochen | 65227537 | 2015-01-16 11:35:27 | [diff] [blame] | 97 | void ReportInvalidReferrerSendOnUI() { |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 98 | base::RecordAction( |
| 99 | base::UserMetricsAction("Net.URLRequest_StartJob_InvalidReferrer")); |
jochen | 65227537 | 2015-01-16 11:35:27 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void ReportInvalidReferrerSend(const GURL& target_url, |
| 103 | const GURL& referrer_url) { |
jochen | 4c874d2 | 2015-04-13 14:01:04 | [diff] [blame] | 104 | LOG(ERROR) << "Cancelling request to " << target_url |
| 105 | << " with invalid referrer " << referrer_url; |
jochen | 65227537 | 2015-01-16 11:35:27 | [diff] [blame] | 106 | // Record information to help debug http://crbug.com/422871 |
| 107 | if (!target_url.SchemeIsHTTPOrHTTPS()) |
| 108 | return; |
| 109 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
tzik | 53a7b902 | 2017-04-24 11:14:48 | [diff] [blame] | 110 | base::BindOnce(&ReportInvalidReferrerSendOnUI)); |
jochen | b5680e6 | 2014-10-13 08:43:41 | [diff] [blame] | 111 | base::debug::DumpWithoutCrashing(); |
jochen | 4c874d2 | 2015-04-13 14:01:04 | [diff] [blame] | 112 | NOTREACHED(); |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 113 | } |
| 114 | |
sclittle | 3c16159e | 2014-12-15 19:53:17 | [diff] [blame] | 115 | // Record network errors that HTTP requests complete with, including OK and |
| 116 | // ABORTED. |
maksim.sisov | 1b83bb7 | 2016-10-07 06:07:23 | [diff] [blame] | 117 | void RecordNetworkErrorHistograms(const net::URLRequest* request, |
| 118 | int net_error) { |
sclittle | 3c16159e | 2014-12-15 19:53:17 | [diff] [blame] | 119 | if (request->url().SchemeIs("http")) { |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 120 | base::UmaHistogramSparse("Net.HttpRequestCompletionErrorCodes", |
| 121 | std::abs(net_error)); |
sclittle | 3c16159e | 2014-12-15 19:53:17 | [diff] [blame] | 122 | |
rdsmith | 4de1fcf | 2016-08-30 05:35:21 | [diff] [blame] | 123 | if (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) { |
Ilya Sherman | 982457e6 | 2017-12-13 02:19:36 | [diff] [blame] | 124 | base::UmaHistogramSparse("Net.HttpRequestCompletionErrorCodes.MainFrame", |
| 125 | std::abs(net_error)); |
sclittle | 3c16159e | 2014-12-15 19:53:17 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 130 | bool IsAccessAllowedInternal(const base::FilePath& path, |
| 131 | const base::FilePath& profile_path) { |
| 132 | #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 133 | return true; |
| 134 | #else |
| 135 | |
| 136 | std::vector<base::FilePath> whitelist; |
| 137 | #if defined(OS_CHROMEOS) |
| 138 | // Use a whitelist to only allow access to files residing in the list of |
| 139 | // directories below. |
| 140 | static const base::FilePath::CharType* const kLocalAccessWhiteList[] = { |
| 141 | "/home/chronos/user/Downloads", |
| 142 | "/home/chronos/user/log", |
| 143 | "/home/chronos/user/WebRTC Logs", |
| 144 | "/media", |
| 145 | "/opt/oem", |
| 146 | "/usr/share/chromeos-assets", |
| 147 | "/var/log", |
| 148 | }; |
| 149 | |
| 150 | base::FilePath temp_dir; |
Avi Drissman | ea15ea0 | 2018-05-07 18:55:12 | [diff] [blame] | 151 | if (base::PathService::Get(base::DIR_TEMP, &temp_dir)) |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 152 | whitelist.push_back(temp_dir); |
| 153 | |
| 154 | // The actual location of "/home/chronos/user/Xyz" is the Xyz directory under |
| 155 | // the profile path ("/home/chronos/user' is a hard link to current primary |
| 156 | // logged in profile.) For the support of multi-profile sessions, we are |
| 157 | // switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such |
| 158 | // access. |
| 159 | if (!profile_path.empty()) { |
| 160 | const base::FilePath downloads = profile_path.AppendASCII("Downloads"); |
| 161 | whitelist.push_back(downloads); |
| 162 | const base::FilePath webrtc_logs = profile_path.AppendASCII("WebRTC Logs"); |
| 163 | whitelist.push_back(webrtc_logs); |
| 164 | } |
| 165 | #elif defined(OS_ANDROID) |
| 166 | // Access to files in external storage is allowed. |
| 167 | base::FilePath external_storage_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 168 | base::PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, |
| 169 | &external_storage_path); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 170 | if (external_storage_path.IsParent(path)) |
| 171 | return true; |
| 172 | |
Xing Liu | b9456c1 | 2018-05-11 01:46:17 | [diff] [blame] | 173 | auto all_download_dirs = base::android::GetAllPrivateDownloadsDirectories(); |
| 174 | for (const auto& dir : all_download_dirs) |
| 175 | whitelist.push_back(dir); |
| 176 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 177 | // Whitelist of other allowed directories. |
| 178 | static const base::FilePath::CharType* const kLocalAccessWhiteList[] = { |
| 179 | "/sdcard", "/mnt/sdcard", |
| 180 | }; |
| 181 | #endif |
| 182 | |
| 183 | for (const auto* whitelisted_path : kLocalAccessWhiteList) |
| 184 | whitelist.push_back(base::FilePath(whitelisted_path)); |
| 185 | |
| 186 | for (const auto& whitelisted_path : whitelist) { |
| 187 | // base::FilePath::operator== should probably handle trailing separators. |
| 188 | if (whitelisted_path == path.StripTrailingSeparators() || |
| 189 | whitelisted_path.IsParent(path)) { |
| 190 | return true; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | DVLOG(1) << "File access denied - " << path.value().c_str(); |
| 195 | return false; |
| 196 | #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 197 | } |
| 198 | |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 199 | } // namespace |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 200 | |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 201 | ChromeNetworkDelegate::ChromeNetworkDelegate( |
Matt Menke | b63ff0d9 | 2018-06-18 21:40:16 | [diff] [blame^] | 202 | extensions::EventRouterForwarder* event_router) |
Chris Mumford | eee25337 | 2018-05-29 21:12:38 | [diff] [blame] | 203 | : extensions_delegate_( |
| 204 | ChromeExtensionsNetworkDelegate::Create(event_router)), |
| 205 | profile_(nullptr), |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 206 | force_google_safe_search_(nullptr), |
| 207 | force_youtube_restrict_(nullptr), |
igorcov | 193d8ad3 | 2016-05-27 11:03:21 | [diff] [blame] | 208 | allowed_domains_for_apps_(nullptr), |
mkwst | 0513c9d | 2015-04-01 05:53:15 | [diff] [blame] | 209 | experimental_web_platform_features_enabled_( |
gayane | 0b46091c | 2016-04-07 21:01:05 | [diff] [blame] | 210 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 211 | switches::kEnableExperimentalWebPlatformFeatures)), |
sclittle | ae932be | 2015-10-08 20:53:50 | [diff] [blame] | 212 | data_use_aggregator_(nullptr), |
Matt Menke | b63ff0d9 | 2018-06-18 21:40:16 | [diff] [blame^] | 213 | is_data_usage_off_the_record_(true) {} |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 214 | |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 215 | ChromeNetworkDelegate::~ChromeNetworkDelegate() {} |
| 216 | |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 217 | void ChromeNetworkDelegate::set_extension_info_map( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 218 | extensions::InfoMap* extension_info_map) { |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 219 | extensions_delegate_->set_extension_info_map(extension_info_map); |
| 220 | } |
| 221 | |
| 222 | void ChromeNetworkDelegate::set_profile(void* profile) { |
| 223 | profile_ = profile; |
| 224 | extensions_delegate_->set_profile(profile); |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | void ChromeNetworkDelegate::set_cookie_settings( |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 228 | content_settings::CookieSettings* cookie_settings) { |
[email protected] | a09159a | 2012-11-29 12:51:48 | [diff] [blame] | 229 | cookie_settings_ = cookie_settings; |
| 230 | } |
| 231 | |
sclittle | ae932be | 2015-10-08 20:53:50 | [diff] [blame] | 232 | void ChromeNetworkDelegate::set_data_use_aggregator( |
| 233 | data_usage::DataUseAggregator* data_use_aggregator, |
| 234 | bool is_data_usage_off_the_record) { |
| 235 | data_use_aggregator_ = data_use_aggregator; |
| 236 | is_data_usage_off_the_record_ = is_data_usage_off_the_record; |
| 237 | } |
| 238 | |
[email protected] | c4a7df8 | 2012-08-09 22:48:46 | [diff] [blame] | 239 | // static |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 240 | void ChromeNetworkDelegate::InitializePrefsOnUIThread( |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 241 | BooleanPrefMember* force_google_safe_search, |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 242 | IntegerPrefMember* force_youtube_restrict, |
igorcov | 193d8ad3 | 2016-05-27 11:03:21 | [diff] [blame] | 243 | StringPrefMember* allowed_domains_for_apps, |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 244 | PrefService* pref_service) { |
anujk.sharma | 2e02ce16 | 2015-04-29 23:10:02 | [diff] [blame] | 245 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 246 | if (force_google_safe_search) { |
treib | 4e26f665 | 2014-12-01 14:34:18 | [diff] [blame] | 247 | force_google_safe_search->Init(prefs::kForceGoogleSafeSearch, pref_service); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 248 | force_google_safe_search->MoveToThread( |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 249 | BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 250 | } |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 251 | if (force_youtube_restrict) { |
| 252 | force_youtube_restrict->Init(prefs::kForceYouTubeRestrict, pref_service); |
| 253 | force_youtube_restrict->MoveToThread( |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 254 | BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
treib | 4e26f665 | 2014-12-01 14:34:18 | [diff] [blame] | 255 | } |
igorcov | 193d8ad3 | 2016-05-27 11:03:21 | [diff] [blame] | 256 | if (allowed_domains_for_apps) { |
| 257 | allowed_domains_for_apps->Init(prefs::kAllowedDomainsForApps, pref_service); |
| 258 | allowed_domains_for_apps->MoveToThread( |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 259 | BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
igorcov | 193d8ad3 | 2016-05-27 11:03:21 | [diff] [blame] | 260 | } |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 261 | } |
| 262 | |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 263 | int ChromeNetworkDelegate::OnBeforeURLRequest( |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 264 | net::URLRequest* request, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 265 | net::CompletionOnceCallback callback, |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 266 | GURL* new_url) { |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 267 | extensions_delegate_->ForwardStartRequestStatus(request); |
[email protected] | 6baff0b5 | 2012-03-06 01:30:18 | [diff] [blame] | 268 | |
treib | 4e26f665 | 2014-12-01 14:34:18 | [diff] [blame] | 269 | bool force_safe_search = |
treib | 4e26f665 | 2014-12-01 14:34:18 | [diff] [blame] | 270 | (force_google_safe_search_ && force_google_safe_search_->GetValue()); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 271 | |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 272 | net::CompletionOnceCallback wrapped_callback = std::move(callback); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 273 | if (force_safe_search) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 274 | wrapped_callback = base::BindOnce( |
| 275 | &ForceGoogleSafeSearchCallbackWrapper, std::move(wrapped_callback), |
| 276 | base::Unretained(request), base::Unretained(new_url)); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 277 | } |
| 278 | |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 279 | int rv = extensions_delegate_->NotifyBeforeURLRequest( |
| 280 | request, std::move(wrapped_callback), new_url); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 281 | |
| 282 | if (force_safe_search && rv == net::OK && new_url->is_empty()) |
[email protected] | 184799df | 2014-07-22 16:03:24 | [diff] [blame] | 283 | safe_search_util::ForceGoogleSafeSearch(request, new_url); |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 284 | |
igorcov | 193d8ad3 | 2016-05-27 11:03:21 | [diff] [blame] | 285 | if (allowed_domains_for_apps_ && |
| 286 | !allowed_domains_for_apps_->GetValue().empty() && |
| 287 | request->url().DomainIs("google.com")) { |
| 288 | request->SetExtraRequestHeaderByName("X-GoogApps-Allowed-Domains", |
| 289 | allowed_domains_for_apps_->GetValue(), |
| 290 | true); |
| 291 | } |
| 292 | |
[email protected] | d1208ba3 | 2012-11-08 11:10:33 | [diff] [blame] | 293 | return rv; |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 294 | } |
| 295 | |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 296 | int ChromeNetworkDelegate::OnBeforeStartTransaction( |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 297 | net::URLRequest* request, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 298 | net::CompletionOnceCallback callback, |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 299 | net::HttpRequestHeaders* headers) { |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 300 | if (force_youtube_restrict_) { |
| 301 | int value = force_youtube_restrict_->GetValue(); |
| 302 | static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0, |
| 303 | "OFF must be first"); |
| 304 | if (value > safe_search_util::YOUTUBE_RESTRICT_OFF && |
| 305 | value < safe_search_util::YOUTUBE_RESTRICT_COUNT) { |
| 306 | safe_search_util::ForceYouTubeRestrict(request, headers, |
| 307 | static_cast<safe_search_util::YouTubeRestrictMode>(value)); |
| 308 | } |
| 309 | } |
[email protected] | 184799df | 2014-07-22 16:03:24 | [diff] [blame] | 310 | |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 311 | return extensions_delegate_->NotifyBeforeStartTransaction( |
| 312 | request, std::move(callback), headers); |
[email protected] | ac03952 | 2010-06-15 16:39:44 | [diff] [blame] | 313 | } |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 314 | |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 315 | void ChromeNetworkDelegate::OnStartTransaction( |
[email protected] | 5796dc94 | 2011-07-14 19:26:10 | [diff] [blame] | 316 | net::URLRequest* request, |
[email protected] | 783573b | 2011-05-13 11:05:15 | [diff] [blame] | 317 | const net::HttpRequestHeaders& headers) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 318 | extensions_delegate_->NotifyStartTransaction(request, headers); |
[email protected] | 82b4230 | 2011-04-20 16:28:16 | [diff] [blame] | 319 | } |
| 320 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 321 | int ChromeNetworkDelegate::OnHeadersReceived( |
| 322 | net::URLRequest* request, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 323 | net::CompletionOnceCallback callback, |
[email protected] | 507af8f | 2012-10-20 00:42:32 | [diff] [blame] | 324 | const net::HttpResponseHeaders* original_response_headers, |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 325 | scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
| 326 | GURL* allowed_unsafe_redirect_url) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 327 | return extensions_delegate_->NotifyHeadersReceived( |
| 328 | request, std::move(callback), original_response_headers, |
| 329 | override_response_headers, allowed_unsafe_redirect_url); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 330 | } |
| 331 | |
[email protected] | 31b2e5f | 2011-04-20 16:58:32 | [diff] [blame] | 332 | void ChromeNetworkDelegate::OnBeforeRedirect(net::URLRequest* request, |
| 333 | const GURL& new_location) { |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 334 | if (domain_reliability_monitor_) |
| 335 | domain_reliability_monitor_->OnBeforeRedirect(request); |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 336 | extensions_delegate_->NotifyBeforeRedirect(request, new_location); |
Dominic Battre | 5e8a1cd | 2018-01-02 16:16:58 | [diff] [blame] | 337 | variations::StripVariationHeaderIfNeeded(new_location, request); |
[email protected] | 31b2e5f | 2011-04-20 16:58:32 | [diff] [blame] | 338 | } |
| 339 | |
maksim.sisov | 1b83bb7 | 2016-10-07 06:07:23 | [diff] [blame] | 340 | void ChromeNetworkDelegate::OnResponseStarted(net::URLRequest* request, |
| 341 | int net_error) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 342 | extensions_delegate_->NotifyResponseStarted(request, net_error); |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 343 | } |
| 344 | |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 345 | void ChromeNetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request, |
| 346 | int64_t bytes_received) { |
brettw | ee486bb | 2016-12-08 17:56:34 | [diff] [blame] | 347 | #if !defined(OS_ANDROID) |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 348 | // Note: Currently, OnNetworkBytesReceived is only implemented for HTTP jobs, |
| 349 | // 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] | 350 | task_manager::TaskManagerInterface::OnRawBytesRead(*request, bytes_received); |
brettw | ee486bb | 2016-12-08 17:56:34 | [diff] [blame] | 351 | #endif // !defined(OS_ANDROID) |
sclittle | ae932be | 2015-10-08 20:53:50 | [diff] [blame] | 352 | |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 353 | ReportDataUsageStats(request, 0 /* tx_bytes */, bytes_received); |
sclittle | ae932be | 2015-10-08 20:53:50 | [diff] [blame] | 354 | } |
| 355 | |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 356 | void ChromeNetworkDelegate::OnNetworkBytesSent(net::URLRequest* request, |
sclittle | ae932be | 2015-10-08 20:53:50 | [diff] [blame] | 357 | int64_t bytes_sent) { |
cburn | e9d2f361 | 2017-06-20 22:15:03 | [diff] [blame] | 358 | #if !defined(OS_ANDROID) |
| 359 | // Note: Currently, OnNetworkBytesSent is only implemented for HTTP jobs, |
| 360 | // not FTP or other types, so those kinds of bytes will not be reported here. |
| 361 | task_manager::TaskManagerInterface::OnRawBytesSent(*request, bytes_sent); |
| 362 | #endif // !defined(OS_ANDROID) |
| 363 | |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 364 | ReportDataUsageStats(request, bytes_sent, 0 /* rx_bytes */); |
[email protected] | 8523ba5 | 2011-05-22 19:00:58 | [diff] [blame] | 365 | } |
| 366 | |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 367 | void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, |
maksim.sisov | 1b83bb7 | 2016-10-07 06:07:23 | [diff] [blame] | 368 | bool started, |
| 369 | int net_error) { |
| 370 | DCHECK_NE(net::ERR_IO_PENDING, net_error); |
sclittle | 3c16159e | 2014-12-15 19:53:17 | [diff] [blame] | 371 | |
maksim.sisov | 1b83bb7 | 2016-10-07 06:07:23 | [diff] [blame] | 372 | // TODO(amohammadkhan): Verify that there is no double recording in data use |
| 373 | // of redirected requests. |
maksim.sisov | 1b83bb7 | 2016-10-07 06:07:23 | [diff] [blame] | 374 | RecordNetworkErrorHistograms(request, net_error); |
| 375 | |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 376 | extensions_delegate_->NotifyCompleted(request, started, net_error); |
[email protected] | 45de676a | 2014-03-18 23:52:02 | [diff] [blame] | 377 | if (domain_reliability_monitor_) |
| 378 | domain_reliability_monitor_->OnCompleted(request, started); |
maksim.sisov | 1b83bb7 | 2016-10-07 06:07:23 | [diff] [blame] | 379 | extensions_delegate_->ForwardProxyErrors(request, net_error); |
[email protected] | 4a2b623 | 2014-06-19 08:44:14 | [diff] [blame] | 380 | extensions_delegate_->ForwardDoneRequestStatus(request); |
[email protected] | 8202d0c | 2011-02-23 08:31:14 | [diff] [blame] | 381 | } |
[email protected] | 4b50cb5 | 2011-03-10 00:29:37 | [diff] [blame] | 382 | |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 383 | void ChromeNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 384 | extensions_delegate_->NotifyURLRequestDestroyed(request); |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 385 | } |
| 386 | |
[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 387 | void ChromeNetworkDelegate::OnPACScriptError(int line_number, |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 388 | const base::string16& error) { |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 389 | extensions_delegate_->NotifyPACScriptError(line_number, error); |
[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 390 | } |
[email protected] | 7efc582d | 2011-08-03 20:46:35 | [diff] [blame] | 391 | |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 392 | net::NetworkDelegate::AuthRequiredResponse |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 393 | ChromeNetworkDelegate::OnAuthRequired(net::URLRequest* request, |
| 394 | const net::AuthChallengeInfo& auth_info, |
| 395 | AuthCallback callback, |
| 396 | net::AuthCredentials* credentials) { |
| 397 | return extensions_delegate_->NotifyAuthRequired( |
| 398 | request, auth_info, std::move(callback), credentials); |
[email protected] | 7efc582d | 2011-08-03 20:46:35 | [diff] [blame] | 399 | } |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 400 | |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 401 | bool ChromeNetworkDelegate::OnCanGetCookies( |
| 402 | const net::URLRequest& request, |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 403 | const net::CookieList& cookie_list) { |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 404 | // nullptr during tests, or when we're running in the system context. |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 405 | if (!cookie_settings_.get()) |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 406 | return true; |
| 407 | |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 408 | bool allow = cookie_settings_->IsCookieAccessAllowed( |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 409 | request.url(), request.site_for_cookies()); |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 410 | |
jam | 092d3be | 2016-09-27 15:56:36 | [diff] [blame] | 411 | const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); |
| 412 | if (info) { |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 413 | BrowserThread::PostTask( |
| 414 | BrowserThread::UI, FROM_HERE, |
tzik | 53a7b902 | 2017-04-24 11:14:48 | [diff] [blame] | 415 | base::BindOnce(&TabSpecificContentSettings::CookiesRead, |
| 416 | info->GetWebContentsGetterForRequest(), request.url(), |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 417 | request.site_for_cookies(), cookie_list, !allow)); |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | return allow; |
| 421 | } |
| 422 | |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 423 | bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, |
Victor Costan | 70f8551 | 2017-11-20 16:14:46 | [diff] [blame] | 424 | const net::CanonicalCookie& cookie, |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 425 | net::CookieOptions* options) { |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 426 | // nullptr during tests, or when we're running in the system context. |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 427 | if (!cookie_settings_.get()) |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 428 | return true; |
| 429 | |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 430 | bool allow = cookie_settings_->IsCookieAccessAllowed( |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 431 | request.url(), request.site_for_cookies()); |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 432 | |
jam | 092d3be | 2016-09-27 15:56:36 | [diff] [blame] | 433 | const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); |
| 434 | if (info) { |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 435 | BrowserThread::PostTask( |
| 436 | BrowserThread::UI, FROM_HERE, |
tzik | 53a7b902 | 2017-04-24 11:14:48 | [diff] [blame] | 437 | base::BindOnce(&TabSpecificContentSettings::CookieChanged, |
| 438 | info->GetWebContentsGetterForRequest(), request.url(), |
Victor Costan | 70f8551 | 2017-11-20 16:14:46 | [diff] [blame] | 439 | request.site_for_cookies(), cookie, *options, !allow)); |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | return allow; |
| 443 | } |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 444 | |
satorux | ddac044 | 2017-05-29 06:06:18 | [diff] [blame] | 445 | bool ChromeNetworkDelegate::OnCanAccessFile( |
| 446 | const net::URLRequest& request, |
| 447 | const base::FilePath& original_path, |
| 448 | const base::FilePath& absolute_path) const { |
satorux | d18e61a | 2017-06-08 06:38:46 | [diff] [blame] | 449 | if (g_access_to_all_files_enabled) |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 450 | return true; |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 451 | return IsAccessAllowed(original_path, absolute_path, profile_path_); |
satorux | 7c536058 | 2017-01-27 07:24:29 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | // static |
| 455 | bool ChromeNetworkDelegate::IsAccessAllowed( |
| 456 | const base::FilePath& path, |
| 457 | const base::FilePath& profile_path) { |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 458 | return IsAccessAllowedInternal(path, profile_path); |
| 459 | } |
| 460 | |
| 461 | // static |
| 462 | bool ChromeNetworkDelegate::IsAccessAllowed( |
| 463 | const base::FilePath& path, |
| 464 | const base::FilePath& absolute_path, |
| 465 | const base::FilePath& profile_path) { |
| 466 | #if defined(OS_ANDROID) |
| 467 | // Android's whitelist relies on symbolic links (ex. /sdcard is whitelisted |
| 468 | // and commonly a symbolic link), thus do not check absolute paths. |
| 469 | return IsAccessAllowedInternal(path, profile_path); |
satorux | 7c536058 | 2017-01-27 07:24:29 | [diff] [blame] | 470 | #else |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 471 | return (IsAccessAllowedInternal(path, profile_path) && |
| 472 | IsAccessAllowedInternal(absolute_path, profile_path)); |
[email protected] | d8e4f13 | 2012-09-06 04:28:05 | [diff] [blame] | 473 | #endif |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 474 | } |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 475 | |
satorux | d18e61a | 2017-06-08 06:38:46 | [diff] [blame] | 476 | // static |
| 477 | void ChromeNetworkDelegate::EnableAccessToAllFilesForTesting(bool enabled) { |
| 478 | g_access_to_all_files_enabled = enabled; |
| 479 | } |
| 480 | |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 481 | bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( |
| 482 | const GURL& url, |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 483 | const GURL& site_for_cookies) const { |
ljusten | 98684cb7 | 2016-10-11 13:26:18 | [diff] [blame] | 484 | // nullptr during tests, or when we're running in the system context. |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 485 | if (!cookie_settings_.get()) |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 486 | return false; |
| 487 | |
Mike West | b85da8ed | 2017-08-10 14:16:46 | [diff] [blame] | 488 | return !cookie_settings_->IsCookieAccessAllowed(url, site_for_cookies); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 489 | } |
| 490 | |
estark | 7625d81 | 2015-10-12 20:10:41 | [diff] [blame] | 491 | bool ChromeNetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const { |
mkwst | 0513c9d | 2015-04-01 05:53:15 | [diff] [blame] | 492 | return experimental_web_platform_features_enabled_; |
| 493 | } |
| 494 | |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 495 | bool ChromeNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader( |
| 496 | const net::URLRequest& request, |
| 497 | const GURL& target_url, |
| 498 | const GURL& referrer_url) const { |
jochen | 65227537 | 2015-01-16 11:35:27 | [diff] [blame] | 499 | ReportInvalidReferrerSend(target_url, referrer_url); |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 500 | return true; |
| 501 | } |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 502 | |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 503 | bool ChromeNetworkDelegate::OnCanQueueReportingReport( |
| 504 | const url::Origin& origin) const { |
| 505 | if (!cookie_settings_) |
Douglas Creager | 81cad47 | 2018-05-17 14:34:09 | [diff] [blame] | 506 | return false; |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 507 | |
| 508 | return cookie_settings_->IsCookieAccessAllowed(origin.GetURL(), |
| 509 | origin.GetURL()); |
| 510 | } |
| 511 | |
Douglas Creager | 7b07ea4 | 2018-02-27 21:08:08 | [diff] [blame] | 512 | void ChromeNetworkDelegate::OnCanSendReportingReports( |
| 513 | std::set<url::Origin> origins, |
| 514 | base::OnceCallback<void(std::set<url::Origin>)> result_callback) const { |
Douglas Creager | 81cad47 | 2018-05-17 14:34:09 | [diff] [blame] | 515 | if (!reporting_permissions_checker_) { |
| 516 | origins.clear(); |
Douglas Creager | 7b07ea4 | 2018-02-27 21:08:08 | [diff] [blame] | 517 | std::move(result_callback).Run(std::move(origins)); |
| 518 | return; |
| 519 | } |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 520 | |
Douglas Creager | 81cad47 | 2018-05-17 14:34:09 | [diff] [blame] | 521 | reporting_permissions_checker_->FilterReportingOrigins( |
| 522 | std::move(origins), std::move(result_callback)); |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | bool ChromeNetworkDelegate::OnCanSetReportingClient( |
| 526 | const url::Origin& origin, |
| 527 | const GURL& endpoint) const { |
| 528 | if (!cookie_settings_) |
Douglas Creager | 81cad47 | 2018-05-17 14:34:09 | [diff] [blame] | 529 | return false; |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 530 | |
| 531 | return cookie_settings_->IsCookieAccessAllowed(endpoint, origin.GetURL()); |
| 532 | } |
| 533 | |
| 534 | bool ChromeNetworkDelegate::OnCanUseReportingClient( |
| 535 | const url::Origin& origin, |
| 536 | const GURL& endpoint) const { |
| 537 | if (!cookie_settings_) |
Douglas Creager | 81cad47 | 2018-05-17 14:34:09 | [diff] [blame] | 538 | return false; |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 539 | |
| 540 | return cookie_settings_->IsCookieAccessAllowed(endpoint, origin.GetURL()); |
| 541 | } |
| 542 | |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 543 | void ChromeNetworkDelegate::ReportDataUsageStats(net::URLRequest* request, |
| 544 | int64_t tx_bytes, |
| 545 | int64_t rx_bytes) { |
| 546 | if (!data_use_aggregator_) |
| 547 | return; |
| 548 | |
| 549 | if (is_data_usage_off_the_record_) { |
| 550 | data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); |
| 551 | return; |
| 552 | } |
| 553 | |
| 554 | data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); |
| 555 | } |