[epiphany/mcatanzaro/decide-policy: 3/3] Fix decide policy callbacks after addition of autoplay policy support



commit 2dc6f29961615724fa1a113fd0b13e0c5d88b709
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Tue Jun 30 21:11:33 2020 -0500

    Fix decide policy callbacks after addition of autoplay policy support
    
    Unfortunately we have split handling of policy decisions between
    EphyWebView and EphyWindow. EphyWebView handles response policy
    decisions, while EpyhWindow handles navigation policy decisions. !712
    added handling of navigation policy decisions at the EphyWebView level,
    which caused all the EphyWindow code to stop running. This broke opening
    links in new tabs and Safe Browsing, for example.

 embed/ephy-web-view.c | 66 ++++++---------------------------------------------
 src/ephy-window.c     | 51 ++++++++++++++++++++++++++++++++-------
 2 files changed, 50 insertions(+), 67 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index a0bf84d7d..e0b4eebe7 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -812,46 +812,10 @@ process_terminated_cb (EphyWebView                       *web_view,
 }
 
 static gboolean
-decide_navigation (WebKitWebView        *web_view,
-                   WebKitPolicyDecision *decision,
-                   gpointer              user_data)
-{
-  EphyEmbedShell *shell = ephy_embed_shell_get_default ();
-  WebKitWebsitePolicies *website_policies = NULL;
-  g_autofree gchar *origin = NULL;
-  WebKitNavigationPolicyDecision *navigation_policy_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision);
-  WebKitNavigationAction *navigation_action = webkit_navigation_policy_decision_get_navigation_action 
(navigation_policy_decision);
-  WebKitURIRequest *request = webkit_navigation_action_get_request (navigation_action);
-  const gchar *navigation_uri = webkit_uri_request_get_uri (request);
-  EphyPermission permission = EPHY_PERMISSION_UNDECIDED;
-
-  origin = ephy_uri_to_security_origin (navigation_uri);
-  if (origin)
-    permission = ephy_permissions_manager_get_permission (ephy_embed_shell_get_permissions_manager (shell),
-                                                          EPHY_PERMISSION_TYPE_AUTOPLAY_POLICY,
-                                                          origin);
-
-  switch (permission) {
-    case EPHY_PERMISSION_UNDECIDED:
-      website_policies = webkit_website_policies_new_with_policies ("autoplay", 
WEBKIT_AUTOPLAY_ALLOW_WITHOUT_SOUND, NULL);
-      break;
-    case EPHY_PERMISSION_PERMIT:
-      website_policies = webkit_website_policies_new_with_policies ("autoplay", WEBKIT_AUTOPLAY_ALLOW, NULL);
-      break;
-    case EPHY_PERMISSION_DENY:
-      website_policies = webkit_website_policies_new_with_policies ("autoplay", WEBKIT_AUTOPLAY_DENY, NULL);
-      break;
-  }
-
-  webkit_policy_decision_use_with_policies (decision, website_policies);
-  g_object_unref (website_policies);
-  return TRUE;
-}
-
-static gboolean
-decide_resource (WebKitWebView        *web_view,
-                 WebKitPolicyDecision *decision,
-                 gpointer              user_data)
+decide_policy_cb (WebKitWebView            *web_view,
+                  WebKitPolicyDecision     *decision,
+                  WebKitPolicyDecisionType  decision_type,
+                  gpointer                  user_data)
 {
   WebKitResponsePolicyDecision *response_decision;
   WebKitURIResponse *response;
@@ -862,6 +826,9 @@ decide_resource (WebKitWebView        *web_view,
   const char *request_uri;
   gboolean is_main_resource;
 
+  if (decision_type != WEBKIT_POLICY_DECISION_TYPE_RESPONSE)
+    return FALSE;
+
   /* If WebKit can handle the MIME type, let it.
    * Otherwise, we'll start a download.
    */
@@ -914,25 +881,6 @@ decide_resource (WebKitWebView        *web_view,
   return TRUE;
 }
 
-static gboolean
-decide_policy_cb (WebKitWebView            *web_view,
-                  WebKitPolicyDecision     *decision,
-                  WebKitPolicyDecisionType  decision_type,
-                  gpointer                  user_data)
-{
-  switch (decision_type) {
-    case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
-      return decide_navigation (web_view, decision, user_data);
-    case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
-      return decide_resource (web_view, decision, user_data);
-    case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
-      /* not handled */
-      break;
-  }
-
-  return TRUE;
-}
-
 typedef struct {
   EphyWebView *web_view;
   WebKitPermissionRequest *request;
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 181b59653..bccc5c4ff 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -45,6 +45,7 @@
 #include "ephy-mouse-gesture-controller.h"
 #include "ephy-notebook.h"
 #include "ephy-pages-view.h"
+#include "ephy-permissions-manager.h"
 #include "ephy-prefs.h"
 #include "ephy-security-popover.h"
 #include "ephy-session.h"
@@ -54,6 +55,7 @@
 #include "ephy-title-box.h"
 #include "ephy-title-widget.h"
 #include "ephy-type-builtins.h"
+#include "ephy-uri-helpers.h"
 #include "ephy-view-source-handler.h"
 #include "ephy-web-app-utils.h"
 #include "ephy-web-view.h"
@@ -2040,6 +2042,42 @@ verify_url_async_data_free (VerifyUrlAsyncData *data)
   g_free (data);
 }
 
+static gboolean
+accept_navigation_policy_decision (EphyWindow           *window,
+                                   WebKitPolicyDecision *decision,
+                                   const char           *uri)
+{
+  g_autoptr (WebKitWebsitePolicies) website_policies = NULL;
+  EphyPermission permission = EPHY_PERMISSION_UNDECIDED;
+  EphyEmbedShell *shell;
+  const char *origin;
+
+  shell = ephy_embed_shell_get_default ();
+
+  origin = ephy_uri_to_security_origin (uri);
+  if (origin) {
+    permission = ephy_permissions_manager_get_permission (ephy_embed_shell_get_permissions_manager (shell),
+                                                          EPHY_PERMISSION_TYPE_AUTOPLAY_POLICY,
+                                                          origin);
+  }
+
+  switch (permission) {
+    case EPHY_PERMISSION_UNDECIDED:
+      website_policies = webkit_website_policies_new_with_policies ("autoplay", 
WEBKIT_AUTOPLAY_ALLOW_WITHOUT_SOUND, NULL);
+      break;
+    case EPHY_PERMISSION_PERMIT:
+      website_policies = webkit_website_policies_new_with_policies ("autoplay", WEBKIT_AUTOPLAY_ALLOW, NULL);
+      break;
+    case EPHY_PERMISSION_DENY:
+      website_policies = webkit_website_policies_new_with_policies ("autoplay", WEBKIT_AUTOPLAY_DENY, NULL);
+      break;
+  }
+
+  webkit_policy_decision_use_with_policies (decision, website_policies);
+
+  return TRUE;
+}
+
 static gboolean
 decide_navigation_policy (WebKitWebView            *web_view,
                           WebKitPolicyDecision     *decision,
@@ -2077,8 +2115,7 @@ decide_navigation_policy (WebKitWebView            *web_view,
         if (error) {
           LOG ("failed to handle non web scheme: %s", error->message);
           g_error_free (error);
-
-          return FALSE;
+          return accept_navigation_policy_decision (window, decision, uri);
         }
       }
     }
@@ -2119,7 +2156,7 @@ decide_navigation_policy (WebKitWebView            *web_view,
     if (navigation_type == WEBKIT_NAVIGATION_TYPE_LINK_CLICKED ||
         (navigation_type == WEBKIT_NAVIGATION_TYPE_OTHER && webkit_navigation_action_is_user_gesture 
(navigation_action))) {
       if (ephy_web_application_is_uri_allowed (uri))
-        return FALSE;
+        return accept_navigation_policy_decision (window, decision, uri);
 
       /* We can't get here under flatpak because this code only
        * executes in web app mode.
@@ -2171,10 +2208,8 @@ decide_navigation_policy (WebKitWebView            *web_view,
         webkit_policy_decision_ignore (decision);
         return TRUE;
       }
-    }
-    /* Those were our special cases, we won't handle this */
-    else {
-      return FALSE;
+    } else {
+      return accept_navigation_policy_decision (window, decision, uri);
     }
 
     embed = ephy_embed_container_get_active_child
@@ -2205,7 +2240,7 @@ decide_navigation_policy (WebKitWebView            *web_view,
     return TRUE;
   }
 
-  return FALSE;
+  return accept_navigation_policy_decision (window, decision, uri);
 }
 
 static void


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