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

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

Issue 354183002: Enforce SafetyMode for YouTube if prefs::kForceSafeSearch is on. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « base/strings/string_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/base_paths.h" 11 #include "base/base_paths.h"
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/prefs/pref_member.h" 16 #include "base/prefs/pref_member.h"
17 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
20 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h"
20 #include "base/time/time.h" 22 #include "base/time/time.h"
21 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/content_settings/cookie_settings.h" 24 #include "chrome/browser/content_settings/cookie_settings.h"
23 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 25 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
24 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 26 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
25 #include "chrome/browser/net/chrome_extensions_network_delegate.h" 27 #include "chrome/browser/net/chrome_extensions_network_delegate.h"
26 #include "chrome/browser/net/client_hints.h" 28 #include "chrome/browser/net/client_hints.h"
27 #include "chrome/browser/net/connect_interceptor.h" 29 #include "chrome/browser/net/connect_interceptor.h"
28 #include "chrome/browser/performance_monitor/performance_monitor.h" 30 #include "chrome/browser/performance_monitor/performance_monitor.h"
29 #include "chrome/browser/prerender/prerender_tracker.h" 31 #include "chrome/browser/prerender/prerender_tracker.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 void ForceGoogleSafeSearchCallbackWrapper( 156 void ForceGoogleSafeSearchCallbackWrapper(
155 const net::CompletionCallback& callback, 157 const net::CompletionCallback& callback,
156 net::URLRequest* request, 158 net::URLRequest* request,
157 GURL* new_url, 159 GURL* new_url,
158 int rv) { 160 int rv) {
159 if (rv == net::OK && new_url->is_empty()) 161 if (rv == net::OK && new_url->is_empty())
160 ForceGoogleSafeSearch(request, new_url); 162 ForceGoogleSafeSearch(request, new_url);
161 callback.Run(rv); 163 callback.Run(rv);
162 } 164 }
163 165
166 const char kYoutubePrefCookieName[] = "PREF";
battre 2014/07/07 09:00:06 What do you think of moving the youtube and safebr
Marc Treib 2014/07/07 16:06:46 It is grungy :-/ I moved the code into new safe_se
167 // Youtube pref flags are stored in bit masks of 31 bits each, called "f1",
168 // "f2" etc. The Safety Mode flag is bit 58, so bit 27 in "f2".
169 const char kYoutubePrefCookieSafetyModeFlagsEntryName[] = "f2";
170 const int kYoutubePrefCookieSafetyModeFlagsEntryValue = (1 << 27);
171 const char kYoutubePrefCookieFlagsValueFormat[] = "%x";
172
173 bool IsYoutubePrefCookie(const std::pair<std::string, std::string>& cookie) {
174 return cookie.first == kYoutubePrefCookieName;
175 }
176
177 bool IsYoutubePrefCookieSafetyModeFlagsEntry(
178 const std::pair<std::string, std::string>& pref_entry) {
179 return pref_entry.first == kYoutubePrefCookieSafetyModeFlagsEntryName;
180 }
181
182 // If |request| is a request to Youtube, enforces Youtube's Safety Mode by
183 // adding/modifying Youtube's PrefCookie header.
184 void ForceYoutubeSafetyMode(const net::URLRequest* request,
185 net::HttpRequestHeaders* headers) {
battre 2014/07/07 09:00:06 Could you add more newlines into this function and
Marc Treib 2014/07/07 16:06:46 Done.
186 if (!google_util::IsYoutubeDomainUrl(
187 request->url(),
188 google_util::ALLOW_SUBDOMAIN,
189 google_util::DISALLOW_NON_STANDARD_PORTS))
190 return;
191
192 std::string cookie_string;
193 headers->GetHeader(base::StringPiece(net::HttpRequestHeaders::kCookie),
194 &cookie_string);
195 base::StringPairs cookies;
196 base::SplitStringIntoKeyValuePairs(cookie_string, '=', ';', &cookies);
197 base::StringPairs::iterator pref_it =
198 std::find_if(cookies.begin(), cookies.end(), IsYoutubePrefCookie);
199 if (pref_it == cookies.end()) {
200 cookies.push_back(std::make_pair(std::string(kYoutubePrefCookieName),
201 std::string()));
202 pref_it = cookies.end() - 1;
203 }
204 base::StringPairs pref_values;
205 base::SplitStringIntoKeyValuePairs(pref_it->second, '=', '&', &pref_values);
206 base::StringPairs::iterator flag_it =
207 std::find_if(pref_values.begin(), pref_values.end(),
208 IsYoutubePrefCookieSafetyModeFlagsEntry);
209 int flag_value = 0;
210 if (flag_it == pref_values.end()) {
211 pref_values.push_back(
212 std::make_pair(std::string(kYoutubePrefCookieSafetyModeFlagsEntryName),
213 std::string()));
214 flag_it = pref_values.end() - 1;
215 } else {
216 base::HexStringToInt(base::StringPiece(flag_it->second), &flag_value);
217 }
218 flag_value |= kYoutubePrefCookieSafetyModeFlagsEntryValue;
219 flag_it->second =
220 base::StringPrintf(kYoutubePrefCookieFlagsValueFormat, flag_value);
221 pref_it->second = JoinStringKeyValuePairs(pref_values, '=', '&');
222 cookie_string = JoinStringKeyValuePairs(cookies, '=', ';');
223 headers->SetHeader(base::StringPiece(net::HttpRequestHeaders::kCookie),
224 base::StringPiece(cookie_string));
225 }
226
164 void UpdateContentLengthPrefs( 227 void UpdateContentLengthPrefs(
165 int received_content_length, 228 int received_content_length,
166 int original_content_length, 229 int original_content_length,
167 data_reduction_proxy::DataReductionProxyRequestType request_type, 230 data_reduction_proxy::DataReductionProxyRequestType request_type,
168 Profile* profile) { 231 Profile* profile) {
169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
170 DCHECK_GE(received_content_length, 0); 233 DCHECK_GE(received_content_length, 0);
171 DCHECK_GE(original_content_length, 0); 234 DCHECK_GE(original_content_length, 0);
172 235
173 // Can be NULL in a unit test. 236 // Can be NULL in a unit test.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 if (connect_interceptor_) 534 if (connect_interceptor_)
472 connect_interceptor_->WitnessURLRequest(request); 535 connect_interceptor_->WitnessURLRequest(request);
473 536
474 return rv; 537 return rv;
475 } 538 }
476 539
477 int ChromeNetworkDelegate::OnBeforeSendHeaders( 540 int ChromeNetworkDelegate::OnBeforeSendHeaders(
478 net::URLRequest* request, 541 net::URLRequest* request,
479 const net::CompletionCallback& callback, 542 const net::CompletionCallback& callback,
480 net::HttpRequestHeaders* headers) { 543 net::HttpRequestHeaders* headers) {
544 bool force_safe_search = force_google_safe_search_ &&
545 force_google_safe_search_->GetValue();
546 if (force_safe_search)
547 ForceYoutubeSafetyMode(request, headers);
548
481 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest"); 549 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request, "SendRequest");
482 return extensions_delegate_->OnBeforeSendHeaders(request, callback, headers); 550 return extensions_delegate_->OnBeforeSendHeaders(request, callback, headers);
483 } 551 }
484 552
485 void ChromeNetworkDelegate::OnBeforeSendProxyHeaders( 553 void ChromeNetworkDelegate::OnBeforeSendProxyHeaders(
486 net::URLRequest* request, 554 net::URLRequest* request,
487 const net::ProxyInfo& proxy_info, 555 const net::ProxyInfo& proxy_info,
488 net::HttpRequestHeaders* headers) { 556 net::HttpRequestHeaders* headers) {
489 if (data_reduction_proxy_auth_request_handler_) { 557 if (data_reduction_proxy_auth_request_handler_) {
490 data_reduction_proxy_auth_request_handler_->MaybeAddRequestHeader( 558 data_reduction_proxy_auth_request_handler_->MaybeAddRequestHeader(
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 data_reduction_proxy::DataReductionProxyRequestType request_type) { 892 data_reduction_proxy::DataReductionProxyRequestType request_type) {
825 DCHECK_GE(received_content_length, 0); 893 DCHECK_GE(received_content_length, 0);
826 DCHECK_GE(original_content_length, 0); 894 DCHECK_GE(original_content_length, 0);
827 StoreAccumulatedContentLength(received_content_length, 895 StoreAccumulatedContentLength(received_content_length,
828 original_content_length, 896 original_content_length,
829 request_type, 897 request_type,
830 reinterpret_cast<Profile*>(profile_)); 898 reinterpret_cast<Profile*>(profile_));
831 received_content_length_ += received_content_length; 899 received_content_length_ += received_content_length;
832 original_content_length_ += original_content_length; 900 original_content_length_ += original_content_length;
833 } 901 }
OLDNEW
« no previous file with comments | « base/strings/string_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698