[epiphany] Allow web extension to control tests performed by URI tester
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Allow web extension to control tests performed by URI tester
- Date: Wed, 23 Nov 2016 22:45:08 +0000 (UTC)
commit 0e0a95b6262a04a07ad5e0908599844cea72660f
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Wed Nov 23 15:58:08 2016 -0600
Allow web extension to control tests performed by URI tester
So we can selectively disable HTTPS Everywhere
embed/ephy-uri-tester.c | 33 ++++++++++++++++++---------
embed/web-extension/ephy-uri-tester-proxy.c | 5 ++-
embed/web-extension/ephy-uri-tester-proxy.h | 5 +++-
embed/web-extension/ephy-web-extension.c | 3 +-
lib/ephy-uri-tester-interface.h | 9 +++++++
5 files changed, 40 insertions(+), 15 deletions(-)
---
diff --git a/embed/ephy-uri-tester.c b/embed/ephy-uri-tester.c
index 175dbbd..5171681 100644
--- a/embed/ephy-uri-tester.c
+++ b/embed/ephy-uri-tester.c
@@ -92,17 +92,20 @@ G_DEFINE_TYPE (EphyUriTester, ephy_uri_tester, G_TYPE_OBJECT)
typedef struct {
char *request_uri;
char *page_uri;
+ EphyUriTestFlags flags;
GDBusMethodInvocation *invocation;
} DeferredRequest;
static DeferredRequest *
deferred_request_new (const char *request_uri,
const char *page_uri,
+ EphyUriTestFlags flags,
GDBusMethodInvocation *invocation)
{
DeferredRequest *request = g_slice_new (DeferredRequest);
request->request_uri = g_strdup (request_uri);
request->page_uri = g_strdup (page_uri);
+ request->flags = flags;
/* Ownership of invocation is passed to g_dbus_method_invocation_return_value(). */
request->invocation = invocation;
return request;
@@ -847,21 +850,24 @@ ephy_uri_tester_test_uri (EphyUriTester *tester,
}
static char *
-ephy_uri_tester_rewrite_uri (EphyUriTester *tester,
- const char *request_uri,
- const char *page_uri)
+ephy_uri_tester_rewrite_uri (EphyUriTester *tester,
+ const char *request_uri,
+ const char *page_uri,
+ EphyUriTestFlags flags)
{
char *modified_uri = NULL;
char *result;
/* Should we block the URL outright? */
- if (g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ENABLE_ADBLOCK) &&
+ if ((flags & EPHY_URI_TEST_ADBLOCK) &&
+ g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ENABLE_ADBLOCK) &&
ephy_uri_tester_test_uri (tester, request_uri, page_uri)) {
g_debug ("Request '%s' blocked (page: '%s')", request_uri, page_uri);
return g_strdup ("");
}
- if (g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DO_NOT_TRACK)) {
+ if ((flags & EPHY_URI_TEST_TRACKING_QUERIES) &&
+ g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DO_NOT_TRACK)) {
/* Remove analytics from URL. Note that this function is a bit annoying to
* use: it returns NULL if it doesn't remove any query parameters. */
modified_uri = ephy_remove_tracking_from_uri (request_uri);
@@ -870,7 +876,8 @@ ephy_uri_tester_rewrite_uri (EphyUriTester *tester,
if (!modified_uri)
modified_uri = g_strdup (request_uri);
- if (g_str_has_prefix (request_uri, SOUP_URI_SCHEME_HTTP)) {
+ if ((flags & EPHY_URI_TEST_HTTPS_EVERYWHERE) &&
+ g_str_has_prefix (request_uri, SOUP_URI_SCHEME_HTTP)) {
result = https_everywhere_context_rewrite (tester->https_everywhere_context,
modified_uri);
g_free (modified_uri);
@@ -922,10 +929,11 @@ static void
ephy_uri_tester_return_response (EphyUriTester *tester,
const char *request_uri,
const char *page_uri,
+ EphyUriTestFlags flags,
GDBusMethodInvocation *invocation)
{
char *rewritten_uri;
- rewritten_uri = ephy_uri_tester_rewrite_uri (tester, request_uri, page_uri);
+ rewritten_uri = ephy_uri_tester_rewrite_uri (tester, request_uri, page_uri, flags);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", rewritten_uri));
g_free (rewritten_uri);
@@ -942,6 +950,7 @@ handle_method_call (GDBusConnection *connection,
gpointer user_data)
{
EphyUriTester *tester = EPHY_URI_TESTER (user_data);
+ EphyUriTestFlags flags = 0;
if (g_strcmp0 (interface_name, EPHY_URI_TESTER_INTERFACE) != 0)
return;
@@ -950,7 +959,7 @@ handle_method_call (GDBusConnection *connection,
const char *request_uri;
const char *page_uri;
- g_variant_get (parameters, "(&s&s)", &request_uri, &page_uri);
+ g_variant_get (parameters, "(&s&si)", &request_uri, &page_uri, &flags);
if (request_uri == NULL || request_uri == '\0') {
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
@@ -964,11 +973,12 @@ handle_method_call (GDBusConnection *connection,
return;
}
- if (!g_str_has_prefix (request_uri, SOUP_URI_SCHEME_HTTP) ||
+ if ((flags & EPHY_URI_TEST_HTTPS_EVERYWHERE) == 0 ||
+ !g_str_has_prefix (request_uri, SOUP_URI_SCHEME_HTTP) ||
https_everywhere_context_get_initialized (tester->https_everywhere_context)) {
- ephy_uri_tester_return_response (tester, request_uri, page_uri, invocation);
+ ephy_uri_tester_return_response (tester, request_uri, page_uri, flags, invocation);
} else {
- DeferredRequest *request = deferred_request_new (request_uri, page_uri, invocation);
+ DeferredRequest *request = deferred_request_new (request_uri, page_uri, flags, invocation);
tester->deferred_requests = g_list_append (tester->deferred_requests, request);
}
}
@@ -1020,6 +1030,7 @@ handle_deferred_request (DeferredRequest *request,
ephy_uri_tester_return_response (tester,
request->request_uri,
request->page_uri,
+ request->flags,
request->invocation);
}
diff --git a/embed/web-extension/ephy-uri-tester-proxy.c b/embed/web-extension/ephy-uri-tester-proxy.c
index 7a156ce..3540681 100644
--- a/embed/web-extension/ephy-uri-tester-proxy.c
+++ b/embed/web-extension/ephy-uri-tester-proxy.c
@@ -90,7 +90,8 @@ ephy_uri_tester_proxy_new (GDBusConnection *connection)
char *
ephy_uri_tester_proxy_maybe_rewrite_uri (EphyUriTesterProxy *uri_tester,
const char *request_uri,
- const char *page_uri)
+ const char *page_uri,
+ EphyUriTestFlags flags)
{
GVariant *variant;
char *modified_uri;
@@ -100,7 +101,7 @@ ephy_uri_tester_proxy_maybe_rewrite_uri (EphyUriTesterProxy *uri_tester,
variant = g_dbus_proxy_call_sync (uri_tester->proxy,
"MaybeRewriteUri",
- g_variant_new ("(ss)", request_uri, page_uri),
+ g_variant_new ("(ssi)", request_uri, page_uri, flags),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
diff --git a/embed/web-extension/ephy-uri-tester-proxy.h b/embed/web-extension/ephy-uri-tester-proxy.h
index 958eaa2..2050203 100644
--- a/embed/web-extension/ephy-uri-tester-proxy.h
+++ b/embed/web-extension/ephy-uri-tester-proxy.h
@@ -22,6 +22,8 @@
#include <gio/gio.h>
+#include "ephy-uri-tester-interface.h"
+
G_BEGIN_DECLS
#define EPHY_TYPE_URI_TESTER_PROXY (ephy_uri_tester_proxy_get_type ())
@@ -32,6 +34,7 @@ EphyUriTesterProxy *ephy_uri_tester_proxy_new (GDBusConnection *connection);
char *ephy_uri_tester_proxy_maybe_rewrite_uri (EphyUriTesterProxy *uri_tester,
const char *request_uri,
- const char *page_uri);
+ const char *page_uri,
+ EphyUriTestFlags flags);
G_END_DECLS
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index a247e6f..ea2b374 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -129,7 +129,8 @@ web_page_send_request (WebKitWebPage *web_page,
modified_uri = ephy_uri_tester_proxy_maybe_rewrite_uri (extension->uri_tester,
request_uri,
- page_uri);
+ page_uri,
+ EPHY_URI_TEST_ALL);
if (strlen (modified_uri) == 0) {
LOG ("Refused to load %s", request_uri);
diff --git a/lib/ephy-uri-tester-interface.h b/lib/ephy-uri-tester-interface.h
index 256277f..a90d2e9 100644
--- a/lib/ephy-uri-tester-interface.h
+++ b/lib/ephy-uri-tester-interface.h
@@ -28,9 +28,18 @@ static const char ephy_uri_tester_introspection_xml[] =
" <method name='MaybeRewriteUri'>"
" <arg name='request_uri' type='s' direction='in'/>"
" <arg name='page_uri' type='s' direction='in'/>"
+ " <arg name='flags' type='i' direction='in'/>"
" <arg name='modified_request_uri' type='s' direction='out'/>"
" </method>"
" </interface>"
"</node>";
+typedef enum
+{
+ EPHY_URI_TEST_ADBLOCK = 1 << 1,
+ EPHY_URI_TEST_TRACKING_QUERIES = 1 << 2,
+ EPHY_URI_TEST_HTTPS_EVERYWHERE = 1 << 3,
+ EPHY_URI_TEST_ALL = EPHY_URI_TEST_ADBLOCK | EPHY_URI_TEST_TRACKING_QUERIES |
EPHY_URI_TEST_HTTPS_EVERYWHERE
+} EphyUriTestFlags;
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]