OLD | NEW |
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 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 | 44 |
45 // Examines the query string containing parameters and adds the necessary ones | 45 // Examines the query string containing parameters and adds the necessary ones |
46 // so that SafeSearch is active. |query| is the string to examine and the | 46 // so that SafeSearch is active. |query| is the string to examine and the |
47 // return value is the |query| string modified such that SafeSearch is active. | 47 // return value is the |query| string modified such that SafeSearch is active. |
48 std::string AddSafeSearchParameters(const std::string& query) { | 48 std::string AddSafeSearchParameters(const std::string& query) { |
49 std::vector<std::string> new_parameters; | 49 std::vector<std::string> new_parameters; |
50 std::string safe_parameter = chrome::kSafeSearchSafeParameter; | 50 std::string safe_parameter = chrome::kSafeSearchSafeParameter; |
51 std::string ssui_parameter = chrome::kSafeSearchSsuiParameter; | 51 std::string ssui_parameter = chrome::kSafeSearchSsuiParameter; |
52 | 52 |
53 std::vector<std::string> parameters; | 53 for (const std::string& param : base::SplitString( |
54 base::SplitString(query, '&', ¶meters); | 54 query, "&", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
55 | 55 if (!HasSameParameterKey(param, safe_parameter) && |
56 std::vector<std::string>::iterator it; | 56 !HasSameParameterKey(param, ssui_parameter)) { |
57 for (it = parameters.begin(); it < parameters.end(); ++it) { | 57 new_parameters.push_back(param); |
58 if (!HasSameParameterKey(*it, safe_parameter) && | |
59 !HasSameParameterKey(*it, ssui_parameter)) { | |
60 new_parameters.push_back(*it); | |
61 } | 58 } |
62 } | 59 } |
63 | 60 |
64 new_parameters.push_back(safe_parameter); | 61 new_parameters.push_back(safe_parameter); |
65 new_parameters.push_back(ssui_parameter); | 62 new_parameters.push_back(ssui_parameter); |
66 return base::JoinString(new_parameters, "&"); | 63 return base::JoinString(new_parameters, "&"); |
67 } | 64 } |
68 | 65 |
69 } // namespace | 66 } // namespace |
70 | 67 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 113 |
117 void ClearForceGoogleSafeSearchCountForTesting() { | 114 void ClearForceGoogleSafeSearchCountForTesting() { |
118 g_force_google_safe_search_count_for_test = 0; | 115 g_force_google_safe_search_count_for_test = 0; |
119 } | 116 } |
120 | 117 |
121 void ClearForceYouTubeSafetyModeCountForTesting() { | 118 void ClearForceYouTubeSafetyModeCountForTesting() { |
122 g_force_youtube_safety_mode_count_for_test = 0; | 119 g_force_youtube_safety_mode_count_for_test = 0; |
123 } | 120 } |
124 | 121 |
125 } // namespace safe_search_util | 122 } // namespace safe_search_util |
OLD | NEW |