Source/WebCore: [GTK] [WebKit2] Move GtkAuthenticationDialog to the UIProcess
authormrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2012 19:06:44 +0000 (19:06 +0000)
committermrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2012 19:06:44 +0000 (19:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=101843

Reviewed by Gustavo Noronha Silva.

Make GtkAuthenticationDialog more general, so that it can be subclassed in
WebKit2. We cannot use the WebCore authentication-related classes directly there.

No new tests. This patch does not change behavior.

* platform/gtk/GtkAuthenticationDialog.cpp:
(WebCore::GtkAuthenticationDialog::GtkAuthenticationDialog): Remove an unused include and reorder
some field initializers.
(WebCore::GtkAuthenticationDialog::authenticate): Now handle both the okay and cancel case here. This
makes it simpler to subclass.
(WebCore::GtkAuthenticationDialog::authenticationDialogResponseCallback): Handle fetching the username
and password here, so that it can be shared with subclasses.
* platform/gtk/GtkAuthenticationDialog.h: Make some methods virtual and protected so they can be
subclasses.

Source/WebKit2: Move authentication dialog to the UIProcess

[GTK] [WebKit2] Move GtkAuthenticationDialog to the UIProcess
https://bugs.webkit.org/show_bug.cgi?id=101843

Reviewed by Gustavo Noronha Silva.

Move the use of GtkAuthenticationDialog to the UIProcess along with the rest of
the GTK+ widgets. This will allow us to to embed the dialog into the WebView
in the future and to test authentication with the WebKit2 C API.

* GNUmakefile.list.am: Add the new class to the source list and remove the
GTK+-only WebFrameLoader implementation file.
* UIProcess/API/gtk/WebKit2GtkAuthenticationDialog.cpp: Added. A subclass of GtkAuthenticationDialog
which uses the WebKit2 classes to do the UIProcess-side authentication.
* UIProcess/API/gtk/WebKit2GtkAuthenticationDialog.h: Added.
* UIProcess/API/gtk/WebKitLoaderClient.cpp: Add a callback for didReceiveAuthenticationChallengeInFrame.
(didReceiveAuthenticationChallengeInFrame): Added.
(attachLoaderClientToView): Use the new callback.
* UIProcess/Authentication/AuthenticationChallengeProxy.h:
(WebKit::AuthenticationChallengeProxy::core): Add this getter for the WebCore class.
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge): Share the implementation
again.
* WebProcess/WebCoreSupport/gtk/WebFrameLoaderClientGtk.cpp: Removed.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/gtk/GtkAuthenticationDialog.cpp
Source/WebCore/platform/gtk/GtkAuthenticationDialog.h
Source/WebKit2/ChangeLog
Source/WebKit2/GNUmakefile.list.am
Source/WebKit2/UIProcess/API/gtk/WebKit2GtkAuthenticationDialog.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKit2GtkAuthenticationDialog.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitLoaderClient.cpp
Source/WebKit2/UIProcess/Authentication/AuthenticationChallengeProxy.h
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebFrameLoaderClientGtk.cpp [deleted file]

index 4ed5a71..a9043b0 100644 (file)
@@ -1,3 +1,25 @@
+2012-11-16  Martin Robinson  <mrobinson@igalia.com>
+
+        [GTK] [WebKit2] Move GtkAuthenticationDialog to the UIProcess
+        https://bugs.webkit.org/show_bug.cgi?id=101843
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Make GtkAuthenticationDialog more general, so that it can be subclassed in 
+        WebKit2. We cannot use the WebCore authentication-related classes directly there.
+
+        No new tests. This patch does not change behavior.
+
+        * platform/gtk/GtkAuthenticationDialog.cpp:
+        (WebCore::GtkAuthenticationDialog::GtkAuthenticationDialog): Remove an unused include and reorder
+        some field initializers.
+        (WebCore::GtkAuthenticationDialog::authenticate): Now handle both the okay and cancel case here. This
+        makes it simpler to subclass.
+        (WebCore::GtkAuthenticationDialog::authenticationDialogResponseCallback): Handle fetching the username
+        and password here, so that it can be shared with subclasses.
+        * platform/gtk/GtkAuthenticationDialog.h: Make some methods virtual and protected so they can be
+        subclasses.
+
 2012-11-16  Mark Pilgrim  <pilgrim@chromium.org>
 
         [Chromium] Remove cookie-related functions from PlatformSupport
