[GTK] Merge WebKitAuthenticationWidget into WebKitAuthenticationDialog
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Sep 2014 08:59:45 +0000 (08:59 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Sep 2014 08:59:45 +0000 (08:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136700

Reviewed by Sergio Villar Senin.

Source/WebCore:

Remove WebKitAuthenticationWidget. The only reason why we had this
widget separated in WebCore was to share it between WebKit1 and
WebKit2, but now it's only used by WebKitAuthenticationDialog in WebKit2.

* PlatformGTK.cmake: Remove files from compilation.
* platform/gtk/WebKitAuthenticationWidget.cpp: Removed.
* platform/gtk/WebKitAuthenticationWidget.h: Removed.

Source/WebCore/platform/gtk/po:

* POTFILES.in: Remove WebKitAuthenticationWidget.cpp and add WebKitAuthenticationDialog.cpp.

Source/WebKit2:

Copy WebKitAuthenticationWidget implementation inside
WebKitAuthenticationDialog using a normal GtkBox instead.

* UIProcess/API/gtk/WebKitAuthenticationDialog.cpp:
(okButtonClicked):
(cancelButtonClicked):
(packTwoColumnLayoutInBox):
(createLabel):
(createEntry):
(webkitAuthenticationDialogInitialize): Remove the
CredentialStorageMode parameter since it's now a member.
(webkitAuthenticationDialogNew): Initialize the
CredentialStorageMode member too.
* UIProcess/API/gtk/WebKitAuthenticationDialog.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@173510 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/PlatformGTK.cmake
Source/WebCore/platform/gtk/WebKitAuthenticationWidget.cpp [deleted file]
Source/WebCore/platform/gtk/WebKitAuthenticationWidget.h [deleted file]
Source/WebCore/platform/gtk/po/ChangeLog
Source/WebCore/platform/gtk/po/POTFILES.in
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.h

index dfaae16..e6cc516 100644 (file)
@@ -1,3 +1,18 @@
+2014-09-11  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Merge WebKitAuthenticationWidget into WebKitAuthenticationDialog
+        https://bugs.webkit.org/show_bug.cgi?id=136700
+
+        Reviewed by Sergio Villar Senin.
+
+        Remove WebKitAuthenticationWidget. The only reason why we had this
+        widget separated in WebCore was to share it between WebKit1 and
+        WebKit2, but now it's only used by WebKitAuthenticationDialog in WebKit2.
+
+        * PlatformGTK.cmake: Remove files from compilation.
+        * platform/gtk/WebKitAuthenticationWidget.cpp: Removed.
+        * platform/gtk/WebKitAuthenticationWidget.h: Removed.
+
 2014-09-10  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Use ASSERT instead of ASSERT_WITH_SECURITY_IMPLICATION
index 2c954ab..854c49c 100644 (file)
@@ -244,7 +244,6 @@ list(APPEND WebCorePlatformGTK_SOURCES
     platform/gtk/SoundGtk.cpp
     platform/gtk/TemporaryLinkStubs.cpp
     platform/gtk/UserAgentGtk.cpp
-    platform/gtk/WebKitAuthenticationWidget.cpp
     platform/gtk/WidgetBackingStoreGtkX11.cpp
     platform/gtk/WidgetGtk.cpp
 
diff --git a/Source/WebCore/platform/gtk/WebKitAuthenticationWidget.cpp b/Source/WebCore/platform/gtk/WebKitAuthenticationWidget.cpp
deleted file mode 100644 (file)
index 77806ef..0000000
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Copyright (C) 2012 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 "WebKitAuthenticationWidget.h"
-
-#include "CredentialBackingStore.h"
-#include "GtkVersioning.h"
-#include <glib/gi18n-lib.h>
-#include <wtf/gobject/GUniquePtr.h>
-#include <wtf/text/CString.h>
-
-using namespace WebCore;
-
-struct _WebKitAuthenticationWidgetPrivate {
-    AuthenticationChallenge challenge;
-    CredentialStorageMode credentialStorageMode;
-
-    GtkWidget* loginEntry;
-    GtkWidget* passwordEntry;
-    GtkWidget* rememberCheckButton;
-};
-
-G_DEFINE_TYPE(WebKitAuthenticationWidget, webkit_authentication_widget, GTK_TYPE_BOX)
-
-static const int gLayoutColumnSpacing = 12;
-static const int gLayoutRowSpacing = 6;
-static const int gButtonSpacing = 5;
-
-#ifdef GTK_API_VERSION_2
-static void packTwoColumnLayoutInBox(GtkWidget* box, ...)
-{
-    va_list argumentList;
-    va_start(argumentList, box);
-
-    GtkWidget* table = gtk_table_new(1, 2, FALSE);
-    gtk_table_set_col_spacings(GTK_TABLE(table), gLayoutColumnSpacing);
-    gtk_table_set_row_spacings(GTK_TABLE(table), gLayoutRowSpacing);
-
-    GtkWidget* firstColumnWidget = va_arg(argumentList, GtkWidget*);
-    int rowNumber = 0;
-    while (firstColumnWidget) {
-        if (rowNumber)
-            gtk_table_resize(GTK_TABLE(table), rowNumber + 1, 2);
-
-        GtkWidget* secondColumnWidget = va_arg(argumentList, GtkWidget*);
-        GtkAttachOptions attachOptions = static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL);
-        gtk_table_attach(
-            GTK_TABLE(table), firstColumnWidget,
-            0, secondColumnWidget ? 1 : 2,
-            rowNumber, rowNumber + 1,
-            attachOptions, attachOptions,
-            0, 0);
-        gtk_widget_show(firstColumnWidget);
-
-        if (secondColumnWidget) {
-            gtk_table_attach_defaults(GTK_TABLE(table), secondColumnWidget, 1, 2, rowNumber, rowNumber + 1);
-            gtk_widget_show(secondColumnWidget);
-        }
-
-        firstColumnWidget = va_arg(argumentList, GtkWidget*);
-        rowNumber++;
-    }
-
-    va_end(argumentList);
-
-    gtk_box_pack_start(GTK_BOX(box), table, FALSE, FALSE, 0);
-    gtk_widget_show(table);
-}
-#else
-static void packTwoColumnLayoutInBox(GtkWidget* box, ...)
-{
-    va_list argumentList;
-    va_start(argumentList, box);
-
-    GtkWidget* grid = gtk_grid_new();
-    gtk_grid_set_column_spacing(GTK_GRID(grid), gLayoutRowSpacing);
-    gtk_grid_set_row_spacing(GTK_GRID(grid), gLayoutRowSpacing);
-    gtk_grid_set_column_homogeneous(GTK_GRID(grid), TRUE);
-
-    GtkWidget* firstColumnWidget = va_arg(argumentList, GtkWidget*);
-    int rowNumber = 0;
-    while (firstColumnWidget) {
-        GtkWidget* secondColumnWidget = va_arg(argumentList, GtkWidget*);
-        int firstWidgetWidth = secondColumnWidget ? 1 : 2;
-
-        gtk_grid_attach(GTK_GRID(grid), firstColumnWidget, 0, rowNumber, firstWidgetWidth, 1);
-        gtk_widget_set_hexpand(firstColumnWidget, TRUE);
-        gtk_widget_set_vexpand(firstColumnWidget, TRUE);
-        gtk_widget_show(firstColumnWidget);
-
-        if (secondColumnWidget) {
-            gtk_grid_attach(GTK_GRID(grid), secondColumnWidget, 1, rowNumber, 1, 1);
-            gtk_widget_set_hexpand(secondColumnWidget, TRUE);
-            gtk_widget_set_vexpand(secondColumnWidget, TRUE);
-            gtk_widget_show(secondColumnWidget);
-        }
-
-        firstColumnWidget = va_arg(argumentList, GtkWidget*);
-        rowNumber++;
-    }
-
-    va_end(argumentList);
-
-    gtk_box_pack_start(GTK_BOX(box), grid, FALSE, FALSE, 0);
-    gtk_widget_show(grid);
-}
-#endif
-
-static GtkWidget* createLabel(const char* labelString, int horizontalPadding = 0)
-{
-    GtkWidget* label = gtk_label_new(labelString);
-    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-    if (horizontalPadding)
-        gtk_misc_set_padding(GTK_MISC(label), 0, horizontalPadding);
-    return label;
-}
-
-static GtkWidget* createEntry(GtkWidget** member)
-{
-    *member = gtk_entry_new();
-    gtk_entry_set_activates_default(GTK_ENTRY(*member), TRUE);
-    return *member;
-}
-
-static void webkitAuthenticationWidgetInitialize(WebKitAuthenticationWidget* authWidget)
-{
-    gtk_orientable_set_orientation(GTK_ORIENTABLE(authWidget), GTK_ORIENTATION_HORIZONTAL);
-    gtk_box_set_spacing(GTK_BOX(authWidget), gLayoutColumnSpacing);
-    gtk_container_set_border_width(GTK_CONTAINER(authWidget), gButtonSpacing);
-
-    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(authWidget), icon, FALSE, FALSE, 0);
-    gtk_widget_show(icon);
-
-    WebKitAuthenticationWidgetPrivate* priv = authWidget->priv;
-    GUniquePtr<char> prompt(g_strdup_printf(
-        _("The site %s:%i requests a username and password"),
-        priv->challenge.protectionSpace().host().utf8().data(),
-        priv->challenge.protectionSpace().port()));
-
-    priv->rememberCheckButton = gtk_check_button_new_with_mnemonic(_("_Remember password"));
-    gtk_label_set_line_wrap(GTK_LABEL(gtk_bin_get_child(GTK_BIN(priv->rememberCheckButton))), TRUE);
-
-    String realm = authWidget->priv->challenge.protectionSpace().realm();
-    if (!realm.isEmpty()) {
-        packTwoColumnLayoutInBox(
-            GTK_WIDGET(authWidget),
-            createLabel(prompt.get(), gLayoutRowSpacing), NULL,
-            createLabel(_("Server message:")), createLabel(realm.utf8().data()),
-            createLabel(_("Username:")), createEntry(&priv->loginEntry),
-            createLabel(_("Password:")), createEntry(&priv->passwordEntry),
-            priv->rememberCheckButton, NULL,
-            NULL);
-
-    } else {
-        packTwoColumnLayoutInBox(
-            GTK_WIDGET(authWidget),
-            createLabel(prompt.get(), gLayoutRowSpacing), NULL,
-            createLabel(_("Username:")), createEntry(&priv->loginEntry),
-            createLabel(_("Password:")), createEntry(&priv->passwordEntry),
-            priv->rememberCheckButton, NULL, NULL,
-            NULL);
-    }
-    gtk_entry_set_visibility(GTK_ENTRY(priv->passwordEntry), FALSE);
-    gtk_widget_set_visible(priv->rememberCheckButton, priv->credentialStorageMode != DisallowPersistentStorage);
-
-    const Credential& credentialFromPersistentStorage = priv->challenge.proposedCredential();
-    if (!credentialFromPersistentStorage.isEmpty()) {
-        gtk_entry_set_text(GTK_ENTRY(priv->loginEntry), credentialFromPersistentStorage.user().utf8().data());
-        gtk_entry_set_text(GTK_ENTRY(priv->passwordEntry), credentialFromPersistentStorage.password().utf8().data());
-        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->rememberCheckButton), TRUE);
-    }
-
-    gtk_widget_grab_focus(priv->loginEntry);
-}
-
-static void webkitAuthenticationWidgetFinalize(GObject* object)
-{
-    WEBKIT_AUTHENTICATION_WIDGET(object)->priv->~WebKitAuthenticationWidgetPrivate();
-    G_OBJECT_CLASS(webkit_authentication_widget_parent_class)->finalize(object);
-}
-
-static void webkit_authentication_widget_init(WebKitAuthenticationWidget* authWidget)
-{
-    WebKitAuthenticationWidgetPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(authWidget, WEBKIT_TYPE_AUTHENTICATION_WIDGET, WebKitAuthenticationWidgetPrivate);
-    new (priv) WebKitAuthenticationWidgetPrivate();
-    authWidget->priv = priv;
-}
-
-static void webkit_authentication_widget_class_init(WebKitAuthenticationWidgetClass* klass)
-{
-    GObjectClass* objectClass = G_OBJECT_CLASS(klass);
-    objectClass->finalize = webkitAuthenticationWidgetFinalize;
-    g_type_class_add_private(objectClass, sizeof(WebKitAuthenticationWidgetPrivate));
-}
-
-GtkWidget* webkitAuthenticationWidgetNew(const AuthenticationChallenge& challenge, CredentialStorageMode mode)
-{
-    WebKitAuthenticationWidget* authWidget = WEBKIT_AUTHENTICATION_WIDGET(g_object_new(WEBKIT_TYPE_AUTHENTICATION_WIDGET, NULL));
-    authWidget->priv->challenge = challenge;
-    authWidget->priv->credentialStorageMode = mode;
-    webkitAuthenticationWidgetInitialize(authWidget);
-    return GTK_WIDGET(authWidget);
-}
-
-Credential webkitAuthenticationWidgetCreateCredential(WebKitAuthenticationWidget* authWidget)
-{
-    const char* username = gtk_entry_get_text(GTK_ENTRY(authWidget->priv->loginEntry));
-    const char* password = gtk_entry_get_text(GTK_ENTRY(authWidget->priv->passwordEntry));
-    bool rememberPassword = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(authWidget->priv->rememberCheckButton));
-
-    CredentialPersistence persistence;
-    if (rememberPassword && authWidget->priv->credentialStorageMode == AllowPersistentStorage)
-        persistence = CredentialPersistencePermanent;
-    else
-        persistence = CredentialPersistenceForSession;
-    return Credential(String::fromUTF8(username), String::fromUTF8(password), persistence);
-}
-
-AuthenticationChallenge& webkitAuthenticationWidgetGetChallenge(WebKitAuthenticationWidget* authWidget)
-{
-    return authWidget->priv->challenge;
-}
diff --git a/Source/WebCore/platform/gtk/WebKitAuthenticationWidget.h b/Source/WebCore/platform/gtk/WebKitAuthenticationWidget.h
deleted file mode 100644 (file)
index d6b93dc..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2012 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 WebKitAuthenticationWidget_h
-#define WebKitAuthenticationWidget_h
-
-#include "AuthenticationChallenge.h"
-#include <gtk/gtk.h>
-
-enum CredentialStorageMode {
-    AllowPersistentStorage, // The user is asked whether to store credential information.
-    DisallowPersistentStorage // Credential information is only kept in the session.
-};
-
-G_BEGIN_DECLS
-
-#define WEBKIT_TYPE_AUTHENTICATION_WIDGET            (webkit_authentication_widget_get_type())
-#define WEBKIT_AUTHENTICATION_WIDGET(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_AUTHENTICATION_WIDGET, WebKitAuthenticationWidget))
-#define WEBKIT_IS_AUTHENTICATION_WIDGET(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_AUTHENTICATION_WIDGET))
-#define WEBKIT_AUTHENTICATION_WIDGET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_AUTHENTICATION_WIDGET, WebKitAuthenticationWidgetClass))
-#define WEBKIT_IS_AUTHENTICATION_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_AUTHENTICATION_WIDGET))
-#define WEBKIT_AUTHENTICATION_WIDGET_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_AUTHENTICATION_WIDGET, WebKitAuthenticationWidgetClass))
-
-typedef struct _WebKitAuthenticationWidget        WebKitAuthenticationWidget;
-typedef struct _WebKitAuthenticationWidgetClass   WebKitAuthenticationWidgetClass;
-typedef struct _WebKitAuthenticationWidgetPrivate WebKitAuthenticationWidgetPrivate;
-
-struct _WebKitAuthenticationWidget {
-    GtkBox parent;
-
-    WebKitAuthenticationWidgetPrivate* priv;
-};
-
-struct _WebKitAuthenticationWidgetClass {
-    GtkBoxClass parentClass;
-};
-
-GType webkit_authentication_widget_get_type();
-GtkWidget* webkitAuthenticationWidgetNew(const WebCore::AuthenticationChallenge&, CredentialStorageMode);
-WebCore::Credential webkitAuthenticationWidgetCreateCredential(WebKitAuthenticationWidget*);
-WebCore::AuthenticationChallenge& webkitAuthenticationWidgetGetChallenge(WebKitAuthenticationWidget*);
-
-G_END_DECLS
-
-#endif // WebKitAuthenticationWidget_h
index 6847f5e..2f33cc3 100644 (file)
@@ -1,3 +1,12 @@
+2014-09-11  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Merge WebKitAuthenticationWidget into WebKitAuthenticationDialog
+        https://bugs.webkit.org/show_bug.cgi?id=136700
+
+        Reviewed by Sergio Villar Senin.
+
+        * POTFILES.in: Remove WebKitAuthenticationWidget.cpp and add WebKitAuthenticationDialog.cpp.
+
 2014-09-02  Christian Stadelmann  <gnome-de@genodeftest.de>
 
         [GTK] Updated German translation
