Title: [262287] trunk/Source/WebKit
Revision
262287
Author
[email protected]
Date
2020-05-29 02:47:16 -0700 (Fri, 29 May 2020)

Log Message

[GTK4] Implement HTTP auth dialog
https://bugs.webkit.org/show_bug.cgi?id=212319

Reviewed by Sergio Villar Senin.

* UIProcess/API/gtk/WebKitAuthenticationDialog.cpp:
(webkitAuthenticationDialogDestroy):
(okButtonClicked):
(cancelButtonClicked):
(authenticationCancelled):
(webkitAuthenticationDialogInitialize):
(webkitAuthenticationDialogMap):
(webkitAuthenticationDialogDispose):
(webkitAuthenticationDialogNew):
* UIProcess/API/gtk/WebKitAuthenticationDialog.h:
* UIProcess/API/gtk/WebKitWebViewGtk.cpp:
(webkitWebViewAuthenticate):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (262286 => 262287)


--- trunk/Source/WebKit/ChangeLog	2020-05-29 09:40:52 UTC (rev 262286)
+++ trunk/Source/WebKit/ChangeLog	2020-05-29 09:47:16 UTC (rev 262287)
@@ -1,5 +1,25 @@
 2020-05-29  Carlos Garcia Campos  <[email protected]>
 
+        [GTK4] Implement HTTP auth dialog
+        https://bugs.webkit.org/show_bug.cgi?id=212319
+
+        Reviewed by Sergio Villar Senin.
+
+        * UIProcess/API/gtk/WebKitAuthenticationDialog.cpp:
+        (webkitAuthenticationDialogDestroy):
+        (okButtonClicked):
+        (cancelButtonClicked):
+        (authenticationCancelled):
+        (webkitAuthenticationDialogInitialize):
+        (webkitAuthenticationDialogMap):
+        (webkitAuthenticationDialogDispose):
+        (webkitAuthenticationDialogNew):
+        * UIProcess/API/gtk/WebKitAuthenticationDialog.h:
+        * UIProcess/API/gtk/WebKitWebViewGtk.cpp:
+        (webkitWebViewAuthenticate):
+
+2020-05-29  Carlos Garcia Campos  <[email protected]>
+
         [GTK4] Implement script dialogs
         https://bugs.webkit.org/show_bug.cgi?id=212318
 

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp (262286 => 262287)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp	2020-05-29 09:40:52 UTC (rev 262286)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp	2020-05-29 09:47:16 UTC (rev 262287)
@@ -20,12 +20,12 @@
 #include "config.h"
 #include "WebKitAuthenticationDialog.h"
 
-#if !USE(GTK4)
-
 #include "AuthenticationDecisionListener.h"
 #include "WebKitAuthenticationRequestPrivate.h"
 #include "WebKitCredentialPrivate.h"
 #include "WebKitWebView.h"
+#include <WebCore/GtkUtilities.h>
+#include <WebCore/GtkVersioning.h>
 #include <glib/gi18n-lib.h>
 #include <wtf/glib/GRefPtr.h>
 #include <wtf/glib/GUniquePtr.h>
@@ -46,6 +46,15 @@
 
 WEBKIT_DEFINE_TYPE(WebKitAuthenticationDialog, webkit_authentication_dialog, WEBKIT_TYPE_WEB_VIEW_DIALOG)
 
+static void webkitAuthenticationDialogDestroy(WebKitAuthenticationDialog* authDialog)
+{
+#if USE(GTK4)
+    gtk_widget_unparent(GTK_WIDGET(authDialog));
+#else
+    gtk_widget_destroy(GTK_WIDGET(authDialog));
+#endif
+}
+
 static void okButtonClicked(GtkButton*, WebKitAuthenticationDialog* authDialog)
 {
     WebKitAuthenticationDialogPrivate* priv = authDialog->priv;
@@ -60,18 +69,18 @@
     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));