index 50227c0..af1242f 100644 (file)
@@ -24,7 +24,6 @@
 #include "GtkVersioning.h"
 #include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
-#include <libsoup/soup.h>
 #include <wtf/gobject/GOwnPtr.h>
 
 namespace WebCore {
@@ -61,11 +60,11 @@ GtkAuthenticationDialog::~GtkAuthenticationDialog()
 }
 
 GtkAuthenticationDialog::GtkAuthenticationDialog(GtkWindow* parentWindow, const AuthenticationChallenge& challenge)
-    : m_challenge(challenge)
-    , m_dialog(gtk_dialog_new())
+    : m_dialog(gtk_dialog_new())
     , m_loginEntry(0)
     , m_passwordEntry(0)
     , m_rememberCheckButton(0)
+    , m_challenge(challenge)
 {
     GtkDialog* dialog = GTK_DIALOG(m_dialog);
     gtk_dialog_add_buttons(dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
@@ -205,22 +204,26 @@ void GtkAuthenticationDialog::destroy()
     delete this;
 }
 
-void GtkAuthenticationDialog::authenticate()
+void GtkAuthenticationDialog::authenticate(const Credential& credential)
 {
-    const char *username = gtk_entry_get_text(GTK_ENTRY(m_loginEntry));
-    const char *password = gtk_entry_get_text(GTK_ENTRY(m_passwordEntry));
-    CredentialPersistence persistence = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_rememberCheckButton)) ?
-        CredentialPersistencePermanent : CredentialPersistenceForSession;
-    m_challenge.authenticationClient()->receivedCredential(m_challenge,
-        Credential(String::fromUTF8(username), String::fromUTF8(password), persistence));
+    if (credential.isEmpty())
+        m_challenge.authenticationClient()->receivedRequestToContinueWithoutCredential(m_challenge);
+    else
+        m_challenge.authenticationClient()->receivedCredential(m_challenge, credential);
 }
 
 void GtkAuthenticationDialog::authenticationDialogResponseCallback(GtkWidget*, gint responseID, GtkAuthenticationDialog* dialog)
 {
-    if (responseID == GTK_RESPONSE_OK)
-        dialog->authenticate();
+    Credential credential;
+    if (responseID == GTK_RESPONSE_OK) {
+        const char *username = gtk_entry_get_text(GTK_ENTRY(dialog->m_loginEntry));
+        const char *password = gtk_entry_get_text(GTK_ENTRY(dialog->m_passwordEntry));
+        CredentialPersistence persistence = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->m_rememberCheckButton)) ?
+            CredentialPersistencePermanent : CredentialPersistenceForSession;
+        credential = Credential(String::fromUTF8(username), String::fromUTF8(password), persistence);
+    }
 
-    dialog->m_challenge.authenticationClient()->receivedRequestToContinueWithoutCredential(dialog->m_challenge);
+    dialog->authenticate(credential);
     dialog->destroy();
 }
 
index d513014..7e6478f 100644 (file)
@@ -35,20 +35,20 @@ class GtkAuthenticationDialog {
 
 public:
     GtkAuthenticationDialog(GtkWindow*, const AuthenticationChallenge&);
-    ~GtkAuthenticationDialog();
-
+    virtual ~GtkAuthenticationDialog();
     void show();
 
-private:
-    void destroy();
-    void authenticate();
-    static void authenticationDialogResponseCallback(GtkWidget*, gint responseID, GtkAuthenticationDialog*);
-
-    AuthenticationChallenge m_challenge;
+protected:
+    virtual void authenticate(const Credential&);
     GtkWidget* m_dialog;
     GtkWidget* m_loginEntry;
     GtkWidget* m_passwordEntry;
     GtkWidget* m_rememberCheckButton;
+
+private:
+    void destroy();
+    static void authenticationDialogResponseCallback(GtkWidget*, gint responseID, GtkAuthenticationDialog*);
+    AuthenticationChallenge m_challenge;
 };
 
 } // namespace WebCore
