Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: chrome/browser/net/chrome_network_delegate.cc

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

Powered by Google App Engine
This is Rietveld 408576698