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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  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 | 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. .../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, 915 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. @@ -76,6 +76,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. <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.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. @@ -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. @@ -202,6 +202,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="not is_android">
  85. <include name="IDR_APP_MANAGEMENT_BITMAP_MOJO_LITE_JS" file="${root_gen_dir}\skia\public\mojom\bitmap.mojom-lite.js" 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. @@ -153,7 +153,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. @@ -275,6 +275,8 @@ jumbo_split_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. @@ -55,6 +55,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. @@ -413,6 +414,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,397 @@
  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. + const base::Value::ListStorage& params = list->GetList();
  810. +
  811. + if ((params.size() != 1) || !params[0].is_dict()) {
  812. + return;
  813. + }
  814. +
  815. + const base::DictionaryValue* config = nullptr;
  816. + if (!list->GetDictionary(0, &config))
  817. + return;
  818. +
  819. + const base::Value *autoDetect = config->FindKeyOfType("auto_detect", base::Value::Type::BOOLEAN);
  820. + if (autoDetect == nullptr)
  821. + return;
  822. +
  823. + if (autoDetect->GetBool()) {
  824. + apply(net::ProxyConfig::CreateAutoDetect());
  825. + return;
  826. + }
  827. +
  828. + const base::Value *pacURL = config->FindKeyOfType("pac_url", base::Value::Type::STRING);
  829. + if (pacURL != nullptr) {
  830. + const base::Value *pacMandatory = config->FindKeyOfType("pac_mandatory", base::Value::Type::BOOLEAN);
  831. + if (pacMandatory == nullptr)
  832. + return;
  833. + auto proxyConfig = net::ProxyConfig::CreateFromCustomPacURL(GURL(pacURL->GetString()));
  834. + proxyConfig.set_pac_mandatory(pacMandatory->GetBool());
  835. +
  836. + apply(proxyConfig);
  837. + return;
  838. + }
  839. +
  840. + const base::Value *rules = config->FindKeyOfType("rules", base::Value::Type::DICTIONARY);
  841. + if (rules == nullptr)
  842. + return;
  843. +
  844. + const base::Value *type = rules->FindKeyOfType("type", base::Value::Type::STRING);
  845. + if (type == nullptr)
  846. + return;
  847. +
  848. + net::ProxyConfig proxyConfig;
  849. +
  850. + bool readBypass = false;
  851. +
  852. + auto t = type->GetString();
  853. + if (t == "list") {
  854. + const base::Value *single_proxies = rules->FindKeyOfType("single_proxies", base::Value::Type::STRING);
  855. + if (single_proxies == nullptr)
  856. + return;
  857. + proxyConfig.proxy_rules().type = net::ProxyConfig::ProxyRules::Type::PROXY_LIST;
  858. + proxyConfig.proxy_rules().single_proxies.SetFromPacString(single_proxies->GetString());
  859. + readBypass = true;
  860. + } else if (t == "list_per_scheme") {
  861. + const base::Value *http = rules->FindKeyOfType("proxies_for_http", base::Value::Type::STRING);
  862. + if (http == nullptr)
  863. + return;
  864. +
  865. + const base::Value *https = rules->FindKeyOfType("proxies_for_https", base::Value::Type::STRING);
  866. + if (https == nullptr)
  867. + return;
  868. +
  869. + const base::Value *ftp = rules->FindKeyOfType("proxies_for_ftp", base::Value::Type::STRING);
  870. + if (ftp == nullptr)
  871. + return;
  872. +
  873. + const base::Value *fallback = rules->FindKeyOfType("fallback_proxies", base::Value::Type::STRING);
  874. + if (fallback == nullptr)
  875. + return;
  876. +
  877. + proxyConfig.proxy_rules().type = net::ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME;
  878. + proxyConfig.proxy_rules().proxies_for_http.SetFromPacString(http->GetString());
  879. + proxyConfig.proxy_rules().proxies_for_https.SetFromPacString(https->GetString());
  880. + proxyConfig.proxy_rules().proxies_for_ftp.SetFromPacString(ftp->GetString());
  881. + proxyConfig.proxy_rules().fallback_proxies.SetFromPacString(fallback->GetString());
  882. + readBypass = true;
  883. + } else if (t == "empty") {
  884. + proxyConfig.proxy_rules().type = net::ProxyConfig::ProxyRules::Type::EMPTY;
  885. + } else {
  886. + // invalid type
  887. + LOG(WARNING) << "invalid proxy configuration type";
  888. + return;
  889. + }
  890. +
  891. + // bypass rules and reverse flag are common to both list types of proxy rules
  892. + if (readBypass) {
  893. + const base::Value *bypass_rules = rules->FindKeyOfType("bypass_rules", base::Value::Type::STRING);
  894. + if (bypass_rules == nullptr)
  895. + return;
  896. +
  897. + const base::Value *reverse_bypass = rules->FindKeyOfType("reverse_bypass", base::Value::Type::BOOLEAN);
  898. + if (reverse_bypass == nullptr)
  899. + return;
  900. +
  901. + proxyConfig.proxy_rules().bypass_rules.ParseFromString(bypass_rules->GetString());
  902. + proxyConfig.proxy_rules().reverse_bypass = reverse_bypass->GetBool();
  903. + }
  904. +
  905. + apply(proxyConfig);
  906. +}
  907. +
  908. +void ProxyConfigMessageHandler::apply(const net::ProxyConfig& proxyConfig) {
  909. + if (proxyConfig.auto_detect()) {
  910. + const base::Value cfg = ProxyConfigDictionary::CreateAutoDetect();
  911. + profile_->GetPrefs()->Set(proxy_config::prefs::kProxy, cfg);
  912. + return;
  913. + } else if (proxyConfig.has_pac_url()) {
  914. + const base::Value cfg = ProxyConfigDictionary::CreatePacScript(proxyConfig.pac_url().spec(), proxyConfig.pac_mandatory());
  915. + profile_->GetPrefs()->Set(proxy_config::prefs::kProxy, cfg);
  916. + return;
  917. + }
  918. +
  919. + auto proxyRulesAsString = proxyConfig.proxy_rules().ToString();
  920. + auto bypassRulesAsString = proxyConfig.proxy_rules().bypass_rules.ToString();
  921. +
  922. + // fixed servers
  923. + const base::Value cfg = ProxyConfigDictionary::CreateFixedServers(proxyRulesAsString,
  924. + bypassRulesAsString, proxyConfig.proxy_rules().reverse_bypass);
  925. + profile_->GetPrefs()->Set(proxy_config::prefs::kProxy, cfg);
  926. +}
  927. +
  928. +} // namespace
  929. +
  930. +ProxyConfigUI::ProxyConfigUI(content::WebUI* web_ui) : WebUIController(web_ui) {
  931. + Profile* profile = Profile::FromWebUI(web_ui);
  932. +
  933. + web_ui->AddMessageHandler(std::make_unique<ProxyConfigMessageHandler>(profile));
  934. +
  935. + // Set up the chrome://proxy/ source.
  936. + content::WebUIDataSource::Add(profile, CreateProxyConfigHTMLSource());
  937. +}
  938. diff --git a/chrome/browser/ui/webui/proxy_config_ui.h b/chrome/browser/ui/webui/proxy_config_ui.h
  939. new file mode 100644
  940. --- /dev/null
  941. +++ b/chrome/browser/ui/webui/proxy_config_ui.h
  942. @@ -0,0 +1,33 @@
  943. +/*
  944. + This file is part of Bromite.
  945. +
  946. + Bromite is free software: you can redistribute it and/or modify
  947. + it under the terms of the GNU General Public License as published by
  948. + the Free Software Foundation, either version 3 of the License, or
  949. + (at your option) any later version.
  950. +
  951. + Bromite is distributed in the hope that it will be useful,
  952. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  953. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  954. + GNU General Public License for more details.
  955. +
  956. + You should have received a copy of the GNU General Public License
  957. + along with Bromite. If not, see <https://www.gnu.org/licenses/>.
  958. +*/
  959. +
  960. +#ifndef CHROME_BROWSER_UI_WEBUI_PROXY_CONFIG_UI_H_
  961. +#define CHROME_BROWSER_UI_WEBUI_PROXY_CONFIG_UI_H_
  962. +
  963. +#include "base/macros.h"
  964. +#include "content/public/browser/web_ui_controller.h"
  965. +
  966. +// The WebUI for chrome://proxy/.
  967. +class ProxyConfigUI : public content::WebUIController {
  968. + public:
  969. + explicit ProxyConfigUI(content::WebUI* web_ui);
  970. +
  971. + private:
  972. + DISALLOW_COPY_AND_ASSIGN(ProxyConfigUI);
  973. +};
  974. +
  975. +#endif // CHROME_BROWSER_UI_WEBUI_PROXY_CONFIG_UI_H_
  976. diff --git a/chrome/common/webui_url_constants.cc b/chrome/common/webui_url_constants.cc
  977. --- a/chrome/common/webui_url_constants.cc
  978. +++ b/chrome/common/webui_url_constants.cc
  979. @@ -189,6 +189,8 @@ const char kChromeUINativePhysicalWebDiagnosticsURL[] =
  980. const char kChromeUINativeScheme[] = "chrome-native";
  981. const char kChromeUIOfflineInternalsHost[] = "offline-internals";
  982. const char kChromeUIPhysicalWebDiagnosticsHost[] = "physical-web-diagnostics";
  983. +const char kChromeUIProxyConfigHost[] = "proxy";
  984. +const char kChromeUIProxyConfigURL[] = "chrome://proxy/";
  985. const char kChromeUISnippetsInternalsHost[] = "snippets-internals";
  986. const char kChromeUIWebApksHost[] = "webapks";
  987. #endif
  988. @@ -456,6 +458,7 @@ bool IsOSSettingsSubPage(const std::string& sub_page) {
  989. kResetSubPage,
  990. kSmartLockSettingsSubPage,
  991. kSmbSharesSubPage,
  992. + kChromeUIProxyConfigHost,
  993. kStorageSubPage,
  994. kStylusSubPage,
  995. kSwitchAccessSubPage,
  996. @@ -556,6 +559,7 @@ const char* const kChromeHostURLs[] = {
  997. #if !defined(OS_ANDROID)
  998. #if !defined(OS_CHROMEOS)
  999. kChromeUIAppLauncherPageHost,
  1000. + kChromeUIProxyConfigHost,
  1001. #endif
  1002. kChromeUIBookmarksHost,
  1003. kChromeUIDownloadsHost,
  1004. diff --git a/chrome/common/webui_url_constants.h b/chrome/common/webui_url_constants.h
  1005. --- a/chrome/common/webui_url_constants.h
  1006. +++ b/chrome/common/webui_url_constants.h
  1007. @@ -110,6 +110,8 @@ extern const char kChromeUIMemoryInternalsHost[];
  1008. extern const char kChromeUINTPTilesInternalsHost[];
  1009. extern const char kChromeUINaClHost[];
  1010. extern const char kChromeUINetExportHost[];
  1011. +extern const char kChromeUIProxyConfigHost[];
  1012. +extern const char kChromeUIProxyConfigURL[];
  1013. extern const char kChromeUINetInternalsHost[];
  1014. extern const char kChromeUINetInternalsURL[];
  1015. extern const char kChromeUINewTabHost[];
  1016. diff --git a/components/policy/core/browser/proxy_policy_handler.cc b/components/policy/core/browser/proxy_policy_handler.cc
  1017. --- a/components/policy/core/browser/proxy_policy_handler.cc
  1018. +++ b/components/policy/core/browser/proxy_policy_handler.cc
  1019. @@ -199,7 +199,7 @@ void ProxyPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
  1020. bypass_list->GetAsString(&bypass_list_string);
  1021. prefs->SetValue(proxy_config::prefs::kProxy,
  1022. ProxyConfigDictionary::CreateFixedServers(
  1023. - proxy_server, bypass_list_string));
  1024. + proxy_server, bypass_list_string, false));
  1025. }
  1026. break;
  1027. }
  1028. diff --git a/components/proxy_config/proxy_config_dictionary.cc b/components/proxy_config/proxy_config_dictionary.cc
  1029. --- a/components/proxy_config/proxy_config_dictionary.cc
  1030. +++ b/components/proxy_config/proxy_config_dictionary.cc
  1031. @@ -28,6 +28,8 @@ const char kProxyPacMandatory[] = "pac_mandatory";
  1032. // String containing proxy bypass rules. For a specification of the
  1033. // expected syntax see net::ProxyBypassRules::ParseFromString().
  1034. const char kProxyBypassList[] = "bypass_list";
  1035. +// Boolean telling whether to reverse the meaning of the bypass list.
  1036. +const char kProxyReverseBypass[] = "reverse_bypass";
  1037. } // namespace
  1038. @@ -79,29 +81,30 @@ const base::Value& ProxyConfigDictionary::GetDictionary() const {
  1039. // static
  1040. base::Value ProxyConfigDictionary::CreateDirect() {
  1041. return CreateDictionary(ProxyPrefs::MODE_DIRECT, std::string(), false,
  1042. - std::string(), std::string());
  1043. + std::string(), std::string(), false);
  1044. }
  1045. // static
  1046. base::Value ProxyConfigDictionary::CreateAutoDetect() {
  1047. return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, std::string(), false,
  1048. - std::string(), std::string());
  1049. + std::string(), std::string(), false);
  1050. }
  1051. // static
  1052. base::Value ProxyConfigDictionary::CreatePacScript(const std::string& pac_url,
  1053. bool pac_mandatory) {
  1054. return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, pac_url, pac_mandatory,
  1055. - std::string(), std::string());
  1056. + std::string(), std::string(), false);
  1057. }
  1058. // static
  1059. base::Value ProxyConfigDictionary::CreateFixedServers(
  1060. const std::string& proxy_server,
  1061. - const std::string& bypass_list) {
  1062. + const std::string& bypass_list,
  1063. + bool reverse_bypass) {
  1064. if (!proxy_server.empty()) {
  1065. return CreateDictionary(ProxyPrefs::MODE_FIXED_SERVERS, std::string(),
  1066. - false, proxy_server, bypass_list);
  1067. + false, proxy_server, bypass_list, reverse_bypass);
  1068. } else {
  1069. return CreateDirect();
  1070. }
  1071. @@ -110,7 +113,7 @@ base::Value ProxyConfigDictionary::CreateFixedServers(
  1072. // static
  1073. base::Value ProxyConfigDictionary::CreateSystem() {
  1074. return CreateDictionary(ProxyPrefs::MODE_SYSTEM, std::string(), false,
  1075. - std::string(), std::string());
  1076. + std::string(), std::string(), false);
  1077. }
  1078. // static
  1079. @@ -119,7 +122,8 @@ base::Value ProxyConfigDictionary::CreateDictionary(
  1080. const std::string& pac_url,
  1081. bool pac_mandatory,
  1082. const std::string& proxy_server,
  1083. - const std::string& bypass_list) {
  1084. + const std::string& bypass_list,
  1085. + bool reverse_bypass) {
  1086. base::Value dict(base::Value::Type::DICTIONARY);
  1087. dict.SetKey(kProxyMode, base::Value(ProxyModeToString(mode)));
  1088. if (!pac_url.empty()) {
  1089. @@ -128,8 +132,10 @@ base::Value ProxyConfigDictionary::CreateDictionary(
  1090. }
  1091. if (!proxy_server.empty())
  1092. dict.SetKey(kProxyServer, base::Value(proxy_server));
  1093. - if (!bypass_list.empty())
  1094. + if (!bypass_list.empty()) {
  1095. dict.SetKey(kProxyBypassList, base::Value(bypass_list));
  1096. + dict.SetKey(kProxyReverseBypass, base::Value(reverse_bypass));
  1097. + }
  1098. return dict;
  1099. }
  1100. diff --git a/components/proxy_config/proxy_config_dictionary.h b/components/proxy_config/proxy_config_dictionary.h
  1101. --- a/components/proxy_config/proxy_config_dictionary.h
  1102. +++ b/components/proxy_config/proxy_config_dictionary.h
  1103. @@ -46,7 +46,8 @@ class PROXY_CONFIG_EXPORT ProxyConfigDictionary {
  1104. static base::Value CreatePacScript(const std::string& pac_url,
  1105. bool pac_mandatory);
  1106. static base::Value CreateFixedServers(const std::string& proxy_server,
  1107. - const std::string& bypass_list);
  1108. + const std::string& bypass_list,
  1109. + bool reverse_bypass);
  1110. static base::Value CreateSystem();
  1111. // Encodes the proxy server as "<url-scheme>=<proxy-scheme>://<proxy>".
  1112. @@ -62,7 +63,8 @@ class PROXY_CONFIG_EXPORT ProxyConfigDictionary {
  1113. const std::string& pac_url,
  1114. bool pac_mandatory,
  1115. const std::string& proxy_server,
  1116. - const std::string& bypass_list);
  1117. + const std::string& bypass_list,
  1118. + bool reverse_bypass);
  1119. base::Value dict_;
  1120. diff --git a/net/proxy_resolution/proxy_config.cc b/net/proxy_resolution/proxy_config.cc
  1121. --- a/net/proxy_resolution/proxy_config.cc
  1122. +++ b/net/proxy_resolution/proxy_config.cc
  1123. @@ -140,6 +140,51 @@ void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) {
  1124. }
  1125. }
  1126. +std::string ProxyConfig::ProxyRules::ToString() const {
  1127. + if (type == Type::EMPTY) {
  1128. + return "";
  1129. + }
  1130. +
  1131. + // special case: a single proxy server specified
  1132. + if (type == Type::PROXY_LIST) {
  1133. + if (single_proxies.size() == 1) {
  1134. + return single_proxies.Get().ToURI();
  1135. + }
  1136. + // more than 1 proxies or 0 proxies is unexpected
  1137. + return "";
  1138. + }
  1139. +
  1140. + if (type != Type::PROXY_LIST_PER_SCHEME) {
  1141. + NOTREACHED();
  1142. + // Unexpected LIST with fallback, or other type values
  1143. + return "";
  1144. + }
  1145. +
  1146. + // start to build a per-scheme list
  1147. + std::string list;
  1148. + for (const ProxyServer& proxy_server :
  1149. + proxies_for_http.GetAll()) {
  1150. + list += "http=" + proxy_server.ToURI() + ";";
  1151. + }
  1152. + for (const ProxyServer& proxy_server :
  1153. + proxies_for_https.GetAll()) {
  1154. + list += "https=" + proxy_server.ToURI() + ";";
  1155. + }
  1156. + for (const ProxyServer& proxy_server :
  1157. + proxies_for_ftp.GetAll()) {
  1158. + list += "ftp=" + proxy_server.ToURI() + ";";
  1159. + }
  1160. + for (const ProxyServer& proxy_server :
  1161. + fallback_proxies.GetAll()) {
  1162. + list += "socks=" + proxy_server.ToURI() + ";";
  1163. + }
  1164. + if (list.length() != 0 ) {
  1165. + // remove last semicolon
  1166. + list.pop_back();
  1167. + }
  1168. + return list;
  1169. +}
  1170. +
  1171. const ProxyList* ProxyConfig::ProxyRules::MapUrlSchemeToProxyList(
  1172. const std::string& url_scheme) const {
  1173. const ProxyList* proxy_server_list = const_cast<ProxyRules*>(this)->
  1174. diff --git a/net/proxy_resolution/proxy_config.h b/net/proxy_resolution/proxy_config.h
  1175. --- a/net/proxy_resolution/proxy_config.h
  1176. +++ b/net/proxy_resolution/proxy_config.h
  1177. @@ -103,6 +103,9 @@ class NET_EXPORT ProxyConfig {
  1178. // and use socks4://foopy2 for all other
  1179. // URLs.
  1180. void ParseFromString(const std::string& proxy_rules);
  1181. + // Returns the proxy rules in a format that can be parsed by ParseFromString;
  1182. + // all information except bypass rules is used.
  1183. + std::string ToString() const;
  1184. // Returns one of {&proxies_for_http, &proxies_for_https, &proxies_for_ftp,
  1185. // &fallback_proxies}, or NULL if there is no proxy to use.
  1186. --
  1187. 2.11.0