summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Dywan <christian@twotoasts.de>2018-11-25 19:08:28 +0200
committerGitHub <noreply@github.com>2018-11-25 19:08:28 +0200
commit6194db688aff4dd14be6cbae0ef79755fec780f1 (patch)
tree915320bee5ae772f1a17f585d92b401d4a389b90
parentd11d3ef4fa326add7e567f43fae62f3438ed76e6 (diff)
downloadmidori-git-6194db688aff4dd14be6cbae0ef79755fec780f1.tar.gz
Implement network proxy settings (#174)
- Implement WebKit.NetworkProxy{Mode,Settings} - Expose the settings under Network preferences ![screenshot from 2018-11-19 22-09-55](https://user-images.githubusercontent.com/1204189/48732351-19d52680-ec48-11e8-923a-b5bb43d444ad.png) Fixes: #125
-rw-r--r--core/app.vala37
-rw-r--r--core/preferences.vala66
-rw-r--r--core/settings.vala30
3 files changed, 129 insertions, 4 deletions
diff --git a/core/app.vala b/core/app.vala
index 454b1753..7c3e8bd4 100644
--- a/core/app.vala
+++ b/core/app.vala
@@ -133,6 +133,16 @@ namespace Midori {
context.get_cookie_manager ().set_accept_policy (
settings.first_party_cookies_only ? WebKit.CookieAcceptPolicy.NO_THIRD_PARTY : WebKit.CookieAcceptPolicy.ALWAYS);
});
+ apply_proxy_settings (settings, context);
+ settings.notify["proxy-type"].connect ((pspec) => {
+ apply_proxy_settings (settings, context);
+ });
+ settings.notify["http-proxy"].connect ((pspec) => {
+ apply_proxy_settings (settings, context);
+ });
+ settings.notify["proxy-port"].connect ((pspec) => {
+ apply_proxy_settings (settings, context);
+ });
add_action_entries (actions, this);
@@ -239,6 +249,23 @@ namespace Midori {
request.unref ();
}
+ void apply_proxy_settings (CoreSettings settings, WebKit.WebContext context) {
+ switch (settings.proxy_type) {
+ case ProxyType.AUTOMATIC:
+ context.set_network_proxy_settings (WebKit.NetworkProxyMode.DEFAULT, null);
+ break;
+ case ProxyType.HTTP:
+ string proxy_uri = "%s:%d".printf (settings.http_proxy, settings.http_proxy_port);
+ context.set_network_proxy_settings (
+ WebKit.NetworkProxyMode.CUSTOM,
+ new WebKit.NetworkProxySettings (proxy_uri, null));
+ break;
+ case ProxyType.NONE:
+ context.set_network_proxy_settings (WebKit.NetworkProxyMode.NO_PROXY, null);
+ break;
+ }
+ }
+
internal WebKit.WebContext ephemeral_context () {
var context = new WebKit.WebContext.ephemeral ();
context.register_uri_scheme ("internal", (request) => {
@@ -270,6 +297,16 @@ namespace Midori {
context.get_cookie_manager ().set_accept_policy (
settings.first_party_cookies_only ? WebKit.CookieAcceptPolicy.NO_THIRD_PARTY : WebKit.CookieAcceptPolicy.ALWAYS);
});
+ apply_proxy_settings (settings, context);
+ settings.notify["proxy-type"].connect ((pspec) => {
+ apply_proxy_settings (settings, context);
+ });
+ settings.notify["http-proxy"].connect ((pspec) => {
+ apply_proxy_settings (settings, context);
+ });
+ settings.notify["proxy-port"].connect ((pspec) => {
+ apply_proxy_settings (settings, context);
+ });
return context;
}
diff --git a/core/preferences.vala b/core/preferences.vala
index 3e406c64..8834d2d9 100644
--- a/core/preferences.vala
+++ b/core/preferences.vala
@@ -17,13 +17,22 @@ namespace Midori {
}
public class LabelWidget : Gtk.Box {
- public string title { get; construct set; }
+ public string? title { get; construct set; }
+ protected Gtk.Label label { get; set; }
public Gtk.Widget? widget { get; construct set; }
+ Gtk.SizeGroup sizegroup = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
- public LabelWidget (string title, Gtk.Widget? widget=null) {
+ public LabelWidget (string? title, Gtk.Widget? widget=null) {
Object (title: title, widget: widget);
}
+ public override void add (Gtk.Widget widget) {
+ base.add (widget);
+ if (widget is LabelWidget) {
+ sizegroup.add_widget (((LabelWidget)widget).label);
+ }
+ }
+
internal LabelWidget.for_days (string title, Object object, string property) {
var combo = new Gtk.ComboBoxText ();
combo.append ("0", _("1 hour"));
@@ -45,14 +54,15 @@ namespace Midori {
bool header = widget == null;
orientation = header ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL;
halign = Gtk.Align.START;
- var label = new Gtk.Label.with_mnemonic (header ? "<b>%s</b>".printf (title) : title);
+ label = new Gtk.Label.with_mnemonic (header ? "<b>%s</b>".printf (title) : title);
label.use_markup = header;
label.halign = Gtk.Align.START;
pack_start (label, false, false, 4);
if (widget != null) {
label.mnemonic_widget = widget;
+ widget.margin = 4;
set_center_widget (widget);
- if (widget is Gtk.Entry) {
+ if (widget is Gtk.Entry && !(widget is Gtk.SpinButton)) {
((Gtk.Entry)widget).width_chars = 30;
}
}
@@ -67,6 +77,8 @@ namespace Midori {
Gtk.Box content_box;
[GtkChild]
Gtk.Stack categories;
+ Gtk.SearchEntry proxy;
+ Gtk.SpinButton port;
public Preferences (Gtk.Window parent) {
Object (transient_for: parent);
@@ -136,6 +148,46 @@ namespace Midori {
box.show_all ();
add (_("Browsing"), box);
+ box = new LabelWidget (_("Proxy server"));
+ var proxy_chooser = new Gtk.ComboBoxText ();
+ proxy_chooser.append ("0", _("Automatic (GNOME or environment)"));
+ proxy_chooser.append ("2", _("HTTP proxy server"));
+ proxy_chooser.append ("1", _("No proxy server"));
+ settings.bind_property ("proxy-type", proxy_chooser, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
+ box.add (new LabelWidget (null, proxy_chooser));
+ proxy = new Gtk.SearchEntry ();
+ proxy.primary_icon_name = null;
+ settings.bind_property ("http-proxy", proxy, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
+ box.add (new LabelWidget (_("URI"), proxy));
+ string proxy_types = "http https";
+ foreach (unowned IOExtension proxy in IOExtensionPoint.lookup (IOExtensionPoint.PROXY).get_extensions ()) {
+ if (!proxy_types.contains (proxy.get_name ())) {
+ proxy_types += " %s".printf (proxy.get_name ());
+ }
+ }
+ proxy.search_changed.connect (() => {
+ string[] parts = settings.http_proxy.split ("://", 2);
+ if (parts[1] == "" || ":" in parts[1] || "/" in parts[1]) {
+ proxy.get_style_context ().add_class ("error");
+ return;
+ }
+ foreach (string type in proxy_types.split (" ")) {
+ if (parts[0] == type) {
+ proxy.get_style_context ().remove_class ("error");
+ return;
+ }
+ }
+ proxy.get_style_context ().add_class ("error");
+ });
+ box.add (new LabelWidget (_("Supported proxy types:"), new Gtk.Label (proxy_types)));
+ port = new Gtk.SpinButton.with_range (1, 65535, 1);
+ settings.bind_property ("http-proxy-port", port, "value", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
+ box.add (new LabelWidget (_("Port"), port));
+ settings.notify["proxy-type"].connect (update_proxy_sensitivity);
+ update_proxy_sensitivity ();
+ box.show_all ();
+ add (_("Network"), box);
+
box = new LabelWidget (_("Cookies and Website data"));
checkbox = new Gtk.CheckButton.with_mnemonic (_("Only accept Cookies from sites you visit"));
settings.bind_property ("first-party-cookies-only", checkbox, "active", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
@@ -162,6 +214,12 @@ namespace Midori {
extensions.foreach ((extensions, info, extension) => { extensions.extension_added (info, extension); });
}
+ void update_proxy_sensitivity () {
+ var settings = CoreSettings.get_default ();
+ proxy.sensitive = settings.proxy_type == ProxyType.HTTP;
+ port.sensitive = settings.proxy_type == ProxyType.HTTP;
+ }
+
/*
* Add a new category of preferences to be shown in the dialog.
* An appropriate margin will automatically be added.
diff --git a/core/settings.vala b/core/settings.vala
index 0d3f6ef0..7924fa94 100644
--- a/core/settings.vala
+++ b/core/settings.vala
@@ -18,6 +18,13 @@ namespace Midori {
DELAYED_PAGES
}
+ [CCode (cprefix = "MIDORI_PROXY_")]
+ public enum ProxyType {
+ AUTOMATIC,
+ HTTP,
+ NONE,
+ }
+
public class CoreSettings : Settings {
static CoreSettings? _default = null;
@@ -136,6 +143,29 @@ namespace Midori {
}
} }
+ public ProxyType proxy_type { get {
+ var proxy = get_string ("settings", "proxy-type", "MIDORI_PROXY_AUTOMATIC");
+ if (proxy.has_suffix ("AUTOMATIC")) {
+ return ProxyType.AUTOMATIC;
+ } else if (proxy.has_suffix ("HTTP")) {
+ return ProxyType.HTTP;
+ } else {
+ return ProxyType.NONE;
+ }
+ } set {
+ set_string ("settings", "proxy-type", value.to_string (), "MIDORI_PROXY_AUTOMATIC");
+ } }
+ public string http_proxy { owned get {
+ return get_string ("settings", "http-proxy", "");
+ } set {
+ set_string ("settings", "http-proxy", value);
+ } }
+ public int http_proxy_port { get {
+ return get_string ("settings", "http-proxy-port", "8080").to_int ();
+ } set {
+ set_string ("settings", "http-proxy-port", value.to_string (), "8080");
+ } }
+
public bool first_party_cookies_only { get {
return get_boolean ("settings", "first-party-cookies-only", true);
} set {