+    webkitAuthenticationDialogDestroy(authDialog);
 }
 
 static void cancelButtonClicked(GtkButton*, WebKitAuthenticationDialog* authDialog)
 {
     webkit_authentication_request_authenticate(authDialog->priv->request.get(), nullptr);
-    gtk_widget_destroy(GTK_WIDGET(authDialog));
+    webkitAuthenticationDialogDestroy(authDialog);
 }
 
 static void authenticationCancelled(WebKitAuthenticationRequest*, WebKitAuthenticationDialog* authDialog)
 {
-    gtk_widget_destroy(GTK_WIDGET(authDialog));
+    webkitAuthenticationDialogDestroy(authDialog);
 }
 
 static GtkWidget* createLabelWithLineWrap(const char* text)
@@ -89,34 +98,54 @@
     GtkWidget* vBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 20);
 
     GtkWidget* box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
-    gtk_style_context_add_class(gtk_widget_get_style_context(box), GTK_STYLE_CLASS_TITLEBAR);
+    gtk_widget_add_css_class(box, GTK_STYLE_CLASS_TITLEBAR);
     gtk_widget_set_size_request(box, -1, 16);
     GtkWidget* title = gtk_label_new(_("Authentication Required"));
     gtk_widget_set_margin_top(title, 6);
     gtk_widget_set_margin_bottom(title, 6);
-    gtk_style_context_add_class(gtk_widget_get_style_context(title), GTK_STYLE_CLASS_TITLE);
+    gtk_widget_add_css_class(title, GTK_STYLE_CLASS_TITLE);
+#if USE(GTK4)
+    gtk_widget_set_hexpand(title, TRUE);
+    gtk_widget_set_halign(title, GTK_ALIGN_CENTER);
+    gtk_box_append(GTK_BOX(vBox), title);
+#else
     gtk_box_set_center_widget(GTK_BOX(box), title);
     gtk_widget_show(title);
     gtk_box_pack_start(GTK_BOX(vBox), box, TRUE, FALSE, 0);
     gtk_widget_show(box);
+#endif
 
+#if USE(GTK4)
+    GtkWidget* buttonBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+    gtk_box_set_homogeneous(GTK_BOX(buttonBox), TRUE);
+    gtk_widget_set_halign(buttonBox, GTK_ALIGN_FILL);
+#else
     GtkWidget* buttonBox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
     gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_EXPAND);
+#endif
     gtk_widget_set_hexpand(buttonBox, TRUE);
-    gtk_style_context_add_class(gtk_widget_get_style_context(buttonBox), "dialog-action-area");
+    gtk_widget_add_css_class(buttonBox, "dialog-action-area");
 
     GtkWidget* button = gtk_button_new_with_mnemonic(_("_Cancel"));
     g_signal_connect(button, "clicked", G_CALLBACK(cancelButtonClicked), authDialog);
+#if USE(GTK4)
+    gtk_box_append(GTK_BOX(buttonBox), button);
+#else
     gtk_box_pack_start(GTK_BOX(buttonBox), button, FALSE, TRUE, 0);
     gtk_widget_show(button);
+#endif
 
     WebKitAuthenticationDialogPrivate* priv = authDialog->priv;
     button = gtk_button_new_with_mnemonic(_("_Authenticate"));
     priv->defaultButton = button;
     g_signal_connect(button, "clicked", G_CALLBACK(okButtonClicked), authDialog);
+#if USE(GTK4)
+    gtk_box_append(GTK_BOX(buttonBox), button);
+#else
     gtk_widget_set_can_default(button, TRUE);
     gtk_box_pack_end(GTK_BOX(buttonBox), button, FALSE, TRUE, 0);
     gtk_widget_show(button);
+#endif
 
     GtkWidget* authBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
     gtk_widget_set_margin_start(authBox, 10);
@@ -127,8 +156,12 @@
     GUniquePtr<char> prompt(g_strdup_printf(_("Authentication required by %s:%i"),
         challenge.protectionSpace().host().utf8().data(), challenge.protectionSpace().port()));
     GtkWidget* label = createLabelWithLineWrap(prompt.get());
