Title: [88929] trunk/Source/WebKit/efl
Revision
88929
Author
[email protected]
Date
2011-06-15 07:49:57 -0700 (Wed, 15 Jun 2011)

Log Message

2011-06-15  Kamil Blank  <[email protected]>

        Reviewed by Kenneth Rohde Christiansen.

        [EFL] Soup authentication feature implementation.
        https://bugs.webkit.org/show_bug.cgi?id=54752

        This implementation is based on GTK implementation.
        During ewk initialization SoupSessionFeature is added which provides possibility to handle HTTP basic auth.

        To support authentication we have to set function (callback) via ewk_auth_show_dialog_callback_set()
        which will be responsible for session authentication.
        If callback is set and authentication required - webkit pauses soup message, calls previously set callback
        and waits for authentication data (username/password) which should be passed by ewk_auth_credentials_set().

        * CMakeListsEfl.txt:
        * ewk/ewk_auth.cpp: Added.
        (ewk_auth_show_dialog_callback_set): Setting callback which should be called when authentication is required.
        (ewk_auth_credentials_set): Passing authentication data.
        * ewk/ewk_auth.h: Added. Authentication API.
        * ewk/ewk_auth_soup.cpp: Added. Soup authentication implementation.
        (_Ewk_Auth_Data::ewk_auth_soup_dialog_class_init):
        (_Ewk_Auth_Data::ewk_auth_soup_dialog_init):
        (_Ewk_Auth_Data::ewk_auth_soup_dialog_session_feature_init):
        (_Ewk_Auth_Data::ewk_auth_soup_show_dialog_callback_set):
        (_Ewk_Auth_Data::ewk_auth_soup_credentials_set):
        (_Ewk_Auth_Data::session_authenticate):
        (_Ewk_Auth_Data::free_auth_data):
        (_Ewk_Auth_Data::attach):
        (_Ewk_Auth_Data::detach):
        * ewk/ewk_auth_soup.h: Added.
        * ewk/ewk_main.cpp:
        (_ewk_init_body): SoupSessionFeature responsible for authentication added to SoupSession.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/efl/CMakeListsEfl.txt (88928 => 88929)


--- trunk/Source/WebKit/efl/CMakeListsEfl.txt	2011-06-15 14:38:14 UTC (rev 88928)
+++ trunk/Source/WebKit/efl/CMakeListsEfl.txt	2011-06-15 14:49:57 UTC (rev 88929)
@@ -100,6 +100,10 @@
 IF (WTF_USE_SOUP)
   LIST(APPEND WebKit_INCLUDE_DIRECTORIES ${LIBSOUP24_INCLUDE_DIRS})
   LIST(APPEND WebKit_LIBRARIES ${LIBSOUP24_LIBRARIES})
+  LIST(APPEND WebKit_SOURCES
+    efl/ewk/ewk_auth.cpp
+    efl/ewk/ewk_auth_soup.cpp
+  )
 ENDIF ()
 
 IF (WTF_USE_CURL)

Modified: trunk/Source/WebKit/efl/ChangeLog (88928 => 88929)


