2007-11-22 Michael Natterer <mitch@imendio.com>
authoralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Nov 2007 01:52:25 +0000 (01:52 +0000)
committeralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Nov 2007 01:52:25 +0000 (01:52 +0000)
        Reviewed by Alp Toker.

        http://bugs.webkit.org/show_bug.cgi?id=15984
        Implement "navigation-requested" signal for WebKit Gtk

        * Api/webkitgtknetworkrequest.h: fix parent class member.

        * Api/webkitgtknetworkrequest.cpp
        * Api/webkitgtkprivate.h: basic implementation featuring an
        "url" member and API.

        * Api/webkitgtkdefines.h: added network request typedefs.

        * Api/webkitgtkpage.h: fix enum name:
        s/WEBKIT_NAVIGATION_REQUEST_RESPONSE/WebKitNavigationRequestResponse/
        and sanitized enum values.

        * Api/webkitgtkpage.cpp: made "navigation-requested" a signal.

        * Api/webkitgtk-marshal.list: added INT:OBJECT,OBJECT

        * WebCoreSupport/FrameLoaderClientGtk.cpp: emit the new signal in
        dispatchDecidePolicyForNavigationAction().

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

WebKit/gtk/Api/webkitgtk-marshal.list
WebKit/gtk/Api/webkitgtkdefines.h
WebKit/gtk/Api/webkitgtknetworkrequest.cpp
WebKit/gtk/Api/webkitgtknetworkrequest.h
WebKit/gtk/Api/webkitgtkpage.cpp
WebKit/gtk/Api/webkitgtkpage.h
WebKit/gtk/Api/webkitgtkprivate.h
WebKit/gtk/ChangeLog
WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp

index 1a011fd87c315f346356aece1882efc27080e1dd..5bafa412e2d6b3e86758b117142fbc2d1ebf3f45 100644 (file)
@@ -5,3 +5,4 @@ BOOLEAN:STRING,INT,STRING
 BOOLEAN:OBJECT,STRING
 BOOLEAN:OBJECT,STRING,BOOLEAN
 BOOLEAN:OBJECT,STRING,STRING,STRING
+INT:OBJECT,OBJECT
index eaf593ffa75eaecf198a6418cc489dd5055f5464..d945488e1b581d203cb0fa37e296157403e06bfb 100644 (file)
@@ -35,11 +35,13 @@ typedef struct _WebKitFrame WebKitFrame;
 typedef struct _WebKitFrameClass WebKitFrameClass;
 
 typedef struct _WebKitFrameData WebKitFrameData;
-typedef struct _WebKitNetworkRequest WebKitNetworkRequest;
 
 typedef struct _WebKitPage WebKitPage;
 typedef struct _WebKitPageClass WebKitPageClass;
 
+typedef struct _WebKitNetworkRequest WebKitNetworkRequest;
+typedef struct _WebKitNetworkRequestClass WebKitNetworkRequestClass;
+
 #ifdef G_OS_WIN32
     #ifdef BUILDING_WEBKIT
         #define WEBKIT_API __declspec(dllexport)
index b3171f5db27fed6ff4fff18405bf233c8877cada..69b882275e0ea28e3159372f3b358bea8704c46e 100644 (file)
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "config.h"
+
 #include "webkitgtknetworkrequest.h"
+#include "webkitgtkprivate.h"
+
+using namespace WebKit;
+using namespace WebCore;
+
+extern "C" {
+
+G_DEFINE_TYPE(WebKitNetworkRequest, webkit_network_request, G_TYPE_OBJECT);
+
+static void webkit_network_request_finalize(GObject* object)
+{
+    WebKitNetworkRequestPrivate* requestPrivate = WEBKIT_NETWORK_REQUEST_GET_PRIVATE(object);
+
+    g_free(requestPrivate->url);
+
+    G_OBJECT_CLASS(webkit_network_request_parent_class)->finalize(object);
+}
+
+static void webkit_network_request_class_init(WebKitNetworkRequestClass* requestClass)
+{
+    g_type_class_add_private(requestClass, sizeof(WebKitNetworkRequestPrivate));
+
+    G_OBJECT_CLASS(requestClass)->finalize = webkit_network_request_finalize;
+}
+
+static void webkit_network_request_init(WebKitNetworkRequest* request)
+{
+}
+
+WebKitNetworkRequest* webkit_network_request_new(const gchar* url)
+{
+    WebKitNetworkRequest* request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, NULL));
+    WebKitNetworkRequestPrivate* requestPrivate = WEBKIT_NETWORK_REQUEST_GET_PRIVATE(request);
+
+    requestPrivate->url = g_strdup(url);
+
+    return request;
+}
+
+void webkit_network_request_set_url(WebKitNetworkRequest* request, const gchar* url)
+{
+    WebKitNetworkRequestPrivate* requestPrivate;
+
+    g_return_if_fail(WEBKIT_IS_NETWORK_REQUEST(request));
+
+    requestPrivate = WEBKIT_NETWORK_REQUEST_GET_PRIVATE(request);
+
+    g_free(requestPrivate->url);
+    requestPrivate->url = g_strdup(url);
+}
+
+const gchar* webkit_network_request_get_url(WebKitNetworkRequest* request)
+{
+    WebKitNetworkRequestPrivate* requestPrivate;
+
+    g_return_val_if_fail(WEBKIT_IS_NETWORK_REQUEST(request), NULL);
+
+    requestPrivate = WEBKIT_NETWORK_REQUEST_GET_PRIVATE(request);
+
+    return requestPrivate->url;
+}
+
+}
index c91e969226b0030430908e5c6e42caf215fa1fa8..6fe2982961122c80af76d9f60c4b201aef5be935 100644 (file)
@@ -43,22 +43,25 @@ G_BEGIN_DECLS
 #define WEBKIT_NETWORK_REQUEST_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_NETWORK_REQUEST, WebKitNetworkRequestClass))
 
 
