summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Catanzaro <mcatanzaro@gnome.org>2021-03-11 12:25:46 -0600
committerMichael Catanzaro <mcatanzaro@gnome.org>2021-03-11 12:41:48 -0600
commit1ea827afe02914444bc02360a5d1abdcbad95e8d (patch)
treec3a18783fcc08022f27f015c86e45756d569e186
parent8c786d148fd116f5815061c1597cf0983ad44e7a (diff)
downloadepiphany-mcatanzaro/opaque-origins.tar.gz
permissions-manager: stop using webkit_security_origin_is_opaquemcatanzaro/opaque-origins
I deprecated this function in WebKit r274270. It no longer does anything, so let's stop using it. The original code here was not quite right anyway, because it would return -1 whenever any origin is opaque. This is not how comparison functions are supposed to work: it means a < b and also b < a at the same time, which is outrageous. It just never mattered because the security origins used here come from the main resource URI, which is never opaque, so we can assert that there is always a protocol and host. If we are looking up permissions for a protocol that doesn't include a host component, like file:/// or something, we have already lost.
-rw-r--r--lib/ephy-permissions-manager.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/ephy-permissions-manager.c b/lib/ephy-permissions-manager.c
index d7c8be82e..3691f6000 100644
--- a/lib/ephy-permissions-manager.c
+++ b/lib/ephy-permissions-manager.c
@@ -191,13 +191,25 @@ static gint
webkit_security_origin_compare (WebKitSecurityOrigin *a,
WebKitSecurityOrigin *b)
{
- if (webkit_security_origin_is_opaque (a))
- return -1;
- if (webkit_security_origin_is_opaque (b))
- return 1;
-
- return g_strcmp0 (webkit_security_origin_get_protocol (a), webkit_security_origin_get_protocol (b)) ||
- g_strcmp0 (webkit_security_origin_get_host (a), webkit_security_origin_get_host (b)) ||
+ const char *protocol_a, *protocol_b;
+ const char *host_a, *host_b;
+
+ protocol_a = webkit_security_origin_get_protocol (a);
+ protocol_b = webkit_security_origin_get_protocol (b);
+ host_a = webkit_security_origin_get_host (a);
+ host_b = webkit_security_origin_get_host (b);
+
+ /* Security origins objects with NULL protocol or host do not represent the
+ * same origin as others with NULL protocol or host. That is, they're not
+ * equal. Therefore, they cannot be ordered, and must not be passed to this
+ * compare function.
+ */
+ g_assert (protocol_a != NULL);
+ g_assert (protocol_b != NULL);
+ g_assert (host_a != NULL);
+ g_assert (host_b != NULL);
+
+ return strcmp (protocol_a, protocol_b) || strcmp (host_a, host_b) ||
webkit_security_origin_get_port (b) - webkit_security_origin_get_port (a);
}