--- trunk/Source/WebKit/efl/ChangeLog	2011-06-15 14:38:14 UTC (rev 88928)
+++ trunk/Source/WebKit/efl/ChangeLog	2011-06-15 14:49:57 UTC (rev 88929)
@@ -1,3 +1,37 @@
+2011-06-15  Kamil Blank  <[email protected]>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [EFL] Soup authentication feature implementation.
+        https://bugs.webkit.org/show_bug.cgi?id=54752
+
+        This implementation is based on GTK implementation.
+        During ewk initialization SoupSessionFeature is added which provides possibility to handle HTTP basic auth.
+
+        To support authentication we have to set function (callback) via ewk_auth_show_dialog_callback_set()
+        which will be responsible for session authentication.
+        If callback is set and authentication required - webkit pauses soup message, calls previously set callback
+        and waits for authentication data (username/password) which should be passed by ewk_auth_credentials_set().
+
+        * CMakeListsEfl.txt:
+        * ewk/ewk_auth.cpp: Added.
+        (ewk_auth_show_dialog_callback_set): Setting callback which should be called when authentication is required.
+        (ewk_auth_credentials_set): Passing authentication data.
+        * ewk/ewk_auth.h: Added. Authentication API.
+        * ewk/ewk_auth_soup.cpp: Added. Soup authentication implementation.
+        (_Ewk_Auth_Data::ewk_auth_soup_dialog_class_init):
+        (_Ewk_Auth_Data::ewk_auth_soup_dialog_init):
+        (_Ewk_Auth_Data::ewk_auth_soup_dialog_session_feature_init):
+        (_Ewk_Auth_Data::ewk_auth_soup_show_dialog_callback_set):
+        (_Ewk_Auth_Data::ewk_auth_soup_credentials_set):
+        (_Ewk_Auth_Data::session_authenticate):
+        (_Ewk_Auth_Data::free_auth_data):
+        (_Ewk_Auth_Data::attach):
+        (_Ewk_Auth_Data::detach):
+        * ewk/ewk_auth_soup.h: Added.
+        * ewk/ewk_main.cpp:
+        (_ewk_init_body): SoupSessionFeature responsible for authentication added to SoupSession.
+
 2011-06-15  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r88723.

Added: trunk/Source/WebKit/efl/ewk/ewk_auth.cpp (0 => 88929)


--- trunk/Source/WebKit/efl/ewk/ewk_auth.cpp	                        (rev 0)
+++ trunk/Source/WebKit/efl/ewk/ewk_auth.cpp	2011-06-15 14:49:57 UTC (rev 88929)
@@ -0,0 +1,44 @@
+/*
+    Copyright (C) 2011 Samsung Electronics
+
+    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 "ewk_auth.h"
+
+#ifdef WTF_USE_SOUP
+#include "ewk_auth_soup.h"
+#endif
+
+/**
+ * Sets callback to be called when authentication is required.
+ *
+ * @param callback callback to be called.
+ */
+void ewk_auth_show_dialog_callback_set(Ewk_Auth_Show_Dialog_Callback callback)
+{
+#if USE(SOUP)
+    ewk_auth_soup_show_dialog_callback_set(callback);
+#endif
+}
+
+void ewk_auth_credentials_set(char* username, char* password, void* data)
+{
+#if USE(SOUP)
+    ewk_auth_soup_credentials_set(username, password, data);
+#endif
+}

Added: trunk/Source/WebKit/efl/ewk/ewk_auth.h (0 => 88929)


--- trunk/Source/WebKit/efl/ewk/ewk_auth.h	                        (rev 0)
+++ trunk/Source/WebKit/efl/ewk/ewk_auth.h	2011-06-15 14:49:57 UTC (rev 88929)
@@ -0,0 +1,60 @@
+/*
+    Copyright (C) 2011 Samsung Electronics
+
+    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.
+*/
+
+/**
+ * @file    ewk_auth.h
+ * @brief   Describes the authentication API.
+ */
+
+#ifndef ewk_auth_h
+#define ewk_auth_h
+
+#include <Eina.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Callback to be called when authentication is required.
+ *
+ * @param realm auth's realm
+ * @param uri uri
+ * @param data points to WebKitAuthData
+ */
+typedef void (*Ewk_Auth_Show_Dialog_Callback)(const char* realm, const char* uri, void* data);
+
+/**
+ * Sets callback to be called when authentication is required
+ */
+EAPI void ewk_auth_show_dialog_callback_set(Ewk_Auth_Show_Dialog_Callback);
+
+/**
+ * Calls authentication method for setting credentials.
+ *
+ * @param username username
+ * @param password user password
+ * @param data soup authentication data
+ */
+EAPI void ewk_auth_credentials_set(char* username, char* password, void* data);
+
+#ifdef __cplusplus
+}
+#endif
+#endif // ewk_auth_h

Added: trunk/Source/WebKit/efl/ewk/ewk_auth_soup.cpp (0 => 88929)