index 8ad365e..b4bffd8 100644 (file)
@@ -1,8 +1,8 @@
 # List of source files which contain translatable strings.
 ErrorsGtk.cpp
 LocalizedStringsGtk.cpp
-WebKitAuthenticationWidget.cpp
 ../../../WebKit2/Shared/Downloads/soup/DownloadSoup.cpp
+../../../WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp
 ../../../WebKit2/UIProcess/API/gtk/WebKitDownload.cpp
 ../../../WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.cpp
 ../../../WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.cpp
index 656058b..19dc3cf 100644 (file)
@@ -1,3 +1,25 @@
+2014-09-11  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Merge WebKitAuthenticationWidget into WebKitAuthenticationDialog
+        https://bugs.webkit.org/show_bug.cgi?id=136700
+
+        Reviewed by Sergio Villar Senin.
+
+        Copy WebKitAuthenticationWidget implementation inside
+        WebKitAuthenticationDialog using a normal GtkBox instead.
+
+        * UIProcess/API/gtk/WebKitAuthenticationDialog.cpp:
+        (okButtonClicked):
+        (cancelButtonClicked):
+        (packTwoColumnLayoutInBox):
+        (createLabel):
+        (createEntry):
+        (webkitAuthenticationDialogInitialize): Remove the
+        CredentialStorageMode parameter since it's now a member.
+        (webkitAuthenticationDialogNew): Initialize the
+        CredentialStorageMode member too.
+        * UIProcess/API/gtk/WebKitAuthenticationDialog.h:
+
 2014-09-10  Antti Koivisto  <antti@apple.com>
 
         NetworkResourceLoader cleanups
