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

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