+#if USE(GTK4)
+    gtk_box_append(GTK_BOX(authBox), label);
+#else
     gtk_widget_show(label);
     gtk_box_pack_start(GTK_BOX(authBox), label, FALSE, FALSE, 0);
+#endif
 
     String realm = challenge.protectionSpace().realm();
     if (!realm.isEmpty()) {
@@ -135,13 +168,21 @@
         // Label on the HTTP authentication dialog. %s is a (probably English) message from the website.
         GUniquePtr<char> message(g_strdup_printf(_("The site says: ā€œ%sā€"), realm.utf8().data()));
         label = createLabelWithLineWrap(message.get());
+#if USE(GTK4)
+        gtk_box_append(GTK_BOX(authBox), label);
+#else
         gtk_widget_show(label);
         gtk_box_pack_start(GTK_BOX(authBox), label, FALSE, FALSE, 0);
+#endif
     }
 
     // Check button on the HTTP authentication dialog.
     priv->rememberCheckButton = gtk_check_button_new_with_mnemonic(_("_Remember password"));
+#if USE(GTK4)
+    gtk_label_set_line_wrap(GTK_LABEL(gtk_button_get_child(GTK_BUTTON(priv->rememberCheckButton))), TRUE);
+#else
     gtk_label_set_line_wrap(GTK_LABEL(gtk_bin_get_child(GTK_BIN(priv->rememberCheckButton))), TRUE);
+#endif
 
     priv->loginEntry = gtk_entry_new();
     gtk_widget_set_hexpand(priv->loginEntry, TRUE);
@@ -152,7 +193,7 @@
     GtkWidget* loginLabel = gtk_label_new_with_mnemonic(_("_Username"));
     gtk_label_set_mnemonic_widget(GTK_LABEL(loginLabel), priv->loginEntry);
     gtk_widget_set_halign(loginLabel, GTK_ALIGN_END);
-    gtk_style_context_add_class(gtk_widget_get_style_context(loginLabel), GTK_STYLE_CLASS_DIM_LABEL);
+    gtk_widget_add_css_class(loginLabel, GTK_STYLE_CLASS_DIM_LABEL);
     gtk_widget_show(loginLabel);
 
     priv->passwordEntry = gtk_entry_new();
@@ -164,7 +205,7 @@
     GtkWidget* passwordLabel = gtk_label_new_with_mnemonic(_("_Password"));
     gtk_label_set_mnemonic_widget(GTK_LABEL(passwordLabel), priv->passwordEntry);
     gtk_widget_set_halign(passwordLabel, GTK_ALIGN_END);
-    gtk_style_context_add_class(gtk_widget_get_style_context(passwordLabel), GTK_STYLE_CLASS_DIM_LABEL);
+    gtk_widget_add_css_class(passwordLabel, GTK_STYLE_CLASS_DIM_LABEL);
     gtk_widget_show(passwordLabel);
 
     GtkWidget* grid = gtk_grid_new();
@@ -175,8 +216,12 @@
     gtk_grid_attach(GTK_GRID(grid), passwordLabel, 0, 1, 1, 1);
     gtk_grid_attach(GTK_GRID(grid), priv->passwordEntry, 1, 1, 1, 1);
     gtk_grid_attach(GTK_GRID(grid), priv->rememberCheckButton, 1, 2, 1, 1);
+#if USE(GTK4)
+    gtk_box_append(GTK_BOX(authBox), grid);
+#else
     gtk_widget_show(grid);
     gtk_box_pack_start(GTK_BOX(authBox), grid, FALSE, FALSE, 0);
+#endif
 
     gtk_entry_set_visibility(GTK_ENTRY(priv->passwordEntry), FALSE);
     gtk_widget_set_visible(priv->rememberCheckButton, priv->credentialStorageMode != DisallowPersistentStorage && !realm.isEmpty());
