[epiphany] Adblocker must not block main resource during redirects



commit f808d220af3508508903b792e294cfe70114048f
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Wed Aug 30 20:51:23 2017 -0500

    Adblocker must not block main resource during redirects
    
    Our logic to avoid blocking the main resource doesn't work during
    redirects.
    
    Also, move the GSettings check inside our helper function.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=787011

 embed/web-extension/ephy-web-extension.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index 9669bba..3ba991f 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -151,12 +151,20 @@ should_use_https_everywhere (const char *request_uri,
 
 static gboolean
 should_use_adblocker (const char *request_uri,
-                      const char *page_uri)
+                      const char *page_uri,
+                      const char *redirected_request_uri)
 {
-  /* Always load the main resource. */
+  if (!g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ENABLE_ADBLOCK))
+    return FALSE;
+
+  /* Always load the main resource... */
   if (g_strcmp0 (request_uri, page_uri) == 0)
     return FALSE;
 
+  /* ...even during a redirect, when page_uri is stale. */
+  if (g_strcmp0 (page_uri, redirected_request_uri) == 0)
+    return FALSE;
+
   /* Always load data requests, as uri_tester won't do any good here. */
   if (g_str_has_prefix (request_uri, SOUP_URI_SCHEME_DATA))
     return FALSE;
@@ -192,9 +200,9 @@ web_page_send_request (WebKitWebPage     *web_page,
 
   request_uri = webkit_uri_request_get_uri (request);
   page_uri = webkit_web_page_get_uri (web_page);
+  redirected_response_uri = redirected_response ? webkit_uri_response_get_uri (redirected_response) : NULL;
 
-  if (!should_use_adblocker (request_uri, page_uri) ||
-      !g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ENABLE_ADBLOCK))
+  if (!should_use_adblocker (request_uri, page_uri, redirected_response_uri))
     flags &= ~EPHY_URI_TEST_ADBLOCK;
 
   if (g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DO_NOT_TRACK)) {
@@ -207,7 +215,6 @@ web_page_send_request (WebKitWebPage     *web_page,
     modified_uri = ephy_remove_tracking_from_uri (request_uri);
   }
 
-  redirected_response_uri = redirected_response ? webkit_uri_response_get_uri (redirected_response) : NULL;
   if (!should_use_https_everywhere (request_uri, redirected_response_uri))
     flags &= ~EPHY_URI_TEST_HTTPS_EVERYWHERE;
 


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