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

Side by Side Diff: chrome/browser/chromeos/net/onc_utils.cc

Issue 1228543002: Translate ONC ProxySettings <-> Shill ProxyConfig (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add SchemeToString Created 5 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
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/chromeos/net/onc_utils.h" 5 #include "chrome/browser/chromeos/net/onc_utils.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/chromeos/ui_proxy_config.h"
13 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
14 #include "chromeos/network/managed_network_configuration_handler.h" 13 #include "chromeos/network/managed_network_configuration_handler.h"
15 #include "chromeos/network/network_configuration_handler.h" 14 #include "chromeos/network/network_configuration_handler.h"
16 #include "chromeos/network/network_handler.h" 15 #include "chromeos/network/network_handler.h"
17 #include "chromeos/network/network_profile.h" 16 #include "chromeos/network/network_profile.h"
18 #include "chromeos/network/network_profile_handler.h" 17 #include "chromeos/network/network_profile_handler.h"
19 #include "chromeos/network/network_state.h" 18 #include "chromeos/network/network_state.h"
20 #include "chromeos/network/network_state_handler.h" 19 #include "chromeos/network/network_state_handler.h"
21 #include "chromeos/network/network_ui_data.h" 20 #include "chromeos/network/network_ui_data.h"
22 #include "chromeos/network/onc/onc_normalizer.h" 21 #include "chromeos/network/onc/onc_normalizer.h"
23 #include "chromeos/network/onc/onc_signature.h" 22 #include "chromeos/network/onc/onc_signature.h"
24 #include "chromeos/network/onc/onc_translator.h" 23 #include "chromeos/network/onc/onc_translator.h"
25 #include "chromeos/network/onc/onc_utils.h" 24 #include "chromeos/network/onc/onc_utils.h"
26 #include "components/proxy_config/proxy_config_dictionary.h"
27 #include "components/user_manager/user.h" 25 #include "components/user_manager/user.h"
28 #include "components/user_manager/user_manager.h" 26 #include "components/user_manager/user_manager.h"
29 #include "net/base/host_port_pair.h"
30 #include "net/proxy/proxy_bypass_rules.h"
31 #include "net/proxy/proxy_server.h"
32 #include "third_party/cros_system_api/dbus/service_constants.h" 27 #include "third_party/cros_system_api/dbus/service_constants.h"
33 #include "url/gurl.h" 28 #include "url/gurl.h"
34 29
35 namespace chromeos { 30 namespace chromeos {
36 namespace onc { 31 namespace onc {
37 32
38 namespace { 33 namespace {
39 34
40 net::ProxyServer ConvertOncProxyLocationToHostPort(
41 net::ProxyServer::Scheme default_proxy_scheme,
42 const base::DictionaryValue& onc_proxy_location) {
43 std::string host;
44 onc_proxy_location.GetStringWithoutPathExpansion(::onc::proxy::kHost, &host);
45 // Parse |host| according to the format [<scheme>"://"]<server>[":"<port>].
46 net::ProxyServer proxy_server =
47 net::ProxyServer::FromURI(host, default_proxy_scheme);
48 int port = 0;
49 onc_proxy_location.GetIntegerWithoutPathExpansion(::onc::proxy::kPort, &port);
50
51 // Replace the port parsed from |host| by the provided |port|.
52 return net::ProxyServer(
53 proxy_server.scheme(),
54 net::HostPortPair(proxy_server.host_port_pair().host(),
55 static_cast<uint16>(port)));
56 }
57
58 void AppendProxyServerForScheme(
59 const base::DictionaryValue& onc_manual,
60 const std::string& onc_scheme,
61 std::string* spec) {
62 const base::DictionaryValue* onc_proxy_location = NULL;
63 if (!onc_manual.GetDictionaryWithoutPathExpansion(onc_scheme,
64 &onc_proxy_location)) {
65 return;
66 }
67
68 net::ProxyServer::Scheme default_proxy_scheme = net::ProxyServer::SCHEME_HTTP;
69 std::string url_scheme;
70 if (onc_scheme == ::onc::proxy::kFtp) {
71 url_scheme = "ftp";
72 } else if (onc_scheme == ::onc::proxy::kHttp) {
73 url_scheme = "http";
74 } else if (onc_scheme == ::onc::proxy::kHttps) {
75 url_scheme = "https";
76 } else if (onc_scheme == ::onc::proxy::kSocks) {
77 default_proxy_scheme = net::ProxyServer::SCHEME_SOCKS4;
78 url_scheme = "socks";
79 } else {
80 NOTREACHED();
81 }
82
83 net::ProxyServer proxy_server = ConvertOncProxyLocationToHostPort(
84 default_proxy_scheme, *onc_proxy_location);
85
86 UIProxyConfig::EncodeAndAppendProxyServer(url_scheme, proxy_server, spec);
87 }
88
89 net::ProxyBypassRules ConvertOncExcludeDomainsToBypassRules(
90 const base::ListValue& onc_exclude_domains) {
91 net::ProxyBypassRules rules;
92 for (base::ListValue::const_iterator it = onc_exclude_domains.begin();
93 it != onc_exclude_domains.end(); ++it) {
94 std::string rule;
95 (*it)->GetAsString(&rule);
96 rules.AddRuleFromString(rule);
97 }
98 return rules;
99 }
100
101 } // namespace
102
103 scoped_ptr<base::DictionaryValue> ConvertOncProxySettingsToProxyConfig(
104 const base::DictionaryValue& onc_proxy_settings) {
105 std::string type;
106 onc_proxy_settings.GetStringWithoutPathExpansion(::onc::proxy::kType, &type);
107 scoped_ptr<base::DictionaryValue> proxy_dict;
108
109 if (type == ::onc::proxy::kDirect) {
110 proxy_dict.reset(ProxyConfigDictionary::CreateDirect());
111 } else if (type == ::onc::proxy::kWPAD) {
112 proxy_dict.reset(ProxyConfigDictionary::CreateAutoDetect());
113 } else if (type == ::onc::proxy::kPAC) {
114 std::string pac_url;
115 onc_proxy_settings.GetStringWithoutPathExpansion(::onc::proxy::kPAC,
116 &pac_url);
117 GURL url(pac_url);
118 DCHECK(url.is_valid())
119 << "PAC field is invalid for this ProxySettings.Type";
120 proxy_dict.reset(ProxyConfigDictionary::CreatePacScript(url.spec(),
121 false));
122 } else if (type == ::onc::proxy::kManual) {
123 const base::DictionaryValue* manual_dict = NULL;
124 onc_proxy_settings.GetDictionaryWithoutPathExpansion(::onc::proxy::kManual,
125 &manual_dict);
126 std::string manual_spec;
127 AppendProxyServerForScheme(*manual_dict, ::onc::proxy::kFtp, &manual_spec);
128 AppendProxyServerForScheme(*manual_dict, ::onc::proxy::kHttp, &manual_spec);
129 AppendProxyServerForScheme(*manual_dict, ::onc::proxy::kSocks,
130 &manual_spec);
131 AppendProxyServerForScheme(*manual_dict, ::onc::proxy::kHttps,
132 &manual_spec);
133
134 const base::ListValue* exclude_domains = NULL;
135 net::ProxyBypassRules bypass_rules;
136 if (onc_proxy_settings.GetListWithoutPathExpansion(
137 ::onc::proxy::kExcludeDomains, &exclude_domains)) {
138 bypass_rules.AssignFrom(
139 ConvertOncExcludeDomainsToBypassRules(*exclude_domains));
140 }
141 proxy_dict.reset(ProxyConfigDictionary::CreateFixedServers(
142 manual_spec, bypass_rules.ToString()));
143 } else {
144 NOTREACHED();
145 }
146 return proxy_dict.Pass();
147 }
148
149 namespace {
150
151 // This class defines which string placeholders of ONC are replaced by which 35 // This class defines which string placeholders of ONC are replaced by which
152 // user attribute. 36 // user attribute.
153 class UserStringSubstitution : public chromeos::onc::StringSubstitution { 37 class UserStringSubstitution : public chromeos::onc::StringSubstitution {
154 public: 38 public:
155 explicit UserStringSubstitution(const user_manager::User* user) 39 explicit UserStringSubstitution(const user_manager::User* user)
156 : user_(user) {} 40 : user_(user) {}
157 ~UserStringSubstitution() override {} 41 ~UserStringSubstitution() override {}
158 42
159 bool GetSubstitute(const std::string& placeholder, 43 bool GetSubstitute(const std::string& placeholder,
160 std::string* substitute) const override { 44 std::string* substitute) const override {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 const PrefService* local_state_prefs, 336 const PrefService* local_state_prefs,
453 const NetworkState& network) { 337 const NetworkState& network) {
454 ::onc::ONCSource ignored_onc_source; 338 ::onc::ONCSource ignored_onc_source;
455 const base::DictionaryValue* policy = onc::GetPolicyForNetwork( 339 const base::DictionaryValue* policy = onc::GetPolicyForNetwork(
456 profile_prefs, local_state_prefs, network, &ignored_onc_source); 340 profile_prefs, local_state_prefs, network, &ignored_onc_source);
457 return policy != NULL; 341 return policy != NULL;
458 } 342 }
459 343
460 } // namespace onc 344 } // namespace onc
461 } // namespace chromeos 345 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698