Title: [88800] trunk/Source
Revision
88800
Author
[email protected]
Date
2011-06-14 07:36:50 -0700 (Tue, 14 Jun 2011)

Log Message

2011-06-14  Carlos Garcia Campos  <[email protected]>

        Reviewed by Martin Robinson.

        [GTK] Support authentication dialogs in WebKit2
        https://bugs.webkit.org/show_bug.cgi?id=62366

        Add a new class to show an authentication dialog that is used by
        both WebKit1 and WebKit2.

        * GNUmakefile.list.am: Add new files to compilation.
        * platform/gtk/GtkAuthenticationDialog.cpp: Added.
        (WebCore::addEntryToTable):
        (WebCore::sessionCanSavePasswords):
        (WebCore::GtkAuthenticationDialog::~GtkAuthenticationDialog):
        (WebCore::GtkAuthenticationDialog::GtkAuthenticationDialog):
        (WebCore::getSavedLogin):
        (WebCore::GtkAuthenticationDialog::show):
        (WebCore::GtkAuthenticationDialog::destroy):
        (WebCore::GtkAuthenticationDialog::savePasswordCallback):
        (WebCore::GtkAuthenticationDialog::savePassword):
        (WebCore::GtkAuthenticationDialog::authenticate):
        (WebCore::GtkAuthenticationDialog::authenticationDialogResponseCallback):
        * platform/gtk/GtkAuthenticationDialog.h: Added.
2011-06-14  Carlos Garcia Campos  <[email protected]>

        Reviewed by Martin Robinson.

        [GTK] Support authentication dialogs in WebKit2
        https://bugs.webkit.org/show_bug.cgi?id=62366

        Move the common code of webkitsoupauthdialog to a common C++ class
        in WebCore so that it can be used by WebKit2 too. The file has
        been converted into a C++ file.

        * GNUmakefile.am: Rename webkitsoupauthdialog.c to
        webkitsoupauthdialog.cpp.
        * webkit/webkitsoupauthdialog.c: Removed.
        * webkit/webkitsoupauthdialog.cpp: Added.
        (webkit_soup_auth_dialog_class_init):
        (webkit_soup_auth_dialog_init):
        (webkit_soup_auth_dialog_session_feature_init):
        (sessionAuthenticate): Use GtkAuthenticationDialog object from
        WebCore.
        (attach):
        (detach):
        * webkit/webkitsoupauthdialog.h:
2011-06-14  Carlos Garcia Campos  <[email protected]>

        Reviewed by Martin Robinson.

        [GTK] Support authentication dialogs in WebKit2
        https://bugs.webkit.org/show_bug.cgi?id=62366

        Add a new soup feature to show an authentication dialog when it
        gets a 401 HTTP response.

        * GNUmakefile.am: Add new files to compilation.
        * WebProcess/gtk/WebAuthDialog.cpp: Added.
        (web_auth_dialog_class_init):
        (web_auth_dialog_init):
        (sessionAuthenticate):
        (attach):
        (detach):
        (webAuthDialogSessionFeatureInit):
        * WebProcess/gtk/WebAuthDialog.h: Added.
        * WebProcess/gtk/WebProcessMainGtk.cpp:
        (WebKit::WebProcessMainGtk):

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (88799 => 88800)


--- trunk/Source/WebCore/ChangeLog	2011-06-14 14:07:55 UTC (rev 88799)
+++ trunk/Source/WebCore/ChangeLog	2011-06-14 14:36:50 UTC (rev 88800)
@@ -1,3 +1,28 @@
+2011-06-14  Carlos Garcia Campos  <[email protected]>
+
+        Reviewed by Martin Robinson.
+
+        [GTK] Support authentication dialogs in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=62366
+
+        Add a new class to show an authentication dialog that is used by
+        both WebKit1 and WebKit2.
+
+        * GNUmakefile.list.am: Add new files to compilation.
+        * platform/gtk/GtkAuthenticationDialog.cpp: Added.
+        (WebCore::addEntryToTable):
+        (WebCore::sessionCanSavePasswords):
+        (WebCore::GtkAuthenticationDialog::~GtkAuthenticationDialog):
+        (WebCore::GtkAuthenticationDialog::GtkAuthenticationDialog):
+        (WebCore::getSavedLogin):
+        (WebCore::GtkAuthenticationDialog::show):
+        (WebCore::GtkAuthenticationDialog::destroy):
+        (WebCore::GtkAuthenticationDialog::savePasswordCallback):
+        (WebCore::GtkAuthenticationDialog::savePassword):
+        (WebCore::GtkAuthenticationDialog::authenticate):
+        (WebCore::GtkAuthenticationDialog::authenticationDialogResponseCallback):
+        * platform/gtk/GtkAuthenticationDialog.h: Added.
+
 2011-06-14  Tommy Widenflycht  <[email protected]>
 
         Reviewed by Tony Gentilcore.

Modified: trunk/Source/WebCore/GNUmakefile.list.am (88799 => 88800)


--- trunk/Source/WebCore/GNUmakefile.list.am	2011-06-14 14:07:55 UTC (rev 88799)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2011-06-14 14:36:50 UTC (rev 88800)
@@ -3817,6 +3817,8 @@
 	Source/WebCore/platform/gtk/GOwnPtrGtk.h \
 	Source/WebCore/platform/gtk/GRefPtrGtk.cpp \
 	Source/WebCore/platform/gtk/GRefPtrGtk.h \
+	Source/WebCore/platform/gtk/GtkAuthenticationDialog.cpp \
+	Source/WebCore/platform/gtk/GtkAuthenticationDialog.h \
 	Source/WebCore/platform/gtk/GtkPluginWidget.cpp \
 	Source/WebCore/platform/gtk/GtkPluginWidget.h \
 	Source/WebCore/platform/gtk/GtkPopupMenu.cpp \

Added: trunk/Source/WebCore/platform/gtk/GtkAuthenticationDialog.cpp (0 => 88800)


