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

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