[epiphany/revert-a186b184] Revert "Remove final leftovers of HTTPS Everywhere support"



commit 9492dc1cd2ebfaf81c3ed565ede0285e184d6b82
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Fri May 10 08:01:36 2019 +0000

    Revert "Remove final leftovers of HTTPS Everywhere support"
    
    This reverts commit a186b184c73a8cbdd0750eb0e6109a95089c28c6

 embed/web-extension/ephy-uri-tester.c    | 23 +++++++++++++++++++----
 embed/web-extension/ephy-uri-tester.h    | 10 +++++-----
 embed/web-extension/ephy-web-extension.c | 18 ++++++++++++++----
 3 files changed, 38 insertions(+), 13 deletions(-)
---
diff --git a/embed/web-extension/ephy-uri-tester.c b/embed/web-extension/ephy-uri-tester.c
index 1191b6069..feaa19c5d 100644
--- a/embed/web-extension/ephy-uri-tester.c
+++ b/embed/web-extension/ephy-uri-tester.c
@@ -566,10 +566,10 @@ file_read_cb (GFile *file, GAsyncResult *result, EphyUriTester *tester)
                                        (GAsyncReadyCallback)file_parse_cb, tester);
 }
 
-gboolean
-ephy_uri_tester_is_uri_allowed (EphyUriTester *tester,
-                                const char    *req_uri,
-                                const char    *page_uri)
+static gboolean
+ephy_uri_tester_block_uri (EphyUriTester *tester,
+                          const char    *req_uri,
+                          const char    *page_uri)
 {
   /* check whitelisting rules before the normal ones */
   if (ephy_uri_tester_is_matched (tester, NULL, req_uri, page_uri, TRUE))
@@ -577,6 +577,21 @@ ephy_uri_tester_is_uri_allowed (EphyUriTester *tester,
   return ephy_uri_tester_is_matched (tester, NULL, req_uri, page_uri, FALSE);
 }
 
+char *
+ephy_uri_tester_rewrite_uri (EphyUriTester    *tester,
+                             const char       *request_uri,
+                             const char       *page_uri)
+{
+  /* Should we block the URL outright? */
+  if (ephy_uri_tester_block_uri (tester, request_uri, page_uri)) {
+    g_debug ("Request '%s' blocked (page: '%s')", request_uri, page_uri);
+
+    return NULL;
+  }
+
+  return g_strdup (request_uri);
+}
+
 static void
 adblock_file_monitor_changed (GFileMonitor     *monitor,
                               GFile            *file,
diff --git a/embed/web-extension/ephy-uri-tester.h b/embed/web-extension/ephy-uri-tester.h
index bb3edcc38..5b22faad9 100644
--- a/embed/web-extension/ephy-uri-tester.h
+++ b/embed/web-extension/ephy-uri-tester.h
@@ -28,11 +28,11 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (EphyUriTester, ephy_uri_tester, EPHY, URI_TESTER, GObject)
 
-EphyUriTester *ephy_uri_tester_new            (const char       *adblock_data_dir);
-void           ephy_uri_tester_load           (EphyUriTester    *tester);
-gboolean       ephy_uri_tester_is_uri_allowed (EphyUriTester    *tester,
-                                               const char       *request_uri,
-                                               const char       *page_uri);
+EphyUriTester *ephy_uri_tester_new         (const char       *adblock_data_dir);
+void           ephy_uri_tester_load        (EphyUriTester    *tester);
+char          *ephy_uri_tester_rewrite_uri (EphyUriTester    *tester,
+                                            const char       *request_uri,
+                                            const char       *page_uri);
 
 
 G_END_DECLS
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index 88367b458..75c6afa2b 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -197,17 +197,27 @@ web_page_send_request (WebKitWebPage     *web_page,
     modified_uri = ephy_remove_tracking_from_uri (request_uri);
 
   if (should_use_adblocker (request_uri, page_uri, redirected_response_uri, extension)) {
-    gboolean result;
+    char *result;
 
     ephy_uri_tester_load (extension->uri_tester);
-    result = ephy_uri_tester_is_uri_allowed (extension->uri_tester,
-                                             modified_uri ? modified_uri : request_uri,
-                                             page_uri);
+    result = ephy_uri_tester_rewrite_uri (extension->uri_tester,
+                                          modified_uri ? modified_uri : request_uri,
+                                          page_uri);
     if (!result) {
       LOG ("Adblocker refused to load %s", request_uri);
       log_to_js_console (extension, web_page, _("Epiphany adblocker refused to load %s"), request_uri);
       return TRUE;
     }
+
+    g_free (modified_uri);
+    modified_uri = result;
+  } else if (!modified_uri) {
+    return FALSE;
+  }
+
+  if (g_strcmp0 (request_uri, modified_uri) != 0) {
+    LOG ("Rewrote %s to %s", request_uri, modified_uri);
+    webkit_uri_request_set_uri (request, modified_uri);
   }
 
   return FALSE;


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