--- trunk/Source/WebKit/efl/ewk/ewk_auth_soup.cpp	                        (rev 0)
+++ trunk/Source/WebKit/efl/ewk/ewk_auth_soup.cpp	2011-06-15 14:49:57 UTC (rev 88929)
@@ -0,0 +1,141 @@
+/*
+    Copyright (C) 2009 Igalia S.L.
+    Copyright (C) 2011 Samsung Electronics
+
+    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 "ewk_auth_soup.h"
+
+#include "EWebKit.h"
+#include "ewk_auth.h"
+#include "ewk_logging.h"
+#include <glib-object.h>
+#include <glib.h>
+#include <libsoup/soup.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * #Ewk_Soup_Auth_Dialog is a #SoupSessionFeature that you can attach to your
+ * #SoupSession to provide a simple authentication dialog while
+ * handling HTTP basic auth. It is built as a simple C-only module
+ * to ease reuse.
+ */
+
+typedef struct _Ewk_Auth_Data {
+    SoupMessage* msg;
+    SoupAuth* auth;
+    SoupSession* session;
+} Ewk_Auth_Data;
+
+static Ewk_Auth_Show_Dialog_Callback ewk_auth_show_dialog_callback = 0;
+
+static void ewk_auth_soup_dialog_session_feature_init(SoupSessionFeatureInterface*, gpointer);
+static void attach(SoupSessionFeature*, SoupSession*);
+static void detach(SoupSessionFeature*, SoupSession*);
+static void free_auth_data(Ewk_Auth_Data*);
+
+G_DEFINE_TYPE_WITH_CODE(Ewk_Soup_Auth_Dialog, ewk_auth_soup_dialog, G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE(SOUP_TYPE_SESSION_FEATURE, ewk_auth_soup_dialog_session_feature_init))
+
+static void ewk_auth_soup_dialog_class_init(Ewk_Soup_Auth_DialogClass* klass)
+{
+}
+
+static void ewk_auth_soup_dialog_init(Ewk_Soup_Auth_Dialog* instance)
+{
+}
+
+static void ewk_auth_soup_dialog_session_feature_init(SoupSessionFeatureInterface *feature_interface, gpointer interface_data)
+{
+    feature_interface->attach = attach;
+    feature_interface->detach = detach;
+}
+
+void ewk_auth_soup_show_dialog_callback_set(Ewk_Auth_Show_Dialog_Callback callback)
+{
+    ewk_auth_show_dialog_callback = callback;
+}
+
+void ewk_auth_soup_credentials_set(const char* username, const char* password, void* data)
+{
+    if (!data)
+        return;
+
+    Ewk_Auth_Data* auth_data = (Ewk_Auth_Data*)data;
+    soup_auth_authenticate(auth_data->auth, username, password);
+    soup_session_unpause_message(auth_data->session, auth_data->msg);
+    free_auth_data(auth_data);
+}
+
+static void session_authenticate(SoupSession* session, SoupMessage* msg, SoupAuth* auth, gboolean retrying, gpointer /* user_data */)
+{
+    SoupURI* uri;
+    Ewk_Auth_Data* auth_data;
+    const char* realm;
+
+    if (!ewk_auth_show_dialog_callback)
+        return;
+
+    auth_data = (Ewk_Auth_Data*)calloc(1, sizeof(Ewk_Auth_Data));
+
+    if (!auth_data) {
+        CRITICAL("could not allocate Ewk_Auth_Data");
+        return;
+    }
+
+    soup_session_pause_message(session, msg);
+    // We need to make sure the message sticks around when pausing it.
+    g_object_ref(msg);
+    g_object_ref(session);
+    g_object_ref(auth);
+
+    auth_data->msg = msg;
+    auth_data->auth = auth;
+    auth_data->session = session;
+
+    uri = soup_message_get_uri(auth_data->msg);
+    realm = soup_auth_get_realm(auth_data->auth);
+
+    // Call application method responsible for showing authentication dialog and sending back authorization data.
+    ewk_auth_show_dialog_callback(realm, soup_uri_to_string(uri, TRUE), auth_data);
+}
+
+static void free_auth_data(Ewk_Auth_Data* auth_data)
+{
+    g_object_unref(auth_data->msg);
+    g_object_unref(auth_data->session);
+    g_object_unref(auth_data->auth);
+    free(auth_data);
+}
+
+static void attach(SoupSessionFeature* manager, SoupSession* session)
+{
+    g_signal_connect(session, "authenticate", G_CALLBACK(session_authenticate), manager);
+}
+
+static void detach(SoupSessionFeature* manager, SoupSession* session)
+{
+    g_signal_handlers_disconnect_by_func(session, (void*)session_authenticate, manager);
+}
+
+#ifdef __cplusplus
+}
+#endif