-typedef struct _WebKitNetworkRequest WebKitNetworkRequest;
-typedef struct _WebKitNetworkRequestClass WebKitNetworkRequestClass;
-
 struct _WebKitNetworkRequest {
     GObject parent;
 };
 
 struct _WebKitNetworkRequestClass {
-    GObject parent;
+    GObjectClass parent;
 };
 
 WEBKIT_API GType
 webkit_network_request_get_type (void);
 
-WEBKIT_API GObject*
-webkit_network_request_new (void);
+WEBKIT_API WebKitNetworkRequest*
+webkit_network_request_new (const gchar* url);
+
+WEBKIT_API void
+webkit_network_request_set_url (WebKitNetworkRequest* request, const gchar* url);
+
+WEBKIT_API const gchar*
+webkit_network_request_get_url (WebKitNetworkRequest* request);
 
 G_END_DECLS
 
index 4fc5d9f19a6fd4527eaadc5db680d7aee93be89b..94add0b2a273f6bdf0f17b16c8c836f3d16a5e42 100644 (file)
@@ -57,6 +57,7 @@ extern "C" {
 
 enum {
     /* normal signals */
+    NAVIGATION_REQUESTED,
     LOAD_STARTED,
     LOAD_PROGRESS_CHANGED,
     LOAD_FINISHED,
@@ -208,10 +209,10 @@ static WebKitPage* webkit_page_real_create_page(WebKitPage*)
     return 0;
 }
 
-static WEBKIT_NAVIGATION_REQUEST_RESPONSE webkit_page_real_navigation_requested(WebKitPage*, WebKitFrame* frame, WebKitNetworkRequest*)
+static WebKitNavigationResponse webkit_page_real_navigation_requested(WebKitPage*, WebKitFrame* frame, WebKitNetworkRequest*)
 {
     notImplemented();
-    return WEBKIT_ACCEPT_NAVIGATION_REQUEST;
+    return WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
 }
 
 static gchar* webkit_page_real_choose_file(WebKitPage*, WebKitFrame*, const gchar* old_name)
@@ -337,6 +338,17 @@ static void webkit_page_class_init(WebKitPageClass* pageClass)
 {
     g_type_class_add_private(pageClass, sizeof(WebKitPagePrivate));
 
+    webkit_page_signals[NAVIGATION_REQUESTED] = g_signal_new("navigation_requested",
+            G_TYPE_FROM_CLASS(pageClass),
+            (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
+            G_STRUCT_OFFSET (WebKitPageClass, navigation_requested),
+            NULL,
+            NULL,
+            webkit_marshal_INT__OBJECT_OBJECT,
+            G_TYPE_INT, 2,
+            G_TYPE_OBJECT,
+            G_TYPE_OBJECT);
+
 
     /*
      * signals
index 5f1201e043ceda08b8eda4174e103796e8506690..25fb88744ce4f0fc6a48a42e0aca739d759a8076 100644 (file)
@@ -45,10 +45,10 @@ G_BEGIN_DECLS
 
 
 typedef enum {
-    WEBKIT_ACCEPT_NAVIGATION_REQUEST,
-    WEBKIT_IGNORE_NAVIGATION_REQUEST,
-    WEBKIT_DOWNLOAD_NAVIGATION_REQUEST
-} WEBKIT_NAVIGATION_REQUEST_RESPONSE;
+    WEBKIT_NAVIGATION_RESPONSE_ACCEPT,
+    WEBKIT_NAVIGATION_RESPONSE_IGNORE,
+    WEBKIT_NAVIGATION_RESPONSE_DOWNLOAD
+} WebKitNavigationResponse;
 
 
 
@@ -70,7 +70,7 @@ struct _WebKitPageClass {
     /*
      * TODO: FIXME: Create something like WebPolicyDecisionListener_Protocol instead
      */
-    WEBKIT_NAVIGATION_REQUEST_RESPONSE (*navigation_requested) (WebKitPage* page, WebKitFrame* frame, WebKitNetworkRequest* request);
+    WebKitNavigationResponse (*navigation_requested) (WebKitPage* page, WebKitFrame* frame, WebKitNetworkRequest* request);
 
     gchar*   (*choose_file) (WebKitPage* page, WebKitFrame* frame, const gchar* old_file);
     gboolean (*script_alert) (WebKitPage* page, WebKitFrame* frame, const gchar* alert_message);
index 10f67b7e475da6cd187bffacc8227d9276fd70bf..9f167a452f35edc8afc219d0afa0f491f09d091c 100644 (file)
@@ -83,6 +83,12 @@ extern "C" {
         gchar* location;
     };
 
+    #define WEBKIT_NETWORK_REQUEST_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_NETWORK_REQUEST, WebKitNetworkRequestPrivate))
+    typedef struct _WebKitNetworkRequestPrivate WebKitNetworkRequestPrivate;
+    struct _WebKitNetworkRequestPrivate {
+        gchar* url;
+    };
+
 
     GObject* webkit_frame_init_with_page(WebKitPage*, WebCore::HTMLFrameOwnerElement*);
 }
index 89ef89df1effb1043d24d15e63be0e4fee6f4e27..6482909e4d1ea4d302c8ddb95c50953c09e98842 100644 (file)
@@ -1,3 +1,29 @@
+2007-11-22  Michael Natterer  <mitch@imendio.com>
+
+        Reviewed by Alp Toker.
+
+        http://bugs.webkit.org/show_bug.cgi?id=15984
+        Implement "navigation-requested" signal for WebKit Gtk
+
+        * Api/webkitgtknetworkrequest.h: fix parent class member.
+
+        * Api/webkitgtknetworkrequest.cpp
+        * Api/webkitgtkprivate.h: basic implementation featuring an
+        "url" member and API.
+
+        * Api/webkitgtkdefines.h: added network request typedefs.
+
+        * Api/webkitgtkpage.h: fix enum name:
+        s/WEBKIT_NAVIGATION_REQUEST_RESPONSE/WebKitNavigationRequestResponse/
+        and sanitized enum values.
+
+        * Api/webkitgtkpage.cpp: made "navigation-requested" a signal.
+
+        * Api/webkitgtk-marshal.list: added INT:OBJECT,OBJECT
+
+        * WebCoreSupport/FrameLoaderClientGtk.cpp: emit the new signal in
+        dispatchDecidePolicyForNavigationAction().
+
 2007-11-18  Christian Dywan  <christian@twotoasts.de>
 
         Reviewed by Alp.
index ab29248254450180782c31750b3b4a5fa1c73de8..fdce5a1c774dbef8d6824c2160567324505486c3 100644 (file)
@@ -243,11 +243,25 @@ void FrameLoaderClient::dispatchDecidePolicyForNewWindowAction(FramePolicyFuncti
     (core(m_frame)->loader()->*policyFunction)(PolicyIgnore);
 }
 
-void FrameLoaderClient::dispatchDecidePolicyForNavigationAction(FramePolicyFunction policyFunction, const NavigationAction&, const ResourceRequest&)
+void FrameLoaderClient::dispatchDecidePolicyForNavigationAction(FramePolicyFunction policyFunction, const NavigationAction& action, const ResourceRequest& resourceRequest)
 {
     ASSERT(policyFunction);
     if (!policyFunction)
         return;
+
+    WebKitPage* page = getPageFromFrame(m_frame);
+    WebKitNetworkRequest* request = webkit_network_request_new(resourceRequest.url().url().utf8().data());
+    WebKitNavigationResponse response;
+
+    g_signal_emit_by_name(page, "navigation_requested", m_frame, request, &response);
+
+    g_object_unref(request);
+
+    if (response == WEBKIT_NAVIGATION_RESPONSE_IGNORE) {
+        (core(m_frame)->loader()->*policyFunction)(PolicyIgnore);
+        return;
+    }
+
     (core(m_frame)->loader()->*policyFunction)(PolicyUse);
 }