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

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

Issue 2401733002: Revert "Added a ForceYouTubeRestrict policy and deprecated the old ForceYouTubeSafetyMode policy" (Closed)
Patch Set: 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
« no previous file with comments | « chrome/browser/net/safe_search_util.h ('k') | chrome/browser/net/safe_search_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/safe_search_util.h" 5 #include "chrome/browser/net/safe_search_util.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
15 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
19 #include "components/google/core/browser/google_util.h" 19 #include "components/google/core/browser/google_util.h"
20 #include "net/cookies/cookie_util.h" 20 #include "net/cookies/cookie_util.h"
21 #include "net/http/http_request_headers.h" 21 #include "net/http/http_request_headers.h"
22 #include "net/url_request/url_request.h" 22 #include "net/url_request/url_request.h"
23 #include "url/gurl.h" 23 #include "url/gurl.h"
24 24
25 namespace { 25 namespace {
26 26
27 int g_force_google_safe_search_count_for_test = 0; 27 int g_force_google_safe_search_count_for_test = 0;
28 int g_force_youtube_restrict_count_for_test = 0; 28 int g_force_youtube_safety_mode_count_for_test = 0;
29 29
30 const char kYouTubeRestrictHeaderName[] = "YouTube-Restrict"; 30 const char kYouTubeSafetyModeHeaderName[] = "YouTube-Safety-Mode";
31 const char kYouTubeRestrictHeaderValueModerate[] = "Moderate"; 31 const char kYouTubeSafetyModeHeaderValue[] = "Active";
32 const char kYouTubeRestrictHeaderValueStrict[] = "Strict";
33 32
34 // Returns whether a URL parameter, |first_parameter| (e.g. foo=bar), has the 33 // Returns whether a URL parameter, |first_parameter| (e.g. foo=bar), has the
35 // same key as the the |second_parameter| (e.g. foo=baz). Both parameters 34 // same key as the the |second_parameter| (e.g. foo=baz). Both parameters
36 // must be in key=value form. 35 // must be in key=value form.
37 bool HasSameParameterKey(const std::string& first_parameter, 36 bool HasSameParameterKey(const std::string& first_parameter,
38 const std::string& second_parameter) { 37 const std::string& second_parameter) {
39 DCHECK(second_parameter.find("=") != std::string::npos); 38 DCHECK(second_parameter.find("=") != std::string::npos);
40 // Prefix for "foo=bar" is "foo=". 39 // Prefix for "foo=bar" is "foo=".
41 std::string parameter_prefix = second_parameter.substr( 40 std::string parameter_prefix = second_parameter.substr(
42 0, second_parameter.find("=") + 1); 41 0, second_parameter.find("=") + 1);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 std::string query = request->url().query(); 81 std::string query = request->url().query();
83 std::string new_query = AddSafeSearchParameters(query); 82 std::string new_query = AddSafeSearchParameters(query);
84 if (query == new_query) 83 if (query == new_query)
85 return; 84 return;
86 85
87 GURL::Replacements replacements; 86 GURL::Replacements replacements;
88 replacements.SetQueryStr(new_query); 87 replacements.SetQueryStr(new_query);
89 *new_url = request->url().ReplaceComponents(replacements); 88 *new_url = request->url().ReplaceComponents(replacements);
90 } 89 }
91 90
92 void ForceYouTubeRestrict(const net::URLRequest* request, 91 // If |request| is a request to YouTube, enforces YouTube's Safety Mode by
93 net::HttpRequestHeaders* headers, 92 // setting YouTube's Safety Mode header.
94 YouTubeRestrictMode mode) { 93 void ForceYouTubeSafetyMode(const net::URLRequest* request,
95 ++g_force_youtube_restrict_count_for_test; 94 net::HttpRequestHeaders* headers) {
95 ++g_force_youtube_safety_mode_count_for_test;
96 96
97 if (!google_util::IsYoutubeDomainUrl( 97 if (!google_util::IsYoutubeDomainUrl(
98 request->url(), 98 request->url(),
99 google_util::ALLOW_SUBDOMAIN, 99 google_util::ALLOW_SUBDOMAIN,
100 google_util::DISALLOW_NON_STANDARD_PORTS)) 100 google_util::DISALLOW_NON_STANDARD_PORTS))
101 return; 101 return;
102 102
103 switch (mode) { 103 headers->SetHeader(kYouTubeSafetyModeHeaderName,
104 case YOUTUBE_RESTRICT_OFF: 104 kYouTubeSafetyModeHeaderValue);
105 case YOUTUBE_RESTRICT_COUNT:
106 NOTREACHED();
107 break;
108
109 case YOUTUBE_RESTRICT_MODERATE:
110 headers->SetHeader(kYouTubeRestrictHeaderName,
111 kYouTubeRestrictHeaderValueModerate);
112 break;
113
114 case YOUTUBE_RESTRICT_STRICT:
115 headers->SetHeader(kYouTubeRestrictHeaderName,
116 kYouTubeRestrictHeaderValueStrict);
117 break;
118 }
119 } 105 }
120 106
121 int GetForceGoogleSafeSearchCountForTesting() { 107 int GetForceGoogleSafeSearchCountForTesting() {
122 return g_force_google_safe_search_count_for_test; 108 return g_force_google_safe_search_count_for_test;
123 } 109 }
124 110
125 int GetForceYouTubeRestrictCountForTesting() { 111 int GetForceYouTubeSafetyModeCountForTesting() {
126 return g_force_youtube_restrict_count_for_test; 112 return g_force_youtube_safety_mode_count_for_test;
127 } 113 }
128 114
129 void ClearForceGoogleSafeSearchCountForTesting() { 115 void ClearForceGoogleSafeSearchCountForTesting() {
130 g_force_google_safe_search_count_for_test = 0; 116 g_force_google_safe_search_count_for_test = 0;
131 } 117 }
132 118
133 void ClearForceYouTubeRestrictCountForTesting() { 119 void ClearForceYouTubeSafetyModeCountForTesting() {
134 g_force_youtube_restrict_count_for_test = 0; 120 g_force_youtube_safety_mode_count_for_test = 0;
135 } 121 }
136 122
137 } // namespace safe_search_util 123 } // namespace safe_search_util
OLDNEW
« no previous file with comments | « chrome/browser/net/safe_search_util.h ('k') | chrome/browser/net/safe_search_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698