[epiphany/kiosk-mode] Introduced support for only 1 tab/window behaviour



commit e71b821344617f101007e546f45257a195ce6c98
Author: Lorenzo Tilve Álvaro <ltilve igalia com>
Date:   Tue Jul 16 10:34:17 2013 +0200

    Introduced support for only 1 tab/window behaviour
    
    For some situations like on the kiosk-mode, it's neccesary that
    all the navigation is done on the same window and tab, which would
    be opened fullscreen and without controls to switch between tabs,
    so everything should be displated in the same view.
    
    A new setting is introduced as part of the lockdown system to
    enable this behaviour.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=703648

 data/org.gnome.epiphany.gschema.xml |    5 +++
 lib/ephy-prefs.h                    |    1 +
 src/ephy-lockdown.c                 |   11 +++++-
 src/ephy-shell.c                    |   25 +++++++++++---
 src/ephy-window.c                   |   59 +++++++++++++++++++++-------------
 5 files changed, 70 insertions(+), 31 deletions(-)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index b22fe65..ebdd109 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -277,5 +277,10 @@
                <key type="b" name="disable-javascript-chrome">
                        <default>false</default>
                </key>
+               <key type="b" name="disable-multiple-tabs">
+                       <default>false</default>
+                       <summary>Disable multiple tabs support</summary>
+                       <description>Whether to disable all the options to create new views in order to make 
all the browsing inside the same tab.</description>
+               </key>
        </schema>
 </schemalist>
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index cc42ccd..f94d1da 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -138,6 +138,7 @@ typedef enum
 #define EPHY_PREFS_LOCKDOWN_COMMAND_LINE      "disable-command-line"
 #define EPHY_PREFS_LOCKDOWN_QUIT              "disable-quit"
 #define EPHY_PREFS_LOCKDOWN_JAVASCRIPT_CHROME "disable-javascript-chrome"
+#define EPHY_PREFS_LOCKDOWN_MULTIPLE_TABS     "disable-multiple-tabs"
 
 G_END_DECLS
 