@@ -188,14 +233,27 @@
         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->rememberCheckButton), TRUE);
     }
 
+#if USE(GTK4)
+    gtk_box_append(GTK_BOX(vBox), authBox);
+#else
     gtk_box_pack_start(GTK_BOX(vBox), authBox, TRUE, TRUE, 0);
     gtk_widget_show(authBox);
+#endif
 
+#if USE(GTK4)
+    gtk_box_append(GTK_BOX(vBox), buttonBox);
+#else
     gtk_box_pack_end(GTK_BOX(vBox), buttonBox, FALSE, TRUE, 0);
     gtk_widget_show(buttonBox);
+#endif
 
+#if USE(GTK4)
+    gtk_widget_add_css_class(vBox, "dialog-vbox");
+    webkitWebViewDialogSetChild(WEBKIT_WEB_VIEW_DIALOG(authDialog), vBox);
+#else
     gtk_container_add(GTK_CONTAINER(authDialog), vBox);
     gtk_widget_show(vBox);
+#endif
 
     authDialog->priv->authenticationCancelledID = g_signal_connect(authDialog->priv->request.get(), "cancelled", G_CALLBACK(authenticationCancelled), authDialog);
 }
@@ -204,7 +262,9 @@
 {
     WebKitAuthenticationDialogPrivate* priv = WEBKIT_AUTHENTICATION_DIALOG(widget)->priv;
     gtk_widget_grab_focus(priv->loginEntry);
-    gtk_widget_grab_default(priv->defaultButton);
+    auto* toplevel = gtk_widget_get_toplevel(widget);
+    if (WebCore::widgetIsOnscreenToplevelWindow(toplevel))
+        gtk_window_set_default(GTK_WINDOW(toplevel), priv->defaultButton);
 
     GTK_WIDGET_CLASS(webkit_authentication_dialog_parent_class)->map(widget);
 }
@@ -217,6 +277,10 @@
         priv->authenticationCancelledID = 0;
     }
 
+#if USE(GTK4)
+    webkitWebViewDialogSetChild(WEBKIT_WEB_VIEW_DIALOG(object), nullptr);
+#endif
+
     G_OBJECT_CLASS(webkit_authentication_dialog_parent_class)->dispose(object);
 }
 
@@ -237,5 +301,3 @@
     webkitAuthenticationDialogInitialize(authDialog);
     return GTK_WIDGET(authDialog);
 }
-
-#endif

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.h (262286 => 262287)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.h	2020-05-29 09:40:52 UTC (rev 262286)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitAuthenticationDialog.h	2020-05-29 09:47:16 UTC (rev 262287)
@@ -19,8 +19,6 @@
 
 #pragma once
 
-#if !USE(GTK4)
-
 #include "WebKitAuthenticationRequest.h"
 #include "WebKitWebViewDialog.h"
 #include <gtk/gtk.h>
@@ -57,5 +55,3 @@
 GtkWidget* webkitAuthenticationDialogNew(WebKitAuthenticationRequest*, CredentialStorageMode);
 
 G_END_DECLS
-
-#endif

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewGtk.cpp (262286 => 262287)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewGtk.cpp	2020-05-29 09:40:52 UTC (rev 262286)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewGtk.cpp	2020-05-29 09:47:16 UTC (rev 262287)
@@ -33,10 +33,8 @@
 
 gboolean webkitWebViewAuthenticate(WebKitWebView* webView, WebKitAuthenticationRequest* request)
 {
-#if !USE(GTK4)
     CredentialStorageMode credentialStorageMode = webkit_authentication_request_can_save_credentials(request) ? AllowPersistentStorage : DisallowPersistentStorage;
     webkitWebViewBaseAddDialog(WEBKIT_WEB_VIEW_BASE(webView), webkitAuthenticationDialogNew(request, credentialStorageMode));
-#endif
 
     return TRUE;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to