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 | 79 ++++
  22. chrome/browser/resources/proxy_config.js | 266 +++++++++++
  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 | 418 ++++++++++++++++++
  26. chrome/browser/ui/webui/proxy_config_ui.h | 31 ++
  27. chrome/common/webui_url_constants.cc | 4 +
  28. chrome/common/webui_url_constants.h | 2 +
  29. .../pref_proxy_config_tracker_impl.cc | 1 +
  30. .../proxy_config/proxy_config_dictionary.cc | 30 +-
  31. .../proxy_config/proxy_config_dictionary.h | 7 +-
  32. .../proxy_config/proxy_policy_handler.cc | 2 +-
  33. net/proxy_resolution/proxy_config.cc | 52 ++-
  34. net/proxy_resolution/proxy_config.h | 3 +
  35. 24 files changed, 995 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. @@ -25,6 +25,9 @@
  45. <!-- Compositor Tab Title Text -->
  46. <bool name="compositor_tab_title_fake_bold_text">true</bool>
  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. @@ -52,6 +52,7 @@ import org.chromium.ui.text.SpanApplier;
  70. public class PrivacySettings
  71. extends PreferenceFragmentCompat implements Preference.OnPreferenceChangeListener,
  72. INeedSnackbarManager {
  73. + private static final String PREF_PROXY_OPTIONS = "proxy";
  74. private SnackbarManager mSnackbarManager;
  75. private Snackbar mSnackbar;
  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. @@ -280,6 +280,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. @@ -89,6 +89,12 @@
  92. <include name="IDR_HANGOUT_SERVICES_MANIFEST" file="resources\hangout_services\manifest.json" 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. <!-- Page not available for guest. -->
  102. <include name="IDR_PAGE_NOT_AVAILABLE_FOR_GUEST_APP_HTML" file="resources\page_not_available_for_guest\app.html" type="BINDATA" />
  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. @@ -73,7 +76,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. @@ -89,3 +105,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. class PrefProxyConfigTracker;
  151. +#include "components/prefs/pref_registry_simple.h"
  152. class PrefService;
  153. class Profile;
  154. @@ -35,6 +36,8 @@ class ProxyServiceFactory {
  155. CreatePrefProxyConfigTrackerOfProfile(PrefService* profile_prefs,
  156. PrefService* local_state_prefs);
  157. + static void RegisterPrefs(PrefRegistrySimple* registry);
  158. +
  159. // Creates a PrefProxyConfigTracker that tracks local state only. This tracker
  160. // should be used for the system request context and the signin screen
  161. // (ChromeOS only).
  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. @@ -159,6 +159,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. @@ -962,6 +964,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. @@ -161,7 +161,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,79 @@
  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 type="module" src="chrome://proxy/proxy_config.js"></script>
  279. +<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
  280. +<link rel="stylesheet" href="proxy_config.css">
  281. +<title>Proxy configuration</title>
  282. +</head>
  283. +<body>
  284. + <div id="main-container">
  285. + <!--
  286. + =========================================================================
  287. + View for "pending" state.
  288. + * Only visible briefly, if at all
  289. + =========================================================================
  290. + -->
  291. + <div id="state-pending">
  292. + <h2>Proxy configuration</h2>
  293. + Loading...
  294. + </div>
  295. +
  296. + <!--
  297. + =========================================================================
  298. + View for "available" and "unset" states.
  299. + * Has controls to change or reset proxy configuration.
  300. + =========================================================================
  301. + -->
  302. + <div id="state-main" hidden>
  303. + <h2>Proxy configuration</h2>
  304. + <button id="reset">Reset</button>
  305. + <div class="section-container">
  306. + Reset will update the displayed configuration to match the one currently in use.
  307. + </div>
  308. + <div class="section-container">
  309. + <input type="radio" id="empty" name="mode" value="empty"><label for="empty">System Default</label><br/>
  310. + <input type="radio" id="direct" name="mode" value="direct"><label for="direct">Direct</label><br/>
  311. + <input type="radio" id="auto-detect" name="mode" value="auto-detect"><label for="auto-detect">Auto-detect (WPAD DHCP/DNS)</label><br/>
  312. + <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>
  313. + <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>
  314. + <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>):
  315. + <textarea id="single-proxies"></textarea>
  316. + </label><br/>
  317. + <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/>
  318. + <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/>
  319. + <textarea id="http-proxies"></textarea></label><br/>
  320. + <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/>
  321. + <textarea id="https-proxies"></textarea></label><br/>
  322. + <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/>
  323. + <textarea id="ftp-proxies"></textarea></label><br/>
  324. + <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/>
  325. + <textarea id="fallback-proxies"></textarea></label>
  326. + <div class="outline-box">
  327. + 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/>
  328. + <textarea id="bypass-rules"></textarea><br/>
  329. + <input type="checkbox" id="reverse-bypass" name="reverse-bypass"><label for="reverse-bypass">Reverse the meaning of bypass rules</label>
  330. + </div>
  331. + </div>
  332. + <button id="apply">Apply</button>
  333. + <button id="clear">Clear</button>
  334. + <div class="section-container">
  335. + Clicking on Clear will remove any proxy configuration preference currently in effect.
  336. + </div>
  337. + </div>
  338. +
  339. + </div>
  340. +</body>
  341. +</html>
  342. diff --git a/chrome/browser/resources/proxy_config.js b/chrome/browser/resources/proxy_config.js
  343. new file mode 100644
  344. --- /dev/null
  345. +++ b/chrome/browser/resources/proxy_config.js
  346. @@ -0,0 +1,266 @@
  347. +/*
  348. + This file is part of Bromite.
  349. +
  350. + Bromite is free software: you can redistribute it and/or modify
  351. + it under the terms of the GNU General Public License as published by
  352. + the Free Software Foundation, either version 3 of the License, or
  353. + (at your option) any later version.
  354. +
  355. + Bromite is distributed in the hope that it will be useful,
  356. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  357. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  358. + GNU General Public License for more details.
  359. +
  360. + You should have received a copy of the GNU General Public License
  361. + along with Bromite. If not, see <https://www.gnu.org/licenses/>.
  362. +*/
  363. +
  364. +import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';
  365. +
  366. +/**
  367. + * Main entry point called once the page has loaded.
  368. + */
  369. +function onLoad() {
  370. + ProxyConfigView.getInstance();
  371. +}
  372. +
  373. +document.addEventListener('DOMContentLoaded', onLoad);
  374. +
  375. +/**
  376. + * This class handles the presentation of the proxy-config view. Used as a
  377. + * singleton.
  378. + */
  379. +var ProxyConfigView = (function() {
  380. + 'use strict';
  381. +
  382. + // --------------------------------------------------------------------------
  383. +
  384. + var kIdStateDivUninitialized = 'state-pending';
  385. + var kIdStateDivMain = 'state-main';
  386. + var kIdApplyButton = 'apply';
  387. + var kIdResetButton = 'reset';
  388. + var kIdClearButton = 'clear';
  389. +
  390. + var kIdModeEmpty = 'empty';
  391. + var kIdModeDirect = 'direct';
  392. + var kIdModeAutoDetect = 'auto-detect';
  393. + var kIdModeUsePacURL = 'use-pac-url';
  394. +
  395. + var kIdModeUseSingleList = 'use-single-list';
  396. + var kIdModeUseListPerScheme = 'use-list-per-scheme';
  397. +
  398. + var kIdPacURL = 'pac-url';
  399. + var kIdPacMandatory = 'pac-mandatory';
  400. + var kIdBypassRules = 'bypass-rules';
  401. + var kIdReverseBypass = 'reverse-bypass';
  402. + var kIdSingleProxies = 'single-proxies';
  403. + var kIdHttpProxies = 'http-proxies';
  404. + var kIdHttpsProxies = 'https-proxies';
  405. + var kIdFtpProxies = 'ftp-proxies';
  406. + var kIdFallbackProxies = 'fallback-proxies';
  407. +
  408. + /**
  409. + * @constructor
  410. + */
  411. + function ProxyConfigView() {
  412. + this.currentConfig = null;
  413. +
  414. + $(kIdResetButton).onclick = this.onReset_.bind(this);
  415. + $(kIdApplyButton).onclick = this.onApply_.bind(this);
  416. + $(kIdClearButton).onclick = this.onClear_.bind(this);
  417. +
  418. + // Tell ProxyConfigMessageHandler to notify the UI of future state changes
  419. + // from this point on.
  420. + chrome.send('enableNotifyUIWithState');
  421. + }
  422. +
  423. + addSingletonGetter(ProxyConfigView);
  424. + window.ProxyConfigView = ProxyConfigView;
  425. +
  426. + ProxyConfigView.prototype = {
  427. + /**
  428. + * Updates the UI to reflect the current state. The state transitions are
  429. + * sent by the browser controller (ProxyConfigMessageHandler):
  430. + *
  431. + * * PENDING - This is the initial state when proxy configuration is opened
  432. + * for the first time, or there was an error during initialization.
  433. + * This state is short-lived and likely not observed; will
  434. + * immediately transition to AVAILABLE).
  435. + *
  436. + * * AVAILABLE - The reported proxy configuration is active; this state is entered
  437. + * on first page load (or right after PENDING if configuration was not
  438. + * available on page load) and every time some configuration change was applied.
  439. + * It can transition to either AVAILABLE or UNSET.
  440. + *
  441. + * * UNSET - Proxy configuration is reported to be currently not set.
  442. + *
  443. + */
  444. + onProxyConfigChanged: function(state) {
  445. + // may happen only on first load; leave the loading page as another update is expected
  446. + // when proxy configuration has finished loading
  447. + if (state.pending) {
  448. + $(kIdStateDivMain).hidden = true;
  449. + $(kIdStateDivUninitialized).hidden = false;
  450. + return;
  451. + }
  452. +
  453. + if (!state.hasOwnProperty('config')) {
  454. + // configuration has been unset, use an empty one
  455. + this.eraseCurrentConfig_();
  456. + } else {
  457. + // save the configuration as current and reset all controls to it
  458. + this.currentConfig = state.config;
  459. + }
  460. +
  461. + this.renderConfig_();
  462. +
  463. + this.toggleButtons_(false);
  464. + $(kIdStateDivUninitialized).hidden = true;
  465. + $(kIdStateDivMain).hidden = false;
  466. + },
  467. +
  468. + /**
  469. + * Set current configuration to an empty (default) one.
  470. + */
  471. + eraseCurrentConfig_: function() {
  472. + this.currentConfig = {
  473. + "auto_detect": false,
  474. + "pending": false,
  475. + "rules": {
  476. + "bypass_rules": "",
  477. + "reverse_bypass": false,
  478. + "type": "none"
  479. + }
  480. + };
  481. + },
  482. +
  483. + /**
  484. + * Serialize the user-selected configuration in an object.
  485. + */
  486. + serializeConfig_: function() {
  487. + if ($(kIdModeEmpty).checked) {
  488. + return {
  489. + "auto_detect": false,
  490. + "rules": {
  491. + "type": "none"
  492. + }
  493. + };
  494. + } else if ($(kIdModeDirect).checked) {
  495. + return {
  496. + "auto_detect": false,
  497. + "rules": {
  498. + "type": "direct"
  499. + }
  500. + };
  501. + } else if ($(kIdModeAutoDetect).checked) {
  502. + return {
  503. + "auto_detect": true
  504. + };
  505. + } else if ($(kIdModeUsePacURL).checked) {
  506. + return {
  507. + "auto_detect": false,
  508. + "pac_url": $(kIdPacURL).value.trim(),
  509. + "pac_mandatory": $(kIdPacMandatory).checked,
  510. + "rules": {}
  511. + };
  512. + } else if ($(kIdModeUseListPerScheme).checked || $(kIdModeUseSingleList).checked) {
  513. + var config = {
  514. + "auto_detect": false,
  515. + "rules": {
  516. + "bypass_rules": $(kIdBypassRules).value.trim(),
  517. + "reverse_bypass": $(kIdReverseBypass).checked,
  518. + "type": "list"
  519. + }
  520. + };
  521. +
  522. + if ($(kIdModeUseListPerScheme).checked) {
  523. + config.rules.type = "list_per_scheme";
  524. +
  525. + config.rules.proxies_for_http = $(kIdHttpProxies).value.trim();
  526. + config.rules.proxies_for_https = $(kIdHttpsProxies).value.trim();
  527. + config.rules.proxies_for_ftp = $(kIdFtpProxies).value.trim();
  528. + config.rules.fallback_proxies = $(kIdFallbackProxies).value.trim();
  529. + } else {
  530. + config.rules.single_proxies = $(kIdSingleProxies).value.trim();
  531. + }
  532. +
  533. + return config;
  534. + }
  535. +
  536. + throw new Error('unexpected mode');
  537. + },
  538. +
  539. + /**
  540. + * Updates the UI to display the current proxy configuration.
  541. + */
  542. + renderConfig_: function() {
  543. + if (this.currentConfig.auto_detect) {
  544. + $(kIdModeAutoDetect).checked = true;
  545. + } else if (this.currentConfig.hasOwnProperty('pac_url')) {
  546. + $(kIdPacURL).value = this.currentConfig.pac_url;
  547. + $(kIdPacMandatory).checked = this.currentConfig.pac_mandatory;
  548. + $(kIdModeUsePacURL).checked = true;
  549. + } else if (this.currentConfig.rules.type == "none") {
  550. + $(kIdModeEmpty).checked = true;
  551. + } else if (this.currentConfig.rules.type == "direct") {
  552. + $(kIdModeDirect).checked = true;
  553. + } else {
  554. + $(kIdBypassRules).value = this.currentConfig.rules.bypass_rules;
  555. + $(kIdReverseBypass).checked = this.currentConfig.rules.reverse_bypass;
  556. +
  557. + switch (this.currentConfig.rules.type) {
  558. + case "list":
  559. + $(kIdModeUseSingleList).checked = true;
  560. + $(kIdSingleProxies).value = this.currentConfig.rules.single_proxies;
  561. + break;
  562. + case "list_per_scheme":
  563. + $(kIdModeUseListPerScheme).checked = true;
  564. + $(kIdHttpProxies).value = this.currentConfig.rules.proxies_for_http;
  565. + $(kIdHttpsProxies).value = this.currentConfig.rules.proxies_for_https;
  566. + $(kIdFtpProxies).value = this.currentConfig.rules.proxies_for_ftp;
  567. + $(kIdFallbackProxies).value = this.currentConfig.rules.fallback_proxies;
  568. + break;
  569. + }
  570. + }
  571. + },
  572. +
  573. + /**
  574. + * Apply the configuration currently displayed.
  575. + */
  576. + onApply_: function() {
  577. + var config = this.serializeConfig_();
  578. +
  579. + // disable buttons; will be enabled back when UI receives a state update
  580. + this.toggleButtons_(true);
  581. + chrome.send('apply', [config]);
  582. + },
  583. +
  584. + /**
  585. + * Apply the configuration currently displayed.
  586. + */
  587. + onClear_: function() {
  588. + // disable buttons; will be enabled back when UI receives a state update
  589. + this.toggleButtons_(true);
  590. + this.eraseCurrentConfig_();
  591. + chrome.send('clear', []);
  592. + },
  593. +
  594. + /**
  595. + * Toggle the disabled status of the action buttons.
  596. + */
  597. + toggleButtons_: function(disabled) {
  598. + $(kIdApplyButton).disabled = disabled;
  599. + $(kIdResetButton).disabled = disabled;
  600. + $(kIdClearButton).disabled = disabled;
  601. + },
  602. +
  603. + /**
  604. + * Reset currently displayed configuration to the last known configuration in use.
  605. + */
  606. + onReset_: function() {
  607. + this.renderConfig_();
  608. + }
  609. + };
  610. +
  611. + return ProxyConfigView;
  612. +})();
  613. diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn
  614. --- a/chrome/browser/ui/BUILD.gn
  615. +++ b/chrome/browser/ui/BUILD.gn
  616. @@ -278,6 +278,8 @@ static_library("ui") {
  617. "webui/metrics_handler.h",
  618. "webui/net_export_ui.cc",
  619. "webui/net_export_ui.h",
  620. + "webui/proxy_config_ui.cc",
  621. + "webui/proxy_config_ui.h",
  622. "webui/net_internals/net_internals_ui.cc",
  623. "webui/net_internals/net_internals_ui.h",
  624. "webui/ntp_tiles_internals_ui.cc",
  625. diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
  626. --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
  627. +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
  628. @@ -53,6 +53,7 @@
  629. #include "chrome/browser/ui/webui/omnibox/omnibox_ui.h"
  630. #include "chrome/browser/ui/webui/policy/policy_ui.h"
  631. #include "chrome/browser/ui/webui/predictors/predictors_ui.h"
  632. +#include "chrome/browser/ui/webui/proxy_config_ui.h"
  633. #include "chrome/browser/ui/webui/quota_internals/quota_internals_ui.h"
  634. #include "chrome/browser/ui/webui/segmentation_internals/segmentation_internals_ui.h"
  635. #include "chrome/browser/ui/webui/signin_internals_ui.h"
  636. @@ -671,6 +672,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
  637. return &NewWebUI<MemoryInternalsUI>;
  638. if (url.host_piece() == chrome::kChromeUINetExportHost)
  639. return &NewWebUI<NetExportUI>;
  640. + if (url.host_piece() == chrome::kChromeUIProxyConfigHost)
  641. + return &NewWebUI<ProxyConfigUI>;
  642. if (url.host_piece() == chrome::kChromeUINetInternalsHost)
  643. return &NewWebUI<NetInternalsUI>;
  644. if (url.host_piece() == chrome::kChromeUINTPTilesInternalsHost)
  645. diff --git a/chrome/browser/ui/webui/proxy_config_ui.cc b/chrome/browser/ui/webui/proxy_config_ui.cc
  646. new file mode 100644
  647. --- /dev/null
  648. +++ b/chrome/browser/ui/webui/proxy_config_ui.cc
  649. @@ -0,0 +1,418 @@
  650. +/*
  651. + This file is part of Bromite.
  652. +
  653. + Bromite is free software: you can redistribute it and/or modify
  654. + it under the terms of the GNU General Public License as published by
  655. + the Free Software Foundation, either version 3 of the License, or
  656. + (at your option) any later version.
  657. +
  658. + Bromite is distributed in the hope that it will be useful,
  659. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  660. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  661. + GNU General Public License for more details.
  662. +
  663. + You should have received a copy of the GNU General Public License
  664. + along with Bromite. If not, see <https://www.gnu.org/licenses/>.
  665. +*/
  666. +
  667. +#include "chrome/browser/ui/webui/proxy_config_ui.h"
  668. +
  669. +#include <stdint.h>
  670. +
  671. +#include <memory>
  672. +#include <string>
  673. +#include <vector>
  674. +
  675. +#include "base/bind.h"
  676. +#include "base/command_line.h"
  677. +#include "base/lazy_instance.h"
  678. +#include "base/memory/ref_counted.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. + ProxyConfigMessageHandler(const ProxyConfigMessageHandler&) = delete;
  726. + ProxyConfigMessageHandler& operator=(const ProxyConfigMessageHandler&) = delete;
  727. + // Creates a ProxyConfigMessageHandler that handles message exchanges with the Javascript
  728. + // side of the UI and gets proxy settings from the Web UI associated profile to watch for changes.
  729. + // The created ProxyConfigMessageHandler must be destroyed before |profile|.
  730. + ProxyConfigMessageHandler(Profile *profile);
  731. + ~ProxyConfigMessageHandler() override;
  732. +
  733. + // WebUIMessageHandler implementation.
  734. + void RegisterMessages() override;
  735. +
  736. + // Messages
  737. + void OnEnableNotifyUIWithState(base::Value::ConstListView list);
  738. + void OnApply(base::Value::ConstListView config);
  739. + void OnClear(base::Value::ConstListView config);
  740. +
  741. + // net::ProxyConfigService::Observer implementation:
  742. + // Calls ProxyConfigView.onProxyConfigChanged JavaScript function in the
  743. + // renderer.
  744. + void OnProxyConfigChanged(
  745. + const net::ProxyConfigWithAnnotation& config,
  746. + net::ProxyConfigService::ConfigAvailability availability) override;
  747. +
  748. + private:
  749. + // Not owned.
  750. + PrefService *pref_service_;
  751. + std::unique_ptr<net::ProxyConfigService> proxy_config_service_;
  752. + // Monitors global and Profile prefs related to proxy configuration.
  753. + std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
  754. + bool is_observing_;
  755. +
  756. + void encodeConfig(const net::ProxyConfig& config, base::DictionaryValue& state);
  757. +
  758. + void apply(const net::ProxyConfig& config);
  759. +
  760. + base::WeakPtrFactory<ProxyConfigMessageHandler> weak_ptr_factory_;
  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(), nullptr);
  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. + base::Value::ConstListView 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(base::Value::ConstListView 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(list);
  927. +}
  928. +
  929. +void ProxyConfigMessageHandler::OnApply(base::Value::ConstListView list) {
  930. + DCHECK_CURRENTLY_ON(BrowserThread::UI);
  931. +
  932. + if ((list.size() != 1) || !list[0].is_dict()) {
  933. + return;
  934. + }
  935. +
  936. + const base::DictionaryValue* config = nullptr;
  937. + if (!list[0].GetAsDictionary(&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. + base::Value::ConstListView empty;
  1008. + OnClear(empty);
  1009. + return;
  1010. + } else {
  1011. + // invalid type
  1012. + LOG(WARNING) << "invalid proxy configuration type";
  1013. + return;
  1014. + }
  1015. +
  1016. + // bypass rules and reverse flag are common to both list types of proxy rules
  1017. + if (readBypass) {
  1018. + const base::Value *bypass_rules = rules->FindKeyOfType("bypass_rules", base::Value::Type::STRING);
  1019. + if (bypass_rules == nullptr)
  1020. + return;
  1021. +
  1022. + const base::Value *reverse_bypass = rules->FindKeyOfType("reverse_bypass", base::Value::Type::BOOLEAN);
  1023. + if (reverse_bypass == nullptr)
  1024. + return;
  1025. +
  1026. + proxyConfig.proxy_rules().bypass_rules.ParseFromString(bypass_rules->GetString());
  1027. + proxyConfig.proxy_rules().reverse_bypass = reverse_bypass->GetBool();
  1028. + }
  1029. +
  1030. + apply(proxyConfig);
  1031. +}
  1032. +
  1033. +void ProxyConfigMessageHandler::apply(const net::ProxyConfig& proxyConfig) {
  1034. + if (proxyConfig.auto_detect()) {
  1035. + const base::Value cfg = ProxyConfigDictionary::CreateAutoDetect();
  1036. + pref_service_->Set(proxy_config::prefs::kProxy, cfg);
  1037. + } else if (proxyConfig.has_pac_url()) {
  1038. + const base::Value cfg = ProxyConfigDictionary::CreatePacScript(proxyConfig.pac_url().spec(), proxyConfig.pac_mandatory());
  1039. + pref_service_->Set(proxy_config::prefs::kProxy, cfg);
  1040. + } else if (proxyConfig.proxy_rules().type == net::ProxyConfig::ProxyRules::Type::EMPTY) {
  1041. + const base::Value cfg = ProxyConfigDictionary::CreateDirect();
  1042. + pref_service_->Set(proxy_config::prefs::kProxy, cfg);
  1043. + } else {
  1044. + auto proxyRulesAsString = proxyConfig.proxy_rules().ToString();
  1045. + auto bypassRulesAsString = proxyConfig.proxy_rules().bypass_rules.ToString();
  1046. +
  1047. + // fixed servers
  1048. + const base::Value cfg = ProxyConfigDictionary::CreateFixedServers(proxyRulesAsString,
  1049. + bypassRulesAsString, proxyConfig.proxy_rules().reverse_bypass);
  1050. + pref_service_->Set(proxy_config::prefs::kProxy, cfg);
  1051. + }
  1052. + pref_service_->CommitPendingWrite();
  1053. +
  1054. + base::Value::ConstListView empty;
  1055. + OnEnableNotifyUIWithState(empty);
  1056. +}
  1057. +
  1058. +} // namespace
  1059. +
  1060. +ProxyConfigUI::ProxyConfigUI(content::WebUI* web_ui) : WebUIController(web_ui) {
  1061. + Profile* profile = Profile::FromWebUI(web_ui);
  1062. +
  1063. + web_ui->AddMessageHandler(std::make_unique<ProxyConfigMessageHandler>(profile));
  1064. +
  1065. + // Set up the chrome://proxy/ source.
  1066. + content::WebUIDataSource::Add(profile, CreateProxyConfigHTMLSource());
  1067. +}
  1068. diff --git a/chrome/browser/ui/webui/proxy_config_ui.h b/chrome/browser/ui/webui/proxy_config_ui.h
  1069. new file mode 100644
  1070. --- /dev/null
  1071. +++ b/chrome/browser/ui/webui/proxy_config_ui.h
  1072. @@ -0,0 +1,31 @@
  1073. +/*
  1074. + This file is part of Bromite.
  1075. +
  1076. + Bromite is free software: you can redistribute it and/or modify
  1077. + it under the terms of the GNU General Public License as published by
  1078. + the Free Software Foundation, either version 3 of the License, or
  1079. + (at your option) any later version.
  1080. +
  1081. + Bromite is distributed in the hope that it will be useful,
  1082. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1083. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1084. + GNU General Public License for more details.
  1085. +
  1086. + You should have received a copy of the GNU General Public License
  1087. + along with Bromite. If not, see <https://www.gnu.org/licenses/>.
  1088. +*/
  1089. +
  1090. +#ifndef CHROME_BROWSER_UI_WEBUI_PROXY_CONFIG_UI_H_
  1091. +#define CHROME_BROWSER_UI_WEBUI_PROXY_CONFIG_UI_H_
  1092. +
  1093. +#include "content/public/browser/web_ui_controller.h"
  1094. +
  1095. +// The WebUI for chrome://proxy/.
  1096. +class ProxyConfigUI : public content::WebUIController {
  1097. + public:
  1098. + ProxyConfigUI(const ProxyConfigUI&) = delete;
  1099. + ProxyConfigUI& operator=(const ProxyConfigUI&) = delete;
  1100. + explicit ProxyConfigUI(content::WebUI* web_ui);
  1101. +};
  1102. +
  1103. +#endif // CHROME_BROWSER_UI_WEBUI_PROXY_CONFIG_UI_H_
  1104. diff --git a/chrome/common/webui_url_constants.cc b/chrome/common/webui_url_constants.cc
  1105. --- a/chrome/common/webui_url_constants.cc
  1106. +++ b/chrome/common/webui_url_constants.cc
  1107. @@ -37,6 +37,8 @@ const char kChromeUICertificateViewerHost[] = "view-cert";
  1108. const char kChromeUICertificateViewerURL[] = "chrome://view-cert/";
  1109. const char kChromeUIChromeSigninHost[] = "chrome-signin";
  1110. const char kChromeUIChromeSigninURL[] = "chrome://chrome-signin/";
  1111. +const char kChromeUIProxyConfigHost[] = "proxy";
  1112. +const char kChromeUIProxyConfigURL[] = "chrome://proxy/";
  1113. const char kChromeUIChromeURLsHost[] = "chrome-urls";
  1114. const char kChromeUIChromeURLsURL[] = "chrome://chrome-urls/";
  1115. const char kChromeUIComponentsHost[] = "components";
  1116. @@ -393,6 +395,7 @@ bool IsSystemWebUIHost(base::StringPiece host) {
  1117. kChromeUIMobileSetupHost,
  1118. kChromeUIMultiDeviceSetupHost,
  1119. kChromeUINetworkHost,
  1120. + kChromeUIProxyConfigHost,
  1121. kChromeUIOobeHost,
  1122. kChromeUIOSCreditsHost,
  1123. kChromeUIOSSettingsHost,
  1124. @@ -627,6 +630,7 @@ const char* const kChromeHostURLs[] = {
  1125. #if !defined(OS_ANDROID)
  1126. #if !BUILDFLAG(IS_CHROMEOS_ASH)
  1127. kChromeUIAppLauncherPageHost,
  1128. + kChromeUIProxyConfigHost,
  1129. #endif
  1130. kChromeUIBookmarksHost,
  1131. kChromeUIDownloadsHost,
  1132. diff --git a/chrome/common/webui_url_constants.h b/chrome/common/webui_url_constants.h
  1133. --- a/chrome/common/webui_url_constants.h
  1134. +++ b/chrome/common/webui_url_constants.h
  1135. @@ -129,6 +129,8 @@ extern const char kChromeUIMemoryInternalsHost[];
  1136. extern const char kChromeUINTPTilesInternalsHost[];
  1137. extern const char kChromeUINaClHost[];
  1138. extern const char kChromeUINetExportHost[];
  1139. +extern const char kChromeUIProxyConfigHost[];
  1140. +extern const char kChromeUIProxyConfigURL[];
  1141. extern const char kChromeUINetInternalsHost[];
  1142. extern const char kChromeUINetInternalsURL[];
  1143. extern const char kChromeUINewTabHost[];
  1144. diff --git a/components/proxy_config/pref_proxy_config_tracker_impl.cc b/components/proxy_config/pref_proxy_config_tracker_impl.cc
  1145. --- a/components/proxy_config/pref_proxy_config_tracker_impl.cc
  1146. +++ b/components/proxy_config/pref_proxy_config_tracker_impl.cc
  1147. @@ -380,6 +380,7 @@ bool PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(
  1148. if (proxy_dict.GetBypassList(&proxy_bypass)) {
  1149. proxy_config.proxy_rules().bypass_rules.ParseFromString(proxy_bypass);
  1150. }
  1151. + proxy_config.proxy_rules().reverse_bypass = proxy_dict.HasReverseBypass();
  1152. *config = net::ProxyConfigWithAnnotation(
  1153. proxy_config, kSettingsProxyConfigTrafficAnnotation);
  1154. return true;
  1155. diff --git a/components/proxy_config/proxy_config_dictionary.cc b/components/proxy_config/proxy_config_dictionary.cc
  1156. --- a/components/proxy_config/proxy_config_dictionary.cc
  1157. +++ b/components/proxy_config/proxy_config_dictionary.cc
  1158. @@ -30,6 +30,8 @@ const char kProxyPacMandatory[] = "pac_mandatory";
  1159. // String containing proxy bypass rules. For a specification of the
  1160. // expected syntax see net::ProxyBypassRules::ParseFromString().
  1161. const char kProxyBypassList[] = "bypass_list";
  1162. +// Boolean telling whether to reverse the meaning of the bypass list.
  1163. +const char kProxyReverseBypass[] = "reverse_bypass";
  1164. } // namespace
  1165. @@ -78,6 +80,14 @@ bool ProxyConfigDictionary::HasBypassList() const {
  1166. return dict_.FindKey(kProxyBypassList);
  1167. }
  1168. +bool ProxyConfigDictionary::HasReverseBypass() const {
  1169. + const base::Value* value = dict_.FindKey(kProxyReverseBypass);
  1170. + if (!value || !value->is_bool()) {
  1171. + return false;
  1172. + }
  1173. + return value->GetBool();
  1174. +}
  1175. +
  1176. const base::Value& ProxyConfigDictionary::GetDictionary() const {
  1177. return dict_;
  1178. }
  1179. @@ -85,29 +95,30 @@ const base::Value& ProxyConfigDictionary::GetDictionary() const {
  1180. // static
  1181. base::Value ProxyConfigDictionary::CreateDirect() {
  1182. return CreateDictionary(ProxyPrefs::MODE_DIRECT, std::string(), false,
  1183. - std::string(), std::string());
  1184. + std::string(), std::string(), false);
  1185. }
  1186. // static
  1187. base::Value ProxyConfigDictionary::CreateAutoDetect() {
  1188. return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, std::string(), false,
  1189. - std::string(), std::string());
  1190. + std::string(), std::string(), false);
  1191. }
  1192. // static
  1193. base::Value ProxyConfigDictionary::CreatePacScript(const std::string& pac_url,
  1194. bool pac_mandatory) {
  1195. return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, pac_url, pac_mandatory,
  1196. - std::string(), std::string());
  1197. + std::string(), std::string(), false);
  1198. }
  1199. // static
  1200. base::Value ProxyConfigDictionary::CreateFixedServers(
  1201. const std::string& proxy_server,
  1202. - const std::string& bypass_list) {
  1203. + const std::string& bypass_list,
  1204. + bool reverse_bypass) {
  1205. if (!proxy_server.empty()) {
  1206. return CreateDictionary(ProxyPrefs::MODE_FIXED_SERVERS, std::string(),
  1207. - false, proxy_server, bypass_list);
  1208. + false, proxy_server, bypass_list, reverse_bypass);
  1209. } else {
  1210. return CreateDirect();
  1211. }
  1212. @@ -116,7 +127,7 @@ base::Value ProxyConfigDictionary::CreateFixedServers(
  1213. // static
  1214. base::Value ProxyConfigDictionary::CreateSystem() {
  1215. return CreateDictionary(ProxyPrefs::MODE_SYSTEM, std::string(), false,
  1216. - std::string(), std::string());
  1217. + std::string(), std::string(), false);
  1218. }
  1219. // static
  1220. @@ -125,7 +136,8 @@ base::Value ProxyConfigDictionary::CreateDictionary(
  1221. const std::string& pac_url,
  1222. bool pac_mandatory,
  1223. const std::string& proxy_server,
  1224. - const std::string& bypass_list) {
  1225. + const std::string& bypass_list,
  1226. + bool reverse_bypass) {
  1227. base::Value dict(base::Value::Type::DICTIONARY);
  1228. dict.SetKey(kProxyMode, base::Value(ProxyModeToString(mode)));
  1229. if (!pac_url.empty()) {
  1230. @@ -134,8 +146,10 @@ base::Value ProxyConfigDictionary::CreateDictionary(
  1231. }
  1232. if (!proxy_server.empty())
  1233. dict.SetKey(kProxyServer, base::Value(proxy_server));
  1234. - if (!bypass_list.empty())
  1235. + if (!bypass_list.empty()) {
  1236. dict.SetKey(kProxyBypassList, base::Value(bypass_list));
  1237. + dict.SetKey(kProxyReverseBypass, base::Value(reverse_bypass));
  1238. + }
  1239. return dict;
  1240. }
  1241. diff --git a/components/proxy_config/proxy_config_dictionary.h b/components/proxy_config/proxy_config_dictionary.h
  1242. --- a/components/proxy_config/proxy_config_dictionary.h
  1243. +++ b/components/proxy_config/proxy_config_dictionary.h
  1244. @@ -42,6 +42,7 @@ class PROXY_CONFIG_EXPORT ProxyConfigDictionary {
  1245. bool GetProxyServer(std::string* out) const;
  1246. bool GetBypassList(std::string* out) const;
  1247. bool HasBypassList() const;
  1248. + bool HasReverseBypass() const;
  1249. const base::Value& GetDictionary() const;
  1250. @@ -50,7 +51,8 @@ class PROXY_CONFIG_EXPORT ProxyConfigDictionary {
  1251. static base::Value CreatePacScript(const std::string& pac_url,
  1252. bool pac_mandatory);
  1253. static base::Value CreateFixedServers(const std::string& proxy_server,
  1254. - const std::string& bypass_list);
  1255. + const std::string& bypass_list,
  1256. + bool reverse_bypass);
  1257. static base::Value CreateSystem();
  1258. // Encodes the proxy server as "<url-scheme>=<proxy-scheme>://<proxy>".
  1259. @@ -66,7 +68,8 @@ class PROXY_CONFIG_EXPORT ProxyConfigDictionary {
  1260. const std::string& pac_url,
  1261. bool pac_mandatory,
  1262. const std::string& proxy_server,
  1263. - const std::string& bypass_list);
  1264. + const std::string& bypass_list,
  1265. + bool reverse_bypass);
  1266. base::Value dict_;
  1267. };
  1268. diff --git a/components/proxy_config/proxy_policy_handler.cc b/components/proxy_config/proxy_policy_handler.cc
  1269. --- a/components/proxy_config/proxy_policy_handler.cc
  1270. +++ b/components/proxy_config/proxy_policy_handler.cc
  1271. @@ -259,7 +259,7 @@ void ProxyPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
  1272. ProxyConfigDictionary::CreateFixedServers(
  1273. server->GetString(), bypass_list && bypass_list->is_string()
  1274. ? bypass_list->GetString()
  1275. - : std::string()));
  1276. + : std::string(), false));
  1277. }
  1278. break;
  1279. }
  1280. diff --git a/net/proxy_resolution/proxy_config.cc b/net/proxy_resolution/proxy_config.cc
  1281. --- a/net/proxy_resolution/proxy_config.cc
  1282. +++ b/net/proxy_resolution/proxy_config.cc
  1283. @@ -112,7 +112,7 @@ void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) {
  1284. &single_proxies,
  1285. ProxyServer::SCHEME_HTTP);
  1286. type = Type::PROXY_LIST;
  1287. - return;
  1288. + continue;
  1289. }
  1290. // Trim whitespace off the url scheme.
  1291. @@ -143,6 +143,56 @@ void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) {
  1292. }
  1293. }
  1294. +std::string ProxyConfig::ProxyRules::ToString() const {
  1295. + if (type == Type::EMPTY) {
  1296. + return "";
  1297. + }
  1298. +
  1299. + // special case: a single proxy servers list specified
  1300. + if (type == Type::PROXY_LIST) {
  1301. + std::string proxy_list;
  1302. + for (const ProxyServer& proxy_server :
  1303. + single_proxies.GetAll()) {
  1304. + proxy_list += ProxyServerToProxyUri(proxy_server) + ";";
  1305. + }
  1306. + // remove last semicolon
  1307. + if (proxy_list.length() != 0 ) {
  1308. + proxy_list.pop_back();
  1309. + }
  1310. + return proxy_list;
  1311. + }
  1312. +
  1313. + if (type != Type::PROXY_LIST_PER_SCHEME) {
  1314. + NOTREACHED();
  1315. + // Unexpected LIST with fallback, or other type values
  1316. + return "";
  1317. + }
  1318. +
  1319. + // start to build a per-scheme list
  1320. + std::string list;
  1321. + for (const ProxyServer& proxy_server :
  1322. + proxies_for_http.GetAll()) {
  1323. + list += "http=" + ProxyServerToProxyUri(proxy_server) + ";";
  1324. + }
  1325. + for (const ProxyServer& proxy_server :
  1326. + proxies_for_https.GetAll()) {
  1327. + list += "https=" + ProxyServerToProxyUri(proxy_server) + ";";
  1328. + }
  1329. + for (const ProxyServer& proxy_server :
  1330. + proxies_for_ftp.GetAll()) {
  1331. + list += "ftp=" + ProxyServerToProxyUri(proxy_server) + ";";
  1332. + }
  1333. + for (const ProxyServer& proxy_server :
  1334. + fallback_proxies.GetAll()) {
  1335. + list += "socks=" + ProxyServerToProxyUri(proxy_server) + ";";
  1336. + }
  1337. + if (list.length() != 0 ) {
  1338. + // remove last semicolon
  1339. + list.pop_back();
  1340. + }
  1341. + return list;
  1342. +}
  1343. +
  1344. const ProxyList* ProxyConfig::ProxyRules::MapUrlSchemeToProxyList(
  1345. const std::string& url_scheme) const {
  1346. const ProxyList* proxy_server_list = const_cast<ProxyRules*>(this)->
  1347. diff --git a/net/proxy_resolution/proxy_config.h b/net/proxy_resolution/proxy_config.h
  1348. --- a/net/proxy_resolution/proxy_config.h
  1349. +++ b/net/proxy_resolution/proxy_config.h
  1350. @@ -103,6 +103,9 @@ class NET_EXPORT ProxyConfig {
  1351. // and use socks4://foopy2 for all other
  1352. // URLs.
  1353. void ParseFromString(const std::string& proxy_rules);
  1354. + // Returns the proxy rules in a format that can be parsed by ParseFromString;
  1355. + // all information except bypass rules is used.
  1356. + std::string ToString() const;
  1357. // Returns one of {&proxies_for_http, &proxies_for_https, &proxies_for_ftp,
  1358. // &fallback_proxies}, or NULL if there is no proxy to use.
  1359. --
  1360. 2.25.1