OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/net/chrome_network_delegate.h" | 5 #include "chrome/browser/net/chrome_network_delegate.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
26 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
27 #include "base/time/time.h" | 27 #include "base/time/time.h" |
28 #include "build/build_config.h" | 28 #include "build/build_config.h" |
29 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
30 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 30 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
31 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 31 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
32 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 32 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
33 #include "chrome/browser/net/chrome_extensions_network_delegate.h" | 33 #include "chrome/browser/net/chrome_extensions_network_delegate.h" |
34 #include "chrome/browser/net/request_source_bandwidth_histograms.h" | 34 #include "chrome/browser/net/request_source_bandwidth_histograms.h" |
35 #include "chrome/browser/net/safe_search_util.h" | |
36 #include "chrome/browser/profiles/profile_manager.h" | 35 #include "chrome/browser/profiles/profile_manager.h" |
37 #include "chrome/browser/task_manager/task_manager_interface.h" | 36 #include "chrome/browser/task_manager/task_manager_interface.h" |
38 #include "chrome/common/chrome_constants.h" | 37 #include "chrome/common/chrome_constants.h" |
39 #include "chrome/common/features.h" | 38 #include "chrome/common/features.h" |
40 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
41 #include "components/content_settings/core/browser/cookie_settings.h" | 40 #include "components/content_settings/core/browser/cookie_settings.h" |
42 #include "components/data_usage/core/data_use_aggregator.h" | 41 #include "components/data_usage/core/data_use_aggregator.h" |
43 #include "components/domain_reliability/monitor.h" | 42 #include "components/domain_reliability/monitor.h" |
44 #include "components/policy/core/browser/url_blacklist_manager.h" | 43 #include "components/policy/core/browser/url_blacklist_manager.h" |
45 #include "components/prefs/pref_member.h" | 44 #include "components/prefs/pref_member.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 } | 139 } |
141 } | 140 } |
142 } | 141 } |
143 | 142 |
144 } // namespace | 143 } // namespace |
145 | 144 |
146 ChromeNetworkDelegate::ChromeNetworkDelegate( | 145 ChromeNetworkDelegate::ChromeNetworkDelegate( |
147 extensions::EventRouterForwarder* event_router, | 146 extensions::EventRouterForwarder* event_router, |
148 BooleanPrefMember* enable_referrers, | 147 BooleanPrefMember* enable_referrers, |
149 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder) | 148 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder) |
150 : profile_(NULL), | 149 : profile_(nullptr), |
151 enable_referrers_(enable_referrers), | 150 enable_referrers_(enable_referrers), |
152 enable_do_not_track_(NULL), | 151 enable_do_not_track_(nullptr), |
153 force_google_safe_search_(NULL), | 152 force_google_safe_search_(nullptr), |
154 force_youtube_safety_mode_(NULL), | 153 force_youtube_restrict_(nullptr), |
155 allowed_domains_for_apps_(nullptr), | 154 allowed_domains_for_apps_(nullptr), |
156 url_blacklist_manager_(NULL), | 155 url_blacklist_manager_(nullptr), |
157 domain_reliability_monitor_(NULL), | 156 domain_reliability_monitor_(nullptr), |
158 data_use_measurement_(metrics_data_use_forwarder), | 157 data_use_measurement_(metrics_data_use_forwarder), |
159 experimental_web_platform_features_enabled_( | 158 experimental_web_platform_features_enabled_( |
160 base::CommandLine::ForCurrentProcess()->HasSwitch( | 159 base::CommandLine::ForCurrentProcess()->HasSwitch( |
161 switches::kEnableExperimentalWebPlatformFeatures)), | 160 switches::kEnableExperimentalWebPlatformFeatures)), |
162 data_use_aggregator_(nullptr), | 161 data_use_aggregator_(nullptr), |
163 is_data_usage_off_the_record_(true) { | 162 is_data_usage_off_the_record_(true) { |
164 DCHECK(enable_referrers); | 163 DCHECK(enable_referrers); |
165 extensions_delegate_.reset( | 164 extensions_delegate_.reset( |
166 ChromeExtensionsNetworkDelegate::Create(event_router)); | 165 ChromeExtensionsNetworkDelegate::Create(event_router)); |
167 } | 166 } |
(...skipping 20 matching lines...) Expand all Loading... | |
188 bool is_data_usage_off_the_record) { | 187 bool is_data_usage_off_the_record) { |
189 data_use_aggregator_ = data_use_aggregator; | 188 data_use_aggregator_ = data_use_aggregator; |
190 is_data_usage_off_the_record_ = is_data_usage_off_the_record; | 189 is_data_usage_off_the_record_ = is_data_usage_off_the_record; |
191 } | 190 } |
192 | 191 |
193 // static | 192 // static |
194 void ChromeNetworkDelegate::InitializePrefsOnUIThread( | 193 void ChromeNetworkDelegate::InitializePrefsOnUIThread( |
195 BooleanPrefMember* enable_referrers, | 194 BooleanPrefMember* enable_referrers, |
196 BooleanPrefMember* enable_do_not_track, | 195 BooleanPrefMember* enable_do_not_track, |
197 BooleanPrefMember* force_google_safe_search, | 196 BooleanPrefMember* force_google_safe_search, |
198 BooleanPrefMember* force_youtube_safety_mode, | 197 IntegerPrefMember* force_youtube_restrict, |
199 StringPrefMember* allowed_domains_for_apps, | 198 StringPrefMember* allowed_domains_for_apps, |
200 PrefService* pref_service) { | 199 PrefService* pref_service) { |
201 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 200 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
202 enable_referrers->Init(prefs::kEnableReferrers, pref_service); | 201 enable_referrers->Init(prefs::kEnableReferrers, pref_service); |
203 enable_referrers->MoveToThread( | 202 enable_referrers->MoveToThread( |
204 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 203 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
205 if (enable_do_not_track) { | 204 if (enable_do_not_track) { |
206 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service); | 205 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service); |
207 enable_do_not_track->MoveToThread( | 206 enable_do_not_track->MoveToThread( |
208 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 207 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
209 } | 208 } |
210 if (force_google_safe_search) { | 209 if (force_google_safe_search) { |
211 force_google_safe_search->Init(prefs::kForceGoogleSafeSearch, pref_service); | 210 force_google_safe_search->Init(prefs::kForceGoogleSafeSearch, pref_service); |
212 force_google_safe_search->MoveToThread( | 211 force_google_safe_search->MoveToThread( |
213 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 212 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
214 } | 213 } |
215 if (force_youtube_safety_mode) { | 214 if (force_youtube_restrict) { |
216 force_youtube_safety_mode->Init(prefs::kForceYouTubeSafetyMode, | 215 force_youtube_restrict->Init(prefs::kForceYouTubeRestrict, pref_service); |
217 pref_service); | 216 force_youtube_restrict->MoveToThread( |
218 force_youtube_safety_mode->MoveToThread( | |
219 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 217 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
220 } | 218 } |
221 if (allowed_domains_for_apps) { | 219 if (allowed_domains_for_apps) { |
222 allowed_domains_for_apps->Init(prefs::kAllowedDomainsForApps, pref_service); | 220 allowed_domains_for_apps->Init(prefs::kAllowedDomainsForApps, pref_service); |
223 allowed_domains_for_apps->MoveToThread( | 221 allowed_domains_for_apps->MoveToThread( |
224 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 222 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
225 } | 223 } |
226 } | 224 } |
227 | 225 |
228 // static | 226 // static |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 true); | 309 true); |
312 } | 310 } |
313 | 311 |
314 return rv; | 312 return rv; |
315 } | 313 } |
316 | 314 |
317 int ChromeNetworkDelegate::OnBeforeStartTransaction( | 315 int ChromeNetworkDelegate::OnBeforeStartTransaction( |
318 net::URLRequest* request, | 316 net::URLRequest* request, |
319 const net::CompletionCallback& callback, | 317 const net::CompletionCallback& callback, |
320 net::HttpRequestHeaders* headers) { | 318 net::HttpRequestHeaders* headers) { |
321 if (force_youtube_safety_mode_ && force_youtube_safety_mode_->GetValue()) | 319 if (force_youtube_restrict_) { |
322 safe_search_util::ForceYouTubeSafetyMode(request, headers); | 320 int value = force_youtube_restrict_->GetValue(); |
321 if (value > safe_search_util::YOUTUBE_RESTRICT_OFF && | |
Thiemo Nagel
2016/10/06 14:05:58
This doesn't call ForceYouTubeRestrict() and thus
ljusten (tachyonic)
2016/10/06 16:16:58
Changed as discussed.
| |
322 value < safe_search_util::kYouTubeRestrictModeCount) { | |
323 safe_search_util::ForceYouTubeRestrict(request, headers, | |
324 static_cast<safe_search_util::YouTubeRestrictMode>(value)); | |
325 } | |
326 } | |
323 | 327 |
324 return extensions_delegate_->OnBeforeStartTransaction(request, callback, | 328 return extensions_delegate_->OnBeforeStartTransaction(request, callback, |
325 headers); | 329 headers); |
326 } | 330 } |
327 | 331 |
328 void ChromeNetworkDelegate::OnStartTransaction( | 332 void ChromeNetworkDelegate::OnStartTransaction( |
329 net::URLRequest* request, | 333 net::URLRequest* request, |
330 const net::HttpRequestHeaders& headers) { | 334 const net::HttpRequestHeaders& headers) { |
331 extensions_delegate_->OnStartTransaction(request, headers); | 335 extensions_delegate_->OnStartTransaction(request, headers); |
332 } | 336 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 const net::AuthChallengeInfo& auth_info, | 418 const net::AuthChallengeInfo& auth_info, |
415 const AuthCallback& callback, | 419 const AuthCallback& callback, |
416 net::AuthCredentials* credentials) { | 420 net::AuthCredentials* credentials) { |
417 return extensions_delegate_->OnAuthRequired( | 421 return extensions_delegate_->OnAuthRequired( |
418 request, auth_info, callback, credentials); | 422 request, auth_info, callback, credentials); |
419 } | 423 } |
420 | 424 |
421 bool ChromeNetworkDelegate::OnCanGetCookies( | 425 bool ChromeNetworkDelegate::OnCanGetCookies( |
422 const net::URLRequest& request, | 426 const net::URLRequest& request, |
423 const net::CookieList& cookie_list) { | 427 const net::CookieList& cookie_list) { |
424 // NULL during tests, or when we're running in the system context. | 428 // nullptr during tests, or when we're running in the system context. |
425 if (!cookie_settings_.get()) | 429 if (!cookie_settings_.get()) |
426 return true; | 430 return true; |
427 | 431 |
428 bool allow = cookie_settings_->IsReadingCookieAllowed( | 432 bool allow = cookie_settings_->IsReadingCookieAllowed( |
429 request.url(), request.first_party_for_cookies()); | 433 request.url(), request.first_party_for_cookies()); |
430 | 434 |
431 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); | 435 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); |
432 if (info) { | 436 if (info) { |
433 BrowserThread::PostTask( | 437 BrowserThread::PostTask( |
434 BrowserThread::UI, FROM_HERE, | 438 BrowserThread::UI, FROM_HERE, |
435 base::Bind(&TabSpecificContentSettings::CookiesRead, | 439 base::Bind(&TabSpecificContentSettings::CookiesRead, |
436 info->GetWebContentsGetterForRequest(), | 440 info->GetWebContentsGetterForRequest(), |
437 request.url(), request.first_party_for_cookies(), | 441 request.url(), request.first_party_for_cookies(), |
438 cookie_list, !allow)); | 442 cookie_list, !allow)); |
439 } | 443 } |
440 | 444 |
441 return allow; | 445 return allow; |
442 } | 446 } |
443 | 447 |
444 bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, | 448 bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, |
445 const std::string& cookie_line, | 449 const std::string& cookie_line, |
446 net::CookieOptions* options) { | 450 net::CookieOptions* options) { |
447 // NULL during tests, or when we're running in the system context. | 451 // nullptr during tests, or when we're running in the system context. |
448 if (!cookie_settings_.get()) | 452 if (!cookie_settings_.get()) |
449 return true; | 453 return true; |
450 | 454 |
451 bool allow = cookie_settings_->IsSettingCookieAllowed( | 455 bool allow = cookie_settings_->IsSettingCookieAllowed( |
452 request.url(), request.first_party_for_cookies()); | 456 request.url(), request.first_party_for_cookies()); |
453 | 457 |
454 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); | 458 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); |
455 if (info) { | 459 if (info) { |
456 BrowserThread::PostTask( | 460 BrowserThread::PostTask( |
457 BrowserThread::UI, FROM_HERE, | 461 BrowserThread::UI, FROM_HERE, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 } | 545 } |
542 | 546 |
543 DVLOG(1) << "File access denied - " << path.value().c_str(); | 547 DVLOG(1) << "File access denied - " << path.value().c_str(); |
544 return false; | 548 return false; |
545 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 549 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
546 } | 550 } |
547 | 551 |
548 bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( | 552 bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( |
549 const GURL& url, | 553 const GURL& url, |
550 const GURL& first_party_for_cookies) const { | 554 const GURL& first_party_for_cookies) const { |
551 // NULL during tests, or when we're running in the system context. | 555 // nullptr during tests, or when we're running in the system context. |
552 if (!cookie_settings_.get()) | 556 if (!cookie_settings_.get()) |
553 return false; | 557 return false; |
554 | 558 |
555 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed( | 559 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed( |
556 url, first_party_for_cookies); | 560 url, first_party_for_cookies); |
557 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed( | 561 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed( |
558 url, first_party_for_cookies); | 562 url, first_party_for_cookies); |
559 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed); | 563 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed); |
560 return privacy_mode; | 564 return privacy_mode; |
561 } | 565 } |
(...skipping 24 matching lines...) Expand all Loading... | |
586 if (!data_use_aggregator_) | 590 if (!data_use_aggregator_) |
587 return; | 591 return; |
588 | 592 |
589 if (is_data_usage_off_the_record_) { | 593 if (is_data_usage_off_the_record_) { |
590 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); | 594 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); |
591 return; | 595 return; |
592 } | 596 } |
593 | 597 |
594 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); | 598 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); |
595 } | 599 } |
OLD | NEW |