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