index 43cd83a..3f948fb 100644 (file)
 #include "WebKitCredentialPrivate.h"
 #include "WebKitPrivate.h"
 #include "WebKitWebView.h"
+#include <glib/gi18n-lib.h>
+#include <wtf/text/CString.h>
 
 using namespace WebKit;
 
 struct _WebKitAuthenticationDialogPrivate {
     GRefPtr<WebKitAuthenticationRequest> request;
-    GtkWidget* authWidget;
+    CredentialStorageMode credentialStorageMode;
+    GtkWidget* loginEntry;
+    GtkWidget* passwordEntry;
+    GtkWidget* rememberCheckButton;
     GtkWidget* defaultButton;
     unsigned long authenticationCancelledID;
     GRefPtr<GtkStyleContext> styleContext;
@@ -41,7 +46,15 @@ WEBKIT_DEFINE_TYPE(WebKitAuthenticationDialog, webkit_authentication_dialog, GTK
 static void okButtonClicked(GtkButton*, WebKitAuthenticationDialog* authDialog)
 {
     WebKitAuthenticationDialogPrivate* priv = authDialog->priv;
-    WebKitCredential* credential = webkitCredentialCreate(webkitAuthenticationWidgetCreateCredential(WEBKIT_AUTHENTICATION_WIDGET(priv->authWidget)));
+    const char* username = gtk_entry_get_text(GTK_ENTRY(priv->loginEntry));
+    const char* password = gtk_entry_get_text(GTK_ENTRY(priv->passwordEntry));
+    bool rememberPassword = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->rememberCheckButton));
+
+    WebCore::CredentialPersistence persistence = rememberPassword && priv->credentialStorageMode == AllowPersistentStorage ?
+        WebCore::CredentialPersistencePermanent : WebCore::CredentialPersistenceForSession;
+
+    // FIXME: Use a stack allocated WebKitCredential.
+    WebKitCredential* credential = webkitCredentialCreate(WebCore::Credential(String::fromUTF8(username), String::fromUTF8(password), persistence));
     webkit_authentication_request_authenticate(priv->request.get(), credential);
     webkit_credential_free(credential);
     gtk_widget_destroy(GTK_WIDGET(authDialog));
@@ -49,7 +62,7 @@ static void okButtonClicked(GtkButton*, WebKitAuthenticationDialog* authDialog)
 
 static void cancelButtonClicked(GtkButton*, WebKitAuthenticationDialog* authDialog)
 {
-    webkit_authentication_request_authenticate(authDialog->priv->request.get(), 0);
+    webkit_authentication_request_authenticate(authDialog->priv->request.get(), nullptr);
     gtk_widget_destroy(GTK_WIDGET(authDialog));
 }
 
@@ -58,7 +71,61 @@ static void authenticationCancelled(WebKitAuthenticationRequest*, WebKitAuthenti
     gtk_widget_destroy(GTK_WIDGET(authDialog));
 }
 
-static void webkitAuthenticationDialogInitialize(WebKitAuthenticationDialog* authDialog, CredentialStorageMode credentialStorageMode)
+static void packTwoColumnLayoutInBox(GtkWidget* box, ...)
+{
+    va_list argumentList;
+    va_start(argumentList, box);
+
+    GtkWidget* grid = gtk_grid_new();
+    gtk_grid_set_column_spacing(GTK_GRID(grid), 6);
+    gtk_grid_set_row_spacing(GTK_GRID(grid), 6);
+    gtk_grid_set_column_homogeneous(GTK_GRID(grid), TRUE);
+
+    GtkWidget* firstColumnWidget = va_arg(argumentList, GtkWidget*);
+    int rowNumber = 0;
+    while (firstColumnWidget) {
+        GtkWidget* secondColumnWidget = va_arg(argumentList, GtkWidget*);
+        int firstWidgetWidth = secondColumnWidget ? 1 : 2;
+
+        gtk_grid_attach(GTK_GRID(grid), firstColumnWidget, 0, rowNumber, firstWidgetWidth, 1);
+        gtk_widget_set_hexpand(firstColumnWidget, TRUE);
+        gtk_widget_set_vexpand(firstColumnWidget, TRUE);
+        gtk_widget_show(firstColumnWidget);
+
+        if (secondColumnWidget) {
+            gtk_grid_attach(GTK_GRID(grid), secondColumnWidget, 1, rowNumber, 1, 1);
+            gtk_widget_set_hexpand(secondColumnWidget, TRUE);
+            gtk_widget_set_vexpand(secondColumnWidget, TRUE);
+            gtk_widget_show(secondColumnWidget);
+        }
+
+        firstColumnWidget = va_arg(argumentList, GtkWidget*);
+        rowNumber++;
+    }
+
+    va_end(argumentList);
+
+    gtk_box_pack_start(GTK_BOX(box), grid, FALSE, FALSE, 0);
+    gtk_widget_show(grid);
+}
+
+static GtkWidget* createLabel(const char* labelString, int horizontalPadding = 0)
+{
+    GtkWidget* label = gtk_label_new(labelString);
+    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+    if (horizontalPadding)
+        gtk_misc_set_padding(GTK_MISC(label), 0, horizontalPadding);
+    return label;
+}
+
+static GtkWidget* createEntry(GtkWidget** member)
+{
+    *member = gtk_entry_new();
+    gtk_entry_set_activates_default(GTK_ENTRY(*member), TRUE);
+    return *member;
+}
+
+static void webkitAuthenticationDialogInitialize(WebKitAuthenticationDialog* authDialog)
 {
     GtkWidget* frame = gtk_frame_new(0);
     gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
@@ -76,16 +143,62 @@ static void webkitAuthenticationDialogInitialize(WebKitAuthenticationDialog* aut
     gtk_box_pack_end(GTK_BOX(buttonBox), button, FALSE, TRUE, 0);
     gtk_widget_show(button);
 
+    WebKitAuthenticationDialogPrivate* priv = authDialog->priv;
     button = gtk_button_new_from_stock(GTK_STOCK_OK);
-    authDialog->priv->defaultButton = button;
+    priv->defaultButton = button;
     g_signal_connect(button, "clicked", G_CALLBACK(okButtonClicked), authDialog);
     gtk_widget_set_can_default(button, TRUE);
     gtk_box_pack_end(GTK_BOX(buttonBox), button, FALSE, TRUE, 0);
     gtk_widget_show(button);
 
-    authDialog->priv->authWidget = webkitAuthenticationWidgetNew(webkitAuthenticationRequestGetAuthenticationChallenge(authDialog->priv->request.get())->core(), credentialStorageMode);
-    gtk_box_pack_start(GTK_BOX(vBox), authDialog->priv->authWidget, TRUE, TRUE, 0);
-    gtk_widget_show(authDialog->priv->authWidget);
+    GtkWidget* authBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
+    gtk_container_set_border_width(GTK_CONTAINER(authBox), 5);
+
+    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(authBox), icon, FALSE, FALSE, 0);
+    gtk_widget_show(icon);
+
+    const WebCore::AuthenticationChallenge& challenge = webkitAuthenticationRequestGetAuthenticationChallenge(priv->request.get())->core();
+    GUniquePtr<char> prompt(g_strdup_printf(_("The site %s:%i requests a username and password"),
+        challenge.protectionSpace().host().utf8().data(), challenge.protectionSpace().port()));
+    priv->rememberCheckButton = gtk_check_button_new_with_mnemonic(_("_Remember password"));
+    gtk_label_set_line_wrap(GTK_LABEL(gtk_bin_get_child(GTK_BIN(priv->rememberCheckButton))), TRUE);
+
+    String realm = challenge.protectionSpace().realm();
+    if (!realm.isEmpty()) {
+        packTwoColumnLayoutInBox(
+            authBox,
+            createLabel(prompt.get(), 6), nullptr,
+            createLabel(_("Server message:")), createLabel(realm.utf8().data()),
+            createLabel(_("Username:")), createEntry(&priv->loginEntry),
+            createLabel(_("Password:")), createEntry(&priv->passwordEntry),
+            priv->rememberCheckButton, nullptr,
+            nullptr);
+
+    } else {
+        packTwoColumnLayoutInBox(
+            authBox,
+            createLabel(prompt.get(), 6), nullptr,
+            createLabel(_("Username:")), createEntry(&priv->loginEntry),
+            createLabel(_("Password:")), createEntry(&priv->passwordEntry),
+            priv->rememberCheckButton, nullptr, nullptr,
+            nullptr);
+    }
+    gtk_entry_set_visibility(GTK_ENTRY(priv->passwordEntry), FALSE);
+    gtk_widget_set_visible(priv->rememberCheckButton, priv->credentialStorageMode != DisallowPersistentStorage);
+
+    const WebCore::Credential& credentialFromPersistentStorage = challenge.proposedCredential();
+    if (!credentialFromPersistentStorage.isEmpty()) {
+        gtk_entry_set_text(GTK_ENTRY(priv->loginEntry), credentialFromPersistentStorage.user().utf8().data());
+        gtk_entry_set_text(GTK_ENTRY(priv->passwordEntry), credentialFromPersistentStorage.password().utf8().data());
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->rememberCheckButton), TRUE);
+    }
+
+    gtk_widget_grab_focus(priv->loginEntry);
+
+    gtk_box_pack_start(GTK_BOX(vBox), authBox, TRUE, TRUE, 0);
+    gtk_widget_show(authBox);
 
     gtk_box_pack_end(GTK_BOX(vBox), buttonBox, FALSE, TRUE, 0);
     gtk_widget_show(buttonBox);
@@ -159,6 +272,7 @@ GtkWidget* webkitAuthenticationDialogNew(WebKitAuthenticationRequest* request, C
 {
     WebKitAuthenticationDialog* authDialog = WEBKIT_AUTHENTICATION_DIALOG(g_object_new(WEBKIT_TYPE_AUTHENTICATION_DIALOG, NULL));
     authDialog->priv->request = request;
-    webkitAuthenticationDialogInitialize(authDialog, mode);
+    authDialog->priv->credentialStorageMode = mode;
+    webkitAuthenticationDialogInitialize(authDialog);
     return GTK_WIDGET(authDialog);
 }
index e5e62a7..0e5071f 100644 (file)
 #define WebKitAuthenticationDialog_h
 
 #include "WebKitAuthenticationRequest.h"
-#include "WebKitAuthenticationWidget.h"
-#include "WebKitWebView.h"
 #include <gtk/gtk.h>
 
+enum CredentialStorageMode {
+    AllowPersistentStorage, // The user is asked whether to store credential information.
+    DisallowPersistentStorage // Credential information is only kept in the session.
+};
+
 G_BEGIN_DECLS
 
 #define WEBKIT_TYPE_AUTHENTICATION_DIALOG            (webkit_authentication_dialog_get_type())