Add-a-proxy-configuration-page.patch 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Thu, 29 Mar 2018 00:43:32 +0200
  3. Subject: Add a proxy configuration page
  4. Accessible from proxy settings and chrome://proxy
  5. Allows to use a PAC script URL, automatic configuration and explicit proxy
  6. settings.
  7. Offer auto-complete for the proxy page URL.
  8. Store proxy settings in LocalState instead of Profile, so that proxy is used
  9. for SimpleURLLoaders as well.
  10. ---
  11. chrome/android/java/res/values/values.xml | 3 +
  12. .../java/res/xml/privacy_preferences.xml | 4 +
  13. .../privacy/settings/PrivacySettings.java | 1 +
  14. .../chrome_autocomplete_provider_client.cc | 2 +
  15. chrome/browser/browser_resources.grd | 6 +
  16. chrome/browser/net/proxy_service_factory.cc | 23 +-
  17. chrome/browser/net/proxy_service_factory.h | 3 +
  18. chrome/browser/prefs/browser_prefs.cc | 4 +
  19. .../prefs/chrome_command_line_pref_store.cc | 2 +-
  20. chrome/browser/resources/proxy_config.css | 61 +++
  21. chrome/browser/resources/proxy_config.html | 79 ++++
  22. chrome/browser/resources/proxy_config.js | 266 +++++++++++
  23. chrome/browser/ui/BUILD.gn | 2 +
  24. .../webui/chrome_web_ui_controller_factory.cc | 3 +
  25. chrome/browser/ui/webui/proxy_config_ui.cc | 419 ++++++++++++++++++
  26. chrome/browser/ui/webui/proxy_config_ui.h | 33 ++
  27. chrome/common/webui_url_constants.cc | 4 +
  28. chrome/common/webui_url_constants.h | 2 +
  29. .../pref_proxy_config_tracker_impl.cc | 1 +
  30. .../proxy_config/proxy_config_dictionary.cc | 30 +-
  31. .../proxy_config/proxy_config_dictionary.h | 7 +-
  32. .../proxy_config/proxy_policy_handler.cc | 2 +-
  33. net/proxy_resolution/proxy_config.cc | 52 ++-
  34. net/proxy_resolution/proxy_config.h | 3 +
  35. 24 files changed, 998 insertions(+), 14 deletions(-)
  36. create mode 100644 chrome/browser/resources/proxy_config.css
  37. create mode 100644 chrome/browser/resources/proxy_config.html
  38. create mode 100644 chrome/browser/resources/proxy_config.js
  39. create mode 100644 chrome/browser/ui/webui/proxy_config_ui.cc
  40. create mode 100644 chrome/browser/ui/webui/proxy_config_ui.h
  41. diff --git a/chrome/android/java/res/values/values.xml b/chrome/android/java/res/values/values.xml
  42. --- a/chrome/android/java/res/values/values.xml
  43. +++ b/chrome/android/java/res/values/values.xml
  44. @@ -25,6 +25,9 @@
  45. <!-- Compositor Tab Title Text -->
  46. <bool name="compositor_tab_title_fake_bold_text">true</bool>
  47. + <string name="proxy_title">Proxy configuration</string>
  48. + <string name="proxy_url">chrome://proxy</string>
  49. +
  50. <!-- Download InfoBar animation. -->
  51. <integer name="download_infobar_sweep_up_delay">500</integer>
  52. <integer name="download_infobar_sweep_down_delay">800</integer>
  53. diff --git a/chrome/android/java/res/xml/privacy_preferences.xml b/chrome/android/java/res/xml/privacy_preferences.xml
  54. --- a/chrome/android/java/res/xml/privacy_preferences.xml
  55. +++ b/chrome/android/java/res/xml/privacy_preferences.xml
  56. @@ -6,6 +6,10 @@
  57. <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
  58. xmlns:app="http://schemas.android.com/apk/res-auto">
  59. + <org.chromium.chrome.browser.about_settings.HyperlinkPreference
  60. + android:key="proxy"
  61. + android:title="@string/proxy_title"
  62. + app:url="@string/proxy_url" />
  63. <Preference
  64. android:key="clear_browsing_data"
  65. android:title="@string/clear_browsing_data_title"
  66. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java b/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
  67. --- a/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
  68. +++ b/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
  69. @@ -52,6 +52,7 @@ import org.chromium.ui.text.SpanApplier;
  70. public class PrivacySettings
  71. extends PreferenceFragmentCompat implements Preference.OnPreferenceChangeListener,
  72. INeedSnackbarManager {
  73. + private static final String PREF_PROXY_OPTIONS = "proxy";
  74. private SnackbarManager mSnackbarManager;
  75. private Snackbar mSnackbar;
  76. diff --git a/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc b/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc
  77. --- a/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc
  78. +++ b/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc
  79. @@ -374,6 +374,8 @@ ChromeAutocompleteProviderClient::GetBuiltinsToProvideAsUserTypes() {
  80. builtins_to_provide.push_back(
  81. base::ASCIIToUTF16(chrome::kChromeUISettingsURL));
  82. #endif
  83. + builtins_to_provide.push_back(
  84. + base::ASCIIToUTF16(chrome::kChromeUIProxyConfigURL));
  85. builtins_to_provide.push_back(
  86. base::ASCIIToUTF16(chrome::kChromeUIVersionURL));
  87. return builtins_to_provide;
  88. diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd
  89. --- a/chrome/browser/browser_resources.grd
  90. +++ b/chrome/browser/browser_resources.grd
  91. @@ -89,6 +89,12 @@
  92. <include name="IDR_HANGOUT_SERVICES_MANIFEST" file="resources\hangout_services\manifest.json" type="BINDATA" />
  93. </if>
  94. + <!-- Bromite Proxy Configuration UI -->
  95. + <if expr="is_android">
  96. + <include name="IDR_PROXY_CONFIG_HTML" file="resources\proxy_config.html" flattenhtml="true" type="BINDATA" compress="gzip" />
  97. + <include name="IDR_PROXY_CONFIG_JS" file="resources\proxy_config.js" type="BINDATA" compress="gzip" />
  98. + </if>
  99. +
  100. <if expr="not is_android">
  101. <!-- Page not available for guest. -->
  102. <include name="IDR_PAGE_NOT_AVAILABLE_FOR_GUEST_APP_HTML" file="resources\page_not_available_for_guest\app.html" type="BINDATA" />
  103. diff --git a/chrome/browser/net/proxy_service_factory.cc b/chrome/browser/net/proxy_service_factory.cc
  104. --- a/chrome/browser/net/proxy_service_factory.cc
  105. +++ b/chrome/browser/net/proxy_service_factory.cc
  106. @@ -15,6 +15,9 @@
  107. #include "content/public/browser/browser_thread.h"
  108. #include "net/proxy_resolution/configured_proxy_resolution_service.h"
  109. #include "net/proxy_resolution/proxy_config_service.h"
  110. +#include "components/proxy_config/proxy_config_pref_names.h"
  111. +#include "components/prefs/pref_service.h"
  112. +#include "components/prefs/pref_registry_simple.h"
  113. #if BUILDFLAG(IS_CHROMEOS_ASH)
  114. #include "chromeos/network/proxy/proxy_config_service_impl.h"
  115. @@ -73,7 +76,20 @@ ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
  116. return std::make_unique<chromeos::ProxyConfigServiceImpl>(
  117. profile_prefs, local_state_prefs, nullptr);
  118. #else
  119. - return std::make_unique<PrefProxyConfigTrackerImpl>(profile_prefs, nullptr);
  120. + // Migrate from profile_prefs to local_state_prefs
  121. + if (local_state_prefs->GetBoolean("proxy_migrated") == false) {
  122. + const base::DictionaryValue* dict =
  123. + profile_prefs->GetDictionary(proxy_config::prefs::kProxy);
  124. +
  125. + LOG(INFO) << "CreatePrefProxyConfigTrackerOfProfile: Migration from profile to local state";
  126. +
  127. + const base::Value /*ProxyConfigDictionary*/ proxy_dict(dict->Clone());
  128. + local_state_prefs->Set(proxy_config::prefs::kProxy, proxy_dict);
  129. +
  130. + local_state_prefs->SetBoolean("proxy_migrated", true);
  131. + local_state_prefs->CommitPendingWrite();
  132. + }
  133. + return std::make_unique<PrefProxyConfigTrackerImpl>(local_state_prefs, nullptr);
  134. #endif // BUILDFLAG(IS_CHROMEOS_ASH)
  135. }
  136. @@ -89,3 +105,8 @@ ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
  137. nullptr);
  138. #endif // BUILDFLAG(IS_CHROMEOS_ASH)
  139. }
  140. +
  141. +// static
  142. +void ProxyServiceFactory::RegisterPrefs(PrefRegistrySimple* registry) {
  143. + registry->RegisterBooleanPref("proxy_migrated", false);
  144. +}
  145. diff --git a/chrome/browser/net/proxy_service_factory.h b/chrome/browser/net/proxy_service_factory.h
  146. --- a/chrome/browser/net/proxy_service_factory.h
  147. +++ b/chrome/browser/net/proxy_service_factory.h
  148. @@ -8,6 +8,7 @@
  149. #include <memory>
  150. #include "base/macros.h"
  151. +#include "components/prefs/pref_registry_simple.h"
  152. class PrefProxyConfigTracker;
  153. class PrefService;
  154. @@ -37,6 +38,8 @@ class ProxyServiceFactory {
  155. CreatePrefProxyConfigTrackerOfProfile(PrefService* profile_prefs,
  156. PrefService* local_state_prefs);
  157. + static void RegisterPrefs(PrefRegistrySimple* registry);
  158. +
  159. // Creates a PrefProxyConfigTracker that tracks local state only. This tracker
  160. // should be used for the system request context and the signin screen
  161. // (ChromeOS only).
  162. diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
  163. --- a/chrome/browser/prefs/browser_prefs.cc
  164. +++ b/chrome/browser/prefs/browser_prefs.cc
  165. @@ -164,6 +164,8 @@
  166. #include "printing/buildflags/buildflags.h"
  167. #include "rlz/buildflags/buildflags.h"
  168. +#include "chrome/browser/net/proxy_service_factory.h"
  169. +
  170. #if BUILDFLAG(ENABLE_BACKGROUND_MODE)
  171. #include "chrome/browser/background/background_mode_manager.h"
  172. #endif
  173. @@ -960,6 +962,8 @@ void RegisterLocalState(PrefRegistrySimple* registry) {
  174. PluginsResourceService::RegisterPrefs(registry);
  175. #endif
  176. + ProxyServiceFactory::RegisterPrefs(registry);
  177. +
  178. #if defined(OS_ANDROID)
  179. ::android::RegisterPrefs(registry);
  180. diff --git a/chrome/browser/prefs/chrome_command_line_pref_store.cc b/chrome/browser/prefs/chrome_command_line_pref_store.cc
  181. --- a/chrome/browser/prefs/chrome_command_line_pref_store.cc
  182. +++ b/chrome/browser/prefs/chrome_command_line_pref_store.cc
  183. @@ -161,7 +161,7 @@ void ChromeCommandLinePrefStore::ApplyProxyMode() {
  184. SetValue(
  185. proxy_config::prefs::kProxy,
  186. std::make_unique<base::Value>(ProxyConfigDictionary::CreateFixedServers(
  187. - proxy_server, bypass_list)),
  188. + proxy_server, bypass_list, false)),
  189. WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
  190. }
  191. }
  192. diff --git a/chrome/browser/resources/proxy_config.css b/chrome/browser/resources/proxy_config.css
  193. new file mode 100644
  194. --- /dev/null
  195. +++ b/chrome/browser/resources/proxy_config.css
  196. @@ -0,0 +1,61 @@
  197. +/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
  198. + * Use of this source code is governed by a BSD-style license that can be
  199. + * found in the LICENSE file.
  200. + */
  201. +
  202. +body {
  203. + font-size: 80%;
  204. + margin: 1em;
  205. +}
  206. +
  207. +#main-container {
  208. + max-width: 60em;
  209. + margin-left: auto;
  210. + margin-right: auto;
  211. +}
  212. +
  213. +button {
  214. + display: block;
  215. + font-size: 110%;
  216. + font-weight: bold;
  217. + margin: 10px auto;
  218. + padding: 1em;
  219. + width: 15em;
  220. +}
  221. +
  222. +h2 {
  223. + color: #546E7A;
  224. + font-weight: normal;
  225. + font-size: 170%;
  226. + margin-bottom: 1.5em;
  227. +}
  228. +
  229. +.radio-button-div {
  230. + margin: 7px auto;
  231. +}
  232. +
  233. +.warning {
  234. + color: red;
  235. + font-size: 90%;
  236. +}
  237. +
  238. +.section-container {
  239. + margin-top: 2em;
  240. +}
  241. +
  242. +#file-path-logging,
  243. +#file-path-stopped {
  244. + font-family: monospace;
  245. +}
  246. +
  247. +.outline-box {
  248. + margin-top: 2em;
  249. + border: 1px solid #ababab;
  250. + padding: 0.5em;
  251. + line-height: 1.5em;
  252. +}
  253. +
  254. +textarea {
  255. + width: 95%;
  256. + height: 4em;
  257. +}
  258. diff --git a/chrome/browser/resources/proxy_config.html b/chrome/browser/resources/proxy_config.html
  259. new file mode 100644
  260. --- /dev/null
  261. +++ b/chrome/browser/resources/proxy_config.html
  262. @@ -0,0 +1,79 @@
  263. +<!doctype html>
  264. +<html>
  265. +<head>
  266. +<meta charset="utf-8">
  267. +<if expr="is_android">
  268. +<meta name="viewport" content="width=device-width">
  269. +</if>
  270. +
  271. +<if expr="is_ios">
  272. +<!-- TODO(crbug.com/487000): Remove this once injected by web. -->
  273. +<script src="chrome://resources/js/ios/web_ui.js"></script>
  274. +</if>
  275. +
  276. +<script src="chrome://resources/js/assert.js"></script>
  277. +<script src="chrome://resources/js/util.js"></script>
  278. +<script type="module" src="chrome://proxy/proxy_config.js"></script>
  279. +<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
  280. +<link rel="stylesheet" href="proxy_config.css">
  281. +<title>Proxy configuration</title>
  282. +</head>
  283. +<body>
  284. + <div id="main-container">
  285. + <!--
  286. + =========================================================================
  287. + View for "pending" state.
  288. + * Only visible briefly, if at all
  289. + =========================================================================
  290. + -->
  291. + <div id="state-pending">
  292. + <h2>Proxy configuration</h2>
  293. + Loading...
  294. + </div>
  295. +
  296. + <!--
  297. + =========================================================================
  298. + View for "available" and "unset" states.
  299. + * Has controls to change or reset proxy configuration.
  300. + =========================================================================
  301. + -->
  302. + <div id="state-main" hidden>
  303. + <h2>Proxy configuration</h2>
  304. + <button id="reset">Reset</button>
  305. + <div class="section-container">
  306. + Reset will update the displayed configuration to match the one currently in use.
  307. + </div>
  308. + <div class="section-container">
  309. + <input type="radio" id="empty" name="mode" value="empty"><label for="empty">System Default</label><br/>
  310. + <input type="radio" id="direct" name="mode" value="direct"><label for="direct">Direct</label><br/>
  311. + <input type="radio" id="auto-detect" name="mode" value="auto-detect"><label for="auto-detect">Auto-detect (WPAD DHCP/DNS)</label><br/>
  312. + <input type="radio" id="use-pac-url" name="mode" value="use-pac-url"><label for="use-pac-url">Use PAC URL: <input id='pac-url' value="" size="40" /></label>
  313. + <p><input type="checkbox" id="pac-mandatory" name="pac-mandatory"><label for="pac-mandatory">Do not allow fallback to direct connection in case PAC script fails</label></p>
  314. + <input type="radio" id="use-single-list" name="mode" value="use-single-list"><label for="use-single-list">Use a single proxy list for all schemes (<a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_(PAC)_file#Description">PAC format</a>):
  315. + <textarea id="single-proxies"></textarea>
  316. + </label><br/>
  317. + <input type="radio" id="use-list-per-scheme" name="mode" value="use-list-per-scheme"><label for="use-list-per-scheme">Use a proxy list per scheme:</label><br/>
  318. + <label for="use-list-per-scheme">HTTP (<a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_(PAC)_file#Description">PAC format</a>):<br/>
  319. + <textarea id="http-proxies"></textarea></label><br/>
  320. + <label for="use-list-per-scheme">HTTPS (<a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_(PAC)_file#Description">PAC format</a>):<br/>
  321. + <textarea id="https-proxies"></textarea></label><br/>
  322. + <label for="use-list-per-scheme">FTP (<a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_(PAC)_file#Description">PAC format</a>):<br/>
  323. + <textarea id="ftp-proxies"></textarea></label><br/>
  324. + <label for="use-list-per-scheme">Fallback (used when the URL does not match any of the standard schemes, <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_(PAC)_file#Description">PAC format</a>):<br/>
  325. + <textarea id="fallback-proxies"></textarea></label>
  326. + <div class="outline-box">
  327. + Bypass rules (a list of matching expressions for the hostname separated by comma or semicolon, can use asterisk; matches against port numbers and IPv4/IPv6); in use only with single or per-scheme proxy lists.<br/>
  328. + <textarea id="bypass-rules"></textarea><br/>
  329. + <input type="checkbox" id="reverse-bypass" name="reverse-bypass"><label for="reverse-bypass">Reverse the meaning of bypass rules</label>
  330. + </div>
  331. + </div>
  332. + <button id="apply">Apply</button>
  333. + <button id="clear">Clear</button>
  334. + <div class="section-container">
  335. + Clicking on Clear will remove any proxy configuration preference currently in effect.
  336. + </div>
  337. + </div>
  338. +
  339. + </div>
  340. +</body>
  341. +</html>
  342. diff --git a/chrome/browser/resources/proxy_config.js b/chrome/browser/resources/proxy_config.js
  343. new file mode 100644
  344. --- /dev/null
  345. +++ b/chrome/browser/resources/proxy_config.js
  346. @@ -0,0 +1,266 @@
  347. +/*
  348. + This file is part of Bromite.
  349. +
  350. + Bromite is free software: you can redistribute it and/or modify
  351. + it under the terms of the GNU General Public License as published by
  352. + the Free Software Foundation, either version 3 of the License, or
  353. + (at your option) any later version.
  354. +
  355. + Bromite is distributed in the hope that it will be useful,
  356. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  357. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  358. + GNU General Public License for more details.
  359. +
  360. + You should have received a copy of the GNU General Public License
  361. + along with Bromite. If not, see <https://www.gnu.org/licenses/>.
  362. +*/
  363. +
  364. +import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';
  365. +
  366. +/**
  367. + * Main entry point called once the page has loaded.
  368. + */
  369. +function onLoad() {
  370. + ProxyConfigView.getInstance();
  371. +}
  372. +
  373. +document.addEventListener('DOMContentLoaded', onLoad);
  374. +
  375. +/**
  376. + * This class handles the presentation of the proxy-config view. Used as a
  377. + * singleton.
  378. + */
  379. +var ProxyConfigView = (function() {
  380. + 'use strict';
  381. +
  382. + // --------------------------------------------------------------------------
  383. +
  384. + var kIdStateDivUninitialized = 'state-pending';
  385. + var kIdStateDivMain = 'state-main';
  386. + var kIdApplyButton = 'apply';
  387. + var kIdResetButton = 'reset';
  388. + var kIdClearButton = 'clear';
  389. +
  390. + var kIdModeEmpty = 'empty';
  391. + var kIdModeDirect = 'direct';
  392. + var kIdModeAutoDetect = 'auto-detect';
  393. + var kIdModeUsePacURL = 'use-pac-url';
  394. +
  395. + var kIdModeUseSingleList = 'use-single-list';
  396. + var kIdModeUseListPerScheme = 'use-list-per-scheme';
  397. +
  398. + var kIdPacURL = 'pac-url';
  399. + var kIdPacMandatory = 'pac-mandatory';
  400. + var kIdBypassRules = 'bypass-rules';
  401. + var kIdReverseBypass = 'reverse-bypass';
  402. + var kIdSingleProxies = 'single-proxies';
  403. + var kIdHttpProxies = 'http-proxies';
  404. + var kIdHttpsProxies = 'https-proxies';
  405. + var kIdFtpProxies = 'ftp-proxies';
  406. + var kIdFallbackProxies = 'fallback-proxies';
  407. +
  408. + /**
  409. + * @constructor
  410. + */
  411. + function ProxyConfigView() {
  412. + this.currentConfig = null;
  413. +
  414. + $(kIdResetButton).onclick = this.onReset_.bind(this);
  415. + $(kIdApplyButton).onclick = this.onApply_.bind(this);
  416. + $(kIdClearButton).onclick = this.onClear_.bind(this);
  417. +
  418. + // Tell ProxyConfigMessageHandler to notify the UI of future state changes
  419. + // from this point on.
  420. + chrome.send('enableNotifyUIWithState');
  421. + }
  422. +
  423. + addSingletonGetter(ProxyConfigView);
  424. + window.ProxyConfigView = ProxyConfigView;
  425. +
  426. + ProxyConfigView.prototype = {
  427. + /**
  428. + * Updates the UI to reflect the current state. The state transitions are
  429. + * sent by the browser controller (ProxyConfigMessageHandler):
  430. + *
  431. + * * PENDING - This is the initial state when proxy configuration is opened
  432. + * for the first time, or there was an error during initialization.
  433. + * This state is short-lived and likely not observed; will
  434. + * immediately transition to AVAILABLE).
  435. + *
  436. + * * AVAILABLE - The reported proxy configuration is active; this state is entered
  437. + * on first page load (or right after PENDING if configuration was not
  438. + * available on page load) and every time some configuration change was applied.
  439. + * It can transition to either AVAILABLE or UNSET.
  440. + *
  441. + * * UNSET - Proxy configuration is reported to be currently not set.
  442. + *
  443. + */
  444. + onProxyConfigChanged: function(state) {
  445. + // may happen only on first load; leave the loading page as another update is expected
  446. + // when proxy configuration has finished loading
  447. + if (state.pending) {
  448. + $(kIdStateDivMain).hidden = true;
  449. + $(kIdStateDivUninitialized).hidden = false;
  450. + return;
  451. + }
  452. +
  453. + if (!state.hasOwnProperty('config')) {
  454. + // configuration has been unset, use an empty one
  455. + this.eraseCurrentConfig_();
  456. + } else {
  457. + // save the configuration as current and reset all controls to it
  458. + this.currentConfig = state.config;
  459. + }
  460. +
  461. + this.renderConfig_();
  462. +
  463. + this.toggleButtons_(false);
  464. + $(kIdStateDivUninitialized).hidden = true;
  465. + $(kIdStateDivMain).hidden = false;
  466. + },
  467. +
  468. + /**
  469. + * Set current configuration to an empty (default) one.
  470. + */
  471. + eraseCurrentConfig_: function() {
  472. + this.currentConfig = {
  473. + "auto_detect": false,
  474. + "pending": false,
  475. + "rules": {
  476. + "bypass_rules": "",
  477. + "reverse_bypass": false,
  478. + "type": "none"
  479. + }
  480. + };
  481. + },
  482. +
  483. + /**
  484. + * Serialize the user-selected configuration in an object.
  485. + */
  486. + serializeConfig_: function() {
  487. + if ($(kIdModeEmpty).checked) {
  488. + return {
  489. + "auto_detect": false,
  490. + "rules": {
  491. + "type": "none"
  492. + }
  493. + };
  494. + } else if ($(kIdModeDirect).checked) {
  495. + return {
  496. + "auto_detect": false,
  497. + "rules": {
  498. + "type": "direct"
  499. + }
  500. + };
  501. + } else if ($(kIdModeAutoDetect).checked) {
  502. + return {
  503. + "auto_detect": true
  504. + };
  505. + } else if ($(kIdModeUsePacURL).checked) {
  506. + return {
  507. + "auto_detect": false,
  508. + "pac_url": $(kIdPacURL).value.trim(),
  509. + "pac_mandatory": $(kIdPacMandatory).checked,
  510. + "rules": {}
  511. + };
  512. + } else if ($(kIdModeUseListPerScheme).checked || $(kIdModeUseSingleList).checked) {
  513. + var config = {
  514. + "auto_detect": false,
  515. + "rules": {
  516. + "bypass_rules": $(kIdBypassRules).value.trim(),
  517. + "reverse_bypass": $(kIdReverseBypass).checked,
  518. + "type": "list"
  519. + }
  520. + };
  521. +
  522. + if ($(kIdModeUseListPerScheme).checked) {
  523. + config.rules.type = "list_per_scheme";
  524. +
  525. + config.rules.proxies_for_http = $(kIdHttpProxies).value.trim();
  526. + config.rules.proxies_for_https = $(kIdHttpsProxies).value.trim();
  527. + config.rules.proxies_for_ftp = $(kIdFtpProxies).value.trim();
  528. + config.rules.fallback_proxies = $(kIdFallbackProxies).value.trim();
  529. + } else {
  530. + config.rules.single_proxies = $(kIdSingleProxies).value.trim();
  531. + }
  532. +
  533. + return config;
  534. + }
  535. +
  536. + throw new Error('unexpected mode');
  537. + },
  538. +
  539. + /**
  540. + * Updates the UI to display the current proxy configuration.
  541. + */
  542. + renderConfig_: function() {
  543. + if (this.currentConfig.auto_detect) {
  544. + $(kIdModeAutoDetect).checked = true;
  545. + } else if (this.currentConfig.hasOwnProperty('pac_url')) {
  546. + $(kIdPacURL).value = this.currentConfig.pac_url;
  547. + $(kIdPacMandatory).checked = this.currentConfig.pac_mandatory;
  548. + $(kIdModeUsePacURL).checked = true;
  549. + } else if (this.currentConfig.rules.type == "none") {
  550. + $(kIdModeEmpty).checked = true;
  551. + } else if (this.currentConfig.rules.type == "direct") {
  552. + $(kIdModeDirect).checked = true;
  553. + } else {
  554. + $(kIdBypassRules).value = this.currentConfig.rules.bypass_rules;
  555. + $(kIdReverseBypass).checked = this.currentConfig.rules.reverse_bypass;
  556. +
  557. + switch (this.currentConfig.rules.type) {
  558. + case "list":
  559. + $(kIdModeUseSingleList).checked = true;
  560. + $(kIdSingleProxies).value = this.currentConfig.rules.single_proxies;
  561. + break;
  562. + case "list_per_scheme":
  563. + $(kIdModeUseListPerScheme).checked = true;
  564. + $(kIdHttpProxies).value = this.currentConfig.rules.proxies_for_http;
  565. + $(kIdHttpsProxies).value = this.currentConfig.rules.proxies_for_https;
  566. + $(kIdFtpProxies).value = this.currentConfig.rules.proxies_for_ftp;
  567. + $(kIdFallbackProxies).value = this.currentConfig.rules.fallback_proxies;
  568. + break;
  569. + }
  570. + }
  571. + },
  572. +
  573. + /**
  574. + * Apply the configuration currently displayed.
  575. + */
  576. + onApply_: function() {
  577. + var config = this.serializeConfig_();
  578. +
  579. + // disable buttons; will be enabled back when UI receives a state update
  580. + this.toggleButtons_(true);
  581. + chrome.send('apply', [config]);
  582. + },
  583. +
  584. + /**
  585. + * Apply the configuration currently displayed.
  586. + */
  587. + onClear_: function() {
  588. + // disable buttons; will be enabled back when UI receives a state update
  589. + this.toggleButtons_(true);
  590. + this.eraseCurrentConfig_();
  591. + chrome.send('clear', []);
  592. + },
  593. +
  594. + /**
  595. + * Toggle the disabled status of the action buttons.
  596. + */
  597. + toggleButtons_: function(disabled) {
  598. + $(kIdApplyButton).disabled = disabled;
  599. + $(kIdResetButton).disabled = disabled;
  600. + $(kIdClearButton).disabled = disabled;
  601. + },
  602. +
  603. + /**
  604. + * Reset currently displayed configuration to the last known configuration in use.
  605. + */
  606. + onReset_: function() {
  607. + this.renderConfig_();
  608. + }
  609. + };
  610. +
  611. + return ProxyConfigView;
  612. +})();
  613. diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn
  614. --- a/chrome/browser/ui/BUILD.gn
  615. +++ b/chrome/browser/ui/BUILD.gn
  616. @@ -278,6 +278,8 @@ static_library("ui") {
  617. "webui/metrics_handler.h",
  618. "webui/net_export_ui.cc",
  619. "webui/net_export_ui.h",
  620. + "webui/proxy_config_ui.cc",
  621. + "webui/proxy_config_ui.h",
  622. "webui/net_internals/net_internals_ui.cc",
  623. "webui/net_internals/net_internals_ui.h",
  624. "webui/ntp_tiles_internals_ui.cc",
  625. diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
  626. --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
  627. +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
  628. @@ -53,6 +53,7 @@
  629. #include "chrome/browser/ui/webui/omnibox/omnibox_ui.h"
  630. #include "chrome/browser/ui/webui/policy/policy_ui.h"
  631. #include "chrome/browser/ui/webui/predictors/predictors_ui.h"
  632. +#include "chrome/browser/ui/webui/proxy_config_ui.h"
  633. #include "chrome/browser/ui/webui/quota_internals/quota_internals_ui.h"
  634. #include "chrome/browser/ui/webui/signin_internals_ui.h"
  635. #include "chrome/browser/ui/webui/support_tool_ui.h"
  636. @@ -644,6 +645,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
  637. return &NewWebUI<MemoryInternalsUI>;
  638. if (url.host_piece() == chrome::kChromeUINetExportHost)
  639. return &NewWebUI<NetExportUI>;
  640. + if (url.host_piece() == chrome::kChromeUIProxyConfigHost)
  641. + return &NewWebUI<ProxyConfigUI>;
  642. if (url.host_piece() == chrome::kChromeUINetInternalsHost)
  643. return &NewWebUI<NetInternalsUI>;
  644. if (url.host_piece() == chrome::kChromeUINTPTilesInternalsHost)
  645. diff --git a/chrome/browser/ui/webui/proxy_config_ui.cc b/chrome/browser/ui/webui/proxy_config_ui.cc
  646. new file mode 100644
  647. --- /dev/null
  648. +++ b/chrome/browser/ui/webui/proxy_config_ui.cc
  649. @@ -0,0 +1,419 @@
  650. +/*
  651. + This file is part of Bromite.
  652. +
  653. + Bromite is free software: you can redistribute it and/or modify
  654. + it under the terms of the GNU General Public License as published by
  655. + the Free Software Foundation, either version 3 of the License, or
  656. + (at your option) any later version.
  657. +
  658. + Bromite is distributed in the hope that it will be useful,
  659. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  660. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  661. + GNU General Public License for more details.
  662. +
  663. + You should have received a copy of the GNU General Public License
  664. + along with Bromite. If not, see <https://www.gnu.org/licenses/>.
  665. +*/
  666. +
  667. +#include "chrome/browser/ui/webui/proxy_config_ui.h"
  668. +
  669. +#include <stdint.h>
  670. +
  671. +#include <memory>
  672. +#include <string>
  673. +#include <vector>
  674. +
  675. +#include "base/bind.h"
  676. +#include "base/command_line.h"
  677. +#include "base/lazy_instance.h"
  678. +#include "base/macros.h"
  679. +#include "base/memory/ref_counted.h"
  680. +#include "base/strings/string_util.h"
  681. +#include "base/strings/utf_string_conversions.h"
  682. +#include "base/values.h"
  683. +#include "chrome/browser/browser_process.h"
  684. +#include "chrome/browser/net/proxy_service_factory.h"
  685. +#include "chrome/browser/platform_util.h"
  686. +#include "chrome/browser/profiles/profile.h"
  687. +#include "chrome/common/url_constants.h"
  688. +#include "chrome/grit/browser_resources.h"
  689. +#include "components/prefs/pref_service.h"
  690. +#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
  691. +#include "components/proxy_config/proxy_config_pref_names.h"
  692. +#include "components/grit/components_resources.h"
  693. +#include "content/public/browser/browser_thread.h"
  694. +#include "content/public/browser/url_data_source.h"
  695. +#include "content/public/browser/web_contents.h"
  696. +#include "content/public/browser/web_ui.h"
  697. +#include "content/public/browser/web_ui_data_source.h"
  698. +#include "content/public/browser/web_ui_message_handler.h"
  699. +
  700. +#include "url/gurl.h"
  701. +
  702. +using content::BrowserThread;
  703. +using content::WebContents;
  704. +using content::WebUIMessageHandler;
  705. +
  706. +namespace {
  707. +
  708. +content::WebUIDataSource* CreateProxyConfigHTMLSource() {
  709. + content::WebUIDataSource* source =
  710. + content::WebUIDataSource::Create(chrome::kChromeUIProxyConfigHost);
  711. +
  712. + source->UseStringsJs();
  713. + source->AddResourcePath("proxy_config.js", IDR_PROXY_CONFIG_JS);
  714. + source->SetDefaultResource(IDR_PROXY_CONFIG_HTML);
  715. + return source;
  716. +}
  717. +
  718. +// This class receives javascript messages from the renderer.
  719. +// Note that the WebUI infrastructure runs on the UI thread, therefore all of
  720. +// this class's public methods are expected to run on the UI thread.
  721. +class ProxyConfigMessageHandler
  722. + : public WebUIMessageHandler,
  723. + public base::SupportsWeakPtr<ProxyConfigMessageHandler>,
  724. + public net::ProxyConfigService::Observer {
  725. + public:
  726. + // Creates a ProxyConfigMessageHandler that handles message exchanges with the Javascript
  727. + // side of the UI and gets proxy settings from the Web UI associated profile to watch for changes.
  728. + // The created ProxyConfigMessageHandler must be destroyed before |profile|.
  729. + ProxyConfigMessageHandler(Profile *profile);
  730. + ~ProxyConfigMessageHandler() override;
  731. +
  732. + // WebUIMessageHandler implementation.
  733. + void RegisterMessages() override;
  734. +
  735. + // Messages
  736. + void OnEnableNotifyUIWithState(base::Value::ConstListView list);
  737. + void OnApply(base::Value::ConstListView config);
  738. + void OnClear(base::Value::ConstListView config);
  739. +
  740. + // net::ProxyConfigService::Observer implementation:
  741. + // Calls ProxyConfigView.onProxyConfigChanged JavaScript function in the
  742. + // renderer.
  743. + void OnProxyConfigChanged(
  744. + const net::ProxyConfigWithAnnotation& config,
  745. + net::ProxyConfigService::ConfigAvailability availability) override;
  746. +
  747. + private:
  748. + // Not owned.
  749. + PrefService *pref_service_;
  750. + std::unique_ptr<net::ProxyConfigService> proxy_config_service_;
  751. + // Monitors global and Profile prefs related to proxy configuration.
  752. + std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
  753. + bool is_observing_;
  754. +
  755. + void encodeConfig(const net::ProxyConfig& config, base::DictionaryValue& state);
  756. +
  757. + void apply(const net::ProxyConfig& config);
  758. +
  759. + base::WeakPtrFactory<ProxyConfigMessageHandler> weak_ptr_factory_;
  760. +
  761. + DISALLOW_COPY_AND_ASSIGN(ProxyConfigMessageHandler);
  762. +};
  763. +
  764. +ProxyConfigMessageHandler::ProxyConfigMessageHandler(Profile *profile)
  765. + :
  766. + weak_ptr_factory_(this) {
  767. +
  768. + // used to set new configuration preferences
  769. + pref_service_ = g_browser_process->local_state();
  770. + // observer is explicitly added only later in enableNotifyUIWithState
  771. + is_observing_ = false;
  772. +
  773. +// If this is the ChromeOS sign-in profile, just create the tracker from global
  774. +// state.
  775. +#if defined(OS_CHROMEOS)
  776. + if (chromeos::ProfileHelper::IsSigninProfile(profile)) {
  777. + pref_proxy_config_tracker_.reset(
  778. + ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
  779. + g_browser_process->local_state()));
  780. + }
  781. +#endif // defined(OS_CHROMEOS)
  782. +
  783. + if (!pref_proxy_config_tracker_) {
  784. + pref_proxy_config_tracker_ =
  785. + ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
  786. + profile->GetPrefs(), g_browser_process->local_state());
  787. + }
  788. +
  789. + proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
  790. + pref_proxy_config_tracker_.get(), nullptr);
  791. +}
  792. +
  793. +void ProxyConfigMessageHandler::OnProxyConfigChanged(
  794. + const net::ProxyConfigWithAnnotation& config,
  795. + net::ProxyConfigService::ConfigAvailability availability) {
  796. + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
  797. + !BrowserThread::IsThreadInitialized(BrowserThread::UI));
  798. +
  799. + base::DictionaryValue state;
  800. + bool pending = false;
  801. + switch (availability) {
  802. + case net::ProxyConfigService::CONFIG_VALID:
  803. + encodeConfig(config.value(), state);
  804. + break;
  805. + case net::ProxyConfigService::CONFIG_UNSET:
  806. + state.SetPath({"config", "rules", "type"}, base::Value("none"));
  807. + break;
  808. + case net::ProxyConfigService::CONFIG_PENDING:
  809. + //NOTE: this can only happen when triggered manually first time
  810. + pending = true;
  811. + break;
  812. + }
  813. + state.SetKey("pending", base::Value(pending));
  814. +
  815. + // call Javascript function
  816. + web_ui()->CallJavascriptFunctionUnsafe("ProxyConfigView.getInstance().onProxyConfigChanged",
  817. + *state.CreateDeepCopy());
  818. +}
  819. +
  820. +const std::string omitDirect(const std::string pacString) {
  821. + if (pacString == "DIRECT") {
  822. + return "";
  823. + }
  824. + return pacString;
  825. +}
  826. +
  827. +void ProxyConfigMessageHandler::encodeConfig(const net::ProxyConfig& config, base::DictionaryValue& state) {
  828. + // when automatic settings are enabled they take precedence over manual settings
  829. + // automatic settings are either the "auto-detect" flag or the existance of a PAC URL
  830. +
  831. + state.SetPath({"config", "auto_detect"}, base::Value(config.auto_detect()));
  832. +
  833. + auto rules = config.proxy_rules();
  834. + if (config.has_pac_url()) {
  835. + state.SetPath({"config", "pac_url"}, base::Value(config.pac_url().spec()));
  836. + state.SetPath({"config", "pac_mandatory"}, base::Value(config.pac_mandatory()));
  837. + state.SetPath({"config", "rules", "type"}, base::Value("none"));
  838. + state.SetPath({"config", "rules", "bypass_rules"}, base::Value(rules.bypass_rules.ToString()));
  839. + state.SetPath({"config", "rules", "reverse_bypass"}, base::Value(rules.reverse_bypass));
  840. + return;
  841. + }
  842. +
  843. + const char *type;
  844. + switch (rules.type) {
  845. + case net::ProxyConfig::ProxyRules::Type::EMPTY:
  846. + type = "direct";
  847. + break;
  848. + case net::ProxyConfig::ProxyRules::Type::PROXY_LIST:
  849. + type = "list";
  850. +
  851. + state.SetPath({"config", "rules", "single_proxies"}, base::Value(omitDirect(rules.single_proxies.ToPacString())));
  852. + break;
  853. + case net::ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME:
  854. + type = "list_per_scheme";
  855. +
  856. + state.SetPath({"config", "rules", "proxies_for_http"}, base::Value(omitDirect(rules.proxies_for_http.ToPacString())));
  857. + state.SetPath({"config", "rules", "proxies_for_https"}, base::Value(omitDirect(rules.proxies_for_https.ToPacString())));
  858. + state.SetPath({"config", "rules", "proxies_for_ftp"}, base::Value(omitDirect(rules.proxies_for_ftp.ToPacString())));
  859. + state.SetPath({"config", "rules", "fallback_proxies"}, base::Value(omitDirect(rules.fallback_proxies.ToPacString())));
  860. + break;
  861. + default:
  862. + NOTREACHED();
  863. + break;
  864. + }
  865. + state.SetPath({"config", "rules", "type"}, base::Value(type));
  866. + state.SetPath({"config", "rules", "bypass_rules"}, base::Value(rules.bypass_rules.ToString()));
  867. + state.SetPath({"config", "rules", "reverse_bypass"}, base::Value(rules.reverse_bypass));
  868. +}
  869. +
  870. +ProxyConfigMessageHandler::~ProxyConfigMessageHandler() {
  871. + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
  872. + !BrowserThread::IsThreadInitialized(BrowserThread::UI));
  873. + if (is_observing_) {
  874. + proxy_config_service_->RemoveObserver(this);
  875. + }
  876. + pref_proxy_config_tracker_->DetachFromPrefService();
  877. +}
  878. +
  879. +void ProxyConfigMessageHandler::RegisterMessages() {
  880. + DCHECK_CURRENTLY_ON(BrowserThread::UI);
  881. +
  882. + web_ui()->RegisterMessageCallback(
  883. + "enableNotifyUIWithState",
  884. + base::BindRepeating(&ProxyConfigMessageHandler::OnEnableNotifyUIWithState,
  885. + base::Unretained(this)));
  886. + web_ui()->RegisterMessageCallback(
  887. + "apply",
  888. + base::BindRepeating(&ProxyConfigMessageHandler::OnApply,
  889. + base::Unretained(this)));
  890. + web_ui()->RegisterMessageCallback(
  891. + "clear",
  892. + base::BindRepeating(&ProxyConfigMessageHandler::OnClear,
  893. + base::Unretained(this)));
  894. +}
  895. +
  896. +// The proxy configuration UI is not notified of state changes until this function runs.
  897. +// After this function, OnProxyConfigChanged() will be called on all proxy state changes.
  898. +void ProxyConfigMessageHandler::OnEnableNotifyUIWithState(
  899. + base::Value::ConstListView list) {
  900. + DCHECK_CURRENTLY_ON(BrowserThread::UI);
  901. +
  902. + if (!is_observing_) {
  903. + is_observing_ = true;
  904. + proxy_config_service_->AddObserver(this);
  905. + }
  906. +
  907. + net::ProxyConfigWithAnnotation config;
  908. + auto availability = proxy_config_service_->GetLatestProxyConfig(&config);
  909. +
  910. + const base::DictionaryValue* dict =
  911. + pref_service_->GetDictionary(proxy_config::prefs::kProxy);
  912. + ProxyConfigDictionary proxy_dict(dict->Clone());
  913. + ProxyPrefs::ProxyMode mode;
  914. + if (!proxy_dict.GetMode(&mode) || mode == ProxyPrefs::MODE_SYSTEM) {
  915. + availability = net::ProxyConfigService::CONFIG_UNSET;
  916. + }
  917. +
  918. + OnProxyConfigChanged(config, availability);
  919. +}
  920. +
  921. +void ProxyConfigMessageHandler::OnClear(base::Value::ConstListView list) {
  922. + DCHECK_CURRENTLY_ON(BrowserThread::UI);
  923. +
  924. + const base::Value cfg = ProxyConfigDictionary::CreateSystem();
  925. + pref_service_->Set(proxy_config::prefs::kProxy, cfg);
  926. + pref_service_->CommitPendingWrite();
  927. + OnEnableNotifyUIWithState(list);
  928. +}
  929. +
  930. +void ProxyConfigMessageHandler::OnApply(base::Value::ConstListView list) {
  931. + DCHECK_CURRENTLY_ON(BrowserThread::UI);
  932. +
  933. + if ((list.size() != 1) || !list[0].is_dict()) {
  934. + return;
  935. + }
  936. +
  937. + const base::DictionaryValue* config = nullptr;
  938. + if (!list[0].GetAsDictionary(&config))
  939. + return;
  940. +
  941. + const base::Value *autoDetect = config->FindKeyOfType("auto_detect", base::Value::Type::BOOLEAN);
  942. + if (autoDetect == nullptr)
  943. + return;
  944. +
  945. + if (autoDetect->GetBool()) {
  946. + apply(net::ProxyConfig::CreateAutoDetect());
  947. + return;
  948. + }
  949. +
  950. + const base::Value *pacURL = config->FindKeyOfType("pac_url", base::Value::Type::STRING);
  951. + if (pacURL != nullptr) {
  952. + const base::Value *pacMandatory = config->FindKeyOfType("pac_mandatory", base::Value::Type::BOOLEAN);
  953. + if (pacMandatory == nullptr)
  954. + return;
  955. + auto proxyConfig = net::ProxyConfig::CreateFromCustomPacURL(GURL(pacURL->GetString()));
  956. + proxyConfig.set_pac_mandatory(pacMandatory->GetBool());
  957. +
  958. + apply(proxyConfig);
  959. + return;
  960. + }
  961. +
  962. + const base::Value *rules = config->FindKeyOfType("rules", base::Value::Type::DICTIONARY);
  963. + if (rules == nullptr)
  964. + return;
  965. +
  966. + const base::Value *type = rules->FindKeyOfType("type", base::Value::Type::STRING);
  967. + if (type == nullptr)
  968. + return;
  969. +
  970. + net::ProxyConfig proxyConfig;
  971. +
  972. + bool readBypass = false;
  973. +
  974. + auto t = type->GetString();
  975. + if (t == "list") {
  976. + const base::Value *single_proxies = rules->FindKeyOfType("single_proxies", base::Value::Type::STRING);
  977. + if (single_proxies == nullptr)
  978. + return;
  979. + proxyConfig.proxy_rules().type = net::ProxyConfig::ProxyRules::Type::PROXY_LIST;
  980. + proxyConfig.proxy_rules().single_proxies.SetFromPacString(single_proxies->GetString());
  981. + readBypass = true;
  982. + } else if (t == "list_per_scheme") {
  983. + const base::Value *http = rules->FindKeyOfType("proxies_for_http", base::Value::Type::STRING);
  984. + if (http == nullptr)
  985. + return;
  986. +
  987. + const base::Value *https = rules->FindKeyOfType("proxies_for_https", base::Value::Type::STRING);
  988. + if (https == nullptr)
  989. + return;
  990. +
  991. + const base::Value *ftp = rules->FindKeyOfType("proxies_for_ftp", base::Value::Type::STRING);
  992. + if (ftp == nullptr)
  993. + return;
  994. +
  995. + const base::Value *fallback = rules->FindKeyOfType("fallback_proxies", base::Value::Type::STRING);
  996. + if (fallback == nullptr)
  997. + return;
  998. +
  999. + proxyConfig.proxy_rules().type = net::ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME;
  1000. + proxyConfig.proxy_rules().proxies_for_http.SetFromPacString(http->GetString());
  1001. + proxyConfig.proxy_rules().proxies_for_https.SetFromPacString(https->GetString());
  1002. + proxyConfig.proxy_rules().proxies_for_ftp.SetFromPacString(ftp->GetString());
  1003. + proxyConfig.proxy_rules().fallback_proxies.SetFromPacString(fallback->GetString());
  1004. + readBypass = true;
  1005. + } else if (t == "direct") {
  1006. + proxyConfig.proxy_rules().type = net::ProxyConfig::ProxyRules::Type::EMPTY;
  1007. + } else if (t == "none") {
  1008. + base::Value::ConstListView empty;
  1009. + OnClear(empty);
  1010. + return;
  1011. + } else {
  1012. + // invalid type
  1013. + LOG(WARNING) << "invalid proxy configuration type";
  1014. + return;
  1015. + }
  1016. +
  1017. + // bypass rules and reverse flag are common to both list types of proxy rules
  1018. + if (readBypass) {
  1019. + const base::Value *bypass_rules = rules->FindKeyOfType("bypass_rules", base::Value::Type::STRING);
  1020. + if (bypass_rules == nullptr)
  1021. + return;
  1022. +
  1023. + const base::Value *reverse_bypass = rules->FindKeyOfType("reverse_bypass", base::Value::Type::BOOLEAN);
  1024. + if (reverse_bypass == nullptr)
  1025. + return;
  1026. +
  1027. + proxyConfig.proxy_rules().bypass_rules.ParseFromString(bypass_rules->GetString());
  1028. + proxyConfig.proxy_rules().reverse_bypass = reverse_bypass->GetBool();
  1029. + }
  1030. +
  1031. + apply(proxyConfig);
  1032. +}
  1033. +
  1034. +void ProxyConfigMessageHandler::apply(const net::ProxyConfig& proxyConfig) {
  1035. + if (proxyConfig.auto_detect()) {
  1036. + const base::Value cfg = ProxyConfigDictionary::CreateAutoDetect();
  1037. + pref_service_->Set(proxy_config::prefs::kProxy, cfg);
  1038. + } else if (proxyConfig.has_pac_url()) {
  1039. + const base::Value cfg = ProxyConfigDictionary::CreatePacScript(proxyConfig.pac_url().spec(), proxyConfig.pac_mandatory());
  1040. + pref_service_->Set(proxy_config::prefs::kProxy, cfg);
  1041. + } else if (proxyConfig.proxy_rules().type == net::ProxyConfig::ProxyRules::Type::EMPTY) {
  1042. + const base::Value cfg = ProxyConfigDictionary::CreateDirect();
  1043. + pref_service_->Set(proxy_config::prefs::kProxy, cfg);
  1044. + } else {
  1045. + auto proxyRulesAsString = proxyConfig.proxy_rules().ToString();
  1046. + auto bypassRulesAsString = proxyConfig.proxy_rules().bypass_rules.ToString();
  1047. +
  1048. + // fixed servers
  1049. + const base::Value cfg = ProxyConfigDictionary::CreateFixedServers(proxyRulesAsString,
  1050. + bypassRulesAsString, proxyConfig.proxy_rules().reverse_bypass);
  1051. + pref_service_->Set(proxy_config::prefs::kProxy, cfg);
  1052. + }
  1053. + pref_service_->CommitPendingWrite();
  1054. +
  1055. + base::Value::ConstListView empty;
  1056. + OnEnableNotifyUIWithState(empty);
  1057. +}
  1058. +
  1059. +} // namespace
  1060. +
  1061. +ProxyConfigUI::ProxyConfigUI(content::WebUI* web_ui) : WebUIController(web_ui) {
  1062. + Profile* profile = Profile::FromWebUI(web_ui);
  1063. +
  1064. + web_ui->AddMessageHandler(std::make_unique<ProxyConfigMessageHandler>(profile));
  1065. +
  1066. + // Set up the chrome://proxy/ source.
  1067. + content::WebUIDataSource::Add(profile, CreateProxyConfigHTMLSource());
  1068. +}
  1069. diff --git a/chrome/browser/ui/webui/proxy_config_ui.h b/chrome/browser/ui/webui/proxy_config_ui.h
  1070. new file mode 100644
  1071. --- /dev/null
  1072. +++ b/chrome/browser/ui/webui/proxy_config_ui.h
  1073. @@ -0,0 +1,33 @@
  1074. +/*
  1075. + This file is part of Bromite.
  1076. +
  1077. + Bromite is free software: you can redistribute it and/or modify
  1078. + it under the terms of the GNU General Public License as published by
  1079. + the Free Software Foundation, either version 3 of the License, or
  1080. + (at your option) any later version.
  1081. +
  1082. + Bromite is distributed in the hope that it will be useful,
  1083. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1084. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1085. + GNU General Public License for more details.
  1086. +
  1087. + You should have received a copy of the GNU General Public License
  1088. + along with Bromite. If not, see <https://www.gnu.org/licenses/>.
  1089. +*/
  1090. +
  1091. +#ifndef CHROME_BROWSER_UI_WEBUI_PROXY_CONFIG_UI_H_
  1092. +#define CHROME_BROWSER_UI_WEBUI_PROXY_CONFIG_UI_H_
  1093. +
  1094. +#include "base/macros.h"
  1095. +#include "content/public/browser/web_ui_controller.h"
  1096. +
  1097. +// The WebUI for chrome://proxy/.
  1098. +class ProxyConfigUI : public content::WebUIController {
  1099. + public:
  1100. + explicit ProxyConfigUI(content::WebUI* web_ui);
  1101. +
  1102. + private:
  1103. + DISALLOW_COPY_AND_ASSIGN(ProxyConfigUI);
  1104. +};
  1105. +
  1106. +#endif // CHROME_BROWSER_UI_WEBUI_PROXY_CONFIG_UI_H_
  1107. diff --git a/chrome/common/webui_url_constants.cc b/chrome/common/webui_url_constants.cc
  1108. --- a/chrome/common/webui_url_constants.cc
  1109. +++ b/chrome/common/webui_url_constants.cc
  1110. @@ -37,6 +37,8 @@ const char kChromeUICertificateViewerHost[] = "view-cert";
  1111. const char kChromeUICertificateViewerURL[] = "chrome://view-cert/";
  1112. const char kChromeUIChromeSigninHost[] = "chrome-signin";
  1113. const char kChromeUIChromeSigninURL[] = "chrome://chrome-signin/";
  1114. +const char kChromeUIProxyConfigHost[] = "proxy";
  1115. +const char kChromeUIProxyConfigURL[] = "chrome://proxy/";
  1116. const char kChromeUIChromeURLsHost[] = "chrome-urls";
  1117. const char kChromeUIChromeURLsURL[] = "chrome://chrome-urls/";
  1118. const char kChromeUIComponentsHost[] = "components";
  1119. @@ -354,6 +356,7 @@ bool IsSystemWebUIHost(base::StringPiece host) {
  1120. kChromeUIMobileSetupHost,
  1121. kChromeUIMultiDeviceSetupHost,
  1122. kChromeUINetworkHost,
  1123. + kChromeUIProxyConfigHost,
  1124. kChromeUIOobeHost,
  1125. kChromeUIOSCreditsHost,
  1126. kChromeUIOSSettingsHost,
  1127. @@ -584,6 +587,7 @@ const char* const kChromeHostURLs[] = {
  1128. #if !defined(OS_ANDROID)
  1129. #if !BUILDFLAG(IS_CHROMEOS_ASH)
  1130. kChromeUIAppLauncherPageHost,
  1131. + kChromeUIProxyConfigHost,
  1132. #endif
  1133. kChromeUIBookmarksHost,
  1134. kChromeUIDownloadsHost,
  1135. diff --git a/chrome/common/webui_url_constants.h b/chrome/common/webui_url_constants.h
  1136. --- a/chrome/common/webui_url_constants.h
  1137. +++ b/chrome/common/webui_url_constants.h
  1138. @@ -127,6 +127,8 @@ extern const char kChromeUIMemoryInternalsHost[];
  1139. extern const char kChromeUINTPTilesInternalsHost[];
  1140. extern const char kChromeUINaClHost[];
  1141. extern const char kChromeUINetExportHost[];
  1142. +extern const char kChromeUIProxyConfigHost[];
  1143. +extern const char kChromeUIProxyConfigURL[];
  1144. extern const char kChromeUINetInternalsHost[];
  1145. extern const char kChromeUINetInternalsURL[];
  1146. extern const char kChromeUINewTabHost[];
  1147. diff --git a/components/proxy_config/pref_proxy_config_tracker_impl.cc b/components/proxy_config/pref_proxy_config_tracker_impl.cc
  1148. --- a/components/proxy_config/pref_proxy_config_tracker_impl.cc
  1149. +++ b/components/proxy_config/pref_proxy_config_tracker_impl.cc
  1150. @@ -380,6 +380,7 @@ bool PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(
  1151. if (proxy_dict.GetBypassList(&proxy_bypass)) {
  1152. proxy_config.proxy_rules().bypass_rules.ParseFromString(proxy_bypass);
  1153. }
  1154. + proxy_config.proxy_rules().reverse_bypass = proxy_dict.HasReverseBypass();
  1155. *config = net::ProxyConfigWithAnnotation(
  1156. proxy_config, kSettingsProxyConfigTrafficAnnotation);
  1157. return true;
  1158. diff --git a/components/proxy_config/proxy_config_dictionary.cc b/components/proxy_config/proxy_config_dictionary.cc
  1159. --- a/components/proxy_config/proxy_config_dictionary.cc
  1160. +++ b/components/proxy_config/proxy_config_dictionary.cc
  1161. @@ -30,6 +30,8 @@ const char kProxyPacMandatory[] = "pac_mandatory";
  1162. // String containing proxy bypass rules. For a specification of the
  1163. // expected syntax see net::ProxyBypassRules::ParseFromString().
  1164. const char kProxyBypassList[] = "bypass_list";
  1165. +// Boolean telling whether to reverse the meaning of the bypass list.
  1166. +const char kProxyReverseBypass[] = "reverse_bypass";
  1167. } // namespace
  1168. @@ -78,6 +80,14 @@ bool ProxyConfigDictionary::HasBypassList() const {
  1169. return dict_.FindKey(kProxyBypassList);
  1170. }
  1171. +bool ProxyConfigDictionary::HasReverseBypass() const {
  1172. + const base::Value* value = dict_.FindKey(kProxyReverseBypass);
  1173. + if (!value || !value->is_bool()) {
  1174. + return false;
  1175. + }
  1176. + return value->GetBool();
  1177. +}
  1178. +
  1179. const base::Value& ProxyConfigDictionary::GetDictionary() const {
  1180. return dict_;
  1181. }
  1182. @@ -85,29 +95,30 @@ const base::Value& ProxyConfigDictionary::GetDictionary() const {
  1183. // static
  1184. base::Value ProxyConfigDictionary::CreateDirect() {
  1185. return CreateDictionary(ProxyPrefs::MODE_DIRECT, std::string(), false,
  1186. - std::string(), std::string());
  1187. + std::string(), std::string(), false);
  1188. }
  1189. // static
  1190. base::Value ProxyConfigDictionary::CreateAutoDetect() {
  1191. return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, std::string(), false,
  1192. - std::string(), std::string());
  1193. + std::string(), std::string(), false);
  1194. }
  1195. // static
  1196. base::Value ProxyConfigDictionary::CreatePacScript(const std::string& pac_url,
  1197. bool pac_mandatory) {
  1198. return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, pac_url, pac_mandatory,
  1199. - std::string(), std::string());
  1200. + std::string(), std::string(), false);
  1201. }
  1202. // static
  1203. base::Value ProxyConfigDictionary::CreateFixedServers(
  1204. const std::string& proxy_server,
  1205. - const std::string& bypass_list) {
  1206. + const std::string& bypass_list,
  1207. + bool reverse_bypass) {
  1208. if (!proxy_server.empty()) {
  1209. return CreateDictionary(ProxyPrefs::MODE_FIXED_SERVERS, std::string(),
  1210. - false, proxy_server, bypass_list);
  1211. + false, proxy_server, bypass_list, reverse_bypass);
  1212. } else {
  1213. return CreateDirect();
  1214. }
  1215. @@ -116,7 +127,7 @@ base::Value ProxyConfigDictionary::CreateFixedServers(
  1216. // static
  1217. base::Value ProxyConfigDictionary::CreateSystem() {
  1218. return CreateDictionary(ProxyPrefs::MODE_SYSTEM, std::string(), false,
  1219. - std::string(), std::string());
  1220. + std::string(), std::string(), false);
  1221. }
  1222. // static
  1223. @@ -125,7 +136,8 @@ base::Value ProxyConfigDictionary::CreateDictionary(
  1224. const std::string& pac_url,
  1225. bool pac_mandatory,
  1226. const std::string& proxy_server,
  1227. - const std::string& bypass_list) {
  1228. + const std::string& bypass_list,
  1229. + bool reverse_bypass) {
  1230. base::Value dict(base::Value::Type::DICTIONARY);
  1231. dict.SetKey(kProxyMode, base::Value(ProxyModeToString(mode)));
  1232. if (!pac_url.empty()) {
  1233. @@ -134,8 +146,10 @@ base::Value ProxyConfigDictionary::CreateDictionary(
  1234. }
  1235. if (!proxy_server.empty())
  1236. dict.SetKey(kProxyServer, base::Value(proxy_server));
  1237. - if (!bypass_list.empty())
  1238. + if (!bypass_list.empty()) {
  1239. dict.SetKey(kProxyBypassList, base::Value(bypass_list));
  1240. + dict.SetKey(kProxyReverseBypass, base::Value(reverse_bypass));
  1241. + }
  1242. return dict;
  1243. }
  1244. diff --git a/components/proxy_config/proxy_config_dictionary.h b/components/proxy_config/proxy_config_dictionary.h
  1245. --- a/components/proxy_config/proxy_config_dictionary.h
  1246. +++ b/components/proxy_config/proxy_config_dictionary.h
  1247. @@ -43,6 +43,7 @@ class PROXY_CONFIG_EXPORT ProxyConfigDictionary {
  1248. bool GetProxyServer(std::string* out) const;
  1249. bool GetBypassList(std::string* out) const;
  1250. bool HasBypassList() const;
  1251. + bool HasReverseBypass() const;
  1252. const base::Value& GetDictionary() const;
  1253. @@ -51,7 +52,8 @@ class PROXY_CONFIG_EXPORT ProxyConfigDictionary {
  1254. static base::Value CreatePacScript(const std::string& pac_url,
  1255. bool pac_mandatory);
  1256. static base::Value CreateFixedServers(const std::string& proxy_server,
  1257. - const std::string& bypass_list);
  1258. + const std::string& bypass_list,
  1259. + bool reverse_bypass);
  1260. static base::Value CreateSystem();
  1261. // Encodes the proxy server as "<url-scheme>=<proxy-scheme>://<proxy>".
  1262. @@ -67,7 +69,8 @@ class PROXY_CONFIG_EXPORT ProxyConfigDictionary {
  1263. const std::string& pac_url,
  1264. bool pac_mandatory,
  1265. const std::string& proxy_server,
  1266. - const std::string& bypass_list);
  1267. + const std::string& bypass_list,
  1268. + bool reverse_bypass);
  1269. base::Value dict_;
  1270. };
  1271. diff --git a/components/proxy_config/proxy_policy_handler.cc b/components/proxy_config/proxy_policy_handler.cc
  1272. --- a/components/proxy_config/proxy_policy_handler.cc
  1273. +++ b/components/proxy_config/proxy_policy_handler.cc
  1274. @@ -259,7 +259,7 @@ void ProxyPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
  1275. ProxyConfigDictionary::CreateFixedServers(
  1276. server->GetString(), bypass_list && bypass_list->is_string()
  1277. ? bypass_list->GetString()
  1278. - : std::string()));
  1279. + : std::string(), false));
  1280. }
  1281. break;
  1282. }
  1283. diff --git a/net/proxy_resolution/proxy_config.cc b/net/proxy_resolution/proxy_config.cc
  1284. --- a/net/proxy_resolution/proxy_config.cc
  1285. +++ b/net/proxy_resolution/proxy_config.cc
  1286. @@ -112,7 +112,7 @@ void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) {
  1287. &single_proxies,
  1288. ProxyServer::SCHEME_HTTP);
  1289. type = Type::PROXY_LIST;
  1290. - return;
  1291. + continue;
  1292. }
  1293. // Trim whitespace off the url scheme.
  1294. @@ -143,6 +143,56 @@ void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) {
  1295. }
  1296. }
  1297. +std::string ProxyConfig::ProxyRules::ToString() const {
  1298. + if (type == Type::EMPTY) {
  1299. + return "";
  1300. + }
  1301. +
  1302. + // special case: a single proxy servers list specified
  1303. + if (type == Type::PROXY_LIST) {
  1304. + std::string proxy_list;
  1305. + for (const ProxyServer& proxy_server :
  1306. + single_proxies.GetAll()) {
  1307. + proxy_list += ProxyServerToProxyUri(proxy_server) + ";";
  1308. + }
  1309. + // remove last semicolon
  1310. + if (proxy_list.length() != 0 ) {
  1311. + proxy_list.pop_back();
  1312. + }
  1313. + return proxy_list;
  1314. + }
  1315. +
  1316. + if (type != Type::PROXY_LIST_PER_SCHEME) {
  1317. + NOTREACHED();
  1318. + // Unexpected LIST with fallback, or other type values
  1319. + return "";
  1320. + }
  1321. +
  1322. + // start to build a per-scheme list
  1323. + std::string list;
  1324. + for (const ProxyServer& proxy_server :
  1325. + proxies_for_http.GetAll()) {
  1326. + list += "http=" + ProxyServerToProxyUri(proxy_server) + ";";
  1327. + }
  1328. + for (const ProxyServer& proxy_server :
  1329. + proxies_for_https.GetAll()) {
  1330. + list += "https=" + ProxyServerToProxyUri(proxy_server) + ";";
  1331. + }
  1332. + for (const ProxyServer& proxy_server :
  1333. + proxies_for_ftp.GetAll()) {
  1334. + list += "ftp=" + ProxyServerToProxyUri(proxy_server) + ";";
  1335. + }
  1336. + for (const ProxyServer& proxy_server :
  1337. + fallback_proxies.GetAll()) {
  1338. + list += "socks=" + ProxyServerToProxyUri(proxy_server) + ";";
  1339. + }
  1340. + if (list.length() != 0 ) {
  1341. + // remove last semicolon
  1342. + list.pop_back();
  1343. + }
  1344. + return list;
  1345. +}
  1346. +
  1347. const ProxyList* ProxyConfig::ProxyRules::MapUrlSchemeToProxyList(
  1348. const std::string& url_scheme) const {
  1349. const ProxyList* proxy_server_list = const_cast<ProxyRules*>(this)->
  1350. diff --git a/net/proxy_resolution/proxy_config.h b/net/proxy_resolution/proxy_config.h
  1351. --- a/net/proxy_resolution/proxy_config.h
  1352. +++ b/net/proxy_resolution/proxy_config.h
  1353. @@ -103,6 +103,9 @@ class NET_EXPORT ProxyConfig {
  1354. // and use socks4://foopy2 for all other
  1355. // URLs.
  1356. void ParseFromString(const std::string& proxy_rules);
  1357. + // Returns the proxy rules in a format that can be parsed by ParseFromString;
  1358. + // all information except bypass rules is used.
  1359. + std::string ToString() const;
  1360. // Returns one of {&proxies_for_http, &proxies_for_https, &proxies_for_ftp,
  1361. // &fallback_proxies}, or NULL if there is no proxy to use.
  1362. --
  1363. 2.20.1