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




commit 81154ba810997e1b4d82fdb6ae430f151be96f72
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 | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/lib/ephy-permissions-manager.c b/lib/ephy-permissions-manager.c
index d7c8be82e..b22055901 100644
--- a/lib/ephy-permissions-manager.c
+++ b/lib/ephy-permissions-manager.c
@@ -191,14 +191,26 @@ 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)) ||
-         webkit_security_origin_get_port (b) - webkit_security_origin_get_port (a);
+  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);
 }
 
 static void


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