index e5fa0b1..41340c8 100644 (file)
@@ -1,3 +1,31 @@
+2012-11-16  Martin Robinson  <mrobinson@igalia.com>
+
+        Move authentication dialog to the UIProcess
+
+        [GTK] [WebKit2] Move GtkAuthenticationDialog to the UIProcess
+        https://bugs.webkit.org/show_bug.cgi?id=101843
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Move the use of GtkAuthenticationDialog to the UIProcess along with the rest of
+        the GTK+ widgets. This will allow us to to embed the dialog into the WebView
+        in the future and to test authentication with the WebKit2 C API.
+
+        * GNUmakefile.list.am: Add the new class to the source list and remove the
+        GTK+-only WebFrameLoader implementation file.
+        * UIProcess/API/gtk/WebKit2GtkAuthenticationDialog.cpp: Added. A subclass of GtkAuthenticationDialog
+        which uses the WebKit2 classes to do the UIProcess-side authentication.
+        * UIProcess/API/gtk/WebKit2GtkAuthenticationDialog.h: Added.
+        * UIProcess/API/gtk/WebKitLoaderClient.cpp: Add a callback for didReceiveAuthenticationChallengeInFrame.
+        (didReceiveAuthenticationChallengeInFrame): Added.
+        (attachLoaderClientToView): Use the new callback.
+        * UIProcess/Authentication/AuthenticationChallengeProxy.h:
+        (WebKit::AuthenticationChallengeProxy::core): Add this getter for the WebCore class.
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge): Share the implementation
+        again.
+        * WebProcess/WebCoreSupport/gtk/WebFrameLoaderClientGtk.cpp: Removed.
+
 2012-11-15  Alexey Proskuryakov  <ap@apple.com>
 
         Private Browsing is a per-page setting that sets a global value
index cdf8d5f..ab523ef 100644 (file)
@@ -630,6 +630,8 @@ webkit2_sources += \
        Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h \
        Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h \
        Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp \
+       Source/WebKit2/UIProcess/API/gtk/WebKit2GtkAuthenticationDialog.cpp \
+       Source/WebKit2/UIProcess/API/gtk/WebKit2GtkAuthenticationDialog.h \
        Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardList.h \
        Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardList.cpp \
        Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.h \
@@ -1113,7 +1115,6 @@ webkit2_sources += \
        Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp \
        Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp \
        Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebErrorsGtk.cpp \
