| 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() != safe_search_util::YOUTUBE_OFF) |
| 317 safe_search_util::ForceYouTubeRestrict( |
| 318 request, headers, static_cast<safe_search_util::YouTubeRestrictMode>( |
| 319 force_youtube_restrict_->GetValue())); |
| 319 | 320 |
| 320 return extensions_delegate_->OnBeforeStartTransaction(request, callback, | 321 return extensions_delegate_->OnBeforeStartTransaction(request, callback, |
| 321 headers); | 322 headers); |
| 322 } | 323 } |
| 323 | 324 |
| 324 void ChromeNetworkDelegate::OnStartTransaction( | 325 void ChromeNetworkDelegate::OnStartTransaction( |
| 325 net::URLRequest* request, | 326 net::URLRequest* request, |
| 326 const net::HttpRequestHeaders& headers) { | 327 const net::HttpRequestHeaders& headers) { |
| 327 extensions_delegate_->OnStartTransaction(request, headers); | 328 extensions_delegate_->OnStartTransaction(request, headers); |
| 328 } | 329 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 const net::AuthChallengeInfo& auth_info, | 409 const net::AuthChallengeInfo& auth_info, |
| 409 const AuthCallback& callback, | 410 const AuthCallback& callback, |
| 410 net::AuthCredentials* credentials) { | 411 net::AuthCredentials* credentials) { |
| 411 return extensions_delegate_->OnAuthRequired( | 412 return extensions_delegate_->OnAuthRequired( |
| 412 request, auth_info, callback, credentials); | 413 request, auth_info, callback, credentials); |
| 413 } | 414 } |
| 414 | 415 |
| 415 bool ChromeNetworkDelegate::OnCanGetCookies( | 416 bool ChromeNetworkDelegate::OnCanGetCookies( |
| 416 const net::URLRequest& request, | 417 const net::URLRequest& request, |
| 417 const net::CookieList& cookie_list) { | 418 const net::CookieList& cookie_list) { |
| 418 // NULL during tests, or when we're running in the system context. | 419 // nullptr during tests, or when we're running in the system context. |
| 419 if (!cookie_settings_.get()) | 420 if (!cookie_settings_.get()) |
| 420 return true; | 421 return true; |
| 421 | 422 |
| 422 bool allow = cookie_settings_->IsReadingCookieAllowed( | 423 bool allow = cookie_settings_->IsReadingCookieAllowed( |
| 423 request.url(), request.first_party_for_cookies()); | 424 request.url(), request.first_party_for_cookies()); |
| 424 | 425 |
| 425 int render_process_id = -1; | 426 int render_process_id = -1; |
| 426 int render_frame_id = -1; | 427 int render_frame_id = -1; |
| 427 if (content::ResourceRequestInfo::GetRenderFrameForRequest( | 428 if (content::ResourceRequestInfo::GetRenderFrameForRequest( |
| 428 &request, &render_process_id, &render_frame_id)) { | 429 &request, &render_process_id, &render_frame_id)) { |
| 429 BrowserThread::PostTask( | 430 BrowserThread::PostTask( |
| 430 BrowserThread::UI, FROM_HERE, | 431 BrowserThread::UI, FROM_HERE, |
| 431 base::Bind(&TabSpecificContentSettings::CookiesRead, | 432 base::Bind(&TabSpecificContentSettings::CookiesRead, |
| 432 render_process_id, render_frame_id, | 433 render_process_id, render_frame_id, |
| 433 request.url(), request.first_party_for_cookies(), | 434 request.url(), request.first_party_for_cookies(), |
| 434 cookie_list, !allow)); | 435 cookie_list, !allow)); |
| 435 } | 436 } |
| 436 | 437 |
| 437 return allow; | 438 return allow; |
| 438 } | 439 } |
| 439 | 440 |
| 440 bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, | 441 bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request, |
| 441 const std::string& cookie_line, | 442 const std::string& cookie_line, |
| 442 net::CookieOptions* options) { | 443 net::CookieOptions* options) { |
| 443 // NULL during tests, or when we're running in the system context. | 444 // nullptr during tests, or when we're running in the system context. |
| 444 if (!cookie_settings_.get()) | 445 if (!cookie_settings_.get()) |
| 445 return true; | 446 return true; |
| 446 | 447 |
| 447 bool allow = cookie_settings_->IsSettingCookieAllowed( | 448 bool allow = cookie_settings_->IsSettingCookieAllowed( |
| 448 request.url(), request.first_party_for_cookies()); | 449 request.url(), request.first_party_for_cookies()); |
| 449 | 450 |
| 450 int render_process_id = -1; | 451 int render_process_id = -1; |
| 451 int render_frame_id = -1; | 452 int render_frame_id = -1; |
| 452 if (content::ResourceRequestInfo::GetRenderFrameForRequest( | 453 if (content::ResourceRequestInfo::GetRenderFrameForRequest( |
| 453 &request, &render_process_id, &render_frame_id)) { | 454 &request, &render_process_id, &render_frame_id)) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 } | 540 } |
| 540 | 541 |
| 541 DVLOG(1) << "File access denied - " << path.value().c_str(); | 542 DVLOG(1) << "File access denied - " << path.value().c_str(); |
| 542 return false; | 543 return false; |
| 543 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 544 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 544 } | 545 } |
| 545 | 546 |
| 546 bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( | 547 bool ChromeNetworkDelegate::OnCanEnablePrivacyMode( |
| 547 const GURL& url, | 548 const GURL& url, |
| 548 const GURL& first_party_for_cookies) const { | 549 const GURL& first_party_for_cookies) const { |
| 549 // NULL during tests, or when we're running in the system context. | 550 // nullptr during tests, or when we're running in the system context. |
| 550 if (!cookie_settings_.get()) | 551 if (!cookie_settings_.get()) |
| 551 return false; | 552 return false; |
| 552 | 553 |
| 553 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed( | 554 bool reading_cookie_allowed = cookie_settings_->IsReadingCookieAllowed( |
| 554 url, first_party_for_cookies); | 555 url, first_party_for_cookies); |
| 555 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed( | 556 bool setting_cookie_allowed = cookie_settings_->IsSettingCookieAllowed( |
| 556 url, first_party_for_cookies); | 557 url, first_party_for_cookies); |
| 557 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed); | 558 bool privacy_mode = !(reading_cookie_allowed && setting_cookie_allowed); |
| 558 return privacy_mode; | 559 return privacy_mode; |
| 559 } | 560 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 584 if (!data_use_aggregator_) | 585 if (!data_use_aggregator_) |
| 585 return; | 586 return; |
| 586 | 587 |
| 587 if (is_data_usage_off_the_record_) { | 588 if (is_data_usage_off_the_record_) { |
| 588 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); | 589 data_use_aggregator_->ReportOffTheRecordDataUse(tx_bytes, rx_bytes); |
| 589 return; | 590 return; |
| 590 } | 591 } |
| 591 | 592 |
| 592 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); | 593 data_use_aggregator_->ReportDataUse(request, tx_bytes, rx_bytes); |
| 593 } | 594 } |
| OLD | NEW |