Use GNOME proxy resolver and GNOME password manager optionally
This commit is contained in:
parent
ee0bda8db3
commit
af86796eab
3 changed files with 103 additions and 19 deletions
|
@ -37,6 +37,21 @@ G_DEFINE_TYPE_WITH_CODE (KatzeHttpAuth, katze_http_auth, G_TYPE_OBJECT,
|
||||||
G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE,
|
G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE,
|
||||||
katze_http_auth_session_feature_iface_init));
|
katze_http_auth_session_feature_iface_init));
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBSOUP_2_27_92
|
||||||
|
static void
|
||||||
|
authentication_message_got_headers_cb (SoupMessage* msg,
|
||||||
|
SoupAuth* auth)
|
||||||
|
{
|
||||||
|
/* Anything but 401 and 5xx means the password was accepted */
|
||||||
|
if (msg->status_code != 401 && msg->status_code < 500)
|
||||||
|
{
|
||||||
|
gchar* username = g_object_get_data (G_OBJECT (msg), "username");
|
||||||
|
gchar* password = g_object_get_data (G_OBJECT (msg), "password");
|
||||||
|
soup_auth_save_password (auth, username, password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
authentication_dialog_response_cb (GtkWidget* dialog,
|
authentication_dialog_response_cb (GtkWidget* dialog,
|
||||||
gint response,
|
gint response,
|
||||||
|
@ -47,6 +62,8 @@ authentication_dialog_response_cb (GtkWidget* dialog,
|
||||||
SoupSession* session;
|
SoupSession* session;
|
||||||
SoupMessage* msg;
|
SoupMessage* msg;
|
||||||
|
|
||||||
|
msg = g_object_get_data (G_OBJECT (dialog), "msg");
|
||||||
|
|
||||||
if (response == GTK_RESPONSE_OK)
|
if (response == GTK_RESPONSE_OK)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -56,10 +73,17 @@ authentication_dialog_response_cb (GtkWidget* dialog,
|
||||||
soup_auth_authenticate (auth,
|
soup_auth_authenticate (auth,
|
||||||
gtk_entry_get_text (GTK_ENTRY (username)),
|
gtk_entry_get_text (GTK_ENTRY (username)),
|
||||||
gtk_entry_get_text (GTK_ENTRY (password)));
|
gtk_entry_get_text (GTK_ENTRY (password)));
|
||||||
|
#ifdef HAVE_LIBSOUP_2_27_92
|
||||||
|
g_object_set_data_full (G_OBJECT (msg), "username",
|
||||||
|
g_strdup (gtk_entry_get_text (GTK_ENTRY (username))), g_free);
|
||||||
|
g_object_set_data_full (G_OBJECT (msg), "password",
|
||||||
|
g_strdup (gtk_entry_get_text (GTK_ENTRY (password))), g_free);
|
||||||
|
g_signal_connect (msg, "got-headers",
|
||||||
|
G_CALLBACK (authentication_message_got_headers_cb), auth);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
session = g_object_get_data (G_OBJECT (dialog), "session");
|
session = g_object_get_data (G_OBJECT (dialog), "session");
|
||||||
msg = g_object_get_data (G_OBJECT (dialog), "msg");
|
|
||||||
gtk_widget_destroy (dialog);
|
gtk_widget_destroy (dialog);
|
||||||
if (g_object_get_data (G_OBJECT (msg), "paused"))
|
if (g_object_get_data (G_OBJECT (msg), "paused"))
|
||||||
soup_session_unpause_message (session, msg);
|
soup_session_unpause_message (session, msg);
|
||||||
|
@ -79,6 +103,9 @@ katze_http_auth_session_authenticate_cb (SoupSession* session,
|
||||||
GtkWidget* label;
|
GtkWidget* label;
|
||||||
GtkWidget* align;
|
GtkWidget* align;
|
||||||
GtkWidget* entry;
|
GtkWidget* entry;
|
||||||
|
#ifdef HAVE_LIBSOUP_2_27_92
|
||||||
|
GSList* users;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* We want to ask for authentication exactly once, so we
|
/* We want to ask for authentication exactly once, so we
|
||||||
enforce this with a tag. There might be a better way. */
|
enforce this with a tag. There might be a better way. */
|
||||||
|
@ -130,6 +157,11 @@ katze_http_auth_session_authenticate_cb (SoupSession* session,
|
||||||
gtk_size_group_add_widget (sizegroup, align);
|
gtk_size_group_add_widget (sizegroup, align);
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), align, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox), align, TRUE, TRUE, 0);
|
||||||
entry = gtk_entry_new ();
|
entry = gtk_entry_new ();
|
||||||
|
#ifdef HAVE_LIBSOUP_2_27_92
|
||||||
|
users = soup_auth_get_saved_users (auth);
|
||||||
|
if (users)
|
||||||
|
gtk_entry_set_text (GTK_ENTRY (entry), users->data);
|
||||||
|
#endif
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
|
||||||
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
|
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
|
||||||
g_object_set_data (G_OBJECT (dialog), "username", entry);
|
g_object_set_data (G_OBJECT (dialog), "username", entry);
|
||||||
|
@ -141,6 +173,14 @@ katze_http_auth_session_authenticate_cb (SoupSession* session,
|
||||||
gtk_size_group_add_widget (sizegroup, align);
|
gtk_size_group_add_widget (sizegroup, align);
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), align, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox), align, TRUE, TRUE, 0);
|
||||||
entry = gtk_entry_new_with_max_length (32);
|
entry = gtk_entry_new_with_max_length (32);
|
||||||
|
#ifdef HAVE_LIBSOUP_2_27_92
|
||||||
|
if (users)
|
||||||
|
{
|
||||||
|
gtk_entry_set_text (GTK_ENTRY (entry),
|
||||||
|
soup_auth_get_saved_password (auth, users->data));
|
||||||
|
g_slist_free (users);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
|
gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
|
||||||
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
|
||||||
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
|
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
|
||||||
|
|
|
@ -1005,36 +1005,63 @@ midori_browser_weak_notify_cb (MidoriBrowser* browser,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
soup_session_settings_notify_http_proxy_cb (MidoriWebSettings* settings,
|
midori_soup_session_set_proxy_uri (SoupSession* session,
|
||||||
GParamSpec* pspec,
|
const gchar* uri)
|
||||||
SoupSession* session)
|
|
||||||
{
|
{
|
||||||
gboolean auto_detect_proxy;
|
gchar* fixed_uri;
|
||||||
gchar* http_proxy;
|
|
||||||
SoupURI* proxy_uri;
|
SoupURI* proxy_uri;
|
||||||
|
|
||||||
auto_detect_proxy = katze_object_get_boolean (settings, "auto-detect-proxy");
|
|
||||||
if (auto_detect_proxy)
|
|
||||||
http_proxy = g_strdup (g_getenv ("http_proxy"));
|
|
||||||
else
|
|
||||||
http_proxy = katze_object_get_string (settings, "http-proxy");
|
|
||||||
/* soup_uri_new expects a non-NULL string with a protocol */
|
/* soup_uri_new expects a non-NULL string with a protocol */
|
||||||
if (http_proxy && g_str_has_prefix (http_proxy, "http://"))
|
if (uri && g_str_has_prefix (uri, "http://"))
|
||||||
proxy_uri = soup_uri_new (http_proxy);
|
proxy_uri = soup_uri_new (uri);
|
||||||
else if (http_proxy && *http_proxy)
|
else if (uri && *uri)
|
||||||
{
|
{
|
||||||
gchar* fixed_http_proxy = g_strconcat ("http://", http_proxy, NULL);
|
fixed_uri = g_strconcat ("http://", uri, NULL);
|
||||||
proxy_uri = soup_uri_new (fixed_http_proxy);
|
proxy_uri = soup_uri_new (fixed_uri);
|
||||||
g_free (fixed_http_proxy);
|
g_free (fixed_uri);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
proxy_uri = NULL;
|
proxy_uri = NULL;
|
||||||
g_free (http_proxy);
|
|
||||||
g_object_set (session, "proxy-uri", proxy_uri, NULL);
|
g_object_set (session, "proxy-uri", proxy_uri, NULL);
|
||||||
if (proxy_uri)
|
if (proxy_uri)
|
||||||
soup_uri_free (proxy_uri);
|
soup_uri_free (proxy_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
soup_session_settings_notify_http_proxy_cb (MidoriWebSettings* settings,
|
||||||
|
GParamSpec* pspec,
|
||||||
|
SoupSession* session)
|
||||||
|
{
|
||||||
|
gboolean auto_detect_proxy;
|
||||||
|
|
||||||
|
auto_detect_proxy = katze_object_get_boolean (settings, "auto-detect-proxy");
|
||||||
|
if (auto_detect_proxy)
|
||||||
|
{
|
||||||
|
gboolean gnome_supported = FALSE;
|
||||||
|
GModule* module;
|
||||||
|
GType (*get_type_function) (void);
|
||||||
|
if (g_module_supported ())
|
||||||
|
if ((module = g_module_open ("libsoup-gnome-2.4.so", G_MODULE_BIND_LOCAL)))
|
||||||
|
{
|
||||||
|
if (g_module_symbol (module, "soup_proxy_resolver_gnome_get_type",
|
||||||
|
(void*) &get_type_function))
|
||||||
|
{
|
||||||
|
soup_session_add_feature_by_type (session, get_type_function ());
|
||||||
|
gnome_supported = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!gnome_supported)
|
||||||
|
midori_soup_session_set_proxy_uri (session, g_getenv ("http_proxy"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gchar* http_proxy = katze_object_get_string (settings, "http-proxy");
|
||||||
|
midori_soup_session_set_proxy_uri (session, http_proxy);
|
||||||
|
g_free (http_proxy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !WEBKIT_CHECK_VERSION (1, 1, 11)
|
||||||
static void
|
static void
|
||||||
soup_session_settings_notify_ident_string_cb (MidoriWebSettings* settings,
|
soup_session_settings_notify_ident_string_cb (MidoriWebSettings* settings,
|
||||||
GParamSpec* pspec,
|
GParamSpec* pspec,
|
||||||
|
@ -1044,6 +1071,7 @@ soup_session_settings_notify_ident_string_cb (MidoriWebSettings* settings,
|
||||||
g_object_set (session, "user-agent", ident_string, NULL);
|
g_object_set (session, "user-agent", ident_string, NULL);
|
||||||
g_free (ident_string);
|
g_free (ident_string);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_soup_session_debug (SoupSession* session)
|
midori_soup_session_debug (SoupSession* session)
|
||||||
|
@ -1064,17 +1092,32 @@ midori_soup_session_prepare (SoupSession* session,
|
||||||
SoupCookieJar* cookie_jar,
|
SoupCookieJar* cookie_jar,
|
||||||
MidoriWebSettings* settings)
|
MidoriWebSettings* settings)
|
||||||
{
|
{
|
||||||
|
GModule* module;
|
||||||
|
GType (*get_type_function) (void);
|
||||||
SoupSessionFeature* feature;
|
SoupSessionFeature* feature;
|
||||||
gchar* config_file;
|
gchar* config_file;
|
||||||
|
|
||||||
|
if (g_module_supported ())
|
||||||
|
if ((module = g_module_open ("libsoup-gnome-2.4.so", G_MODULE_BIND_LOCAL)))
|
||||||
|
{
|
||||||
|
#ifdef HAVE_LIBSOUP_2_27_92
|
||||||
|
if (g_module_symbol (module, "soup_password_manager_gnome_get_type",
|
||||||
|
(void*) &get_type_function))
|
||||||
|
soup_session_add_feature_by_type (session, get_type_function ());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
soup_session_settings_notify_http_proxy_cb (settings, NULL, session);
|
soup_session_settings_notify_http_proxy_cb (settings, NULL, session);
|
||||||
soup_session_settings_notify_ident_string_cb (settings, NULL, session);
|
|
||||||
g_signal_connect (settings, "notify::http-proxy",
|
g_signal_connect (settings, "notify::http-proxy",
|
||||||
G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session);
|
G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session);
|
||||||
g_signal_connect (settings, "notify::auto-detect-proxy",
|
g_signal_connect (settings, "notify::auto-detect-proxy",
|
||||||
G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session);
|
G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session);
|
||||||
|
|
||||||
|
#if !WEBKIT_CHECK_VERSION (1, 1, 11)
|
||||||
|
soup_session_settings_notify_ident_string_cb (settings, NULL, session);
|
||||||
g_signal_connect (settings, "notify::ident-string",
|
g_signal_connect (settings, "notify::ident-string",
|
||||||
G_CALLBACK (soup_session_settings_notify_ident_string_cb), session);
|
G_CALLBACK (soup_session_settings_notify_ident_string_cb), session);
|
||||||
|
#endif
|
||||||
|
|
||||||
soup_session_add_feature_by_type (session, KATZE_TYPE_HTTP_AUTH);
|
soup_session_add_feature_by_type (session, KATZE_TYPE_HTTP_AUTH);
|
||||||
midori_soup_session_debug (session);
|
midori_soup_session_debug (session);
|
||||||
|
|
1
wscript
1
wscript
|
@ -210,6 +210,7 @@ def configure (conf):
|
||||||
check_pkg ('webkit-1.0', '1.1.1', args=args)
|
check_pkg ('webkit-1.0', '1.1.1', args=args)
|
||||||
check_pkg ('libsoup-2.4', '2.25.2')
|
check_pkg ('libsoup-2.4', '2.25.2')
|
||||||
conf.define ('HAVE_LIBSOUP_2_25_2', 1)
|
conf.define ('HAVE_LIBSOUP_2_25_2', 1)
|
||||||
|
check_pkg ('libsoup-2.4', '2.27.92', False, var='LIBSOUP_2_27_92')
|
||||||
check_pkg ('libxml-2.0', '2.6')
|
check_pkg ('libxml-2.0', '2.6')
|
||||||
|
|
||||||
if option_enabled ('hildon'):
|
if option_enabled ('hildon'):
|
||||||
|
|
Loading…
Reference in a new issue