[epiphany] First iteration for 'Incognito mode'



commit 5660617413c37eb397a50361b6ca5bdd250b5be5
Author: Xan Lopez <xan igalia com>
Date:   Wed Dec 12 10:58:06 2012 +0100

    First iteration for 'Incognito mode'
    
    For now this is just a private mode but with the following two twists:
    
    - We use the dark theme.
    
    - We steal our history and bookmarks from the main profile. This is
      done in 'read-only' mode though, so any changes made in this session
      will be lost.
    
    Add command line options and a UI item to launch the browser in this
    mode.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676914

 lib/ephy-file-helpers.c                    |   49 ++++++++-
 lib/ephy-file-helpers.h                    |    1 +
 src/ephy-main.c                            |   33 +++++-
 src/ephy-shell.c                           |    9 ++
 src/ephy-window.c                          |    3 +
 src/resources/epiphany-application-menu.ui |    5 +
 src/resources/epiphany-ui.xml              |    1 +
 src/window-commands.c                      |    9 ++
 src/window-commands.h                      |  166 ++++++++++++++--------------
 9 files changed, 184 insertions(+), 92 deletions(-)
---
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 92adcce..898e218 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -3,6 +3,7 @@
  *  Copyright  2002 Jorn Baayen
  *  Copyright  2003, 2004 Marco Pesenti Gritti
  *  Copyright  2004, 2005, 2006 Christian Persch
+ *  Copyright  2012 Igalia S.L.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -303,7 +304,9 @@ ephy_file_helpers_init (const char *profile_dir,
 			EphyFileHelpersFlags flags,
 			GError **error)
 {
+	gboolean ret = TRUE;
 	gboolean private_profile;
+	gboolean steal_data_from_profile;
 
 	ephy_file_helpers_error_quark = g_quark_from_static_string ("ephy-file-helpers-error");
 
@@ -314,8 +317,9 @@ ephy_file_helpers_init (const char *profile_dir,
 
 	keep_directory = flags & EPHY_FILE_HELPERS_KEEP_DIR;
 	private_profile = flags & EPHY_FILE_HELPERS_PRIVATE_PROFILE;
+	steal_data_from_profile = flags & EPHY_FILE_HELPERS_STEAL_DATA;
 
-	if (private_profile && profile_dir != NULL)
+	if (private_profile && profile_dir != NULL && !steal_data_from_profile)
 	{
 		dot_dir = g_strdup (profile_dir);
 	}
@@ -344,9 +348,46 @@ ephy_file_helpers_init (const char *profile_dir,
 	}
 
 	if (flags & EPHY_FILE_HELPERS_ENSURE_EXISTS)
-		return ephy_ensure_dir_exists (ephy_dot_dir (), error);
-	else
-		return TRUE;
+		ret = ephy_ensure_dir_exists (ephy_dot_dir (), error);
+
+	if (steal_data_from_profile && profile_dir)
+	{
+		int i;
+		char *files_to_copy[] = { "ephy-history.db", "ephy-bookmarks.xml" };
+		
+		for (i = 0; i < G_N_ELEMENTS (files_to_copy); i++)
+		{
+			char *filename;
+			GError *error = NULL;
+			GFile *source, *destination;
+
+			filename = g_build_filename (profile_dir,
+						     files_to_copy[i],
+						     NULL);
+			source = g_file_new_for_path (filename);
+			g_free (filename);
+			
+			filename = g_build_filename (dot_dir,
+						     files_to_copy[i],
+						     NULL);
+			destination = g_file_new_for_path (filename);
+			g_free (filename);
+
+			g_file_copy (source, destination,
+				     G_FILE_COPY_OVERWRITE,
+				     NULL, NULL, NULL, &error);
+			if (error)
+			{
+				printf("Error stealing file %s from profile: %s\n", files_to_copy[i], error->message);
+				g_error_free (error);
+			}
+				
+			g_object_unref (source);
+			g_object_unref (destination);
+		}
+	}
+
+	return ret;
 }
 
 static void
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index 8ed792f..5eed9ed 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -48,6 +48,7 @@ typedef enum
 	EPHY_FILE_HELPERS_KEEP_DIR	   = 1 << 1,
 	EPHY_FILE_HELPERS_PRIVATE_PROFILE  = 1 << 2,
 	EPHY_FILE_HELPERS_ENSURE_EXISTS	   = 1 << 3,
+	EPHY_FILE_HELPERS_STEAL_DATA       = 1 << 4
 } EphyFileHelpersFlags;
 
 gboolean           ephy_file_helpers_init                   (const char            *profile_dir,
diff --git a/src/ephy-main.c b/src/ephy-main.c
index 10450d7..04c82b6 100644
--- a/src/ephy-main.c
+++ b/src/ephy-main.c
@@ -56,6 +56,7 @@ static char *application_to_delete = NULL;
 
 /* Only set from options in debug builds */
 static gboolean private_instance = FALSE;
+static gboolean incognito_mode = FALSE;
 static gboolean application_mode = FALSE;
 static gboolean keep_temp_directory = FALSE;
 static char *profile_directory = NULL;
@@ -86,6 +87,10 @@ static const GOptionEntry option_entries[] =
     N_("Add a bookmark"), N_("URL") },
   { "private-instance", 'p', 0, G_OPTION_ARG_NONE, &private_instance,
     N_("Start a private instance"), NULL },