-       Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebFrameLoaderClientGtk.cpp \
        Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebPopupMenuGtk.cpp \
        Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp \
        Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.h \
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKit2GtkAuthenticationDialog.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKit2GtkAuthenticationDialog.cpp
new file mode 100644 (file)
index 0000000..ef2da1c
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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 "WebKit2GtkAuthenticationDialog.h"
+
+#include "AuthenticationChallengeProxy.h"
+#include "AuthenticationDecisionListener.h"
+#include "WebCredential.h"
+
+namespace WebKit {
+
+WebKit2GtkAuthenticationDialog::WebKit2GtkAuthenticationDialog(AuthenticationChallengeProxy* authenticationChallenge)
+    : GtkAuthenticationDialog(0, authenticationChallenge->core())
+    , m_authenticationChallenge(authenticationChallenge)
+{
+    // We aren't passing a toplevel to the GtkAuthenticationDialog constructor,
+    // because eventually this widget will be embedded into the WebView itself.
+}
+
+void WebKit2GtkAuthenticationDialog::authenticate(const WebCore::Credential& credential)
+{
+    RefPtr<WebCredential> webCredential = WebCredential::create(credential);
+    m_authenticationChallenge->listener()->useCredential(webCredential.get());
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKit2GtkAuthenticationDialog.h b/Source/WebKit2/UIProcess/API/gtk/WebKit2GtkAuthenticationDialog.h
new file mode 100644 (file)
index 0000000..60c5e05
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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 "AuthenticationChallengeProxy.h"
+#include "WKRetainPtr.h"
+#include <WebCore/Credential.h>
+#include <WebCore/GtkAuthenticationDialog.h>
+
+namespace WebKit {
+
+class WebKit2GtkAuthenticationDialog : public WebCore::GtkAuthenticationDialog {
+public:
+    WebKit2GtkAuthenticationDialog(AuthenticationChallengeProxy*);
+
+protected:
+    virtual void authenticate(const WebCore::Credential&);
+
+private:
+    RefPtr<AuthenticationChallengeProxy> m_authenticationChallenge;
+};
+
+} // namespace WebKit
index 0b9275f..be06edd 100644 (file)
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "WebKitLoaderClient.h"
 
+#include "WebKit2GtkAuthenticationDialog.h"
 #include "WebKitBackForwardListPrivate.h"
 #include "WebKitURIResponsePrivate.h"
 #include "WebKitWebViewBasePrivate.h"
@@ -115,6 +116,12 @@ static void didChangeBackForwardList(WKPageRef page, WKBackForwardListItemRef ad
     webkitBackForwardListChanged(webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(clientInfo)), toImpl(addedItem), toImpl(removedItems));
 }
 
+static void didReceiveAuthenticationChallengeInFrame(WKPageRef page, WKFrameRef frame, WKAuthenticationChallengeRef authenticationChallenge, const void *clientInfo)
+{
+    WebKit2GtkAuthenticationDialog* dialog = new WebKit2GtkAuthenticationDialog(toImpl(authenticationChallenge));
+    dialog->show();
+}
+
 void attachLoaderClientToView(WebKitWebView* webView)
 {
     WKPageLoaderClient wkLoaderClient = {
@@ -135,7 +142,7 @@ void attachLoaderClientToView(WebKitWebView* webView)
         0, // didDisplayInsecureContentForFrame
         0, // didRunInsecureContentForFrame
         0, // canAuthenticateAgainstProtectionSpaceInFrame
-        0, // didReceiveAuthenticationChallengeInFrame
+        didReceiveAuthenticationChallengeInFrame,
         didChangeProgress, // didStartProgress
         didChangeProgress,
         didChangeProgress, // didFinishProgress
index a429ac5..51379ee 100644 (file)
@@ -61,6 +61,7 @@ public:
     WebCredential* proposedCredential() const;
     WebProtectionSpace* protectionSpace() const;
     int previousFailureCount() const { return m_coreAuthenticationChallenge.previousFailureCount(); }
+    const WebCore::AuthenticationChallenge& core() { return m_coreAuthenticationChallenge; }
 
 private:
     AuthenticationChallengeProxy(const WebCore::AuthenticationChallenge&, uint64_t challengeID, WebProcessProxy*);
index f740f08..b3df3b5 100644 (file)
@@ -202,7 +202,6 @@ bool WebFrameLoaderClient::shouldUseCredentialStorage(DocumentLoader*, unsigned
     return webPage->injectedBundleResourceLoadClient().shouldUseCredentialStorage(webPage, m_frame, identifier);
 }
 
-#if !PLATFORM(GTK)
 void WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge& challenge)
 {
     // FIXME: Authentication is a per-resource concept, but we don't do per-resource handling in the UIProcess at the API level quite yet.
@@ -214,7 +213,6 @@ void WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(DocumentLoa
 
     AuthenticationManager::shared().didReceiveAuthenticationChallenge(m_frame, challenge);
 }
-#endif
 
 void WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long /*identifier*/, const AuthenticationChallenge&)    
 {
diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebFrameLoaderClientGtk.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebFrameLoaderClientGtk.cpp
deleted file mode 100644 (file)
index a6ff36e..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2012, Igalia S.L.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY IGALIA S.L. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "config.h"
-#include "WebFrameLoaderClient.h"
-
-#include <WebCore/AuthenticationChallenge.h>
-#include <WebCore/GtkAuthenticationDialog.h>
-#include <WebCore/ResourceHandle.h>
-
-namespace WebKit {
-
-using WebCore::GtkAuthenticationDialog;
-using WebCore::AuthenticationChallenge;
-
-void WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(WebCore::DocumentLoader*, unsigned long, const AuthenticationChallenge& challenge)
-{
-    GtkAuthenticationDialog* dialog = new GtkAuthenticationDialog(0, challenge);
-    dialog->show();
-}
-
-} // namespace WebKit