--- trunk/Source/WebCore/platform/gtk/GtkAuthenticationDialog.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/gtk/GtkAuthenticationDialog.cpp	2011-06-14 14:36:50 UTC (rev 88800)
@@ -0,0 +1,248 @@
+/*
+ * Copyright (C) 2009, 2011 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "GtkAuthenticationDialog.h"
+
+#include "GtkVersioning.h"
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libsoup/soup.h>
+
+namespace WebCore {
+
+static GtkWidget* addEntryToTable(GtkTable* table, int row, const char* labelText)
+{
+    GtkWidget* label = gtk_label_new(labelText);
+    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+
+    GtkWidget* entry = gtk_entry_new();
+    gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
+
+    gtk_table_attach(table, label, 0, 1, row, row + 1, GTK_FILL, static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), 0, 0);
+    gtk_table_attach_defaults(table, entry, 1, 2, row, row + 1);
+
+    return entry;
+}
+
+static bool sessionCanSavePasswords(SoupSession* session)
+{
+#ifdef SOUP_TYPE_PASSWORD_MANAGER
+    return soup_session_get_feature(session, SOUP_TYPE_PASSWORD_MANAGER);
+#else
+    return false;
+#endif
+}
+
+GtkAuthenticationDialog::~GtkAuthenticationDialog()
+{
+}
+
+GtkAuthenticationDialog::GtkAuthenticationDialog(GtkWindow* parentWindow, SoupSession* session, SoupMessage* message, SoupAuth* auth)
+    : m_dialog(gtk_dialog_new())
+    , m_session(session)
+    , m_message(message)
+    , m_auth(auth)
+    , m_loginEntry(0)
+    , m_passwordEntry(0)
+    , m_rememberCheckButton(0)
+#ifdef SOUP_TYPE_PASSWORD_MANAGER
+    , m_isSavingPassword(false)
+    , m_savePasswordHandler(0)
+#endif
+{
+    GtkDialog* dialog = GTK_DIALOG(m_dialog);
+    gtk_dialog_add_buttons(dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
+
+    // Set the dialog up with HIG properties.
+    gtk_container_set_border_width(GTK_CONTAINER(dialog), 5);
+    gtk_box_set_spacing(GTK_BOX(gtk_dialog_get_content_area(dialog)), 2); /* 2 * 5 + 2 = 12 */
+    gtk_container_set_border_width(GTK_CONTAINER(gtk_dialog_get_action_area(dialog)), 5);
+    gtk_box_set_spacing(GTK_BOX(gtk_dialog_get_action_area(dialog)), 6);
+
+    GtkWindow* window = GTK_WINDOW(m_dialog);
+    gtk_window_set_resizable(window, FALSE);
+    gtk_window_set_title(window, "");
+    gtk_window_set_icon_name(window, GTK_STOCK_DIALOG_AUTHENTICATION);
+
+    gtk_dialog_set_default_response(dialog, GTK_RESPONSE_OK);
+
+    if (parentWindow)
+        gtk_window_set_transient_for(window, parentWindow);
+
+    // Build contents.
+    GtkWidget* hBox = gtk_hbox_new(FALSE, 12);
+    gtk_container_set_border_width(GTK_CONTAINER(hBox), 5);
+    gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(dialog)), hBox, TRUE, TRUE, 0);
+
+    GtkWidget* icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_DIALOG);
+    gtk_misc_set_alignment(GTK_MISC(icon), 0.5, 0.0);
+    gtk_box_pack_start(GTK_BOX(hBox), icon, FALSE, FALSE, 0);
+
+    GtkWidget* mainVBox = gtk_vbox_new(FALSE, 18);
+    gtk_box_pack_start(GTK_BOX(hBox), mainVBox, TRUE, TRUE, 0);
+
+    SoupURI* uri = soup_message_get_uri(m_message.get());
+    GOwnPtr<char>description(g_strdup_printf(_("A username and password are being requested by the site %s"), uri->host));
+    GtkWidget* descriptionLabel = gtk_label_new(description.get());
+    gtk_misc_set_alignment(GTK_MISC(descriptionLabel), 0.0, 0.5);
+    gtk_label_set_line_wrap(GTK_LABEL(descriptionLabel), TRUE);
+    gtk_box_pack_start(GTK_BOX(mainVBox), GTK_WIDGET(descriptionLabel), FALSE, FALSE, 0);
+
+    GtkWidget* vBox = gtk_vbox_new(FALSE, 6);
+    gtk_box_pack_start(GTK_BOX(mainVBox), vBox, FALSE, FALSE, 0);
+
+    // The table that holds the entries.
+    GtkWidget* entryContainer = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
+    gtk_alignment_set_padding(GTK_ALIGNMENT(entryContainer), 0, 0, 0, 0);
+    gtk_box_pack_start(GTK_BOX(vBox), entryContainer, FALSE, FALSE, 0);
+
+    const char* realm = soup_auth_get_realm(m_auth);
+    // Checking that realm is not an empty string.
+    bool hasRealm = (realm && realm[0] != '\0');
+
+    GtkWidget* table = gtk_table_new(hasRealm ? 3 : 2, 2, FALSE);
+    gtk_table_set_col_spacings(GTK_TABLE(table), 12);
+    gtk_table_set_row_spacings(GTK_TABLE(table), 6);
+    gtk_container_add(GTK_CONTAINER(entryContainer), table);
+
+    if (hasRealm) {
+        GtkWidget* serverMessageDescriptionLabel = gtk_label_new(_("Server message:"));
+        gtk_misc_set_alignment(GTK_MISC(serverMessageDescriptionLabel), 0.0, 0.5);
+        gtk_label_set_line_wrap(GTK_LABEL(serverMessageDescriptionLabel), TRUE);
+        gtk_table_attach_defaults(GTK_TABLE(table), serverMessageDescriptionLabel, 0, 1, 0, 1);
+
+        GtkWidget* serverMessageLabel = gtk_label_new(realm);
+        gtk_misc_set_alignment(GTK_MISC(serverMessageLabel), 0.0, 0.5);
+        gtk_label_set_line_wrap(GTK_LABEL(serverMessageLabel), TRUE);
+        gtk_table_attach_defaults(GTK_TABLE(table), serverMessageLabel, 1, 2, 0, 1);
+    }
+
+    m_loginEntry = addEntryToTable(GTK_TABLE(table), hasRealm ? 1 : 0, _("Username:"));
+    m_passwordEntry = addEntryToTable(GTK_TABLE(table), hasRealm ? 2 : 1, _("Password:"));
+    gtk_entry_set_visibility(GTK_ENTRY(m_passwordEntry), FALSE);
+
+    if (sessionCanSavePasswords(m_session)) {
+        GtkWidget* rememberBox = gtk_vbox_new(FALSE, 6);
+        gtk_box_pack_start(GTK_BOX(vBox), rememberBox, FALSE, FALSE, 0);
+
+        m_rememberCheckButton = gtk_check_button_new_with_mnemonic(_("_Remember password"));
+        gtk_label_set_line_wrap(GTK_LABEL(gtk_bin_get_child(GTK_BIN(m_rememberCheckButton))), TRUE);
+        gtk_box_pack_start(GTK_BOX(rememberBox), m_rememberCheckButton, FALSE, FALSE, 0);
+    }
+}
+
+static bool getSavedLogin(SoupAuth* auth, const char** username, const char** password)
+{
+#ifdef SOUP_TYPE_PASSWORD_MANAGER
+    GSList* users = soup_auth_get_saved_users(auth);
+    if (!users)
+        return false;
+
+    *username = static_cast<char*>(users->data);
+    *password = soup_auth_get_saved_password(auth, *username);
+    g_slist_free(users);
+
+    return *username && *password;
+#else
+    return false;
+#endif
+}
+
+void GtkAuthenticationDialog::show()
+{
+    const char* username = 0;
+    const char* password = 0;
+    bool haveSavedLogin = getSavedLogin(m_auth, &username, &password);
+    soup_session_pause_message(m_session, m_message.get());
+    gtk_entry_set_text(GTK_ENTRY(m_loginEntry), username ? username : "");
+    gtk_entry_set_text(GTK_ENTRY(m_passwordEntry), password ? password : "");
+    if (m_rememberCheckButton && haveSavedLogin)
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_rememberCheckButton), TRUE);
+    g_signal_connect(m_dialog, "response", G_CALLBACK(authenticationDialogResponseCallback), this);
+    gtk_widget_show_all(m_dialog);
+}
+
+void GtkAuthenticationDialog::destroy()
+{
+    bool shouldDelete = true;
+
+    soup_session_unpause_message(m_session, m_message.get());
+    gtk_widget_destroy(m_dialog);
+
+#ifdef SOUP_TYPE_PASSWORD_MANAGER
+    shouldDelete = !m_isSavingPassword;
+#endif
+
+    // Do not delete the object if it's still saving the password,
+    // the save password callback will delete it.
+    if (shouldDelete)
+        delete this;
+}
+
+#ifdef SOUP_TYPE_PASSWORD_MANAGER
+void GtkAuthenticationDialog::savePasswordCallback(SoupMessage* message, GtkAuthenticationDialog* dialog)
+{
+    dialog->savePassword();
+}
+
+void GtkAuthenticationDialog::savePassword()
+{
+    ASSERT(!m_username.isNull());
+    ASSERT(!m_password.isNull());
+
+    // Anything but 401 and 5xx means the password was accepted.
+    if (m_message.get()->status_code != 401 && m_message.get()->status_code < 500)
+        soup_auth_save_password(m_auth, m_username.data(), m_password.data());
+
+    // Disconnect the callback. If the authentication succeeded we are done,
+    // and if it failed we'll create a new GtkAuthenticationDialog and we'll
+    // connect to 'got-headers' again in GtkAuthenticationDialog::authenticate()
+    g_signal_handler_disconnect(m_message.get(), m_savePasswordHandler);
+
+    // Dialog has been already destroyed, after saving the password it should be deleted.
+    delete this;
+}
+#endif
+
+void GtkAuthenticationDialog::authenticate()
+{
+    const char *username = gtk_entry_get_text(GTK_ENTRY(m_loginEntry));
+    const char *password = gtk_entry_get_text(GTK_ENTRY(m_passwordEntry));
+    soup_auth_authenticate(m_auth, username, password);
+
+#ifdef SOUP_TYPE_PASSWORD_MANAGER
+    if (m_rememberCheckButton && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_rememberCheckButton))) {
+        m_username = username;
+        m_password = password;
+        m_isSavingPassword = true;
+        m_savePasswordHandler = g_signal_connect(m_message.get(), "got-headers", G_CALLBACK(savePasswordCallback), this);
+    }
+#endif
+}
+
+void GtkAuthenticationDialog::authenticationDialogResponseCallback(GtkWidget*, gint responseID, GtkAuthenticationDialog* dialog)
+{
+    if (responseID == GTK_RESPONSE_OK)
+        dialog->authenticate();
+
+    dialog->destroy();
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/gtk/GtkAuthenticationDialog.h (0 => 88800)


--- trunk/Source/WebCore/platform/gtk/GtkAuthenticationDialog.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/gtk/GtkAuthenticationDialog.h	2011-06-14 14:36:50 UTC (rev 88800)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2009, 2011 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GtkAuthenticationDialog_h
+#define GtkAuthenticationDialog_h
+
+#define LIBSOUP_I_HAVE_READ_BUG_594377_AND_KNOW_SOUP_PASSWORD_MANAGER_MIGHT_GO_AWAY
+
+#include "GOwnPtr.h"
+#include "GRefPtrGtk.h"
+#include <libsoup/soup.h>
+#include <wtf/FastAllocBase.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+class GtkAuthenticationDialog {
+    WTF_MAKE_NONCOPYABLE(GtkAuthenticationDialog);
+    WTF_MAKE_FAST_ALLOCATED;
+
+public:
+    GtkAuthenticationDialog(GtkWindow*, SoupSession*, SoupMessage*, SoupAuth*);
+    ~GtkAuthenticationDialog();
+
+    void show();
+
+private:
+    GtkAuthenticationDialog();
+
+    void destroy();
+    void authenticate();
+
+#ifdef SOUP_TYPE_PASSWORD_MANAGER
+    void savePassword();
+    static void savePasswordCallback(SoupMessage*, GtkAuthenticationDialog*);
+#endif
+
+    static void authenticationDialogResponseCallback(GtkWidget*, gint responseID, GtkAuthenticationDialog*);
+
+    GtkWidget* m_dialog;
+    SoupSession* m_session;
+    GRefPtr<SoupMessage> m_message;
+    SoupAuth* m_auth;
+
+    GtkWidget* m_loginEntry;
+    GtkWidget* m_passwordEntry;
+    GtkWidget* m_rememberCheckButton;
+
+#ifdef SOUP_TYPE_PASSWORD_MANAGER
+    bool m_isSavingPassword;
+    unsigned long m_savePasswordHandler;
+    CString m_username;
+    CString m_password;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // GtkAuthenticationDialog_h

Modified: trunk/Source/WebKit/gtk/ChangeLog (88799 => 88800)


--- trunk/Source/WebKit/gtk/ChangeLog	2011-06-14 14:07:55 UTC (rev 88799)
+++ trunk/Source/WebKit/gtk/ChangeLog	2011-06-14 14:36:50 UTC (rev 88800)
@@ -1,3 +1,27 @@
+2011-06-14  Carlos Garcia Campos  <[email protected]>
+
+        Reviewed by Martin Robinson.
+
+        [GTK] Support authentication dialogs in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=62366
+
+        Move the common code of webkitsoupauthdialog to a common C++ class
+        in WebCore so that it can be used by WebKit2 too. The file has
+        been converted into a C++ file.
+
+        * GNUmakefile.am: Rename webkitsoupauthdialog.c to
+        webkitsoupauthdialog.cpp.
+        * webkit/webkitsoupauthdialog.c: Removed.
+        * webkit/webkitsoupauthdialog.cpp: Added.
+        (webkit_soup_auth_dialog_class_init):
+        (webkit_soup_auth_dialog_init):
+        (webkit_soup_auth_dialog_session_feature_init):
+        (sessionAuthenticate): Use GtkAuthenticationDialog object from
+        WebCore.
+        (attach):
+        (detach):
+        * webkit/webkitsoupauthdialog.h:
+
 2011-06-13  Joone Hur  <[email protected]>
 
         Reviewed by Martin Robinson.

Modified: trunk/Source/WebKit/gtk/GNUmakefile.am (88799 => 88800)


--- trunk/Source/WebKit/gtk/GNUmakefile.am	2011-06-14 14:07:55 UTC (rev 88799)
+++ trunk/Source/WebKit/gtk/GNUmakefile.am	2011-06-14 14:36:50 UTC (rev 88800)
@@ -217,7 +217,7 @@
 	Source/WebKit/gtk/webkit/webkitnetworkresponseprivate.h \
 	Source/WebKit/gtk/webkit/webkitsecurityorigin.cpp \
 	Source/WebKit/gtk/webkit/webkitsecurityoriginprivate.h \
-	Source/WebKit/gtk/webkit/webkitsoupauthdialog.c \
+	Source/WebKit/gtk/webkit/webkitsoupauthdialog.cpp \
 	Source/WebKit/gtk/webkit/webkitspellchecker.cpp \
 	Source/WebKit/gtk/webkit/webkitspellcheckerenchant.cpp \
 	Source/WebKit/gtk/webkit/webkitspellcheckerenchant.h \

Deleted: trunk/Source/WebKit/gtk/webkit/webkitsoupauthdialog.c (88799 => 88800)


--- trunk/Source/WebKit/gtk/webkit/webkitsoupauthdialog.c	2011-06-14 14:07:55 UTC (rev 88799)
+++ trunk/Source/WebKit/gtk/webkit/webkitsoupauthdialog.c	2011-06-14 14:36:50 UTC (rev 88800)
@@ -1,372 +0,0 @@
-/*
- * Copyright (C) 2009 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-
-#define LIBSOUP_I_HAVE_READ_BUG_594377_AND_KNOW_SOUP_PASSWORD_MANAGER_MIGHT_GO_AWAY
-
-#include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
-#include <libsoup/soup.h>
-
-#include "GtkVersioning.h"
-#include "webkitmarshal.h"
-#include "webkitsoupauthdialog.h"
-
-/**
- * SECTION:webkitsoupauthdialog
- * @short_description: A #SoupSessionFeature to provide a simple
- * authentication dialog for HTTP basic auth support.
- *
- * #WebKitSoupAuthDialog is a #SoupSessionFeature that you can attach to your
- * #SoupSession to provide a simple authentication dialog while
- * handling HTTP basic auth. It is built as a simple C-only module
- * to ease reuse.
- */
-
-static void webkit_soup_auth_dialog_session_feature_init(SoupSessionFeatureInterface* feature_interface, gpointer interface_data);
-static void attach(SoupSessionFeature* manager, SoupSession* session);
-static void detach(SoupSessionFeature* manager, SoupSession* session);
-
-enum {
-    CURRENT_TOPLEVEL,
-    LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE_WITH_CODE(WebKitSoupAuthDialog, webkit_soup_auth_dialog, G_TYPE_OBJECT,
-                        G_IMPLEMENT_INTERFACE(SOUP_TYPE_SESSION_FEATURE,
-                                              webkit_soup_auth_dialog_session_feature_init))
-
-static void webkit_soup_auth_dialog_class_init(WebKitSoupAuthDialogClass* klass)
-{
-    GObjectClass* object_class = G_OBJECT_CLASS(klass);
-
-    /**
-     * WebKitSoupAuthDialog::current-toplevel:
-     * @authDialog: the object on which the signal is emitted
-     * @message: the #SoupMessage being used in the authentication process
-     *
-     * This signal is emitted by the @authDialog when it needs to know
-     * the current toplevel widget in order to correctly set the
-     * transiency for the authentication dialog.
-     *
-     * Return value: (transfer none): the current toplevel #GtkWidget or %NULL if there's none
-     *
-     * Since: 1.1.1
-     */
-    signals[CURRENT_TOPLEVEL] =
-      g_signal_new("current-toplevel",
-                   G_OBJECT_CLASS_TYPE(object_class),
-                   G_SIGNAL_RUN_LAST,
-                   G_STRUCT_OFFSET(WebKitSoupAuthDialogClass, current_toplevel),
-                   NULL, NULL,
-                   webkit_marshal_OBJECT__OBJECT,
-                   GTK_TYPE_WIDGET, 1,
-                   SOUP_TYPE_MESSAGE);
-}
-
-static void webkit_soup_auth_dialog_init(WebKitSoupAuthDialog* instance)
-{
-}
-
-static void webkit_soup_auth_dialog_session_feature_init(SoupSessionFeatureInterface *feature_interface,
-                                                         gpointer interface_data)
-{
-    feature_interface->attach = attach;
-    feature_interface->detach = detach;
-}
-
-typedef struct _WebKitAuthData {
-    SoupMessage* msg;
-    SoupAuth* auth;
-    SoupSession* session;
-    SoupSessionFeature* manager;
-    GtkWidget* loginEntry;
-    GtkWidget* passwordEntry;
-    GtkWidget* checkButton;
-    char *username;
-    char *password;
-} WebKitAuthData;
-
-static void free_authData(WebKitAuthData* authData)
-{
-    g_object_unref(authData->msg);
-    g_free(authData->username);
-    g_free(authData->password);
-    g_slice_free(WebKitAuthData, authData);
-}
-
-#ifdef SOUP_TYPE_PASSWORD_MANAGER
-static void save_password_callback(SoupMessage* msg, WebKitAuthData* authData)
-{
-    /* Anything but 401 and 5xx means the password was accepted */
-    if (msg->status_code != 401 && msg->status_code < 500)
-        soup_auth_save_password(authData->auth, authData->username, authData->password);
-
-    /* Disconnect the callback. If the authentication succeeded we are
-     * done, and if it failed we'll create a new authData and we'll
-     * connect to 'got-headers' again in response_callback */
-    g_signal_handlers_disconnect_by_func(msg, save_password_callback, authData);
-
-    free_authData(authData);
-}
-#endif
-
-static void response_callback(GtkDialog* dialog, gint response_id, WebKitAuthData* authData)
-{
-    gboolean freeAuthData = TRUE;
-
-    if (response_id == GTK_RESPONSE_OK) {
-        authData->username = g_strdup(gtk_entry_get_text(GTK_ENTRY(authData->loginEntry)));
-        authData->password = g_strdup(gtk_entry_get_text(GTK_ENTRY(authData->passwordEntry)));
-
-        soup_auth_authenticate(authData->auth, authData->username, authData->password);
-
-#ifdef SOUP_TYPE_PASSWORD_MANAGER
-        if (authData->checkButton &&
-            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(authData->checkButton))) {
-            g_signal_connect(authData->msg, "got-headers", G_CALLBACK(save_password_callback), authData);
-            freeAuthData = FALSE;
-        }
-#endif
-    }
-
-    soup_session_unpause_message(authData->session, authData->msg);
-    if (freeAuthData)
-        free_authData(authData);
-    gtk_widget_destroy(GTK_WIDGET(dialog));
-}
-
-static GtkWidget *
-table_add_entry(GtkWidget*  table,
-                int         row,
-                const char* label_text,
-                const char* value,
-                gpointer    user_data)
-{
-    GtkWidget* entry;
-    GtkWidget* label;
-
-    label = gtk_label_new(label_text);
-    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
-
-    entry = gtk_entry_new();
-    gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
-
-    if (value)
-        gtk_entry_set_text(GTK_ENTRY(entry), value);
-
-    gtk_table_attach(GTK_TABLE(table), label,
-                     0, 1, row, row + 1,
-                     GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
-    gtk_table_attach_defaults(GTK_TABLE(table), entry,
-                              1, 2, row, row + 1);
-
-    return entry;
-}
-
-static gboolean session_can_save_passwords(SoupSession* session)
-{
-#ifdef SOUP_TYPE_PASSWORD_MANAGER
-    return soup_session_get_feature(session, SOUP_TYPE_PASSWORD_MANAGER) != NULL;
-#else
-    return FALSE;
-#endif
-}
-
-static void show_auth_dialog(WebKitAuthData* authData, const char* login, const char* password)
-{
-    GtkWidget* toplevel;
-    GtkWidget* widget;
-    GtkDialog* dialog;
-    GtkWindow* window;
-    GtkWidget* entryContainer;
-    GtkWidget* hbox;
-    GtkWidget* mainVBox;
-    GtkWidget* vbox;
-    GtkWidget* icon;
-    GtkWidget* table;
-    GtkWidget* serverMessageDescriptionLabel;
-    GtkWidget* serverMessageLabel;
-    GtkWidget* descriptionLabel;
-    char* description;
-    const char* realm;
-    gboolean hasRealm;
-    SoupURI* uri;
-    GtkWidget* rememberBox;
-    GtkWidget* checkButton;
-
-    /* From GTK+ gtkmountoperation.c, modified and simplified. LGPL 2 license */
-
-    widget = gtk_dialog_new();
-    window = GTK_WINDOW(widget);
-    dialog = GTK_DIALOG(widget);
-
-    gtk_dialog_add_buttons(dialog,
-                           GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                           GTK_STOCK_OK, GTK_RESPONSE_OK,
-                           NULL);
-
-    /* Set the dialog up with HIG properties */
-    gtk_container_set_border_width(GTK_CONTAINER(dialog), 5);
-    gtk_box_set_spacing(GTK_BOX(gtk_dialog_get_content_area(dialog)), 2); /* 2 * 5 + 2 = 12 */
-    gtk_container_set_border_width(GTK_CONTAINER(gtk_dialog_get_action_area(dialog)), 5);
-    gtk_box_set_spacing(GTK_BOX(gtk_dialog_get_action_area(dialog)), 6);
-
-    gtk_window_set_resizable(window, FALSE);
-    gtk_window_set_title(window, "");
-    gtk_window_set_icon_name(window, GTK_STOCK_DIALOG_AUTHENTICATION);
-
-    gtk_dialog_set_default_response(dialog, GTK_RESPONSE_OK);
-
-    /* Get the current toplevel */
-    g_signal_emit(authData->manager, signals[CURRENT_TOPLEVEL], 0, authData->msg, &toplevel);
-
-    if (toplevel)
-        gtk_window_set_transient_for(window, GTK_WINDOW(toplevel));
-
-    /* Build contents */
-    hbox = gtk_hbox_new(FALSE, 12);
-    gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
-    gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(dialog)), hbox, TRUE, TRUE, 0);
-
-    icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_AUTHENTICATION,
-                                    GTK_ICON_SIZE_DIALOG);
-
-    gtk_misc_set_alignment(GTK_MISC(icon), 0.5, 0.0);
-    gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, FALSE, 0);
-
-    mainVBox = gtk_vbox_new(FALSE, 18);
-    gtk_box_pack_start(GTK_BOX(hbox), mainVBox, TRUE, TRUE, 0);
-
-    uri = soup_message_get_uri(authData->msg);
-    description = g_strdup_printf(_("A username and password are being requested by the site %s"), uri->host);
-    descriptionLabel = gtk_label_new(description);
-    g_free(description);
-    gtk_misc_set_alignment(GTK_MISC(descriptionLabel), 0.0, 0.5);
-    gtk_label_set_line_wrap(GTK_LABEL(descriptionLabel), TRUE);
-    gtk_box_pack_start(GTK_BOX(mainVBox), GTK_WIDGET(descriptionLabel),
-                       FALSE, FALSE, 0);
-
-    vbox = gtk_vbox_new(FALSE, 6);
-    gtk_box_pack_start(GTK_BOX(mainVBox), vbox, FALSE, FALSE, 0);
-
-    /* The table that holds the entries */
-    entryContainer = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
-
-    gtk_alignment_set_padding(GTK_ALIGNMENT(entryContainer),
-                              0, 0, 0, 0);
-
-    gtk_box_pack_start(GTK_BOX(vbox), entryContainer,
-                       FALSE, FALSE, 0);
-
-    realm = soup_auth_get_realm(authData->auth);
-    // Checking that realm is not an empty string
-    hasRealm = (realm && (strlen(realm) > 0));
-
-    table = gtk_table_new(hasRealm ? 3 : 2, 2, FALSE);
-    gtk_table_set_col_spacings(GTK_TABLE(table), 12);
-    gtk_table_set_row_spacings(GTK_TABLE(table), 6);
-    gtk_container_add(GTK_CONTAINER(entryContainer), table);
-
-    if (hasRealm) {
-        serverMessageDescriptionLabel = gtk_label_new(_("Server message:"));
-        serverMessageLabel = gtk_label_new(realm);
-        gtk_misc_set_alignment(GTK_MISC(serverMessageDescriptionLabel), 0.0, 0.5);
-        gtk_label_set_line_wrap(GTK_LABEL(serverMessageDescriptionLabel), TRUE);
-        gtk_misc_set_alignment(GTK_MISC(serverMessageLabel), 0.0, 0.5);
-        gtk_label_set_line_wrap(GTK_LABEL(serverMessageLabel), TRUE);
-
-        gtk_table_attach_defaults(GTK_TABLE(table), serverMessageDescriptionLabel,
-                                  0, 1, 0, 1);
-        gtk_table_attach_defaults(GTK_TABLE(table), serverMessageLabel,
-                                  1, 2, 0, 1);
-    }
-
-    authData->loginEntry = table_add_entry(table, hasRealm ? 1 : 0, _("Username:"),
-                                           login, NULL);
-    authData->passwordEntry = table_add_entry(table, hasRealm ? 2 : 1, _("Password:"),
-                                              password, NULL);
-
-    gtk_entry_set_visibility(GTK_ENTRY(authData->passwordEntry), FALSE);
-
-    if (session_can_save_passwords(authData->session)) {
-        rememberBox = gtk_vbox_new(FALSE, 6);
-        gtk_box_pack_start(GTK_BOX(vbox), rememberBox,
-                           FALSE, FALSE, 0);
-        checkButton = gtk_check_button_new_with_mnemonic(_("_Remember password"));
-        if (login && password)
-            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkButton), TRUE);
-        gtk_label_set_line_wrap(GTK_LABEL(gtk_bin_get_child(GTK_BIN(checkButton))), TRUE);
-        gtk_box_pack_start(GTK_BOX(rememberBox), checkButton, FALSE, FALSE, 0);
-        authData->checkButton = checkButton;
-    }
-
-    g_signal_connect(dialog, "response", G_CALLBACK(response_callback), authData);
-    gtk_widget_show_all(widget);
-}
-
-static void session_authenticate(SoupSession* session, SoupMessage* msg, SoupAuth* auth, gboolean retrying, gpointer user_data)
-{
-    SoupURI* uri;
-    WebKitAuthData* authData;
-    SoupSessionFeature* manager = (SoupSessionFeature*)user_data;
-#ifdef SOUP_TYPE_PASSWORD_MANAGER
-    GSList* users;
-#endif
-    const char *login, *password;
-
-    soup_session_pause_message(session, msg);
-    /* We need to make sure the message sticks around when pausing it */
-    g_object_ref(msg);
-
-    uri = soup_message_get_uri(msg);
-    authData = g_slice_new0(WebKitAuthData);
-    authData->msg = msg;
-    authData->auth = auth;
-    authData->session = session;
-    authData->manager = manager;
-
-    login = password = NULL;
-
-#ifdef SOUP_TYPE_PASSWORD_MANAGER
-    users = soup_auth_get_saved_users(auth);
-    if (users) {
-        login = users->data;
-        password = soup_auth_get_saved_password(auth, login);
-        g_slist_free(users);
-    }
-#endif
-
-    show_auth_dialog(authData, login, password);
-}
-
-static void attach(SoupSessionFeature* manager, SoupSession* session)
-{
-    g_signal_connect(session, "authenticate", G_CALLBACK(session_authenticate), manager);
-}
-
-static void detach(SoupSessionFeature* manager, SoupSession* session)
-{
-    g_signal_handlers_disconnect_by_func(session, session_authenticate, manager);
-}
-
-

