[epiphany/mcatanzaro/opaque-origins] permissions-manager: stop using webkit_security_origin_is_opaque




commit 1ea827afe02914444bc02360a5d1abdcbad95e8d
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Thu Mar 11 12:25:46 2021 -0600

    permissions-manager: stop using webkit_security_origin_is_opaque
    
    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.

 lib/ephy-permissions-manager.c | 26 +++++++++++++++++++-------
 1 file 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);
 }
 


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