+  { "incognito-mode", 'i', 0, G_OPTION_ARG_NONE, &incognito_mode,
+    N_("Start an instance in incognito mode"), NULL },
+  { "netbank-mode", 0, 0, G_OPTION_ARG_NONE, &incognito_mode,
+    N_("Start an instance in netbank mode"), NULL },
   { "application-mode", 'a', 0, G_OPTION_ARG_NONE, &application_mode,
     N_("Start the browser in application mode"), NULL },
   { "profile", 0, 0, G_OPTION_ARG_STRING, &profile_directory,
@@ -353,8 +358,8 @@ main (int argc,
     exit (1);
   }
 
-  if (profile_directory != NULL && private_instance == FALSE && application_mode == FALSE) {
-    g_print ("--profile can only be used in combination with --private-instance or --application-mode\n");
+  if (profile_directory != NULL && private_instance == FALSE && application_mode == FALSE && incognito_mode == FALSE) {
+    g_print ("--profile can only be used in combination with --private-instance, --incognito-mode or --application-mode\n");
     exit (1);
   }
 
@@ -368,12 +373,18 @@ main (int argc,
       exit (1);
   }
 
+  if (incognito_mode && profile_directory == NULL) {
+    g_print ("--incognito-mode needs a --profile parameter to steal the data from\n");
+    exit (1);
+  }
+
   /* Work-around Flash Player crash */
   g_setenv ("XLIB_SKIP_ARGB_VISUALS", "1", FALSE);
 
   /* Run the migration in all cases, except when running a private
-     instance without a given profile directory. */
-  if (!(private_instance && profile_directory == FALSE)) {
+     instance without a given profile directory or running in
+     incognito mode. */
+  if (!(private_instance && profile_directory == NULL) && incognito_mode == FALSE) {
     /* If the migration fails we don't really want to continue. */
     if (!ephy_profile_utils_do_migration ((const char *)profile_directory, -1, FALSE)) {
       g_print ("Failed to run the migrator process, Web will now abort.");
@@ -384,8 +395,10 @@ main (int argc,
   /* Start our services */
   flags = EPHY_FILE_HELPERS_ENSURE_EXISTS;
 
-  if (private_instance || application_mode)
+  if (incognito_mode || private_instance || application_mode)
     flags |= EPHY_FILE_HELPERS_PRIVATE_PROFILE;
+  if (incognito_mode)
+    flags |= EPHY_FILE_HELPERS_STEAL_DATA;
   if (keep_temp_directory || profile_directory)
     flags |= EPHY_FILE_HELPERS_KEEP_DIR;
 
@@ -433,7 +446,15 @@ main (int argc,
   /* Now create the shell */
   if (private_instance)
     mode = EPHY_EMBED_SHELL_MODE_PRIVATE;
-  else if (application_mode) {
+  else if (incognito_mode) {
+    /* Internally incognito mode is also a private mode. */
+    mode = EPHY_EMBED_SHELL_MODE_PRIVATE;
+
+    /* Use the right theming. */
+    g_object_set (gtk_settings_get_default (),
+                  "gtk-application-prefer-dark-theme", TRUE,
+                  NULL);
+  } else if (application_mode) {
     char *app_name;
     char *app_icon;
 
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 3c4cbfc..813eea3 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -165,6 +165,14 @@ new_window (GSimpleAction *action,
 }
 
 static void
+new_incognito_window (GSimpleAction *action,
+                      GVariant *parameter,
+                      gpointer user_data)
+{
+  window_cmd_file_new_incognito_window (NULL, NULL);
+}
+
+static void
 show_bookmarks (GSimpleAction *action,
                 GVariant *parameter,
                 gpointer user_data)
@@ -218,6 +226,7 @@ quit_application (GSimpleAction *action,
 
 static GActionEntry app_entries[] = {
   { "new", new_window, NULL, NULL, NULL },
+  { "incognito", new_incognito_window, NULL, NULL, NULL },
   { "bookmarks", show_bookmarks, NULL, NULL, NULL },
   { "history", show_history, NULL, NULL, NULL },
   { "preferences", show_preferences, NULL, NULL, NULL },
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 6858b47..dbabe40 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -103,6 +103,8 @@ static const GtkActionEntry ephy_menu_entries [] = {
 
 	{ "FileNewWindow", NULL, N_("_New Window"), "<control>N", NULL,
 	  G_CALLBACK (window_cmd_file_new_window) },
+	{ "FileNewWindowIncognito", NULL, N_("New _Incognito Window"), "<control><shift>N", NULL,
+	  G_CALLBACK (window_cmd_file_new_incognito_window) },
 	{ "FileOpen", NULL, N_("_Openâ"), "<control>O", NULL,
 	  G_CALLBACK (window_cmd_file_open) },
 	{ "FileSaveAs", NULL, N_("Save _Asâ"), "<shift><control>S", NULL,
@@ -3777,6 +3779,7 @@ _gtk_css_provider_load_from_resource (GtkCssProvider* provider,
 
 static const gchar* app_actions[] = {
 	"FileNewWindow",
+	"FileNewWindowIncognito",
 	"EditPreferences",
 	"EditPersonalData",
 	"EditBookmarks",
diff --git a/src/resources/epiphany-application-menu.ui b/src/resources/epiphany-application-menu.ui
index ab0202b..36fa068 100644
--- a/src/resources/epiphany-application-menu.ui
+++ b/src/resources/epiphany-application-menu.ui
@@ -4,6 +4,11 @@
     <section>
       <item>
         <attribute name="label" translatable="yes">_New Window</attribute>
+        <attribute name="action">app.new-incognito</attribute>
+        <attribute name="accel">&lt;Primary&gt;i</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">New _Incognito Window</attribute>
         <attribute name="action">app.new</attribute>
         <attribute name="accel">&lt;Primary&gt;n</attribute>
       </item>
diff --git a/src/resources/epiphany-ui.xml b/src/resources/epiphany-ui.xml
index 493cff2..4afa856 100644
--- a/src/resources/epiphany-ui.xml
+++ b/src/resources/epiphany-ui.xml
@@ -69,6 +69,7 @@
 
 	<popup name="PagePopup" action="PagePopupAction" accelerators="true">
                 <menuitem name="FileNewWindowMenu" action="FileNewWindow"/>
+                <menuitem name="FileNewWindowIncognitoMenu" action="FileNewWindowIncognito"/>
                 <menuitem name="FileNewTabMenu" action="FileNewTab"/>
                 <menuitem name="FileOpenMenu" action="FileOpen"/>
                 <separator name="FileSep1"/>	
diff --git a/src/window-commands.c b/src/window-commands.c
index 17f334a..99b8c1a 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -734,6 +734,15 @@ window_cmd_file_new_window (GtkAction *action,
 }
 
 void
+window_cmd_file_new_incognito_window (GtkAction *action,
+				      EphyWindow *window)
+{
+	char *str = g_strdup_printf ("epiphany --incognito-mode --profile %s", ephy_dot_dir ());
+	g_spawn_command_line_async (str, NULL);
+	g_free (str);
+}
+
+void
 window_cmd_edit_undo (GtkAction *action,
 		      EphyWindow *window)
 {
diff --git a/src/window-commands.h b/src/window-commands.h
index b689bb4..4d8582f 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -30,88 +30,90 @@
 
 G_BEGIN_DECLS
 
-void window_cmd_edit_find                (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_view_stop                (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_go_location              (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_view_reload              (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_new                      (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_file_bookmark_page       (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_file_open                (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_file_save_as             (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_file_save_as_application (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_file_print               (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_file_send_to             (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_file_work_offline        (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_file_close_window        (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_edit_undo                (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_edit_redo                (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_edit_cut                 (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_edit_copy                (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_edit_paste               (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_edit_delete              (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_edit_select_all          (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_edit_find_next           (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_edit_find_prev           (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_view_fullscreen          (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_view_zoom_in             (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_view_zoom_out            (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_view_zoom_normal         (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_view_page_source         (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_help_about               (GtkAction  *action,
-                                          GtkWidget  *window);
-void window_cmd_tabs_next                (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_tabs_previous            (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_tabs_move_left           (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_tabs_move_right          (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_tabs_detach              (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_load_location            (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_browse_with_caret        (GtkAction  *action,
-                                          EphyWindow *window);
-void window_cmd_file_quit                (GtkAction *action,
-                                          EphyWindow *window);
-void window_cmd_edit_bookmarks           (GtkAction *action,
-                                          EphyWindow *window);
-void window_cmd_edit_history             (GtkAction *action,
-                                          EphyWindow *window);
-void window_cmd_file_new_window          (GtkAction *action,
-                                          EphyWindow *window);
-void window_cmd_edit_preferences         (GtkAction *action,
-                                          EphyWindow *window);
-void window_cmd_edit_personal_data       (GtkAction *action,
-                                          EphyWindow *window);
+void window_cmd_edit_find                 (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_view_stop                 (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_go_location               (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_view_reload               (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_new                       (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_file_bookmark_page        (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_file_open                 (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_file_save_as              (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_file_save_as_application  (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_file_print                (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_file_send_to              (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_file_work_offline         (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_file_close_window         (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_undo                 (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_redo                 (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_cut                  (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_copy                 (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_paste                (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_delete               (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_select_all           (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_find_next            (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_find_prev            (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_view_fullscreen           (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_view_zoom_in              (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_view_zoom_out             (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_view_zoom_normal          (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_view_page_source          (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_help_about                (GtkAction  *action,
+                                           GtkWidget  *window);
+void window_cmd_tabs_next                 (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_tabs_previous             (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_tabs_move_left            (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_tabs_move_right           (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_tabs_detach               (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_load_location             (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_browse_with_caret         (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_file_quit                 (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_bookmarks            (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_history              (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_file_new_window           (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_file_new_incognito_window (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_preferences          (GtkAction  *action,
+                                           EphyWindow *window);
+void window_cmd_edit_personal_data        (GtkAction  *action,
+                                           EphyWindow *window);
 
 G_END_DECLS
 



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