diff --git a/src/ephy-lockdown.c b/src/ephy-lockdown.c
index 56a4900..2a54a61 100644
--- a/src/ephy-lockdown.c
+++ b/src/ephy-lockdown.c
@@ -103,7 +103,10 @@ static const BindAction window_actions[] = {
   { EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "FileSaveAs", "sensitive" },
 
   { EPHY_PREFS_LOCKDOWN_FULLSCREEN, "ViewFullscreen", "sensitive" },
-  { EPHY_PREFS_LOCKDOWN_FULLSCREEN, "TabsDetach", "sensitive" }
+  { EPHY_PREFS_LOCKDOWN_FULLSCREEN, "TabsDetach", "sensitive" },
+
+  { EPHY_PREFS_LOCKDOWN_MULTIPLE_TABS, "FileNewWindow", "sensitive" },
+  { EPHY_PREFS_LOCKDOWN_MULTIPLE_TABS, "FileNewWindowIncognito", "sensitive"},
 };
 
 static const BindAction popup_actions[] = {
@@ -111,7 +114,9 @@ static const BindAction popup_actions[] = {
   { EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "DownloadLinkAs", "sensitive" },
   { EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "SaveImageAs", "sensitive" },
   { EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK, "OpenImage", "sensitive" },
-  { EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "BookmarkLink", "sensitive" }
+  { EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING, "BookmarkLink", "sensitive" },
+  { EPHY_PREFS_LOCKDOWN_MULTIPLE_TABS, "OpenLinkInNewTab", "sensitive" },
+  { EPHY_PREFS_LOCKDOWN_MULTIPLE_TABS, "OpenLinkInNewWindow", "sensitive" },
 };
 
 static const BindAction special_toolbar_actions[] = {
@@ -119,6 +124,8 @@ static const BindAction special_toolbar_actions[] = {
   { EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationBack", "sensitive" },
   { EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationForward", "visible" },
   { EPHY_PREFS_LOCKDOWN_HISTORY, "NavigationForward", "sensitive" },
+  { EPHY_PREFS_LOCKDOWN_MULTIPLE_TABS, "FileNewTab", "visible" },
+  { EPHY_PREFS_LOCKDOWN_MULTIPLE_TABS, "FileNewTab", "sensitive" },
 };
 
 static gboolean
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 1859e0b..208c3da 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -247,6 +247,7 @@ static void
 ephy_shell_startup (GApplication* application)
 {
   EphyEmbedShellMode mode;
+  GAction *gaction;
 #ifdef HAVE_WEBKIT2
   char *disk_cache_dir;
 #endif
@@ -300,6 +301,19 @@ ephy_shell_startup (GApplication* application)
                                   G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
     g_object_unref (builder);
   }
+
+  gaction = g_action_map_lookup_action (G_ACTION_MAP (application),
+                                        "new");
+  g_settings_bind (EPHY_SETTINGS_LOCKDOWN,
+                   EPHY_PREFS_LOCKDOWN_MULTIPLE_TABS,
+                   gaction, "enabled",
+                   G_SETTINGS_BIND_GET | G_SETTINGS_BIND_INVERT_BOOLEAN);
+  gaction = g_action_map_lookup_action (G_ACTION_MAP (application),
+                                        "new-incognito");
+  g_settings_bind (EPHY_SETTINGS_LOCKDOWN,
+                   EPHY_PREFS_LOCKDOWN_MULTIPLE_TABS,
+                   gaction, "enabled",
+                   G_SETTINGS_BIND_GET | G_SETTINGS_BIND_INVERT_BOOLEAN);
 }
 
 static void
@@ -327,15 +341,14 @@ ephy_shell_activate (GApplication *application)
 {
   EphyShell *shell = EPHY_SHELL (application);
 
+  EphyShellStartupContext *ctx = shell->priv->startup_context;
   /*
    * We get here on each new instance (remote or not). Autoresume the
-   * session unless we are in application mode and queue the
-   * commands.
+   * session unless we are in application mode or with multiple tabs disabled,
+   * and queue the commands.
    */
-  if (ephy_embed_shell_get_mode (EPHY_EMBED_SHELL (shell)) != EPHY_EMBED_SHELL_MODE_APPLICATION) {
-    EphyShellStartupContext *ctx;
-
-    ctx = shell->priv->startup_context;
+  if ((ephy_embed_shell_get_mode (EPHY_EMBED_SHELL (shell)) != EPHY_EMBED_SHELL_MODE_APPLICATION) &&
+    (ctx->arguments == NULL || !g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN, 
EPHY_PREFS_LOCKDOWN_MULTIPLE_TABS))) {
     ephy_session_resume (ephy_shell_get_session (shell),
                          ctx->user_time, NULL, session_load_cb, shell);
   } else
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 3eefd36..a183122 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -1,4 +1,5 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* vim: set sw=8 ts=8 sts=8 noet: */
 /*
  *  Copyright © 2000, 2001, 2002, 2003, 2004 Marco Pesenti Gritti
  *  Copyright © 2003, 2004 Christian Persch
@@ -2390,31 +2391,37 @@ create_web_view_cb (WebKitWebView *web_view,
        EphyNewTabFlags flags;
        EphyWindow *parent_window;
 
-       if (g_settings_get_boolean (EPHY_SETTINGS_MAIN,
-                                   EPHY_PREFS_NEW_WINDOWS_IN_TABS))
-       {
-               parent_window = window;
-               flags = EPHY_NEW_TAB_IN_EXISTING_WINDOW |
-                       EPHY_NEW_TAB_JUMP |
-                       EPHY_NEW_TAB_APPEND_AFTER;
-       }
-       else
-       {
-               parent_window = NULL;
-               flags = EPHY_NEW_TAB_IN_NEW_WINDOW |
-                       EPHY_NEW_TAB_DONT_SHOW_WINDOW;
-       }
+       if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN, EPHY_PREFS_LOCKDOWN_MULTIPLE_TABS)) {
+               flags = EPHY_NEW_TAB_OPEN_PAGE |
+                       EPHY_NEW_TAB_IN_EXISTING_WINDOW |
+                       EPHY_NEW_TAB_JUMP;
+               new_web_view = web_view;
+       } else {
+               if (g_settings_get_boolean (EPHY_SETTINGS_MAIN, EPHY_PREFS_NEW_WINDOWS_IN_TABS))
+               {
+                       parent_window = window;
+                       flags = EPHY_NEW_TAB_IN_EXISTING_WINDOW |
+                               EPHY_NEW_TAB_JUMP |
+                               EPHY_NEW_TAB_APPEND_AFTER;
+               }
+               else
+               {
+                       parent_window = NULL;
+                       flags = EPHY_NEW_TAB_IN_NEW_WINDOW |
+                               EPHY_NEW_TAB_DONT_SHOW_WINDOW;
+               }
 
-       embed = ephy_shell_new_tab_full (ephy_shell_get_default (),
-                                        parent_window,
-                                        EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (web_view),
-                                        NULL,
-                                        flags,
-                                        EPHY_WEB_VIEW_CHROME_ALL,
-                                        FALSE, /* is popup? */
-                                        0);
+               embed = ephy_shell_new_tab_full (ephy_shell_get_default (),
+                                                parent_window,
+                                                EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (web_view),
+                                                NULL,
+                                                flags,
+                                                EPHY_WEB_VIEW_CHROME_ALL,
+                                                FALSE, /* is popup? */
+                                                0);
 
-       new_web_view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
+               new_web_view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
+       }
 #ifdef HAVE_WEBKIT2
        g_signal_connect (new_web_view, "ready-to-show",
                          G_CALLBACK (web_view_ready_cb),
@@ -2548,6 +2555,12 @@ decide_policy_cb (WebKitWebView *web_view,
                ephy_web_view_set_visit_type (EPHY_WEB_VIEW (web_view),
                                              EPHY_PAGE_VISIT_LINK);
 
+               /* This avoids setting NEW_TAB / NEW_WINDOW flags when multiple tabs locked down and
+                * clicking the middle button or with CTRL or CTRL+SHIFT pressed */
+               if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN, EPHY_PREFS_LOCKDOWN_MULTIPLE_TABS)) {
+                       return TRUE;
+               };
+
                /* New tab in new window for control+shift+click */
                if (button == 1 && state == (GDK_SHIFT_MASK | GDK_CONTROL_MASK))
                {


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