From af86796eabda0fd05fb746455b26de74333c0e96 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sat, 29 Aug 2009 23:33:24 +0200 Subject: [PATCH] Use GNOME proxy resolver and GNOME password manager optionally --- katze/katze-http-auth.c | 42 +++++++++++++++++++++- midori/main.c | 79 +++++++++++++++++++++++++++++++---------- wscript | 1 + 3 files changed, 103 insertions(+), 19 deletions(-) diff --git a/katze/katze-http-auth.c b/katze/katze-http-auth.c index ae7b2382..2149df5e 100644 --- a/katze/katze-http-auth.c +++ b/katze/katze-http-auth.c @@ -37,6 +37,21 @@ G_DEFINE_TYPE_WITH_CODE (KatzeHttpAuth, katze_http_auth, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (SOUP_TYPE_SESSION_FEATURE, 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 authentication_dialog_response_cb (GtkWidget* dialog, gint response, @@ -47,6 +62,8 @@ authentication_dialog_response_cb (GtkWidget* dialog, SoupSession* session; SoupMessage* msg; + msg = g_object_get_data (G_OBJECT (dialog), "msg"); + if (response == GTK_RESPONSE_OK) { @@ -56,10 +73,17 @@ authentication_dialog_response_cb (GtkWidget* dialog, soup_auth_authenticate (auth, gtk_entry_get_text (GTK_ENTRY (username)), 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"); - msg = g_object_get_data (G_OBJECT (dialog), "msg"); gtk_widget_destroy (dialog); if (g_object_get_data (G_OBJECT (msg), "paused")) soup_session_unpause_message (session, msg); @@ -79,6 +103,9 @@ katze_http_auth_session_authenticate_cb (SoupSession* session, GtkWidget* label; GtkWidget* align; GtkWidget* entry; + #ifdef HAVE_LIBSOUP_2_27_92 + GSList* users; + #endif /* We want to ask for authentication exactly once, so we 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_box_pack_start (GTK_BOX (hbox), align, TRUE, TRUE, 0); 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_entry_set_activates_default (GTK_ENTRY (entry), TRUE); 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_box_pack_start (GTK_BOX (hbox), align, TRUE, TRUE, 0); 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_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE); diff --git a/midori/main.c b/midori/main.c index b464718b..8a3f2299 100644 --- a/midori/main.c +++ b/midori/main.c @@ -1005,36 +1005,63 @@ midori_browser_weak_notify_cb (MidoriBrowser* browser, } static void -soup_session_settings_notify_http_proxy_cb (MidoriWebSettings* settings, - GParamSpec* pspec, - SoupSession* session) +midori_soup_session_set_proxy_uri (SoupSession* session, + const gchar* uri) { - gboolean auto_detect_proxy; - gchar* http_proxy; + gchar* fixed_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 */ - if (http_proxy && g_str_has_prefix (http_proxy, "http://")) - proxy_uri = soup_uri_new (http_proxy); - else if (http_proxy && *http_proxy) + if (uri && g_str_has_prefix (uri, "http://")) + proxy_uri = soup_uri_new (uri); + else if (uri && *uri) { - gchar* fixed_http_proxy = g_strconcat ("http://", http_proxy, NULL); - proxy_uri = soup_uri_new (fixed_http_proxy); - g_free (fixed_http_proxy); + fixed_uri = g_strconcat ("http://", uri, NULL); + proxy_uri = soup_uri_new (fixed_uri); + g_free (fixed_uri); } else proxy_uri = NULL; - g_free (http_proxy); g_object_set (session, "proxy-uri", proxy_uri, NULL); if (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 soup_session_settings_notify_ident_string_cb (MidoriWebSettings* settings, 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_free (ident_string); } +#endif static void midori_soup_session_debug (SoupSession* session) @@ -1064,17 +1092,32 @@ midori_soup_session_prepare (SoupSession* session, SoupCookieJar* cookie_jar, MidoriWebSettings* settings) { + GModule* module; + GType (*get_type_function) (void); SoupSessionFeature* feature; 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_ident_string_cb (settings, NULL, session); g_signal_connect (settings, "notify::http-proxy", G_CALLBACK (soup_session_settings_notify_http_proxy_cb), session); g_signal_connect (settings, "notify::auto-detect-proxy", 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_CALLBACK (soup_session_settings_notify_ident_string_cb), session); + #endif soup_session_add_feature_by_type (session, KATZE_TYPE_HTTP_AUTH); midori_soup_session_debug (session); diff --git a/wscript b/wscript index 68cd1927..d0a29b10 100644 --- a/wscript +++ b/wscript @@ -210,6 +210,7 @@ def configure (conf): check_pkg ('webkit-1.0', '1.1.1', args=args) check_pkg ('libsoup-2.4', '2.25.2') 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') if option_enabled ('hildon'): -- 2.39.5