Added: trunk/Source/WebKit/gtk/webkit/webkitsoupauthdialog.cpp (0 => 88800)


--- trunk/Source/WebKit/gtk/webkit/webkitsoupauthdialog.cpp	                        (rev 0)
+++ trunk/Source/WebKit/gtk/webkit/webkitsoupauthdialog.cpp	2011-06-14 14:36:50 UTC (rev 88800)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2009 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "webkitsoupauthdialog.h"
+
+#include "GtkAuthenticationDialog.h"
+#include "webkitmarshal.h"
+
+using namespace WebCore;
+
+/**
+ * SECTION:webkitsoupauthdialog
+ * @short_description: A #SoupSessionFeature to provide a simple
+ * authentication dialog for HTTP basic auth support.
+ *
+ * #WebKitSoupAuthDialog is a #SoupSessionFeature that you can attach to your
+ * #SoupSession to provide a simple authentication dialog while
+ * handling HTTP basic auth.
+ */
+
+static void webkit_soup_auth_dialog_session_feature_init(SoupSessionFeatureInterface*, gpointer);
+static void attach(SoupSessionFeature*, SoupSession*);
+static void detach(SoupSessionFeature*, SoupSession*);
+
+enum {
+    CURRENT_TOPLEVEL,
+    LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE_WITH_CODE(WebKitSoupAuthDialog, webkit_soup_auth_dialog, G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE(SOUP_TYPE_SESSION_FEATURE,
+                                              webkit_soup_auth_dialog_session_feature_init))
+
+static void webkit_soup_auth_dialog_class_init(WebKitSoupAuthDialogClass* klass)
+{
+    GObjectClass* objectClass = G_OBJECT_CLASS(klass);
+
+    /**
+     * WebKitSoupAuthDialog::current-toplevel:
+     * @authDialog: the object on which the signal is emitted
+     * @message: the #SoupMessage being used in the authentication process
+     *
+     * This signal is emitted by the @authDialog when it needs to know
+     * the current toplevel widget in order to correctly set the
+     * transiency for the authentication dialog.
+     *
+     * Return value: (transfer none): the current toplevel #GtkWidget or %NULL if there's none
+     *
+     * Since: 1.1.1
+     */
+    signals[CURRENT_TOPLEVEL] =
+      g_signal_new("current-toplevel",
+                   G_OBJECT_CLASS_TYPE(objectClass),
+                   G_SIGNAL_RUN_LAST,
+                   G_STRUCT_OFFSET(WebKitSoupAuthDialogClass, current_toplevel),
+                   0, 0,
+                   webkit_marshal_OBJECT__OBJECT,
+                   GTK_TYPE_WIDGET, 1,
+                   SOUP_TYPE_MESSAGE);
+}
+
+static void webkit_soup_auth_dialog_init(WebKitSoupAuthDialog*)
+{
+}
+
+static void webkit_soup_auth_dialog_session_feature_init(SoupSessionFeatureInterface *featureInterface, gpointer)
+{
+    featureInterface->attach = attach;
+    featureInterface->detach = detach;
+}
+
+static void sessionAuthenticate(SoupSession* session, SoupMessage* message, SoupAuth* auth, gboolean, SoupSessionFeature* manager)
+{
+    GtkAuthenticationDialog* authDialog;
+    GtkWidget* toplevel = 0;
+
+    /* Get the current toplevel */
+    g_signal_emit(manager, signals[CURRENT_TOPLEVEL], 0, message, &toplevel);
+
+    authDialog = new GtkAuthenticationDialog(toplevel ? GTK_WINDOW(toplevel) : 0, session, message, auth);
+    authDialog->show();
+}
+
+static void attach(SoupSessionFeature* manager, SoupSession* session)
+{
+    g_signal_connect(session, "authenticate", G_CALLBACK(sessionAuthenticate), manager);
+}
+
+static void detach(SoupSessionFeature* manager, SoupSession* session)
+{
+    g_signal_handlers_disconnect_by_func(session, reinterpret_cast<gpointer>(sessionAuthenticate), manager);
+}
+
+

Modified: trunk/Source/WebKit/gtk/webkit/webkitsoupauthdialog.h (88799 => 88800)


--- trunk/Source/WebKit/gtk/webkit/webkitsoupauthdialog.h	2011-06-14 14:07:55 UTC (rev 88799)
+++ trunk/Source/WebKit/gtk/webkit/webkitsoupauthdialog.h	2011-06-14 14:36:50 UTC (rev 88800)
@@ -21,6 +21,7 @@
 #define webkitsoupauthdialog_h
 
 #include <gtk/gtk.h>
+#include <libsoup/soup.h>
 #include <webkit/webkitdefines.h>
 
 G_BEGIN_DECLS

Modified: trunk/Source/WebKit2/ChangeLog (88799 => 88800)


--- trunk/Source/WebKit2/ChangeLog	2011-06-14 14:07:55 UTC (rev 88799)
+++ trunk/Source/WebKit2/ChangeLog	2011-06-14 14:36:50 UTC (rev 88800)
@@ -1,3 +1,25 @@
+2011-06-14  Carlos Garcia Campos  <[email protected]>
+
+        Reviewed by Martin Robinson.
+
+        [GTK] Support authentication dialogs in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=62366
+
+        Add a new soup feature to show an authentication dialog when it
+        gets a 401 HTTP response.
+
+        * GNUmakefile.am: Add new files to compilation.
+        * WebProcess/gtk/WebAuthDialog.cpp: Added.
+        (web_auth_dialog_class_init):
+        (web_auth_dialog_init):
+        (sessionAuthenticate):
+        (attach):
+        (detach):
+        (webAuthDialogSessionFeatureInit):
+        * WebProcess/gtk/WebAuthDialog.h: Added.
+        * WebProcess/gtk/WebProcessMainGtk.cpp:
+        (WebKit::WebProcessMainGtk):
+
 2011-06-14  No'am Rosenthal  <[email protected]> and Viatcheslav Ostapenko <[email protected]>
 
         Reviewed by Kenneth Rohde Christiansen.

Modified: trunk/Source/WebKit2/GNUmakefile.am (88799 => 88800)


--- trunk/Source/WebKit2/GNUmakefile.am	2011-06-14 14:07:55 UTC (rev 88799)
+++ trunk/Source/WebKit2/GNUmakefile.am	2011-06-14 14:36:50 UTC (rev 88800)
@@ -526,6 +526,8 @@
 	Source/WebKit2/WebProcess/Geolocation/GeolocationPermissionRequestManager.h \
 	Source/WebKit2/WebProcess/Geolocation/WebGeolocationManager.cpp \
 	Source/WebKit2/WebProcess/Geolocation/WebGeolocationManager.h \
+	Source/WebKit2/WebProcess/gtk/WebAuthDialog.cpp \
+	Source/WebKit2/WebProcess/gtk/WebAuthDialog.h \
 	Source/WebKit2/WebProcess/gtk/WebProcessGtk.cpp \
 	Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp \
 	Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.h \

Added: trunk/Source/WebKit2/WebProcess/gtk/WebAuthDialog.cpp (0 => 88800)


--- trunk/Source/WebKit2/WebProcess/gtk/WebAuthDialog.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/gtk/WebAuthDialog.cpp	2011-06-14 14:36:50 UTC (rev 88800)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebAuthDialog.h"
+
+#include <WebCore/GtkAuthenticationDialog.h>
+
+typedef struct {
+    GObject parent;
+} WebAuthDialog;
+
+typedef struct {
+    GObjectClass parent;
+} WebAuthDialogClass;
+
+static void webAuthDialogSessionFeatureInit(SoupSessionFeatureInterface*, gpointer);
+
+G_DEFINE_TYPE_WITH_CODE(WebAuthDialog, web_auth_dialog, G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE(SOUP_TYPE_SESSION_FEATURE,
+                                              webAuthDialogSessionFeatureInit))
+
+static void web_auth_dialog_class_init(WebAuthDialogClass*)
+{
+}
+
+static void web_auth_dialog_init(WebAuthDialog*)
+{
+}
+
+static void sessionAuthenticate(SoupSession* session, SoupMessage* message, SoupAuth* auth, gboolean, gpointer)
+{
+    WebCore::GtkAuthenticationDialog* authDialog = new WebCore::GtkAuthenticationDialog(0, session, message, auth);
+    authDialog->show();
+}
+
+static void attach(SoupSessionFeature*, SoupSession* session)
+{
+    g_signal_connect(session, "authenticate", G_CALLBACK(sessionAuthenticate), 0);
+}
+
+static void detach(SoupSessionFeature*, SoupSession* session)
+{
+    g_signal_handlers_disconnect_by_func(session, reinterpret_cast<gpointer>(sessionAuthenticate), 0);
+}
+
+static void webAuthDialogSessionFeatureInit(SoupSessionFeatureInterface* feature, gpointer)
+{
+    feature->attach = attach;
+    feature->detach = detach;
+}

Added: trunk/Source/WebKit2/WebProcess/gtk/WebAuthDialog.h (0 => 88800)


--- trunk/Source/WebKit2/WebProcess/gtk/WebAuthDialog.h	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/gtk/WebAuthDialog.h	2011-06-14 14:36:50 UTC (rev 88800)
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebAuthDialog_h
+#define WebAuthDialog_h
+
+#include <glib-object.h>
+
+#define WEB_TYPE_AUTH_DIALOG (web_auth_dialog_get_type())
+
+GType web_auth_dialog_get_type();
+
+#endif // WebAuthDialog_h

Modified: trunk/Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp (88799 => 88800)


--- trunk/Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp	2011-06-14 14:07:55 UTC (rev 88799)
+++ trunk/Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp	2011-06-14 14:36:50 UTC (rev 88800)
@@ -27,7 +27,9 @@
 #include "config.h"
 #include "WebProcessMainGtk.h"
 
+#include "WebAuthDialog.h"
 #include "WKBase.h"
+#include <WebCore/GtkAuthenticationDialog.h>
 #include <WebCore/ResourceHandle.h>
 #include <WebKit2/RunLoop.h>
 #include <WebKit2/WebProcess.h>
@@ -56,12 +58,14 @@
     RunLoop::initializeMainRunLoop();
     SoupSession* session = WebCore::ResourceHandle::defaultSession();
 
-    SoupSessionFeature* sniffer = static_cast<SoupSessionFeature*>(g_object_new(SOUP_TYPE_CONTENT_SNIFFER, NULL));
-    soup_session_add_feature(session, sniffer);
-    g_object_unref(sniffer);
+    GRefPtr<SoupSessionFeature> sniffer = adoptGRef(static_cast<SoupSessionFeature*>(g_object_new(SOUP_TYPE_CONTENT_SNIFFER, NULL)));
+    soup_session_add_feature(session, sniffer.get());
 
     soup_session_add_feature_by_type(session, SOUP_TYPE_CONTENT_DECODER);
 
+    GRefPtr<SoupSessionFeature> authDialog = adoptGRef(static_cast<SoupSessionFeature*>(g_object_new(WEB_TYPE_AUTH_DIALOG, NULL)));
+    soup_session_add_feature(session, authDialog.get());
+
     int socket = atoi(argv[1]);
     WebProcess::shared().initialize(socket, RunLoop::main());
     RunLoop::run();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to