[Xfce4-commits] <midori:master> Move private/ web app into dedicated constructors
Christian Dywan
noreply at xfce.org
Thu Nov 29 02:46:01 CET 2012
Updating branch refs/heads/master
to e3673ce2d8811be455eabb53160674de725ec314 (commit)
from 35e9ccee9f8295e62aa6bb831c3ec663467c9683 (commit)
commit e3673ce2d8811be455eabb53160674de725ec314
Author: Christian Dywan <christian at twotoasts.de>
Date: Thu Nov 29 00:43:02 2012 +0100
Move private/ web app into dedicated constructors
midori/main.c | 213 +++++++++++---------------------------------------
midori/midori-app.c | 181 +++++++++++++++++++++++++++++++++++++++++++-
midori/midori-app.h | 16 ++++
3 files changed, 243 insertions(+), 167 deletions(-)
diff --git a/midori/main.c b/midori/main.c
index 600014f..14c508b 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -251,20 +251,6 @@ snapshot_load_finished_cb (GtkWidget* web_view,
gtk_main_quit ();
}
-static MidoriBrowser*
-midori_web_app_browser_new_window_cb (MidoriBrowser* browser,
- MidoriBrowser* new_browser,
- gpointer user_data)
-{
- if (new_browser == NULL)
- new_browser = midori_browser_new ();
- g_object_set (new_browser,
- "settings", midori_browser_get_settings (browser),
- NULL);
- gtk_widget_show (GTK_WIDGET (new_browser));
- return new_browser;
-}
-
int
main (int argc,
char** argv)
@@ -513,174 +499,69 @@ main (int argc,
midori_private_data_register_built_ins ();
- if (private)
- midori_paths_init (MIDORI_RUNTIME_MODE_PRIVATE, config);
- else if (webapp)
- midori_paths_init (MIDORI_RUNTIME_MODE_APP, config);
- else if (portable)
- midori_paths_init (MIDORI_RUNTIME_MODE_PORTABLE, config);
- else
- midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, config);
-
- /* Web Application or Private Browsing support */
if (webapp || private || run)
- {
- MidoriBrowser* browser = midori_browser_new ();
- g_signal_connect (browser, "new-window",
- G_CALLBACK (midori_web_app_browser_new_window_cb), NULL);
- g_object_set_data (G_OBJECT (webkit_get_default_session ()),
- "pass-through-console", (void*)1);
midori_startup_timer ("Browser: \t%f");
- if (private || !webapp)
- {
- settings = midori_settings_new_full (NULL);
- search_engines = midori_search_engines_new_from_folder (NULL);
- g_object_set (browser,
- "search-engines", search_engines,
- "settings", settings,
- NULL);
- g_object_unref (search_engines);
- }
- else
- settings = g_object_ref (midori_browser_get_settings (browser));
-
- if (private)
- {
- /* Mask the timezone, which can be read by Javascript */
- g_setenv ("TZ", "UTC", TRUE);
- /* In-memory trash for re-opening closed tabs */
- trash = katze_array_new (KATZE_TYPE_ITEM);
- g_signal_connect_after (trash, "add-item",
- G_CALLBACK (midori_trash_add_item_no_save_cb), NULL);
- g_object_set (browser, "trash", trash, NULL);
-
- g_object_set (settings,
- "preferred-languages", "en",
- "enable-private-browsing", TRUE,
- #ifdef HAVE_LIBSOUP_2_29_91
- "first-party-cookies-only", TRUE,
- #endif
- "enable-html5-database", FALSE,
- "enable-html5-local-storage", FALSE,
- "enable-offline-web-application-cache", FALSE,
- /* Arguably DNS prefetching is or isn't a privacy concern. For the
- * lack of more fine-grained control we'll go the safe route. */
- #if WEBKIT_CHECK_VERSION (1, 3, 11)
- "enable-dns-prefetching", FALSE,
- #endif
- "strip-referer", TRUE, NULL);
- midori_browser_set_action_visible (browser, "Tools", FALSE);
- midori_browser_set_action_visible (browser, "ClearPrivateData", FALSE);
- #if GTK_CHECK_VERSION (3, 0, 0)
- g_object_set (gtk_widget_get_settings (GTK_WIDGET (browser)),
- "gtk-application-prefer-dark-theme", TRUE,
- NULL);
- #endif
-
- /* Informative text unless we have a URI */
- if (webapp == NULL && uris == NULL)
- midori_browser_add_uri (browser, "about:private");
- }
-
- midori_load_soup_session (settings);
+ if (run)
+ {
+ gchar* script = NULL;
+ error = NULL;
- if (run)
+ if (g_file_get_contents (uris ? *uris : NULL, &script, NULL, &error))
{
- gchar* script = NULL;
- error = NULL;
-
- if (g_file_get_contents (uris ? *uris : NULL, &script, NULL, &error))
+ MidoriBrowser* browser = midori_browser_new ();
+ settings = midori_browser_get_settings (browser);
+ g_object_set_data (G_OBJECT (webkit_get_default_session ()), "pass-through-console", (void*)1);
+ midori_load_soup_session (settings);
+
+ gchar* msg = NULL;
+ GtkWidget* view = midori_view_new_with_item (NULL, settings);
+ g_object_set (settings, "open-new-pages-in", MIDORI_NEW_PAGE_WINDOW, NULL);
+ midori_browser_add_tab (browser, view);
+ gtk_widget_show_all (GTK_WIDGET (browser));
+ gtk_widget_hide (GTK_WIDGET (browser));
+ midori_view_execute_script (MIDORI_VIEW (view), script, &msg);
+ if (msg != NULL)
{
- #if 0 /* HAVE_OFFSCREEN */
- GtkWidget* offscreen = gtk_offscreen_window_new ();
- #endif
- gchar* msg = NULL;
- GtkWidget* view = midori_view_new_with_item (NULL, settings);
- g_object_set (settings, "open-new-pages-in", MIDORI_NEW_PAGE_WINDOW, NULL);
- midori_browser_add_tab (browser, view);
- #if 0 /* HAVE_OFFSCREEN */
- gtk_container_add (GTK_CONTAINER (offscreen), GTK_WIDGET (browser));
- gtk_widget_show_all (offscreen);
- #else
- gtk_widget_show_all (GTK_WIDGET (browser));
- gtk_widget_hide (GTK_WIDGET (browser));
- #endif
- midori_view_execute_script (MIDORI_VIEW (view), script, &msg);
- if (msg != NULL)
- {
- g_error ("%s\n", msg);
- g_free (msg);
- }
+ g_error ("%s\n", msg);
+ g_free (msg);
}
- else if (error != NULL)
- {
- g_error ("%s\n", error->message);
- g_error_free (error);
- }
- else
- g_error ("%s\n", _("An unknown error occured"));
- g_free (script);
- }
-
- if (webapp)
- {
- gchar* tmp_uri = sokoke_prepare_uri (webapp);
- midori_browser_set_action_visible (browser, "Menubar", FALSE);
- midori_browser_set_action_visible (browser, "CompactMenu", FALSE);
- midori_browser_add_uri (browser, tmp_uri);
- g_object_set (settings,
- "show-menubar", FALSE,
- "show-navigationbar", FALSE,
- "toolbar-items", "Back,Forward,ReloadStop,Location,Homepage",
- "show-statusbar", FALSE,
- "enable-developer-extras", FALSE,
- "homepage", tmp_uri,
- NULL);
- g_object_set (browser, "show-tabs", FALSE, NULL);
- g_free (tmp_uri);
- }
-
- g_object_set (settings,
- "show-panel", FALSE,
- "last-window-state", MIDORI_WINDOW_NORMAL,
- "inactivity-reset", inactivity_reset,
- "block-uris", block_uris,
- NULL);
- midori_browser_set_action_visible (browser, "Panel", FALSE);
- midori_startup_timer ("Setup config: \t%f");
- g_signal_connect (browser, "quit",
- G_CALLBACK (gtk_main_quit), NULL);
- g_signal_connect (browser, "destroy",
- G_CALLBACK (gtk_main_quit), NULL);
- if (!run)
- {
- gtk_widget_show (GTK_WIDGET (browser));
- midori_browser_activate_action (browser, "Location");
- }
- if (execute)
- {
- for (i = 0; uris[i] != NULL; i++)
- midori_browser_activate_action (browser, uris[i]);
+ gtk_main ();
}
- else if (uris != NULL)
+ else if (error != NULL)
{
- for (i = 0; uris[i] != NULL; i++)
- {
- gchar* new_uri = sokoke_prepare_uri (uris[i]);
- midori_browser_add_uri (browser, new_uri);
- g_free (new_uri);
- }
+ g_error ("%s\n", error->message);
+ g_error_free (error);
}
+ else
+ g_error ("%s\n", _("An unknown error occured"));
+ g_free (script);
+ return 0;
+ }
- if (midori_browser_get_current_uri (browser) == NULL)
- midori_browser_add_uri (browser, "about:blank");
+ if (private)
+ {
+ midori_private_app_new (config, webapp,
+ execute ? NULL : uris, execute ? uris : NULL, inactivity_reset, block_uris);
+ midori_startup_timer ("Private App created: \t%f");
+ gtk_main ();
+ return 0;
+ }
- midori_startup_timer ("App created: \t%f");
+ if (webapp)
+ {
+ midori_web_app_new (config, webapp,
+ execute ? NULL : uris, execute ? uris : NULL, inactivity_reset, block_uris);
+ midori_startup_timer ("Web App created: \t%f");
gtk_main ();
return 0;
}
+ if (portable)
+ midori_paths_init (MIDORI_RUNTIME_MODE_PORTABLE, config);
+ else
+ midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, config);
+
app = midori_app_new ();
midori_startup_timer ("App created: \t%f");
diff --git a/midori/midori-app.c b/midori/midori-app.c
index c00ba52..3160915 100644
--- a/midori/midori-app.c
+++ b/midori/midori-app.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2008-2010 Christian Dywan <christian at twotoasts.de>
+ Copyright (C) 2008-2012 Christian Dywan <christian at twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -22,6 +22,8 @@
#include "midori-app.h"
#include "midori-platform.h"
#include "midori-core.h"
+#include "midori-session.h"
+#include "midori-searchaction.h"
#include <string.h>
#include <gtk/gtk.h>
@@ -1008,6 +1010,183 @@ midori_app_new (void)
return app;
}
+static MidoriBrowser*
+midori_web_app_browser_new_window_cb (MidoriBrowser* browser,
+ MidoriBrowser* new_browser,
+ gpointer user_data)
+{
+ if (new_browser == NULL)
+ new_browser = midori_browser_new ();
+ g_object_set (new_browser,
+ "settings", midori_browser_get_settings (browser),
+ NULL);
+ gtk_widget_show (GTK_WIDGET (new_browser));
+ return new_browser;
+}
+
+void
+midori_web_app_new (const gchar* config,
+ const gchar* webapp,
+ gchar** open_uris,
+ gchar** execute_commands,
+ gint inactivity_reset,
+ const gchar* block_uris)
+{
+ midori_paths_init (MIDORI_RUNTIME_MODE_APP, config);
+ g_object_set_data (G_OBJECT (webkit_get_default_session ()), "pass-through-console", (void*)1);
+
+ MidoriBrowser* browser = midori_browser_new ();
+ g_signal_connect (browser, "new-window",
+ G_CALLBACK (midori_web_app_browser_new_window_cb), NULL);
+
+ gchar* tmp_uri = sokoke_prepare_uri (webapp);
+ midori_browser_set_action_visible (browser, "Menubar", FALSE);
+ midori_browser_set_action_visible (browser, "CompactMenu", FALSE);
+
+ MidoriWebSettings* settings = midori_browser_get_settings (browser);
+ g_object_set (settings,
+ "show-menubar", FALSE,
+ "show-navigationbar", FALSE,
+ "toolbar-items", "Back,Forward,ReloadStop,Location,Homepage",
+ "show-statusbar", FALSE,
+ "homepage", tmp_uri,
+ "show-panel", FALSE,
+ "last-window-state", MIDORI_WINDOW_NORMAL,
+ "inactivity-reset", inactivity_reset,
+ "block-uris", block_uris,
+ NULL);
+ midori_load_soup_session (settings);
+
+ KatzeArray* search_engines = midori_search_engines_new_from_folder (NULL);
+ g_object_set (browser,
+ "show-tabs", open_uris != NULL,
+ NULL);
+ midori_browser_set_action_visible (browser, "Panel", FALSE);
+ g_object_unref (search_engines);
+
+ midori_browser_add_uri (browser, tmp_uri);
+ g_free (tmp_uri);
+ g_signal_connect (browser, "quit", G_CALLBACK (gtk_main_quit), NULL);
+ g_signal_connect (browser, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+ gtk_widget_show (GTK_WIDGET (browser));
+
+ guint i;
+ if (open_uris != NULL)
+ for (i = 0; open_uris[i] != NULL; i++)
+ {
+ gchar* new_uri = sokoke_prepare_uri (open_uris[i]);
+ midori_browser_add_uri (browser, new_uri);
+ g_free (new_uri);
+ }
+
+ if (execute_commands != NULL)
+ for (i = 0; execute_commands[i] != NULL; i++)
+ midori_browser_activate_action (browser, execute_commands[i]);
+}
+
+static void
+midori_trash_add_item_no_save_cb (KatzeArray* trash,
+ GObject* item)
+{
+ if (katze_array_get_nth_item (trash, 10))
+ {
+ KatzeItem* obsolete_item = katze_array_get_nth_item (trash, 0);
+ katze_array_remove_item (trash, obsolete_item);
+ }
+}
+
+void
+midori_private_app_new (const gchar* config,
+ const gchar* webapp,
+ gchar** open_uris,
+ gchar** execute_commands,
+ gint inactivity_reset,
+ const gchar* block_uris)
+{
+ midori_paths_init (MIDORI_RUNTIME_MODE_PRIVATE, config);
+ g_object_set_data (G_OBJECT (webkit_get_default_session ()), "pass-through-console", (void*)1);
+
+ /* Mask the timezone, which can be read by Javascript */
+ g_setenv ("TZ", "UTC", TRUE);
+
+ MidoriBrowser* browser = midori_browser_new ();
+ g_signal_connect (browser, "new-window",
+ G_CALLBACK (midori_web_app_browser_new_window_cb), NULL);
+
+ MidoriWebSettings* settings = midori_settings_new_full (NULL);
+ g_object_set (settings,
+ "preferred-languages", "en",
+ "enable-private-browsing", TRUE,
+ #ifdef HAVE_LIBSOUP_2_29_91
+ "first-party-cookies-only", TRUE,
+ #endif
+ "enable-html5-database", FALSE,
+ "enable-html5-local-storage", FALSE,
+ "enable-offline-web-application-cache", FALSE,
+ /* Arguably DNS prefetching is or isn't a privacy concern. For the
+ * lack of more fine-grained control we'll go the safe route. */
+ #if WEBKIT_CHECK_VERSION (1, 3, 11)
+ "enable-dns-prefetching", FALSE,
+ #endif
+ "strip-referer", TRUE,
+ "show-panel", FALSE,
+ "last-window-state", MIDORI_WINDOW_NORMAL,
+ "inactivity-reset", inactivity_reset,
+ "block-uris", block_uris,
+ NULL);
+ midori_load_soup_session (settings);
+
+ /* In-memory trash for re-opening closed tabs */
+ KatzeArray* trash = katze_array_new (KATZE_TYPE_ITEM);
+ g_signal_connect_after (trash, "add-item",
+ G_CALLBACK (midori_trash_add_item_no_save_cb), NULL);
+
+ KatzeArray* search_engines = midori_search_engines_new_from_folder (NULL);
+ g_object_set (browser,
+ "settings", settings,
+ "trash", trash,
+ "search-engines", search_engines,
+ NULL);
+ g_object_unref (settings);
+ g_object_unref (trash);
+ g_object_unref (search_engines);
+
+ midori_browser_set_action_visible (browser, "Tools", FALSE);
+ midori_browser_set_action_visible (browser, "ClearPrivateData", FALSE);
+ midori_browser_set_action_visible (browser, "Panel", FALSE);
+ #if GTK_CHECK_VERSION (3, 0, 0)
+ g_object_set (gtk_widget_get_settings (GTK_WIDGET (browser)),
+ "gtk-application-prefer-dark-theme", TRUE,
+ NULL);
+ #endif
+
+ if (webapp != NULL)
+ {
+ gchar* tmp_uri = sokoke_prepare_uri (webapp);
+ midori_browser_add_uri (browser, tmp_uri);
+ g_free (tmp_uri);
+ }
+ else if (open_uris == NULL)
+ midori_browser_add_uri (browser, "about:private");
+
+ g_signal_connect (browser, "quit", G_CALLBACK (gtk_main_quit), NULL);
+ g_signal_connect (browser, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+ gtk_widget_show (GTK_WIDGET (browser));
+
+ guint i;
+ if (open_uris != NULL)
+ for (i = 0; open_uris[i] != NULL; i++)
+ {
+ gchar* new_uri = sokoke_prepare_uri (open_uris[i]);
+ midori_browser_add_uri (browser, new_uri);
+ g_free (new_uri);
+ }
+
+ if (execute_commands != NULL)
+ for (i = 0; execute_commands[i] != NULL; i++)
+ midori_browser_activate_action (browser, execute_commands[i]);
+}
+
/**
* midori_app_instance_is_running:
* @app: a #MidoriApp
diff --git a/midori/midori-app.h b/midori/midori-app.h
index b63034d..e89bcb4 100644
--- a/midori/midori-app.h
+++ b/midori/midori-app.h
@@ -41,6 +41,22 @@ midori_app_get_type (void) G_GNUC_CONST;
MidoriApp*
midori_app_new (void);
+void
+midori_web_app_new (const gchar* config,
+ const gchar* webapp,
+ gchar** open_uris,
+ gchar** execute_commands,
+ gint inactivity_reset,
+ const gchar* block_uris);
+
+void
+midori_private_app_new (const gchar* config,
+ const gchar* webapp,
+ gchar** open_uris,
+ gchar** execute_commands,
+ gint inactivity_reset,
+ const gchar* block_uris);
+
const gchar*
midori_app_get_name (MidoriApp* app);
More information about the Xfce4-commits
mailing list