OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/proxy_policy_handler.h" | 5 #include "chrome/browser/net/proxy_policy_handler.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/pref_value_map.h" | 8 #include "base/prefs/pref_value_map.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
12 #include "components/policy/core/browser/configuration_policy_handler.h" | 12 #include "components/policy/core/browser/configuration_policy_handler.h" |
13 #include "components/policy/core/browser/policy_error_map.h" | 13 #include "components/policy/core/browser/policy_error_map.h" |
14 #include "components/policy/core/common/policy_map.h" | 14 #include "components/policy/core/common/policy_map.h" |
15 #include "components/proxy_config/proxy_config_dictionary.h" | 15 #include "components/proxy_config/proxy_config_dictionary.h" |
16 #include "components/proxy_config/proxy_prefs.h" | 16 #include "components/proxy_config/proxy_config_pref_names.h" |
17 #include "grit/components_strings.h" | 17 #include "grit/components_strings.h" |
18 #include "policy/policy_constants.h" | 18 #include "policy/policy_constants.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // This is used to check whether for a given ProxyMode value, the ProxyPacUrl, | 22 // This is used to check whether for a given ProxyMode value, the ProxyPacUrl, |
23 // the ProxyBypassList and the ProxyServer policies are allowed to be specified. | 23 // the ProxyBypassList and the ProxyServer policies are allowed to be specified. |
24 // |error_message_id| is the message id of the localized error message to show | 24 // |error_message_id| is the message id of the localized error message to show |
25 // when the policies are not specified as allowed. Each value of ProxyMode | 25 // when the policies are not specified as allowed. Each value of ProxyMode |
26 // has a ProxyModeValidationEntry in the |kProxyModeValidationMap| below. | 26 // has a ProxyModeValidationEntry in the |kProxyModeValidationMap| below. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 default: | 165 default: |
166 proxy_mode = ProxyPrefs::MODE_DIRECT; | 166 proxy_mode = ProxyPrefs::MODE_DIRECT; |
167 NOTREACHED(); | 167 NOTREACHED(); |
168 } | 168 } |
169 } else { | 169 } else { |
170 return; | 170 return; |
171 } | 171 } |
172 | 172 |
173 switch (proxy_mode) { | 173 switch (proxy_mode) { |
174 case ProxyPrefs::MODE_DIRECT: | 174 case ProxyPrefs::MODE_DIRECT: |
175 prefs->SetValue(prefs::kProxy, | 175 prefs->SetValue(ProxyPrefs::prefs::kProxy, |
176 make_scoped_ptr(ProxyConfigDictionary::CreateDirect())); | 176 make_scoped_ptr(ProxyConfigDictionary::CreateDirect())); |
177 break; | 177 break; |
178 case ProxyPrefs::MODE_AUTO_DETECT: | 178 case ProxyPrefs::MODE_AUTO_DETECT: |
179 prefs->SetValue( | 179 prefs->SetValue( |
180 prefs::kProxy, | 180 ProxyPrefs::prefs::kProxy, |
181 make_scoped_ptr(ProxyConfigDictionary::CreateAutoDetect())); | 181 make_scoped_ptr(ProxyConfigDictionary::CreateAutoDetect())); |
182 break; | 182 break; |
183 case ProxyPrefs::MODE_PAC_SCRIPT: { | 183 case ProxyPrefs::MODE_PAC_SCRIPT: { |
184 std::string pac_url_string; | 184 std::string pac_url_string; |
185 if (pac_url && pac_url->GetAsString(&pac_url_string)) { | 185 if (pac_url && pac_url->GetAsString(&pac_url_string)) { |
186 prefs->SetValue(prefs::kProxy, | 186 prefs->SetValue(ProxyPrefs::prefs::kProxy, |
187 make_scoped_ptr(ProxyConfigDictionary::CreatePacScript( | 187 make_scoped_ptr(ProxyConfigDictionary::CreatePacScript( |
188 pac_url_string, false))); | 188 pac_url_string, false))); |
189 } else { | 189 } else { |
190 NOTREACHED(); | 190 NOTREACHED(); |
191 } | 191 } |
192 break; | 192 break; |
193 } | 193 } |
194 case ProxyPrefs::MODE_FIXED_SERVERS: { | 194 case ProxyPrefs::MODE_FIXED_SERVERS: { |
195 std::string proxy_server; | 195 std::string proxy_server; |
196 std::string bypass_list_string; | 196 std::string bypass_list_string; |
197 if (server->GetAsString(&proxy_server)) { | 197 if (server->GetAsString(&proxy_server)) { |
198 if (bypass_list) | 198 if (bypass_list) |
199 bypass_list->GetAsString(&bypass_list_string); | 199 bypass_list->GetAsString(&bypass_list_string); |
200 prefs->SetValue( | 200 prefs->SetValue( |
201 prefs::kProxy, | 201 ProxyPrefs::prefs::kProxy, |
202 make_scoped_ptr(ProxyConfigDictionary::CreateFixedServers( | 202 make_scoped_ptr(ProxyConfigDictionary::CreateFixedServers( |
203 proxy_server, bypass_list_string))); | 203 proxy_server, bypass_list_string))); |
204 } | 204 } |
205 break; | 205 break; |
206 } | 206 } |
207 case ProxyPrefs::MODE_SYSTEM: | 207 case ProxyPrefs::MODE_SYSTEM: |
208 prefs->SetValue(prefs::kProxy, | 208 prefs->SetValue(ProxyPrefs::prefs::kProxy, |
209 make_scoped_ptr(ProxyConfigDictionary::CreateSystem())); | 209 make_scoped_ptr(ProxyConfigDictionary::CreateSystem())); |
210 break; | 210 break; |
211 case ProxyPrefs::kModeCount: | 211 case ProxyPrefs::kModeCount: |
212 NOTREACHED(); | 212 NOTREACHED(); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 const base::Value* ProxyPolicyHandler::GetProxyPolicyValue( | 216 const base::Value* ProxyPolicyHandler::GetProxyPolicyValue( |
217 const PolicyMap& policies, const char* policy_name) { | 217 const PolicyMap& policies, const char* policy_name) { |
218 // See note on the ProxyPolicyHandler implementation above. | 218 // See note on the ProxyPolicyHandler implementation above. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 key::kProxyServerMode, | 329 key::kProxyServerMode, |
330 IDS_POLICY_OUT_OF_RANGE_ERROR, | 330 IDS_POLICY_OUT_OF_RANGE_ERROR, |
331 base::IntToString(server_mode_value)); | 331 base::IntToString(server_mode_value)); |
332 return false; | 332 return false; |
333 } | 333 } |
334 } | 334 } |
335 return true; | 335 return true; |
336 } | 336 } |
337 | 337 |
338 } // namespace policy | 338 } // namespace policy |
OLD | NEW |