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/chromeos/ui_proxy_config.h" | 5 #include "chrome/browser/chromeos/ui_proxy_config.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | |
8 #include "base/logging.h" | 7 #include "base/logging.h" |
9 #include "base/values.h" | 8 #include "base/values.h" |
10 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" | 9 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" |
11 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 10 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
12 #include "net/proxy/proxy_config.h" | 11 #include "net/proxy/proxy_config.h" |
13 | 12 |
14 namespace chromeos { | 13 namespace chromeos { |
15 | 14 |
16 UIProxyConfig::UIProxyConfig() | 15 UIProxyConfig::UIProxyConfig() |
17 : mode(MODE_DIRECT), | 16 : mode(MODE_DIRECT), |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 socks_proxy.server = rules.fallback_proxies.Get(); | 93 socks_proxy.server = rules.fallback_proxies.Get(); |
95 bypass_rules = rules.bypass_rules; | 94 bypass_rules = rules.bypass_rules; |
96 return true; | 95 return true; |
97 default: | 96 default: |
98 NOTREACHED() << "Unrecognized proxy config mode"; | 97 NOTREACHED() << "Unrecognized proxy config mode"; |
99 break; | 98 break; |
100 } | 99 } |
101 return false; | 100 return false; |
102 } | 101 } |
103 | 102 |
104 base::DictionaryValue* UIProxyConfig::ToPrefProxyConfig() { | 103 base::DictionaryValue* UIProxyConfig::ToPrefProxyConfig() const { |
105 switch (mode) { | 104 switch (mode) { |
106 case MODE_DIRECT: { | 105 case MODE_DIRECT: { |
107 return ProxyConfigDictionary::CreateDirect(); | 106 return ProxyConfigDictionary::CreateDirect(); |
108 } | 107 } |
109 case MODE_AUTO_DETECT: { | 108 case MODE_AUTO_DETECT: { |
110 return ProxyConfigDictionary::CreateAutoDetect(); | 109 return ProxyConfigDictionary::CreateAutoDetect(); |
111 } | 110 } |
112 case MODE_PAC_SCRIPT: { | 111 case MODE_PAC_SCRIPT: { |
113 return ProxyConfigDictionary::CreatePacScript( | 112 return ProxyConfigDictionary::CreatePacScript( |
114 automatic_proxy.pac_url.spec(), false); | 113 automatic_proxy.pac_url.spec(), false); |
(...skipping 28 matching lines...) Expand all Loading... |
143 if (scheme == "https") | 142 if (scheme == "https") |
144 return &https_proxy; | 143 return &https_proxy; |
145 if (scheme == "ftp") | 144 if (scheme == "ftp") |
146 return &ftp_proxy; | 145 return &ftp_proxy; |
147 if (scheme == "socks") | 146 if (scheme == "socks") |
148 return &socks_proxy; | 147 return &socks_proxy; |
149 NOTREACHED() << "Invalid scheme: " << scheme; | 148 NOTREACHED() << "Invalid scheme: " << scheme; |
150 return NULL; | 149 return NULL; |
151 } | 150 } |
152 | 151 |
153 bool UIProxyConfig::SerializeForNetwork(std::string* output) { | |
154 scoped_ptr<base::DictionaryValue> proxy_dict_ptr(ToPrefProxyConfig()); | |
155 if (!proxy_dict_ptr.get()) | |
156 return false; | |
157 | |
158 // Return empty string for direct mode for portal check to work correctly. | |
159 base::DictionaryValue *dict = proxy_dict_ptr.get(); | |
160 ProxyConfigDictionary proxy_dict(dict); | |
161 ProxyPrefs::ProxyMode mode; | |
162 if (proxy_dict.GetMode(&mode)) { | |
163 if (mode == ProxyPrefs::MODE_DIRECT) { | |
164 output->clear(); | |
165 return true; | |
166 } | |
167 } | |
168 base::JSONWriter::Write(dict, output); | |
169 return true; | |
170 } | |
171 | |
172 // static | 152 // static |
173 void UIProxyConfig::EncodeAndAppendProxyServer(const std::string& url_scheme, | 153 void UIProxyConfig::EncodeAndAppendProxyServer(const std::string& url_scheme, |
174 const net::ProxyServer& server, | 154 const net::ProxyServer& server, |
175 std::string* spec) { | 155 std::string* spec) { |
176 if (!server.is_valid()) | 156 if (!server.is_valid()) |
177 return; | 157 return; |
178 | 158 |
179 if (!spec->empty()) | 159 if (!spec->empty()) |
180 *spec += ';'; | 160 *spec += ';'; |
181 | 161 |
182 if (!url_scheme.empty()) { | 162 if (!url_scheme.empty()) { |
183 *spec += url_scheme; | 163 *spec += url_scheme; |
184 *spec += "="; | 164 *spec += "="; |
185 } | 165 } |
186 *spec += server.ToURI(); | 166 *spec += server.ToURI(); |
187 } | 167 } |
188 | 168 |
189 } // namespace chromeos | 169 } // namespace chromeos |
OLD | NEW |