Added: trunk/Source/WebKit/efl/ewk/ewk_auth_soup.h (0 => 88929)


--- trunk/Source/WebKit/efl/ewk/ewk_auth_soup.h	                        (rev 0)
+++ trunk/Source/WebKit/efl/ewk/ewk_auth_soup.h	2011-06-15 14:49:57 UTC (rev 88929)
@@ -0,0 +1,67 @@
+/*
+    Copyright (C) 2009 Igalia S.L.
+    Copyright (C) 2011 Samsung Electronics
+
+    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 ewk_auth_soup_h
+#define ewk_auth_soup_h
+
+#include "ewk_auth.h"
+#include <glib-object.h>
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define EWK_TYPE_SOUP_AUTH_DIALOG            (ewk_auth_soup_dialog_get_type())
+#define EWK_SOUP_AUTH_DIALOG(object)         (G_TYPE_CHECK_INSTANCE_CAST((object), EWK_TYPE_SOUP_AUTH_DIALOG, Ewk_Soup_Auth_Dialog))
+#define EWK_SOUP_AUTH_DIALOG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), EWK_TYPE_SOUP_AUTH_DIALOG, Ewk_Soup_Auth_Dialog))
+#define EWK_IS_SOUP_AUTH_DIALOG(object)      (G_TYPE_CHECK_INSTANCE_TYPE((object), EWK_TYPE_SOUP_AUTH_DIALOG))
+#define EWK_IS_SOUP_AUTH_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EWK_TYPE_SOUP_AUTH_DIALOG))
+#define EWK_SOUP_AUTH_DIALOG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), EWK_TYPE_SOUP_AUTH_DIALOG, Ewk_Soup_Auth_Dialog))
+
+typedef struct {
+    GObject parent_instance;
+} Ewk_Soup_Auth_Dialog;
+
+typedef struct {
+    GObjectClass parent_class;
+} Ewk_Soup_Auth_DialogClass;
+
+GType ewk_auth_soup_dialog_get_type(void);
+
+/**
+ *  Sets callback to be called when authentication is required.
+ */
+void ewk_auth_soup_show_dialog_callback_set(Ewk_Auth_Show_Dialog_Callback callback);
+
+/**
+ *  Method for setting credentials
+ *
+ *  @param username username
+ *  @param password password
+ *  @param data soup authentication data
+ */
+void ewk_auth_soup_credentials_set(const char* username, const char* password, void* data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // ewk_auth_soup_h

Modified: trunk/Source/WebKit/efl/ewk/ewk_main.cpp (88928 => 88929)


--- trunk/Source/WebKit/efl/ewk/ewk_main.cpp	2011-06-15 14:38:14 UTC (rev 88928)
+++ trunk/Source/WebKit/efl/ewk/ewk_main.cpp	2011-06-15 14:49:57 UTC (rev 88929)
@@ -53,6 +53,7 @@
 #if USE(SOUP)
 // REMOVE-ME: see todo below
 #include "ResourceHandle.h"
+#include "ewk_auth_soup.h"
 #include <libsoup/soup.h>
 #endif
 
@@ -210,9 +211,11 @@
         SoupSession* session = WebCore::ResourceHandle::defaultSession();
         soup_session_add_feature_by_type(session, SOUP_TYPE_CONTENT_SNIFFER);
         soup_session_add_feature_by_type(session, SOUP_TYPE_CONTENT_DECODER);
+
+        SoupSessionFeature* auth_dialog = static_cast<SoupSessionFeature*>(g_object_new(EWK_TYPE_SOUP_AUTH_DIALOG, 0));
+        soup_session_add_feature(session, auth_dialog);
     }
 #endif
 
     return EINA_TRUE;
 }
-
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to