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

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