[Webkit-unassigned] [Bug 16947] [GTK] Missing HTTP Auth challenge

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Feb 18 19:24:11 PST 2008


http://bugs.webkit.org/show_bug.cgi?id=16947


alp at atoker.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #19162|review?                     |review-
               Flag|                            |




------- Comment #5 from alp at atoker.com  2008-02-18 19:24 PDT -------
(From update of attachment 19162)
This is conceptually fine. There are a few style issues and bugs to be resolved
before getting it in:

>Index: ChangeLog
>===================================================================
>--- ChangeLog	(revision 30341)
>+++ ChangeLog	(working copy)
>@@ -1,3 +1,12 @@
>+2008-02-16  Luca Bruno  <lethalman88 at gmail.com>
>+
>+        Reviewed by NOBODY (OOPS!).
>+
>+        http://bugs.webkit.org/show_bug.cgi?id=16947
>+        Bug 16947: [GTK] Missing HTTP Auth challenge
>+
>+        * GNUmakefile.am: add webkitauthenticationchallenge.cpp and webkitauthenticationchallenge.h
>+
> 2008-02-15  Alp Toker  <alp at atoker.com>
> 
>         Reviewed by Holger.
>Index: GNUmakefile.am
>===================================================================
>--- GNUmakefile.am	(revision 30340)
>+++ GNUmakefile.am	(working copy)
>@@ -249,6 +249,7 @@ webkitgtk_cppflags += \
> 
> webkitgtk_h_api += \
> 	WebKit/gtk/webkit/webkit.h \
>+	WebKit/gtk/webkit/webkitauthenticationchallenge.h \
> 	WebKit/gtk/webkit/webkitdefines.h \
> 	WebKit/gtk/webkit/webkitnetworkrequest.h \
> 	WebKit/gtk/webkit/webkitwebbackforwardlist.h \
>@@ -272,6 +273,7 @@ webkitgtk_headers += \
> 	WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.h
> 
> webkitgtk_sources += \
>+	WebKit/gtk/webkit/webkitauthenticationchallenge.cpp \
> 	WebKit/gtk/webkit/webkitnetworkrequest.cpp \
> 	WebKit/gtk/webkit/webkitprivate.cpp \
> 	WebKit/gtk/webkit/webkitwebbackforwardlist.cpp \
>Index: WebCore/ChangeLog
>===================================================================
>--- WebCore/ChangeLog	(revision 30341)
>+++ WebCore/ChangeLog	(working copy)
>@@ -1,3 +1,25 @@
>+2008-02-16  Luca Bruno  <lethalman88 at gmail.com>
>+
>+        Reviewed by NOBODY (OOPS!).
>+
>+        WARNING: NO TEST CASES ADDED OR CHANGED
>+
>+        http://bugs.webkit.org/show_bug.cgi?id=16947
>+        Bug 16947: [GTK] Missing HTTP Auth challenge
>+
>+        * WebCore.pro: add webkitauthenticationchallenge.cpp and webkitauthenticationchallenge.h
>+        * platform/network/ResourceHandle.h:
>+        * platform/network/ResourceHandleInternal.h:
>+        (WebCore::ResourceHandleInternal::ResourceHandleInternal):
>+        * platform/network/curl/ResourceHandleCurl.cpp:
>+        (WebCore::ResourceHandle::didReceiveAuthenticationChallenge): added, called by cURL backend
>+        (WebCore::ResourceHandle::receivedCredential): added
>+        (WebCore::ResourceHandle::receivedRequestToContinueWithoutCredential): added
>+        (WebCore::ResourceHandle::receivedCancellation): added
>+        * platform/network/curl/ResourceHandleManager.cpp:
>+        (WebCore::headerCallback): check for authentication
>+        (WebCore::ResourceHandleManager::startJob): use the authentication
>+
> 2008-02-16  Kevin Ollivier  <kevino at theolliviers.com>
> 
>         wx build fix.
>Index: WebCore/WebCore.pro
>===================================================================
>--- WebCore/WebCore.pro	(revision 30340)
>+++ WebCore/WebCore.pro	(working copy)
>@@ -993,6 +993,7 @@ gtk-port {
>         ../WebCore/platform/gtk/ClipboardGtk.h \
>         ../WebCore/platform/gtk/PasteboardHelper.h \
>         ../WebKit/gtk/webkit/webkit.h \
>+        ../WebKit/gtk/webkit/webkitauthenticationchallenge.h \
>         ../WebKit/gtk/webkit/webkitdefines.h \
>         ../WebKit/gtk/webkit/webkitnetworkrequest.h \
>         ../WebKit/gtk/webkit/webkitprivate.h \
>@@ -1074,6 +1075,7 @@ gtk-port {
>         platform/image-decoders/bmp/BMPImageDecoder.cpp \
>         platform/image-decoders/ico/ICOImageDecoder.cpp \
>         platform/image-decoders/xbm/XBMImageDecoder.cpp \
>+        ../WebKit/gtk/webkit/webkitauthenticationchallenge.cpp \
>         ../WebKit/gtk/webkit/webkitnetworkrequest.cpp \
>         ../WebKit/gtk/webkit/webkitprivate.cpp \
>         ../WebKit/gtk/webkit/webkitwebbackforwardlist.cpp \
>Index: WebCore/platform/network/ResourceHandle.h
>===================================================================
>--- WebCore/platform/network/ResourceHandle.h	(revision 30340)
>+++ WebCore/platform/network/ResourceHandle.h	(working copy)
>@@ -116,6 +116,12 @@ public:
>     static void setHostAllowsAnyHTTPSCertificate(const String&);
>     static void setClientCertificate(const String& host, CFDataRef);
> #endif
>+#if PLATFORM(GTK)
>+    void didReceiveAuthenticationChallenge(const AuthenticationChallenge&);
>+    void receivedCredential(const AuthenticationChallenge&, const Credential&);
>+    void receivedRequestToContinueWithoutCredential(const AuthenticationChallenge&);
>+    void receivedCancellation(const AuthenticationChallenge&);
>+#endif

^ Don't copy this block, just add GTK to the existing block eg.

#if PLATFORM(MAC) || USE(CFNETWORK) || PLATFORM(GTK)



>     PassRefPtr<SharedBuffer> bufferedData();
>     static bool supportsBufferedData();
>     
>Index: WebCore/platform/network/ResourceHandleInternal.h
>===================================================================
>--- WebCore/platform/network/ResourceHandleInternal.h	(revision 30340)
>+++ WebCore/platform/network/ResourceHandleInternal.h	(working copy)
>@@ -101,6 +101,8 @@ namespace WebCore {
>             , m_file(0)
>             , m_formDataElementIndex(0)
>             , m_formDataElementDataOffset(0)
>+            , m_webChallenge()
>+            , m_continueWithoutCredential(false)
> #endif
> #if PLATFORM(QT)
>             , m_job(0)
>@@ -159,6 +161,9 @@ namespace WebCore {
>         size_t m_formDataElementIndex;
>         size_t m_formDataElementDataOffset;
>         Vector<char> m_postBytes;
>+
>+        AuthenticationChallenge m_webChallenge;
>+        bool m_continueWithoutCredential;
> #endif
> #if PLATFORM(QT)
> #if QT_VERSION < 0x040400
>Index: WebCore/platform/network/curl/ResourceHandleCurl.cpp
>===================================================================
>--- WebCore/platform/network/curl/ResourceHandleCurl.cpp	(revision 30340)
>+++ WebCore/platform/network/curl/ResourceHandleCurl.cpp	(working copy)
>@@ -95,4 +95,69 @@ void ResourceHandle::loadResourceSynchro
>     notImplemented();
> }
> 
>+void ResourceHandle::didReceiveAuthenticationChallenge(const AuthenticationChallenge& challenge)
>+{
>+    /* FIXME: add support for FTP, HTTPS, and FTPS authentication,
>+     * get the right port, server and authentication scheme
>+     */
>+    ResourceHandleInternal* d = getInternal();
>+    if (d->m_continueWithoutCredential)
>+        return;
>+    cancel();
>+
>+    ProtectionSpace protectionSpace;
>+    unsigned previousFailureCount = 0;
>+    if (challenge.isNull()) {
>+        protectionSpace = ProtectionSpace(d->m_response.httpHeaderField("Host"),
>+                                          80,
>+                                          ProtectionSpaceServerHTTP,
>+                                          d->m_response.httpHeaderField("Realm"),
>+                                          ProtectionSpaceAuthenticationSchemeDefault);
>+    } else {
>+        protectionSpace = d->m_webChallenge.protectionSpace();
>+        previousFailureCount = d->m_webChallenge.previousFailureCount()+1;
>+    }
>+    
>+    d->m_webChallenge = AuthenticationChallenge(protectionSpace,
>+                                                challenge.proposedCredential(),
>+                                                previousFailureCount,
>+                                                d->m_response,
>+                                                challenge.error());
>+
>+    if (d->client())
>+        d->client()->didReceiveAuthenticationChallenge(this, d->m_webChallenge);
>+}
>+
>+void ResourceHandle::receivedCredential(const AuthenticationChallenge& challenge, const Credential& credential)
>+{
>+    ASSERT(!challenge.isNull());   
>+    ResourceHandleInternal* d = getInternal();
>+    if (challenge != d->m_webChallenge)
>+        return;
>+
>+    d->m_webChallenge = AuthenticationChallenge(challenge.protectionSpace(),
>+                                                credential,
>+                                                challenge.previousFailureCount(),
>+                                                challenge.failureResponse(),
>+                                                challenge.error());
>+
>+    ResourceHandleManager::sharedInstance()->add(this);
>+}
>+
>+void ResourceHandle::receivedRequestToContinueWithoutCredential(const AuthenticationChallenge& challenge)
>+{
>+    ASSERT(!challenge.isNull());   
>+    ResourceHandleInternal* d = getInternal();
>+    if (challenge != d->m_webChallenge)
>+        return;
>+
>+    d->m_continueWithoutCredential = true;
>+    ResourceHandleManager::sharedInstance()->add(this);
>+}
>+
>+void ResourceHandle::receivedCancellation(const AuthenticationChallenge& challenge)
>+{
>+    notImplemented();
>+}
>+
> } // namespace WebCore
>Index: WebCore/platform/network/curl/ResourceHandleManager.cpp
>===================================================================
>--- WebCore/platform/network/curl/ResourceHandleManager.cpp	(revision 30340)
>+++ WebCore/platform/network/curl/ResourceHandleManager.cpp	(working copy)
>@@ -168,6 +168,10 @@ static size_t headerCallback(char* ptr, 
>         d->m_response.setTextEncodingName(extractCharsetFromMediaType(d->m_response.httpHeaderField("Content-Type")));
>         d->m_response.setSuggestedFilename(filenameFromHTTPContentDisposition(d->m_response.httpHeaderField("Content-Disposition")));
> 
>+        // HTTP authentication
>+        if (httpCode == 401 && d->m_response.isHTTP())
>+            job->didReceiveAuthenticationChallenge(d->m_webChallenge);
>+
>         // HTTP redirection
>         if (httpCode >= 300 && httpCode < 400) {
>             String location = d->m_response.httpHeaderField("location");
>@@ -546,6 +550,9 @@ void ResourceHandleManager::startJob(Res
>     }
> 
>     d->m_handle = curl_easy_init();
>+    // HTTP Authentication cancels the job so be sure the new job is not cancelled
>+    d->m_cancelled = false;  
>+
> #ifndef NDEBUG
>     if (getenv("DEBUG_CURL"))
>         curl_easy_setopt(d->m_handle, CURLOPT_VERBOSE, 1);
>@@ -575,6 +582,23 @@ void ResourceHandleManager::startJob(Res
>         curl_easy_setopt(d->m_handle, CURLOPT_COOKIEJAR, m_cookieJarFileName);
>     }
> 
>+    if (!d->m_webChallenge.isNull() && !d->m_continueWithoutCredential) {
>+        long curlAuth;
>+        switch(d->m_webChallenge.protectionSpace().authenticationScheme()) {          
>+        case ProtectionSpaceAuthenticationSchemeHTTPBasic:
>+        case ProtectionSpaceAuthenticationSchemeDefault:
>+        default:
>+            curlAuth = CURLAUTH_BASIC;
>+            break;
>+        }
>+
>+        Credential credential = d->m_webChallenge.proposedCredential();
>+        String userpwd = credential.user() + ":" + credential.password();
>+        
>+        curl_easy_setopt(d->m_handle, CURLOPT_HTTPAUTH, curlAuth);
>+        curl_easy_setopt(d->m_handle, CURLOPT_USERPWD, strdup(userpwd.utf8().data()));
>+    }
>+
>     struct curl_slist* headers = 0;
>     if (job->request().httpHeaderFields().size() > 0) {
>         HTTPHeaderMap customHeaders = job->request().httpHeaderFields();
>Index: WebKit/gtk/ChangeLog
>===================================================================
>--- WebKit/gtk/ChangeLog	(revision 30341)
>+++ WebKit/gtk/ChangeLog	(working copy)
>@@ -1,3 +1,19 @@
>+2008-02-16  Luca Bruno  <lethalman88 at gmail.com>
>+
>+        Reviewed by NOBODY (OOPS!).
>+
>+        http://bugs.webkit.org/show_bug.cgi?id=16947
>+        Bug 16947: [GTK] Missing HTTP Auth challenge
>+
>+        * WebCoreSupport/FrameLoaderClientGtk.cpp:
>+        (WebKit::FrameLoaderClient::dispatchDidReceiveAuthenticationChallenge): implemented
>+        * webkit/webkitdefines.h:
>+        * webkit/webkitprivate.h:
>+        * webkit/webkitwebview.cpp: add authentication-requested signal and create auth dialog
>+        * webkit/webkitwebview.h:
>+        * webkit/webkitauthenticationchallenge.cpp: added
>+        * webkit/webkitauthenticationchallenge.h: added
>+
> 2008-02-15  Alp Toker  <alp at atoker.com>
> 
>         Fix the GTK+ build following breakage introduced in r30243.
>Index: WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
>===================================================================
>--- WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp	(revision 30340)
>+++ WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp	(working copy)
>@@ -30,6 +30,7 @@
> #include "HTMLFrameOwnerElement.h"
> #include "HTMLNames.h"
> #include "Language.h"
>+#include "MainResourceLoader.h"
> #include "MIMETypeRegistry.h"
> #include "NotImplemented.h"
> #include "PlatformString.h"
>@@ -39,6 +40,7 @@
> #include "kjs_binding.h"
> #include "kjs_proxy.h"
> #include "kjs_window.h"
>+#include "webkitauthenticationchallenge.h"
> #include "webkitwebview.h"
> #include "webkitwebframe.h"
> #include "webkitprivate.h"
>@@ -165,9 +167,24 @@ void FrameLoaderClient::committedLoad(Do
>     fl->addData(data, length);
> }
> 
>-void FrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long  identifier, const AuthenticationChallenge&)
>+void FrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(DocumentLoader* documentLoader, unsigned long identifier, const AuthenticationChallenge& webChallenge)
> {
>-    notImplemented();
>+    ResourceHandle* handle = documentLoader->mainResourceLoader()->handle();
>+    ASSERT(handle);
>+    if (!handle)
>+        return;
>+    
>+    WebKitAuthenticationChallenge* challenge = webkit_authentication_challenge_new();
>+    WebKitAuthenticationChallengePrivate* challengePrivate = WEBKIT_AUTHENTICATION_CHALLENGE_GET_PRIVATE(challenge);
>+    *challengePrivate->webChallenge = webChallenge;
>+    challengePrivate->webHandle = handle;
>+    
>+    Credential credential = webChallenge.proposedCredential();
>+    webkit_authentication_challenge_set_user(challenge, credential.user().utf8().data());
>+    webkit_authentication_challenge_set_password(challenge, credential.password().utf8().data());
>+    
>+    WebKitWebView* webView = getViewFromFrame(m_frame);
>+    g_signal_emit_by_name(webView, "authentication-requested", m_frame, challenge, NULL);
> }
> 
> void FrameLoaderClient::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long  identifier, const AuthenticationChallenge&)
>Index: WebKit/gtk/webkit/webkitauthenticationchallenge.cpp
>===================================================================
>--- WebKit/gtk/webkit/webkitauthenticationchallenge.cpp	(revision 0)
>+++ WebKit/gtk/webkit/webkitauthenticationchallenge.cpp	(revision 0)
>@@ -0,0 +1,138 @@
>+/*
>+ * Copyright (C) 2008 Luca Bruno
>+ *
>+ * 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 "webkitauthenticationchallenge.h"
>+#include "webkitprivate.h"
>+
>+#include "Credential.h"
>+#include "ResourceHandle.h"
>+
>+using namespace WebKit;
>+using namespace WebCore;
>+
>+extern "C" {
>+
>+G_DEFINE_TYPE(WebKitAuthenticationChallenge, webkit_authentication_challenge, G_TYPE_OBJECT);
>+
>+static void webkit_authentication_challenge_finalize(GObject* object)
>+{
>+    WebKitAuthenticationChallengePrivate* challengePrivate = WEBKIT_AUTHENTICATION_CHALLENGE_GET_PRIVATE(object);
>+
>+    delete challengePrivate->webChallenge;
>+    g_free(challengePrivate->user);
>+    g_free(challengePrivate->password);
>+
>+    G_OBJECT_CLASS(webkit_authentication_challenge_parent_class)->finalize(object);
>+}
>+
>+static void webkit_authentication_challenge_class_init(WebKitAuthenticationChallengeClass* challengeClass)
>+{
>+    g_type_class_add_private(challengeClass, sizeof(WebKitAuthenticationChallengePrivate));
>+
>+    G_OBJECT_CLASS(challengeClass)->finalize = webkit_authentication_challenge_finalize;
>+}
>+
>+static void webkit_authentication_challenge_init(WebKitAuthenticationChallenge* challenge)

^ A better name (by our conventions so far) for this would be
WebKitWebAuthChallenge. You'll need to change the filenames etc. to match this.



>+{
>+    WebKitAuthenticationChallengePrivate* challengePrivate = WEBKIT_AUTHENTICATION_CHALLENGE_GET_PRIVATE(challenge);
>+
>+    challengePrivate->webChallenge = new AuthenticationChallenge();
>+    challengePrivate->webHandle = NULL;
>+    challengePrivate->user = NULL;
>+    challengePrivate->password = NULL;
>+}
>+
>+WebKitAuthenticationChallenge* webkit_authentication_challenge_new()
>+{
>+    WebKitAuthenticationChallenge* challenge = WEBKIT_AUTHENTICATION_CHALLENGE(g_object_new(WEBKIT_TYPE_AUTHENTICATION_CHALLENGE, NULL));
>+
>+    return challenge;
>+}
>+
>+void webkit_authentication_challenge_set_user(WebKitAuthenticationChallenge* challenge, const gchar* user)
>+{
>+    g_return_if_fail(WEBKIT_IS_AUTHENTICATION_CHALLENGE(challenge));
>+    g_return_if_fail(user);
>+    
>+    WebKitAuthenticationChallengePrivate* challengePrivate = WEBKIT_AUTHENTICATION_CHALLENGE_GET_PRIVATE(challenge);
>+
>+    g_free(challengePrivate->user);
>+    challengePrivate->user = g_strdup(user);
>+}
>+
>+const gchar* webkit_authentication_challenge_get_user(WebKitAuthenticationChallenge* challenge)
>+{
>+    g_return_val_if_fail(WEBKIT_IS_AUTHENTICATION_CHALLENGE(challenge), NULL);
>+
>+    WebKitAuthenticationChallengePrivate* challengePrivate = WEBKIT_AUTHENTICATION_CHALLENGE_GET_PRIVATE(challenge);
>+
>+    return challengePrivate->user;
>+}
>+
>+void webkit_authentication_challenge_set_password(WebKitAuthenticationChallenge* challenge, const gchar* password)
>+{
>+    g_return_if_fail(WEBKIT_IS_AUTHENTICATION_CHALLENGE(challenge));
>+    g_return_if_fail(password);
>+    
>+    WebKitAuthenticationChallengePrivate* challengePrivate = WEBKIT_AUTHENTICATION_CHALLENGE_GET_PRIVATE(challenge);
>+
>+    g_free(challengePrivate->password);
>+    challengePrivate->password = g_strdup(password);
>+}
>+
>+const gchar* webkit_authentication_challenge_get_password(WebKitAuthenticationChallenge* challenge)
>+{
>+    g_return_val_if_fail(WEBKIT_IS_AUTHENTICATION_CHALLENGE(challenge), NULL);
>+
>+    WebKitAuthenticationChallengePrivate* challengePrivate = WEBKIT_AUTHENTICATION_CHALLENGE_GET_PRIVATE(challenge);

^ We changed coding style when you were gone :-) We now use a direct struct
reference to ->priv. You'll need to take a look at the other classes to see how
it's done and update this patch.


>+
>+    return challengePrivate->password;
>+}
>+
>+void webkit_authentication_challenge_use_credential(WebKitAuthenticationChallenge* challenge)
>+{
>+    g_return_if_fail(WEBKIT_IS_AUTHENTICATION_CHALLENGE(challenge));
>+
>+    WebKitAuthenticationChallengePrivate* challengePrivate = WEBKIT_AUTHENTICATION_CHALLENGE_GET_PRIVATE(challenge);
>+    Credential credential = Credential(challengePrivate->user,
>+                                       challengePrivate->password,
>+                                       CredentialPersistenceForSession);

^ Careful, you need to use String::fromUTF8() here and for every other string
conversion in this patch. I filed Bug #17432 to get this harmful implicit
conversion removed, but till then you need to be vigilant.



>+    challengePrivate->webHandle->receivedCredential(*challengePrivate->webChallenge, credential);
>+}
>+
>+void webkit_authentication_challenge_continue_without_credential(WebKitAuthenticationChallenge* challenge)
>+{
>+    g_return_if_fail(WEBKIT_IS_AUTHENTICATION_CHALLENGE(challenge));
>+
>+    WebKitAuthenticationChallengePrivate* challengePrivate = WEBKIT_AUTHENTICATION_CHALLENGE_GET_PRIVATE(challenge);
>+    challengePrivate->webHandle->receivedRequestToContinueWithoutCredential(*challengePrivate->webChallenge);
>+}
>+
>+void webkit_authentication_challenge_cancel(WebKitAuthenticationChallenge* challenge)
>+{
>+    g_return_if_fail(WEBKIT_IS_AUTHENTICATION_CHALLENGE(challenge));
>+
>+    WebKitAuthenticationChallengePrivate* challengePrivate = WEBKIT_AUTHENTICATION_CHALLENGE_GET_PRIVATE(challenge);
>+
>+    challengePrivate->webHandle->receivedCancellation(*challengePrivate->webChallenge);
>+}
>+
>+}
>Index: WebKit/gtk/webkit/webkitauthenticationchallenge.h
>===================================================================
>--- WebKit/gtk/webkit/webkitauthenticationchallenge.h	(revision 0)
>+++ WebKit/gtk/webkit/webkitauthenticationchallenge.h	(revision 0)
>@@ -0,0 +1,73 @@
>+/*
>+ * Copyright (C) 2008 Luca Bruno
>+ *
>+ * 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 WEBKIT_AUTHENTICATION_CHALLENGE_H
>+#define WEBKIT_AUTHENTICATION_CHALLENGE_H
>+
>+#include <glib-object.h>
>+
>+#include "webkitdefines.h"
>+
>+G_BEGIN_DECLS
>+
>+#define WEBKIT_TYPE_AUTHENTICATION_CHALLENGE            (webkit_authentication_challenge_get_type())
>+#define WEBKIT_AUTHENTICATION_CHALLENGE(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_AUTHENTICATION_CHALLENGE, WebKitAuthenticationChallenge))
>+#define WEBKIT_AUTHENTICATION_CHALLENGE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_AUTHENTICATION_CHALLENGE, WebKitAuthenticationChallengeClass))
>+#define WEBKIT_IS_AUTHENTICATION_CHALLENGE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_AUTHENTICATION_CHALLENGE))
>+#define WEBKIT_IS_AUTHENTICATION_CHALLENGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_AUTHENTICATION_CHALLENGE))
>+#define WEBKIT_AUTHENTICATION_CHALLENGE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_AUTHENTICATION_CHALLENGE, WebKitAuthenticationChallengeClass))
>+
>+struct _WebKitAuthenticationChallenge {
>+    GObject parent;
>+};
>+
>+struct _WebKitAuthenticationChallengeClass {
>+    GObjectClass parent;
>+};
>+
>+WEBKIT_API GType
>+webkit_authentication_challenge_get_type (void);
>+
>+WEBKIT_API WebKitAuthenticationChallenge*
>+webkit_authentication_challenge_new ();
>+
>+WEBKIT_API void
>+webkit_authentication_challenge_set_user (WebKitAuthenticationChallenge* challenge, const gchar* user);
>+
>+WEBKIT_API const gchar*
>+webkit_authentication_challenge_get_user (WebKitAuthenticationChallenge* challenge);
>+
>+WEBKIT_API void
>+webkit_authentication_challenge_set_password (WebKitAuthenticationChallenge* challenge, const gchar* password);
>+
>+WEBKIT_API const gchar*
>+webkit_authentication_challenge_get_password (WebKitAuthenticationChallenge* challenge);
>+
>+WEBKIT_API void
>+webkit_authentication_challenge_use_credential (WebKitAuthenticationChallenge* challenge);
>+
>+WEBKIT_API void
>+webkit_authentication_challenge_continue_without_credential (WebKitAuthenticationChallenge* challenge);
>+
>+WEBKIT_API void
>+webkit_authentication_challenge_cancel (WebKitAuthenticationChallenge* challenge);
>+
>+G_END_DECLS
>+
>+#endif
>Index: WebKit/gtk/webkit/webkitdefines.h
>===================================================================
>--- WebKit/gtk/webkit/webkitdefines.h	(revision 30340)
>+++ WebKit/gtk/webkit/webkitdefines.h	(working copy)
>@@ -40,6 +40,9 @@
> 
> G_BEGIN_DECLS
> 
>+typedef struct _WebKitAuthenticationChallenge WebKitAuthenticationChallenge;
>+typedef struct _WebKitAuthenticationChallengeClass WebKitAuthenticationChallengeClass;
>+
> typedef struct _WebKitNetworkRequest WebKitNetworkRequest;
> typedef struct _WebKitNetworkRequestClass WebKitNetworkRequestClass;
> 
>Index: WebKit/gtk/webkit/webkitprivate.h
>===================================================================
>--- WebKit/gtk/webkit/webkitprivate.h	(revision 30340)
>+++ WebKit/gtk/webkit/webkitprivate.h	(working copy)
>@@ -26,6 +26,7 @@
>  * They are using WebCore which musn't be exposed to the outer world.
>  */
> 
>+#include <webkit/webkitauthenticationchallenge.h>
> #include <webkit/webkitdefines.h>
> #include <webkit/webkitwebview.h>
> #include <webkit/webkitwebframe.h>
>@@ -33,6 +34,7 @@
> #include <webkit/webkitnetworkrequest.h>
> #include <webkit/webkitwebbackforwardlist.h>
> 
>+#include "AuthenticationChallenge.h"
> #include "BackForwardList.h"
> #include "HistoryItem.h"
> #include "Settings.h"
>@@ -103,6 +105,15 @@ extern "C" {
>     struct _WebKitNetworkRequestPrivate {
>         gchar* uri;
>     };
>+ 
>+    #define WEBKIT_AUTHENTICATION_CHALLENGE_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_AUTHENTICATION_CHALLENGE, WebKitAuthenticationChallengePrivate))
>+    typedef struct _WebKitAuthenticationChallengePrivate WebKitAuthenticationChallengePrivate;
>+    struct _WebKitAuthenticationChallengePrivate {
>+        WebCore::AuthenticationChallenge* webChallenge;
>+        WebCore::ResourceHandle* webHandle;
>+        gchar* user;
>+        gchar* password;
>+    };
> 
>     WebKitWebFrame*
>     webkit_web_frame_init_with_web_view(WebKitWebView*, WebCore::HTMLFrameOwnerElement*);
>Index: WebKit/gtk/webkit/webkitwebview.cpp
>===================================================================
>--- WebKit/gtk/webkit/webkitwebview.cpp	(revision 30340)
>+++ WebKit/gtk/webkit/webkitwebview.cpp	(working copy)
>@@ -85,6 +85,7 @@ enum {
>     COPY_CLIPBOARD,
>     PASTE_CLIPBOARD,
>     CUT_CLIPBOARD,
>+    AUTHENTICATION_REQUESTED,
>     LAST_SIGNAL
> };
> 
>@@ -379,7 +380,7 @@ static gboolean webkit_web_view_focus_in
>     GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
>     if (GTK_WIDGET_TOPLEVEL(toplevel) && gtk_window_has_toplevel_focus(GTK_WINDOW(toplevel))) {
>         WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
>-
>+        
>         Frame* frame = core(webView)->mainFrame();
>         core(webView)->focusController()->setActive(frame);
>     }
>@@ -605,6 +606,82 @@ static void webkit_web_view_real_paste_c
>     frame->editor()->command("Paste").execute();
> }
> 
>+typedef struct
>+{
>+    GtkWidget* user_entry;
>+    GtkWidget* password_entry;
>+    WebKitAuthenticationChallenge* challenge;
>+} AuthenticationDialogData;
>+
>+static void webkit_web_view_authentication_dialog_response_cb(GtkWidget* dialog, gint response, gpointer user_data)
>+{
>+    AuthenticationDialogData* data = reinterpret_cast<AuthenticationDialogData*>(user_data);
>+
>+    switch (response) {
>+    case GTK_RESPONSE_NONE:
>+    case GTK_RESPONSE_DELETE_EVENT:
>+    case GTK_RESPONSE_REJECT:
>+        webkit_authentication_challenge_continue_without_credential(data->challenge);
>+        break;
>+    case GTK_RESPONSE_ACCEPT:
>+        webkit_authentication_challenge_set_user(data->challenge,
>+                                                 gtk_entry_get_text(GTK_ENTRY(data->user_entry)));
>+        webkit_authentication_challenge_set_password(data->challenge,
>+                                                     gtk_entry_get_text(GTK_ENTRY(data->password_entry)));
>+        webkit_authentication_challenge_use_credential(data->challenge);
>+        break;
>+    default:
>+        g_assert_not_reached ();
>+        break;
>+    }
>+
>+    gtk_widget_destroy(dialog);
>+    g_object_unref(data->challenge);
>+}
>+
>+static void webkit_web_view_real_authentication_requested(WebKitWebView* webView, WebKitWebFrame* webFrame,
>+                                                          WebKitAuthenticationChallenge* challenge)
>+{
>+    GtkWidget* window;
>+    GtkWidget* dialog;
>+    GtkWidget* table;
>+    GtkWidget* label;
>+    AuthenticationDialogData* data;
>+
>+    window = gtk_widget_get_toplevel(GTK_WIDGET(webView));
>+    gchar* title = g_strconcat("Authentication - ", webkit_web_frame_get_uri(webFrame), NULL);
>+    dialog = gtk_dialog_new_with_buttons(title, GTK_WIDGET_TOPLEVEL(window) ? GTK_WINDOW(window) : 0,
>+                                         (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
>+                                         GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
>+                                         GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
>+                                         NULL);
>+    g_free(title);
>+    gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_REJECT);
>+
>+    data = g_new(AuthenticationDialogData, 1);
>+    data->user_entry = gtk_entry_new();
>+    data->password_entry = gtk_entry_new();
>+    gtk_entry_set_visibility(GTK_ENTRY(data->password_entry), FALSE);
>+    data->challenge = challenge;
>+    g_signal_connect(dialog, "response", G_CALLBACK(webkit_web_view_authentication_dialog_response_cb), data);
>+
>+    table = gtk_table_new(2, 2, FALSE);
>+    gtk_table_set_col_spacings(GTK_TABLE(table), 3);
>+    gtk_table_set_row_spacings(GTK_TABLE(table), 3);
>+
>+    label = gtk_label_new("Username:");
>+    gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
>+    gtk_table_attach_defaults(GTK_TABLE(table), data->user_entry, 1, 2, 0, 1);
>+
>+    label = gtk_label_new("Password:");
>+    gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
>+    gtk_table_attach_defaults(GTK_TABLE(table), data->password_entry, 1, 2, 1, 2);
>+
>+    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table);
>+    gtk_widget_show_all(table);
>+    gtk_widget_show(dialog);
>+}
>+
> static void webkit_web_view_finalize(GObject* object)
> {
>     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
>@@ -971,6 +1048,25 @@ static void webkit_web_view_class_init(W
>             g_cclosure_marshal_VOID__VOID,
>             G_TYPE_NONE, 0);
> 
>+    /**
>+     * WebKitWebView::authentication-requested:
>+     * @web_view: the object which received the signal
>+     *
>+     * The ::authentication-requested signal is emitted when an authentication is
>+     * requested from the server to access a resource.
>+     *
>+     * The default behavior for this signal is creating an input dialog to get a suitable credential.
>+     */
>+    webkit_web_view_signals[AUTHENTICATION_REQUESTED] = g_signal_new("authentication-requested",
>+            G_TYPE_FROM_CLASS(webViewClass),
>+            (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
>+            G_STRUCT_OFFSET(WebKitWebViewClass, authentication_requested),
>+            NULL, NULL,
>+            webkit_marshal_VOID__OBJECT_OBJECT,
>+            G_TYPE_NONE, 2,
>+            WEBKIT_TYPE_WEB_FRAME,
>+            WEBKIT_TYPE_AUTHENTICATION_CHALLENGE);
>+
>     /*
>      * implementations of virtual methods
>      */
>@@ -986,6 +1082,7 @@ static void webkit_web_view_class_init(W
>     webViewClass->cut_clipboard = webkit_web_view_real_cut_clipboard;
>     webViewClass->copy_clipboard = webkit_web_view_real_copy_clipboard;
>     webViewClass->paste_clipboard = webkit_web_view_real_paste_clipboard;
>+    webViewClass->authentication_requested = webkit_web_view_real_authentication_requested;
> 
>     GObjectClass* objectClass = G_OBJECT_CLASS(webViewClass);
>     objectClass->finalize = webkit_web_view_finalize;
>Index: WebKit/gtk/webkit/webkitwebview.h
>===================================================================
>--- WebKit/gtk/webkit/webkitwebview.h	(revision 30340)
>+++ WebKit/gtk/webkit/webkitwebview.h	(working copy)
>@@ -83,6 +83,7 @@ struct _WebKitWebViewClass {
>     void (*cut_clipboard) (WebKitWebView* web_view);
>     void (*copy_clipboard) (WebKitWebView* web_view);
>     void (*paste_clipboard) (WebKitWebView* web_view);
>+    void (*authentication_requested) (WebKitWebView* web_view, WebKitWebFrame* web_frame, WebKitAuthenticationChallenge* authentication_challenge);
> 
>     /*
>      * internal




I think apart from these issues the patch is good to go. Looking forward to
seeing the revised patch.


-- 
Configure bugmail: http://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list