[epiphany] application mode: track origins related to the application



commit 57c863c1680285c6af41a9b75a67c5d6dae58b73
Author: Gustavo Noronha Silva <gns gnome org>
Date:   Sat Oct 7 11:48:51 2017 -0300

    application mode: track origins related to the application
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788845

 embed/ephy-embed-shell.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++
 embed/ephy-embed-shell.h |    4 +++
 src/ephy-shell.c         |    5 ++++
 3 files changed, 67 insertions(+), 0 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 3d913df..9f45841 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -37,6 +37,7 @@
 #include "ephy-settings.h"
 #include "ephy-snapshot-service.h"
 #include "ephy-tabs-catalog.h"
+#include "ephy-uri-helpers.h"
 #include "ephy-uri-tester-shared.h"
 #include "ephy-web-app-utils.h"
 #include "ephy-web-extension-proxy.h"
@@ -73,6 +74,7 @@ typedef struct {
   EphyFiltersManager *filters_manager;
   EphySearchEngineManager *search_engine_manager;
   GCancellable *cancellable;
+  GList *app_origins;
 } EphyEmbedShellPrivate;
 
 enum {
@@ -184,6 +186,16 @@ ephy_embed_shell_dispose (GObject *object)
 }
 
 static void
+ephy_embed_shell_finalize (GObject *object)
+{
+  EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (EPHY_EMBED_SHELL (object));
+
+  g_list_free_full (priv->app_origins, g_free);
+
+  G_OBJECT_CLASS (ephy_embed_shell_parent_class)->dispose (object);
+}
+
+static void
 web_extension_form_auth_data_message_received_cb (WebKitUserContentManager *manager,
                                                   WebKitJavascriptResult   *message,
                                                   EphyEmbedShell           *shell)
@@ -1193,6 +1205,7 @@ ephy_embed_shell_class_init (EphyEmbedShellClass *klass)
   GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
 
   object_class->dispose = ephy_embed_shell_dispose;
+  object_class->finalize = ephy_embed_shell_finalize;
   object_class->set_property = ephy_embed_shell_set_property;
   object_class->get_property = ephy_embed_shell_get_property;
   object_class->constructed = ephy_embed_shell_constructed;
@@ -1484,6 +1497,51 @@ ephy_embed_shell_get_mode (EphyEmbedShell *shell)
 }
 
 /**
+ * ephy_embed_shell_add_app_related_uri:
+ * @shell: an #EphyEmbedShell
+ * @uri: the URI
+ **/
+void
+ephy_embed_shell_add_app_related_uri (EphyEmbedShell *shell, const char *uri)
+{
+  EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
+  char *origin;
+
+  g_assert (EPHY_IS_EMBED_SHELL (shell));
+  g_assert (priv->mode == EPHY_EMBED_SHELL_MODE_APPLICATION);
+
+  origin = ephy_uri_to_security_origin (uri);
+
+  if (!g_list_find_custom (priv->app_origins, origin, (GCompareFunc)g_strcmp0))
+    priv->app_origins = g_list_append (priv->app_origins, origin);
+}
+
+/**
+ * ephy_embed_shell_uri_looks_related_to_application:
+ * @shell: an #EphyEmbedShell
+ * @uri: the URI
+ *
+ * Returns: %TRUE if @uri looks related, %FALSE otherwise
+ **/
+gboolean
+ephy_embed_shell_uri_looks_related_to_app (EphyEmbedShell *shell,
+                                           const char     *uri)
+{
+  EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
+
+  g_assert (EPHY_IS_EMBED_SHELL (shell));
+  g_assert (priv->mode == EPHY_EMBED_SHELL_MODE_APPLICATION);
+
+  for (GList *iter = priv->app_origins; iter != NULL; iter = iter->next) {
+    const char *iter_uri = (const char *)iter->data;
+    if (ephy_embed_utils_urls_have_same_origin (iter_uri, uri))
+      return TRUE;
+  }
+
+  return FALSE;
+}
+
+/**
  * ephy_embed_shell_launch_handler:
  * @shell: an #EphyEmbedShell
  * @file: a #GFile to open
diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h
index 44d6cc7..c5b5dfd 100644
--- a/embed/ephy-embed-shell.h
+++ b/embed/ephy-embed-shell.h
@@ -73,6 +73,10 @@ gboolean           ephy_embed_shell_launch_handler             (EphyEmbedShell
                                                                 GFile            *file,
                                                                 const char       *mime_type,
                                                                 guint32           user_time);
+void               ephy_embed_shell_add_app_related_uri        (EphyEmbedShell   *shell,
+                                                                const char       *uri);
+gboolean           ephy_embed_shell_uri_looks_related_to_app   (EphyEmbedShell   *shell,
+                                                                const char       *uri);
 void               ephy_embed_shell_clear_cache                (EphyEmbedShell   *shell);
 void               ephy_embed_shell_set_thumbnail_path         (EphyEmbedShell   *shell,
                                                                 const char       *url,
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 5f9bf33..a715725 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -1230,6 +1230,11 @@ ephy_shell_open_uris (EphyShell       *shell,
 
   g_assert (EPHY_IS_SHELL (shell));
 
+  if (ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()) == EPHY_EMBED_SHELL_MODE_APPLICATION) {
+    for (int i = 0; uris[i] != NULL; i++)
+      ephy_embed_shell_add_app_related_uri (ephy_embed_shell_get_default (), uris[i]);
+  }
+
   data = open_uris_data_new (shell, uris, startup_flags, user_time);
   id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
                         (GSourceFunc)ephy_shell_open_uris_idle,


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