webkitsoupauthdialog.cpp [plain text]
#include "config.h"
#include "webkitsoupauthdialog.h"
#include "AuthenticationClient.h"
#include "ResourceHandle.h"
#include "webkitauthenticationdialog.h"
#include "webkitmarshal.h"
#include <wtf/text/CString.h>
using namespace WebCore;
class WebKitSoupAuthDialogAuthenticationClient : public WebCore::AuthenticationClient, public RefCounted<WebKitSoupAuthDialogAuthenticationClient> {
using RefCounted<WebKitSoupAuthDialogAuthenticationClient>::ref;
using RefCounted<WebKitSoupAuthDialogAuthenticationClient>::deref;
public:
virtual void didReceiveAuthenticationChallenge(const AuthenticationChallenge& challenge)
{
}
virtual void receivedRequestToContinueWithoutCredential(const AuthenticationChallenge& challenge)
{
soup_session_unpause_message(challenge.soupSession(), challenge.soupMessage());
}
virtual void receivedCredential(const AuthenticationChallenge& challenge, const Credential& credential)
{
soup_auth_authenticate(challenge.soupAuth(), credential.user().utf8().data(), credential.password().utf8().data());
soup_session_unpause_message(challenge.soupSession(), challenge.soupMessage());
}
virtual void receivedCancellation(const AuthenticationChallenge& challenge)
{
soup_session_unpause_message(challenge.soupSession(), challenge.soupMessage());
}
void derefWebKitSoupAuthDialogAuthenticationClient()
{
deref();
}
private:
virtual void refAuthenticationClient() { ref(); }
virtual void derefAuthenticationClient() { deref(); }
};
static void webkit_soup_auth_dialog_session_feature_init(SoupSessionFeatureInterface*, gpointer);
static void attach(SoupSessionFeature*, SoupSession*);
static void detach(SoupSessionFeature*, SoupSession*);
enum {
CURRENT_TOPLEVEL,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE_WITH_CODE(WebKitSoupAuthDialog, webkit_soup_auth_dialog, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(SOUP_TYPE_SESSION_FEATURE,
webkit_soup_auth_dialog_session_feature_init))
static void webkit_soup_auth_dialog_class_init(WebKitSoupAuthDialogClass* klass)
{
GObjectClass* objectClass = G_OBJECT_CLASS(klass);
signals[CURRENT_TOPLEVEL] = g_signal_new("current-toplevel",
G_OBJECT_CLASS_TYPE(objectClass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(WebKitSoupAuthDialogClass, current_toplevel),
0, 0,
webkit_marshal_OBJECT__OBJECT,
GTK_TYPE_WIDGET, 1,
SOUP_TYPE_MESSAGE);
}
static void webkit_soup_auth_dialog_init(WebKitSoupAuthDialog*)
{
}
static void webkit_soup_auth_dialog_session_feature_init(SoupSessionFeatureInterface *featureInterface, gpointer)
{
featureInterface->attach = attach;
featureInterface->detach = detach;
}
static void sessionAuthenticate(SoupSession* session, SoupMessage* message, SoupAuth* auth, gboolean retrying, SoupSessionFeature* manager)
{
GtkWindow* toplevel = 0;
g_signal_emit(manager, signals[CURRENT_TOPLEVEL], 0, message, &toplevel);
WebKitSoupAuthDialogAuthenticationClient* client = new WebKitSoupAuthDialogAuthenticationClient();
AuthenticationChallenge challenge(session, message, auth, retrying, client);
soup_session_unpause_message(session, message);
client->derefWebKitSoupAuthDialogAuthenticationClient();
GtkWidget* authDialog = createAuthenticationDialog(toplevel, challenge, DisallowPersistentStorage);
gtk_widget_show(authDialog);
}
static void attach(SoupSessionFeature* manager, SoupSession* session)
{
g_signal_connect(session, "authenticate", G_CALLBACK(sessionAuthenticate), manager);
}
static void detach(SoupSessionFeature* manager, SoupSession* session)
{
g_signal_handlers_disconnect_by_func(session, reinterpret_cast<gpointer>(sessionAuthenticate), manager);
}