[epiphany/wip/notification-permissions: 1/8] uri-helpers: Add function to convert URI to security origin



commit e924464c25e796cee17b2032f6756bacbadc76d5
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Thu Dec 29 12:54:43 2016 -0600

    uri-helpers: Add function to convert URI to security origin

 lib/ephy-uri-helpers.c |   16 +++++++++++++++-
 lib/ephy-uri-helpers.h |    2 ++
 2 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/lib/ephy-uri-helpers.c b/lib/ephy-uri-helpers.c
index 6a82221..be3ef44 100644
--- a/lib/ephy-uri-helpers.c
+++ b/lib/ephy-uri-helpers.c
@@ -1,6 +1,7 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  *  Copyright © 2013 Bastien Nocera <hadess hadess net>
+ *  Copyright © 2016 Igalia S.L.
  *
  *  This file is part of Epiphany.
  *
@@ -25,6 +26,7 @@
 #include <libsoup/soup.h>
 #include <string.h>
 #include <unicode/uidna.h>
+#include <webkit2/webkit2.h>
 
 /**
  * SECTION:ephy-uri-helpers
@@ -340,4 +342,16 @@ ephy_uri_normalize (const char *uri_string)
   return encoded_uri;
 }
 
-/* vim: set sw=2 ts=2 sts=2 et: */
+char *
+ephy_uri_to_security_origin (const char *uri_string)
+{
+  WebKitSecurityOrigin *origin;
+  const char *result;
+
+  /* Convert to URI containing only protocol, host, and port. */
+  origin = webkit_security_origin_new_for_uri (uri_string);
+  result = webkit_security_origin_to_string (origin);
+  webkit_security_origin_unref (origin);
+
+  return result != NULL ? g_strdup (result) : NULL;
+}
diff --git a/lib/ephy-uri-helpers.h b/lib/ephy-uri-helpers.h
index 4b77a96..cf46a6a 100644
--- a/lib/ephy-uri-helpers.h
+++ b/lib/ephy-uri-helpers.h
@@ -1,6 +1,7 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /*
  *  Copyright © 2013 Bastien Nocera <hadess hadess net>
+ *  Copyright © 2016 Igalia S.L.
  *
  *  This file is part of Epiphany.
  *
@@ -27,5 +28,6 @@ G_BEGIN_DECLS
 char *ephy_remove_tracking_from_uri (const char *uri);
 char *ephy_uri_decode (const char *uri);
 char *ephy_uri_normalize (const char *uri);
+char *ephy_uri_to_security_origin (const char *uri);
 
 G_END_DECLS


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