[yelp/wip/amigadave/webkit2-port: 39/53] yelp-view: Do not block/unlock policy decision callback



commit 7b4690cbd26958a73494d4363d2a7a678d381069
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Thu Apr 9 14:28:53 2015 +0200

    yelp-view: Do not block/unlock policy decision callback
    
    Use a boolean variable to decide whether we need to resolve the uri or
    not in policy decision callback.

 libyelp/yelp-view.c |   34 ++++++++++++++--------------------
 1 files changed, 14 insertions(+), 20 deletions(-)
---
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index 251e2b2..d7216bd 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
@@ -260,7 +260,7 @@ struct _YelpViewPrivate {
 
     GSList         *link_actions;
 
-    gint            navigation_requested;
+    gboolean        resolve_uri_on_policy_decision;
 };
 
 #define TARGET_TYPE_URI_LIST     "text/uri-list"
@@ -341,9 +341,9 @@ yelp_view_init (YelpView *view)
                               G_CALLBACK (gtk_xft_dpi_changed), view);
     }
 
-    priv->navigation_requested =
-        g_signal_connect (view, "decide-policy",
-                          G_CALLBACK (view_policy_decision_requested), NULL);
+    priv->resolve_uri_on_policy_decision = TRUE;
+    g_signal_connect (view, "decide-policy",
+                      G_CALLBACK (view_policy_decision_requested), NULL);
     g_signal_connect (view, "load-changed",
                       G_CALLBACK (view_load_status_changed), NULL);
     g_signal_connect (view, "load-failed",
@@ -1691,16 +1691,20 @@ view_policy_decision_requested (YelpView                *view,
                                 gpointer                 user_data)
 {
     YelpViewPrivate *priv = GET_PRIV (view);
-    WebKitNavigationPolicyDecision *navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision);
-    WebKitURIRequest *request = webkit_navigation_policy_decision_get_request (navigation_decision);
-    const gchar *requri = webkit_uri_request_get_uri (request);
+    WebKitURIRequest *request;
     gchar *fixed_uri;
     YelpUri *uri;
 
     if (type != WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION)
         return FALSE;
 
-    fixed_uri = build_yelp_uri (requri);
+    if (!priv->resolve_uri_on_policy_decision) {
+        priv->resolve_uri_on_policy_decision = TRUE;
+        return FALSE;
+    }
+
+    request = webkit_navigation_policy_decision_get_request (WEBKIT_NAVIGATION_POLICY_DECISION (decision));
+    fixed_uri = build_yelp_uri (webkit_uri_request_get_uri (request));
 
     webkit_policy_decision_ignore (decision);
 
@@ -1777,9 +1781,6 @@ view_load_status_changed (WebKitWebView   *view,
         break;
     }
     case WEBKIT_LOAD_FINISHED:
-
-        g_signal_handler_unblock (view, priv->navigation_requested);
-
         g_object_set (view, "state", YELP_VIEW_STATE_LOADED, NULL);
 
         /* Setting adjustments only work after the page is loaded. These
@@ -1828,9 +1829,6 @@ view_load_failed (WebKitWebView  *view,
                   GError         *error,
                   gpointer        user_data)
 {
-    YelpViewPrivate *priv = GET_PRIV (view);
-
-    g_signal_handler_unblock (view, priv->navigation_requested);
     view_show_error_page (YELP_VIEW (view), error);
 }
 
@@ -1866,8 +1864,6 @@ view_history_action (GAction   *action,
     GList *newcur;
     YelpViewPrivate *priv = GET_PRIV (view);
 
-    g_signal_handler_unblock (view, priv->navigation_requested);
-
     if (priv->back_cur == NULL)
         return;
 
@@ -1899,8 +1895,6 @@ view_navigation_action (GAction  *action,
     gchar *page_id, *new_id, *xref;
     YelpUri *new_uri;
 
-    g_signal_handler_unblock (view, priv->navigation_requested);
-
     page_id = yelp_uri_get_page_id (priv->uri);
 
     if (g_str_equal (g_action_get_name (action), "yelp-view-go-previous"))
@@ -2021,7 +2015,7 @@ view_load_page (YelpView *view)
     uri_str = build_network_uri (uri_str);
     g_free (tmp_uri);
 
-    g_signal_handler_block (view, priv->navigation_requested);
+    priv->resolve_uri_on_policy_decision = FALSE;
     webkit_web_view_load_uri (WEBKIT_WEB_VIEW (view), uri_str);
 
     g_free (uri_str);
@@ -2173,7 +2167,7 @@ view_show_error_page (YelpView *view,
 
     g_signal_emit (view, signals[LOADED], 0);
 
-    g_signal_handler_block (view, priv->navigation_requested);
+    priv->resolve_uri_on_policy_decision = FALSE;
     webkit_web_view_load_html  (WEBKIT_WEB_VIEW (view),
                                 page,
                                 "file:///error/");


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