| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 137 } |
| 139 } | 138 } |
| 140 } | 139 } |
| 141 | 140 |
| 142 } // namespace | 141 } // namespace |
| 143 | 142 |
| 144 ChromeNetworkDelegate::ChromeNetworkDelegate( | 143 ChromeNetworkDelegate::ChromeNetworkDelegate( |
| 145 extensions::EventRouterForwarder* event_router, | 144 extensions::EventRouterForwarder* event_router, |
| 146 BooleanPrefMember* enable_referrers, | 145 BooleanPrefMember* enable_referrers, |
| 147 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder) | 146 const metrics::UpdateUsagePrefCallbackType& metrics_data_use_forwarder) |
| 148 : profile_(NULL), | 147 : profile_(nullptr), |
| 149 enable_referrers_(enable_referrers), | 148 enable_referrers_(enable_referrers), |
| 150 enable_do_not_track_(NULL), | 149 enable_do_not_track_(nullptr), |
| 151 force_google_safe_search_(NULL), | 150 force_google_safe_search_(nullptr), |
| 152 force_youtube_safety_mode_(NULL), | 151 force_youtube_restrict_(nullptr), |
| 153 allowed_domains_for_apps_(nullptr), | 152 allowed_domains_for_apps_(nullptr), |
| 154 url_blacklist_manager_(NULL), | 153 url_blacklist_manager_(nullptr), |
| 155 domain_reliability_monitor_(NULL), | 154 domain_reliability_monitor_(nullptr), |
| 156 data_use_measurement_(metrics_data_use_forwarder), | 155 data_use_measurement_(metrics_data_use_forwarder), |
| 157 experimental_web_platform_features_enabled_( | 156 experimental_web_platform_features_enabled_( |
| 158 base::CommandLine::ForCurrentProcess()->HasSwitch( | 157 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 159 switches::kEnableExperimentalWebPlatformFeatures)), | 158 switches::kEnableExperimentalWebPlatformFeatures)), |
| 160 data_use_aggregator_(nullptr), | 159 data_use_aggregator_(nullptr), |
| 161 is_data_usage_off_the_record_(true) { | 160 is_data_usage_off_the_record_(true) { |
| 162 DCHECK(enable_referrers); | 161 DCHECK(enable_referrers); |
| 163 extensions_delegate_.reset( | 162 extensions_delegate_.reset( |
| 164 ChromeExtensionsNetworkDelegate::Create(event_router)); | 163 ChromeExtensionsNetworkDelegate::Create(event_router)); |
| 165 } | 164 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 186 bool is_data_usage_off_the_record) { | 185 bool is_data_usage_off_the_record) { |
| 187 data_use_aggregator_ = data_use_aggregator; | 186 data_use_aggregator_ = data_use_aggregator; |
| 188 is_data_usage_off_the_record_ = is_data_usage_off_the_record; | 187 is_data_usage_off_the_record_ = is_data_usage_off_the_record; |
| 189 } | 188 } |
| 190 | 189 |
| 191 // static | 190 // static |
| 192 void ChromeNetworkDelegate::InitializePrefsOnUIThread( | 191 void ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 193 BooleanPrefMember* enable_referrers, | 192 BooleanPrefMember* enable_referrers, |
| 194 BooleanPrefMember* enable_do_not_track, | 193 BooleanPrefMember* enable_do_not_track, |
| 195 BooleanPrefMember* force_google_safe_search, | 194 BooleanPrefMember* force_google_safe_search, |
| 196 BooleanPrefMember* force_youtube_safety_mode, | 195 IntegerPrefMember* force_youtube_restrict, |
| 197 StringPrefMember* allowed_domains_for_apps, | 196 StringPrefMember* allowed_domains_for_apps, |
| 198 PrefService* pref_service) { | 197 PrefService* pref_service) { |
| 199 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 198 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 200 enable_referrers->Init(prefs::kEnableReferrers, pref_service); | 199 enable_referrers->Init(prefs::kEnableReferrers, pref_service); |
| 201 enable_referrers->MoveToThread( | 200 enable_referrers->MoveToThread( |
| 202 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 201 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 203 if (enable_do_not_track) { | 202 if (enable_do_not_track) { |
| 204 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service); | 203 enable_do_not_track->Init(prefs::kEnableDoNotTrack, pref_service); |
| 205 enable_do_not_track->MoveToThread( | 204 enable_do_not_track->MoveToThread( |
| 206 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 205 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 207 } | 206 } |
| 208 if (force_google_safe_search) { | 207 if (force_google_safe_search) { |
| 209 force_google_safe_search->Init(prefs::kForceGoogleSafeSearch, pref_service); | 208 force_google_safe_search->Init(prefs::kForceGoogleSafeSearch, pref_service); |
| 210 force_google_safe_search->MoveToThread( | 209 force_google_safe_search->MoveToThread( |
| 211 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 210 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 212 } | 211 } |
| 213 if (force_youtube_safety_mode) { | 212 if (force_youtube_restrict) { |
| 214 force_youtube_safety_mode->Init(prefs::kForceYouTubeSafetyMode, | 213 force_youtube_restrict->Init(prefs::kForceYouTubeRestrict, pref_service); |
| 215 pref_service); | 214 force_youtube_restrict->MoveToThread( |
| 216 force_youtube_safety_mode->MoveToThread( | |
| 217 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 215 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 218 } | 216 } |
| 219 if (allowed_domains_for_apps) { | 217 if (allowed_domains_for_apps) { |
| 220 allowed_domains_for_apps->Init(prefs::kAllowedDomainsForApps, pref_service); | 218 allowed_domains_for_apps->Init(prefs::kAllowedDomainsForApps, pref_service); |
| 221 allowed_domains_for_apps->MoveToThread( | 219 allowed_domains_for_apps->MoveToThread( |
| 222 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 220 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 223 } | 221 } |
| 224 } | 222 } |
| 225 | 223 |
| 226 // static | 224 // static |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 true); | 305 true); |
| 308 } | 306 } |
| 309 | 307 |
| 310 return rv; | 308 return rv; |
| 311 } | 309 } |
| 312 | 310 |
| 313 int ChromeNetworkDelegate::OnBeforeStartTransaction( | 311 int ChromeNetworkDelegate::OnBeforeStartTransaction( |
| 314 net::URLRequest* request, | 312 net::URLRequest* request, |
| 315 const net::CompletionCallback& callback, | 313 const net::CompletionCallback& callback, |
| 316 net::HttpRequestHeaders* headers) { | 314 net::HttpRequestHeaders* headers) { |
| 317 if (force_youtube_safety_mode_ && force_youtube_safety_mode_->GetValue()) | 315 if (force_youtube_restrict_ && |
| 318 safe_search_util::ForceYouTubeSafetyMode(request, headers); | 316 force_youtube_restrict_->GetValue() != |
| 317 static_cast<int>(safe_search_util::YouTubeRestrictMode::OFF)) { |
| 318 safe_search_util::ForceYouTubeRestrict( |
| 319 request, headers, static_cast<safe_search_util::YouTubeRestrictMode>( |
| 320 force_youtube_restrict_->GetValue())); |
| 321 } |
| 319 | 322 |
| 320 return extensions_delegate_->OnBeforeStartTransaction(request, callback, | 323 return extensions_delegate_->OnBeforeStartTransaction(request, callback, |
| 321 headers); | 324 headers); |
| 322 } | 325 } |
| 323 | 326 |
| 324 void ChromeNetworkDelegate::OnStartTransaction( | 327 void ChromeNetworkDelegate::OnStartTransaction( |
| 325 net::URLRequest* request, | 328 net::URLRequest* request, |
| 326 const net::HttpRequestHeaders& headers) { | 329 const net::HttpRequestHeaders& headers) { |
| 327 extensions_delegate_->OnStartTransaction(request, headers); | 330 extensions_delegate_->OnStartTransaction(request, headers); |
| 328 } | 331 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 const net::AuthChallengeInfo& auth_info, | 411 const net::AuthChallengeInfo& auth_info, |
| 409 const AuthCallback& callback, | 412 const AuthCallback& callback, |
| 410 net::AuthCredentials* credentials) { | 413 net::AuthCredentials* credentials) { |
| 411 return extensions_delegate_->OnAuthRequired( | 414 return extensions_delegate_->OnAuthRequired( |
| 412 request, auth_info, callback, credentials); | 415 request, auth_info, callback, credentials); |
| 413 } | 416 } |
| 414 | 417 |
| 415 bool ChromeNetworkDelegate::OnCanGetCookies( | 418 bool ChromeNetworkDelegate::OnCanGetCookies( |
| 416 const net::URLRequest& request, | 419 const net::URLRequest& request, |
| 417 const net::CookieList& cookie_list) { | 420 const net::CookieList& cookie_list) { |
| 418 // NULL during tests, or when we're running in the system context. | 421 // nullptr during tests, or when we're running in the system context. |
| 419 if (!cookie_settings_.get()) | 422 if (!cookie_settings_.get()) |
| 420 return true; | 423 return true; |
| 421 | 424 |
| 422 bool allow = cookie_settings_->IsReadingCookieAllowed( | 425 bool allow = cookie_settings_->IsReadingCookieAllowed( |
| 423 request.url(), request.first_party_for_cookies()); | 426 request.url(), request.first_party_for_cookies()); |
| 424 | 427 |
| 425 int render_process_id = -1; | 428 int render_process_id = -1; |
| 426 int render_frame_id = -1; | 429 int render_frame_id = -1; |
| 427 if (content::ResourceRequestInfo::GetRenderFrameForRequest( | 430 if (content::ResourceRequestInfo::GetRenderFrameForRequest( |
| 428 &request, &render_process_id, &render_frame_id)) { | 431 &request, &render_process_id, &render_frame_id)) { |
| 429 BrowserThread::PostTask( | 432 BrowserThread::PostTask( |
| 430 BrowserThread::UI, FROM_HERE, | 433 BrowserThread::UI, FROM_HERE, |
| 431 base::Bind(&TabSpecificContentSettings::CookiesRead, | 434 base::Bind(&TabSpecificContentSettings::CookiesRead, |
| 432 render_process_id, render_frame_id, | 435 render_process_id, render_frame_id, |
| 433 request.url(), request.first_party_for_cookies(), | 436 request.url(), request.first_party_for_cookies(), |
| 434 cookie_list, !allow)); | 437 cookie_list, !allow)); |
| 435 } | 438 } |
| 436 | 439 |
| 437 return allow; | 440 return allow; |
| 438 } | 441 } |
| 439 | 442 |
| 440 bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, | 443 bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, |
| 441 const std::string& cookie_line, | 444 const std::string& cookie_line, |
| 442 net::CookieOptions* options) { | 445 net::CookieOptions* options) { |
| 443 // NULL during tests, or when we're running in the system context. | 446 // nullptr during tests, or when we're running in the system context. |
| 444 if (!cookie_settings_.get()) | 447 if (!cookie_settings_.get()) |
| 445 return true; | 448 return true; |
| 446 | 449 |
| 447 bool allow = cookie_settings_->IsSettingCookieAllowed( | 450 bool allow = cookie_settings_->IsSettingCookieAllowed( |
| 448 request.url(), request.first_party_for_cookies()); | 451 request.url(), request.first_party_for_cookies()); |
| 449 | 452 |
| 450 int render_process_id = -1; | 453 int render_process_id = -1; |
| 451 int render_frame_id = -1; | 454 int render_frame_id = -1; |
| 452 if (content::ResourceRequestInfo::GetRenderFrameForRequest( | 455 if (content::ResourceRequestInfo::GetRenderFrameForRequest( |
| 453 &request, &render_process_id, &render_frame_id)) { | 456 &request, &render_process_id, &render_frame_id)) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 } | 542 } |
| 540 | 543 |
| 541 DVLOG(1) << "File access denied - " << path.value().c_str(); | 544 DVLOG(1) << "File access denied - " << path.value().c_str(); |
| 542 return false; | 545 return false; |
| 543 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 546 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 544 } | 547 } |
| 545 | 548 |
| 546 bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( | 549 bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( |
| 547 const GURL& url, | 550 const GURL& url, |
| 548 const GURL& first_party_for_cookies) const { | 551 const GURL& first_party_for_cookies) const { |
| 549 // NULL during tests, or when we're running in the system context. | 552 // nullptr during tests, or when we're running in the system context. |
| 550 if (!cookie_settings_.get()) | 553 if (!cookie_settings_.get()) |
| 551 return false; | 554 return false; |
| 552 | 555 |
| 553 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed( | 556 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed( |
| 554 url, first_party_for_cookies); | 557 url, first_party_for_cookies); |
| 555 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed( | 558 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed( |
| 556 url, first_party_for_cookies); | 559 url, first_party_for_cookies); |
| 557 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed); | 560 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed); |
| 558 return privacy_mode; | 561 return privacy_mode; |
| 559 } | 562 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 584 if (!data_use_aggregator_) | 587 if (!data_use_aggregator_) |
| 585 return; | 588 return; |
| 586 | 589 |
| 587 if (is_data_usage_off_the_record_) { | 590 if (is_data_usage_off_the_record_) { |
| 588 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); | 591 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); |
| 589 return; | 592 return; |
| 590 } | 593 } |
| 591 | 594 |
| 592 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); | 595 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); |
| 593 } | 596 } |
| OLD | NEW |