| 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" |
| 35 #include "chrome/browser/profiles/profile_manager.h" | 36 #include "chrome/browser/profiles/profile_manager.h" |
| 36 #include "chrome/browser/task_manager/task_manager_interface.h" | 37 #include "chrome/browser/task_manager/task_manager_interface.h" |
| 37 #include "chrome/common/features.h" | 38 #include "chrome/common/features.h" |
| 38 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 39 #include "components/content_settings/core/browser/cookie_settings.h" | 40 #include "components/content_settings/core/browser/cookie_settings.h" |
| 40 #include "components/data_usage/core/data_use_aggregator.h" | 41 #include "components/data_usage/core/data_use_aggregator.h" |
| 41 #include "components/domain_reliability/monitor.h" | 42 #include "components/domain_reliability/monitor.h" |
| 42 #include "components/policy/core/browser/url_blacklist_manager.h" | 43 #include "components/policy/core/browser/url_blacklist_manager.h" |
| 43 #include "components/prefs/pref_member.h" | 44 #include "components/prefs/pref_member.h" |
| 44 #include "components/prefs/pref_service.h" | 45 #include "components/prefs/pref_service.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 139 } |
| 139 } | 140 } |
| 140 } | 141 } |
| 141 | 142 |
| 142 } // namespace | 143 } // namespace |
| 143 | 144 |
| 144 ChromeNetworkDelegate::ChromeNetworkDelegate( | 145 ChromeNetworkDelegate::ChromeNetworkDelegate( |
| 145 extensions::EventRouterForwarder* event_router, | 146 extensions::EventRouterForwarder* event_router, |
| 146 BooleanPrefMember* enable_referrers, | 147 BooleanPrefMember* enable_referrers, |
| 147 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder) | 148 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder) |
| 148 : profile_(nullptr), | 149 : profile_(NULL), |
| 149 enable_referrers_(enable_referrers), | 150 enable_referrers_(enable_referrers), |
| 150 enable_do_not_track_(nullptr), | 151 enable_do_not_track_(NULL), |
| 151 force_google_safe_search_(nullptr), | 152 force_google_safe_search_(NULL), |
| 152 force_youtube_restrict_(nullptr), | 153 force_youtube_safety_mode_(NULL), |
| 153 allowed_domains_for_apps_(nullptr), | 154 allowed_domains_for_apps_(nullptr), |
| 154 url_blacklist_manager_(nullptr), | 155 url_blacklist_manager_(NULL), |
| 155 domain_reliability_monitor_(nullptr), | 156 domain_reliability_monitor_(NULL), |
| 156 data_use_measurement_(metrics_data_use_forwarder), | 157 data_use_measurement_(metrics_data_use_forwarder), |
| 157 experimental_web_platform_features_enabled_( | 158 experimental_web_platform_features_enabled_( |
| 158 base::CommandLine::ForCurrentProcess()->HasSwitch( | 159 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 159 switches::kEnableExperimentalWebPlatformFeatures)), | 160 switches::kEnableExperimentalWebPlatformFeatures)), |
| 160 data_use_aggregator_(nullptr), | 161 data_use_aggregator_(nullptr), |
| 161 is_data_usage_off_the_record_(true) { | 162 is_data_usage_off_the_record_(true) { |
| 162 DCHECK(enable_referrers); | 163 DCHECK(enable_referrers); |
| 163 extensions_delegate_.reset( | 164 extensions_delegate_.reset( |
| 164 ChromeExtensionsNetworkDelegate::Create(event_router)); | 165 ChromeExtensionsNetworkDelegate::Create(event_router)); |
| 165 } | 166 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 186 bool is_data_usage_off_the_record) { | 187 bool is_data_usage_off_the_record) { |
| 187 data_use_aggregator_ = data_use_aggregator; | 188 data_use_aggregator_ = data_use_aggregator; |
| 188 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; |
| 189 } | 190 } |
| 190 | 191 |
| 191 // static | 192 // static |
| 192 void ChromeNetworkDelegate::InitializePrefsOnUIThread( | 193 void ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 193 BooleanPrefMember* enable_referrers, | 194 BooleanPrefMember* enable_referrers, |
| 194 BooleanPrefMember* enable_do_not_track, | 195 BooleanPrefMember* enable_do_not_track, |
| 195 BooleanPrefMember* force_google_safe_search, | 196 BooleanPrefMember* force_google_safe_search, |
| 196 IntegerPrefMember* force_youtube_restrict, | 197 BooleanPrefMember* force_youtube_safety_mode, |
| 197 StringPrefMember* allowed_domains_for_apps, | 198 StringPrefMember* allowed_domains_for_apps, |
| 198 PrefService* pref_service) { | 199 PrefService* pref_service) { |
| 199 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 200 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 200 enable_referrers->Init(prefs::kEnableReferrers, pref_service); | 201 enable_referrers->Init(prefs::kEnableReferrers, pref_service); |
| 201 enable_referrers->MoveToThread( | 202 enable_referrers->MoveToThread( |
| 202 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 203 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 203 if (enable_do_not_track) { | 204 if (enable_do_not_track) { |
| 204 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service); | 205 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service); |
| 205 enable_do_not_track->MoveToThread( | 206 enable_do_not_track->MoveToThread( |
| 206 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 207 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 207 } | 208 } |
| 208 if (force_google_safe_search) { | 209 if (force_google_safe_search) { |
| 209 force_google_safe_search->Init(prefs::kForceGoogleSafeSearch, pref_service); | 210 force_google_safe_search->Init(prefs::kForceGoogleSafeSearch, pref_service); |
| 210 force_google_safe_search->MoveToThread( | 211 force_google_safe_search->MoveToThread( |
| 211 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 212 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 212 } | 213 } |
| 213 if (force_youtube_restrict) { | 214 if (force_youtube_safety_mode) { |
| 214 force_youtube_restrict->Init(prefs::kForceYouTubeRestrict, pref_service); | 215 force_youtube_safety_mode->Init(prefs::kForceYouTubeSafetyMode, |
| 215 force_youtube_restrict->MoveToThread( | 216 pref_service); |
| 217 force_youtube_safety_mode->MoveToThread( |
| 216 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 218 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 217 } | 219 } |
| 218 if (allowed_domains_for_apps) { | 220 if (allowed_domains_for_apps) { |
| 219 allowed_domains_for_apps->Init(prefs::kAllowedDomainsForApps, pref_service); | 221 allowed_domains_for_apps->Init(prefs::kAllowedDomainsForApps, pref_service); |
| 220 allowed_domains_for_apps->MoveToThread( | 222 allowed_domains_for_apps->MoveToThread( |
| 221 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 223 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 222 } | 224 } |
| 223 } | 225 } |
| 224 | 226 |
| 225 // static | 227 // static |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 true); | 310 true); |
| 309 } | 311 } |
| 310 | 312 |
| 311 return rv; | 313 return rv; |
| 312 } | 314 } |
| 313 | 315 |
| 314 int ChromeNetworkDelegate::OnBeforeStartTransaction( | 316 int ChromeNetworkDelegate::OnBeforeStartTransaction( |
| 315 net::URLRequest* request, | 317 net::URLRequest* request, |
| 316 const net::CompletionCallback& callback, | 318 const net::CompletionCallback& callback, |
| 317 net::HttpRequestHeaders* headers) { | 319 net::HttpRequestHeaders* headers) { |
| 318 if (force_youtube_restrict_) { | 320 if (force_youtube_safety_mode_ && force_youtube_safety_mode_->GetValue()) |
| 319 int value = force_youtube_restrict_->GetValue(); | 321 safe_search_util::ForceYouTubeSafetyMode(request, headers); |
| 320 static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0, | |
| 321 "OFF must be first"); | |
| 322 if (value > safe_search_util::YOUTUBE_RESTRICT_OFF && | |
| 323 value < safe_search_util::YOUTUBE_RESTRICT_COUNT) { | |
| 324 safe_search_util::ForceYouTubeRestrict(request, headers, | |
| 325 static_cast<safe_search_util::YouTubeRestrictMode>(value)); | |
| 326 } | |
| 327 } | |
| 328 | 322 |
| 329 return extensions_delegate_->OnBeforeStartTransaction(request, callback, | 323 return extensions_delegate_->OnBeforeStartTransaction(request, callback, |
| 330 headers); | 324 headers); |
| 331 } | 325 } |
| 332 | 326 |
| 333 void ChromeNetworkDelegate::OnStartTransaction( | 327 void ChromeNetworkDelegate::OnStartTransaction( |
| 334 net::URLRequest* request, | 328 net::URLRequest* request, |
| 335 const net::HttpRequestHeaders& headers) { | 329 const net::HttpRequestHeaders& headers) { |
| 336 extensions_delegate_->OnStartTransaction(request, headers); | 330 extensions_delegate_->OnStartTransaction(request, headers); |
| 337 } | 331 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 const net::AuthChallengeInfo& auth_info, | 413 const net::AuthChallengeInfo& auth_info, |
| 420 const AuthCallback& callback, | 414 const AuthCallback& callback, |
| 421 net::AuthCredentials* credentials) { | 415 net::AuthCredentials* credentials) { |
| 422 return extensions_delegate_->OnAuthRequired( | 416 return extensions_delegate_->OnAuthRequired( |
| 423 request, auth_info, callback, credentials); | 417 request, auth_info, callback, credentials); |
| 424 } | 418 } |
| 425 | 419 |
| 426 bool ChromeNetworkDelegate::OnCanGetCookies( | 420 bool ChromeNetworkDelegate::OnCanGetCookies( |
| 427 const net::URLRequest& request, | 421 const net::URLRequest& request, |
| 428 const net::CookieList& cookie_list) { | 422 const net::CookieList& cookie_list) { |
| 429 // nullptr during tests, or when we're running in the system context. | 423 // NULL during tests, or when we're running in the system context. |
| 430 if (!cookie_settings_.get()) | 424 if (!cookie_settings_.get()) |
| 431 return true; | 425 return true; |
| 432 | 426 |
| 433 bool allow = cookie_settings_->IsReadingCookieAllowed( | 427 bool allow = cookie_settings_->IsReadingCookieAllowed( |
| 434 request.url(), request.first_party_for_cookies()); | 428 request.url(), request.first_party_for_cookies()); |
| 435 | 429 |
| 436 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); | 430 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); |
| 437 if (info) { | 431 if (info) { |
| 438 BrowserThread::PostTask( | 432 BrowserThread::PostTask( |
| 439 BrowserThread::UI, FROM_HERE, | 433 BrowserThread::UI, FROM_HERE, |
| 440 base::Bind(&TabSpecificContentSettings::CookiesRead, | 434 base::Bind(&TabSpecificContentSettings::CookiesRead, |
| 441 info->GetWebContentsGetterForRequest(), | 435 info->GetWebContentsGetterForRequest(), |
| 442 request.url(), request.first_party_for_cookies(), | 436 request.url(), request.first_party_for_cookies(), |
| 443 cookie_list, !allow)); | 437 cookie_list, !allow)); |
| 444 } | 438 } |
| 445 | 439 |
| 446 return allow; | 440 return allow; |
| 447 } | 441 } |
| 448 | 442 |
| 449 bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, | 443 bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, |
| 450 const std::string& cookie_line, | 444 const std::string& cookie_line, |
| 451 net::CookieOptions* options) { | 445 net::CookieOptions* options) { |
| 452 // nullptr during tests, or when we're running in the system context. | 446 // NULL during tests, or when we're running in the system context. |
| 453 if (!cookie_settings_.get()) | 447 if (!cookie_settings_.get()) |
| 454 return true; | 448 return true; |
| 455 | 449 |
| 456 bool allow = cookie_settings_->IsSettingCookieAllowed( | 450 bool allow = cookie_settings_->IsSettingCookieAllowed( |
| 457 request.url(), request.first_party_for_cookies()); | 451 request.url(), request.first_party_for_cookies()); |
| 458 | 452 |
| 459 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); | 453 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request); |
| 460 if (info) { | 454 if (info) { |
| 461 BrowserThread::PostTask( | 455 BrowserThread::PostTask( |
| 462 BrowserThread::UI, FROM_HERE, | 456 BrowserThread::UI, FROM_HERE, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 } | 531 } |
| 538 | 532 |
| 539 DVLOG(1) << "File access denied - " << path.value().c_str(); | 533 DVLOG(1) << "File access denied - " << path.value().c_str(); |
| 540 return false; | 534 return false; |
| 541 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 535 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 542 } | 536 } |
| 543 | 537 |
| 544 bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( | 538 bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( |
| 545 const GURL& url, | 539 const GURL& url, |
| 546 const GURL& first_party_for_cookies) const { | 540 const GURL& first_party_for_cookies) const { |
| 547 // nullptr during tests, or when we're running in the system context. | 541 // NULL during tests, or when we're running in the system context. |
| 548 if (!cookie_settings_.get()) | 542 if (!cookie_settings_.get()) |
| 549 return false; | 543 return false; |
| 550 | 544 |
| 551 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed( | 545 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed( |
| 552 url, first_party_for_cookies); | 546 url, first_party_for_cookies); |
| 553 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed( | 547 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed( |
| 554 url, first_party_for_cookies); | 548 url, first_party_for_cookies); |
| 555 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed); | 549 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed); |
| 556 return privacy_mode; | 550 return privacy_mode; |
| 557 } | 551 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 582 if (!data_use_aggregator_) | 576 if (!data_use_aggregator_) |
| 583 return; | 577 return; |
| 584 | 578 |
| 585 if (is_data_usage_off_the_record_) { | 579 if (is_data_usage_off_the_record_) { |
| 586 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); | 580 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); |
| 587 return; | 581 return; |
| 588 } | 582 } |
| 589 | 583 |
| 590 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); | 584 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); |
| 591 } | 585 } |
| OLD | NEW |