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

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