[balsa/gtk3] Handle all types of clicked links



commit 4c1f1879cd1218fc4cf04379d5b71f24d16df31f
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Thu Mar 28 09:03:29 2013 -0400

    Handle all types of clicked links
    
        * libbalsa/html.c (lbh_navigation_policy_decision),
        (lbh_new_window_policy_decision), (lbh_response_policy_decision):
        Clicking a link may cause a new window policy decision, instead
        of a navigation policy decision; we handle both cases.

 ChangeLog       |    7 +++++++
 libbalsa/html.c |   50 ++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 45 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d7cacac..43eb98c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-03-28  Peter Bloomfield
+
+       * libbalsa/html.c (lbh_navigation_policy_decision),
+       (lbh_new_window_policy_decision), (lbh_response_policy_decision):
+       Clicking a link may cause a new window policy decision, instead
+       of a navigation policy decision; we handle both cases.
+
 2013-03-27  Peter Bloomfield
 
        * libbalsa/html.c: reduce zoom factor to +/- 20%.
diff --git a/libbalsa/html.c b/libbalsa/html.c
index 6ee48ae..f4086d6 100644
--- a/libbalsa/html.c
+++ b/libbalsa/html.c
@@ -85,6 +85,13 @@ lbh_get_body_content(LibBalsaMessageBody * body, gchar ** buf)
  * Experimental support for WebKit2.
  */
 
+#define DEBUG_WEBKIT2 FALSE
+#if DEBUG_WEBKIT2
+#define d(x) x
+#else
+#define d(x)
+#endif
+
 #include <webkit2/webkit2.h>
 #include <JavaScriptCore/JavaScript.h>
 
@@ -189,14 +196,23 @@ lbh_navigation_policy_decision(WebKitPolicyDecision * decision,
     switch (webkit_navigation_policy_decision_get_navigation_type
             (navigation_decision)) {
     case WEBKIT_NAVIGATION_TYPE_OTHER:
+    case WEBKIT_NAVIGATION_TYPE_RELOAD:
+        d(g_print("%s type %d, used\n", __func__,
+                  webkit_navigation_policy_decision_get_navigation_type
+                  (navigation_decision)));
         webkit_policy_decision_use(decision);
         break;
     case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED:
         request =
             webkit_navigation_policy_decision_get_request
             (navigation_decision);
+        d(g_print("%s clicked %s\n", __func__,
+                  webkit_uri_request_get_uri(request)));
         (*info->clicked_cb) (webkit_uri_request_get_uri(request));
     default:
+        d(g_print("%s type %d, ignored\n", __func__,
+                  webkit_navigation_policy_decision_get_navigation_type
+                  (navigation_decision)));
         webkit_policy_decision_ignore(decision);
     }
 }
@@ -207,25 +223,35 @@ lbh_new_window_policy_decision(WebKitPolicyDecision * decision,
 {
     WebKitNavigationPolicyDecision *navigation_decision =
         WEBKIT_NAVIGATION_POLICY_DECISION(decision);
+    LibBalsaWebKitInfo *info = data;
+    WebKitURIRequest *request;
 
-    g_print("%s type %d\n", __func__,
-            webkit_navigation_policy_decision_get_navigation_type
-            (navigation_decision));
-    webkit_policy_decision_ignore(decision);
+    switch (webkit_navigation_policy_decision_get_navigation_type
+            (navigation_decision)) {
+    case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED:
+        request =
+            webkit_navigation_policy_decision_get_request
+            (navigation_decision);
+        d(g_print("%s clicked %s\n", __func__,
+                  webkit_uri_request_get_uri(request)));
+        (*info->clicked_cb) (webkit_uri_request_get_uri(request));
+    default:
+        d(g_print("%s type %d, ignored\n", __func__,
+                  webkit_navigation_policy_decision_get_navigation_type
+                  (navigation_decision)));
+
+        webkit_policy_decision_ignore(decision);
+    }
 }
 
 static void
 lbh_response_policy_decision(WebKitPolicyDecision * decision,
                              gpointer               data)
 {
-    WebKitResponsePolicyDecision *response =
-        WEBKIT_RESPONSE_POLICY_DECISION(decision);
-    WebKitURIRequest *request;
-    const gchar *uri;
-
-    request = webkit_response_policy_decision_get_request(response);
-    uri = webkit_uri_request_get_uri(request);
-    g_print("%s uri %s\n", __func__, uri);
+    d(g_print("%s uri %s, ignored\n", __func__,
+              webkit_uri_request_get_uri
+              (webkit_response_policy_decision_get_request
+               (WEBKIT_RESPONSE_POLICY_DECISION(decision)))));
     webkit_policy_decision_ignore(decision);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]