1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file.
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef CHROME_BROWSER_CHROMEOS_UI_PROXY_CONFIG_H_
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define CHROME_BROWSER_CHROMEOS_UI_PROXY_CONFIG_H_
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <string>
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/prefs/proxy_prefs.h"
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "net/proxy/proxy_bypass_rules.h"
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "net/proxy/proxy_server.h"
137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace base {
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class DictionaryValue;
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace net {
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class ProxyConfig;
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace chromeos {
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Contrary to other platforms which simply use the systems' UI to allow users
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// to configure proxies, we have to implement our own UI on the chromeos device.
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// This requires extra and specific UI requirements that net::ProxyConfig does
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// not supply.  So we create an augmented analog to net::ProxyConfig here to
29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// include and handle these UI requirements, e.g.
30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// - state of configuration e.g. where it was picked up from - policy,
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)//   extension, etc (refer to ProxyPrefs::ConfigState)
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// - the read/write access of a proxy setting
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// - may add more stuff later.
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// This is then converted to the common net::ProxyConfig before being pushed
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// to PrefProxyConfigTrackerImpl::OnProxyConfigChanged and then to the network
36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// stack.
37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)struct UIProxyConfig {
38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Specifies if proxy config is direct, auto-detect, using pac script,
39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // single-proxy, or proxy-per-scheme.
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  enum Mode {
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    MODE_DIRECT,
42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    MODE_AUTO_DETECT,
43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    MODE_PAC_SCRIPT,
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    MODE_SINGLE_PROXY,
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    MODE_PROXY_PER_SCHEME,
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Proxy setting for mode = direct or auto-detect or using pac script.
49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  struct AutomaticProxy {
50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    GURL pac_url;  // Set if proxy is using pac script.
51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Proxy setting for mode = single-proxy or proxy-per-scheme.
54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  struct ManualProxy {
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    net::ProxyServer server;
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  UIProxyConfig();
59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ~UIProxyConfig();
60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void SetPacUrl(const GURL& pac_url);
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void SetSingleProxy(const net::ProxyServer& server);
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // |scheme| is one of "http", "https", "ftp" or "socks".
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void SetProxyForScheme(const std::string& scheme,
66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         const net::ProxyServer& server);
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Only valid for MODE_SINGLE_PROXY or MODE_PROXY_PER_SCHEME.
69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void SetBypassRules(const net::ProxyBypassRules& rules);
70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Converts net::ProxyConfig to |this|.
72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool FromNetProxyConfig(const net::ProxyConfig& net_config);
73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Converts |this| to Dictionary of ProxyConfigDictionary format (which
75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // is the same format used by prefs).
76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  base::DictionaryValue* ToPrefProxyConfig() const;
77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Map |scheme| (one of "http", "https", "ftp" or "socks") to the correct
79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // ManualProxy.  Returns NULL if scheme is invalid.
80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ManualProxy* MapSchemeToProxy(const std::string& scheme);
81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Encodes the proxy server as "<url-scheme>=<proxy-scheme>://<proxy>"
83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static void EncodeAndAppendProxyServer(const std::string& url_scheme,
84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                         const net::ProxyServer& server,
85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                         std::string* spec);
86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  Mode mode;
88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ProxyPrefs::ConfigState state;
90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // True if user can modify proxy settings via UI.
92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // If proxy is managed by policy or extension or other_precde or is for
93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // shared network but kUseSharedProxies is turned off, it can't be modified
94868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // by user.
95868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool user_modifiable;
96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Set if mode is MODE_DIRECT or MODE_AUTO_DETECT or MODE_PAC_SCRIPT.
98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  AutomaticProxy  automatic_proxy;
99868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Set if mode is MODE_SINGLE_PROXY.
100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ManualProxy     single_proxy;
101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Set if mode is MODE_PROXY_PER_SCHEME and has http proxy.
102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ManualProxy     http_proxy;
103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Set if mode is MODE_PROXY_PER_SCHEME and has https proxy.
104868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ManualProxy     https_proxy;
105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Set if mode is MODE_PROXY_PER_SCHEME and has ftp proxy.
106868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ManualProxy     ftp_proxy;
107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Set if mode is MODE_PROXY_PER_SCHEME and has socks proxy.
108868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ManualProxy     socks_proxy;
109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Exceptions for when not to use a proxy.
111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  net::ProxyBypassRules bypass_rules;
112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace chromeos
115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
116868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif  // CHROME_BROWSER_CHROMEOS_UI_PROXY_CONFIG_H_
117