diff options
-rw-r--r-- | embed/ephy-embed-shell.c | 78 | ||||
-rw-r--r-- | embed/ephy-embed-shell.h | 8 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/ephy-application.c | 449 | ||||
-rw-r--r-- | src/ephy-application.h | 92 | ||||
-rw-r--r-- | src/ephy-main.c | 24 | ||||
-rw-r--r-- | src/ephy-session.c | 8 | ||||
-rw-r--r-- | src/ephy-shell.c | 346 | ||||
-rw-r--r-- | src/ephy-shell.h | 36 | ||||
-rw-r--r-- | src/ephy-window.c | 2 | ||||
-rw-r--r-- | tests/ephy-download.c | 2 | ||||
-rw-r--r-- | tests/ephy-embed-single.c | 2 |
12 files changed, 448 insertions, 603 deletions
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c index de147b489..aef7bb214 100644 --- a/embed/ephy-embed-shell.c +++ b/embed/ephy-embed-shell.c @@ -1,5 +1,7 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright © 2000-2003 Marco Pesenti Gritti + * Copyright © 2011 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 @@ -57,6 +59,7 @@ struct _EphyEmbedShellPrivate GtkPageSetup *page_setup; GtkPrintSettings *print_settings; guint object_count; + gboolean private_instance; guint single_initialised : 1; }; @@ -71,12 +74,21 @@ enum static guint signals[LAST_SIGNAL]; +enum +{ + PROP_0, + PROP_PRIVATE_INSTANCE, + N_PROPERTIES +}; + +static GParamSpec *object_properties[N_PROPERTIES] = { NULL, }; + static void ephy_embed_shell_class_init (EphyEmbedShellClass *klass); static void ephy_embed_shell_init (EphyEmbedShell *shell); EphyEmbedShell *embed_shell = NULL; -G_DEFINE_TYPE (EphyEmbedShell, ephy_embed_shell, G_TYPE_OBJECT) +G_DEFINE_TYPE (EphyEmbedShell, ephy_embed_shell, GTK_TYPE_APPLICATION) static void ephy_embed_shell_dispose (GObject *object) @@ -272,6 +284,42 @@ ephy_embed_shell_prepare_close (EphyEmbedShell *shell) } static void +ephy_embed_shell_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EphyEmbedShell *embed_shell = EPHY_EMBED_SHELL (object); + + switch (prop_id) + { + case PROP_PRIVATE_INSTANCE: + embed_shell->priv->private_instance = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +ephy_embed_shell_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EphyEmbedShell *embed_shell = EPHY_EMBED_SHELL (object); + + switch (prop_id) + { + case PROP_PRIVATE_INSTANCE: + g_value_set_boolean (value, embed_shell->priv->private_instance); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void ephy_embed_shell_init (EphyEmbedShell *shell) { shell->priv = EPHY_EMBED_SHELL_GET_PRIVATE (shell); @@ -290,9 +338,23 @@ ephy_embed_shell_class_init (EphyEmbedShellClass *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; klass->get_embed_single = impl_get_embed_single; + object_properties[PROP_PRIVATE_INSTANCE] = + g_param_spec_boolean ("private-instance", + "Private instance", + "Whether this Epiphany instance is private.", + FALSE, + G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | + G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY); + + g_object_class_install_properties (object_class, + N_PROPERTIES, + object_properties); + /** * EphyEmbed::download-added: * @shell: the #EphyEmbedShell @@ -622,3 +684,17 @@ _ephy_embed_shell_track_object (EphyEmbedShell *shell, GObject *object) g_object_weak_ref (object, (GWeakNotify)object_notify_cb, shell); shell->priv->object_count++; } + +/** + * ephy_embed_shell_is_private_instance: + * @shell: an #EphyEmbedShell + * + * Returns: whether @shell is a private instance + **/ +gboolean +ephy_embed_shell_is_private_instance (EphyEmbedShell *shell) +{ + g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), FALSE); + + return shell->priv->private_instance; +} diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h index 00087fa9b..c91dc9d80 100644 --- a/embed/ephy-embed-shell.h +++ b/embed/ephy-embed-shell.h @@ -1,5 +1,7 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright © 2000-2003 Marco Pesenti Gritti + * Copyright © 2011 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 @@ -47,7 +49,7 @@ extern EphyEmbedShell *embed_shell; struct _EphyEmbedShell { - GObject parent; + GtkApplication parent; /*< private >*/ EphyEmbedShellPrivate *priv; @@ -55,7 +57,7 @@ struct _EphyEmbedShell struct _EphyEmbedShellClass { - GObjectClass parent_class; + GtkApplicationClass parent_class; void (* download_added) (EphyEmbedShell *shell, EphyDownload *download); void (* download_removed) (EphyEmbedShell *shell, EphyDownload *download); @@ -99,6 +101,8 @@ void ephy_embed_shell_add_download (EphyEmbedShell *shell, void ephy_embed_shell_remove_download (EphyEmbedShell *shell, EphyDownload *download); +gboolean ephy_embed_shell_is_private_instance (EphyEmbedShell *shell); + /* Private API */ void _ephy_embed_shell_track_object (EphyEmbedShell *shell, GObject *object); diff --git a/src/Makefile.am b/src/Makefile.am index 4492b3bcf..98cdf0100 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,7 +40,6 @@ NOINST_H_FILES = \ window-commands.h INST_H_FILES = \ - ephy-application.h \ ephy-extension.h \ ephy-extensions-manager.h \ ephy-link.h \ @@ -53,7 +52,6 @@ INST_H_FILES = \ libephymain_la_SOURCES = \ ephy-action-helper.c \ - ephy-application.c \ ephy-completion-model.c \ ephy-completion-model.h \ ephy-encoding-dialog.c \ @@ -258,7 +256,6 @@ EPHY_GIR_H_FILES = \ $(top_srcdir)/lib/widgets/ephy-download-widget.h \ $(top_srcdir)/lib/widgets/ephy-search-entry.h \ $(top_srcdir)/src/bookmarks/ephy-bookmarks.h \ - $(top_srcdir)/src/ephy-application.h \ $(top_srcdir)/src/ephy-extension.h \ $(top_srcdir)/src/ephy-extensions-manager.h \ $(top_srcdir)/src/ephy-find-toolbar.h \ @@ -290,7 +287,6 @@ EPHY_GIR_C_FILES = \ $(top_srcdir)/lib/widgets/ephy-download-widget.c \ $(top_srcdir)/lib/widgets/ephy-search-entry.c \ $(top_srcdir)/src/bookmarks/ephy-bookmarks.c \ - $(top_srcdir)/src/ephy-application.c \ $(top_srcdir)/src/ephy-extension.c \ $(top_srcdir)/src/ephy-extensions-manager.c \ $(top_srcdir)/src/ephy-find-toolbar.c \ diff --git a/src/ephy-application.c b/src/ephy-application.c deleted file mode 100644 index 969b591a3..000000000 --- a/src/ephy-application.c +++ /dev/null @@ -1,449 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * Copyright © 2011 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 - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "config.h" - -#include "ephy-application.h" -#include "ephy-file-helpers.h" -#include "ephy-shell.h" -#include "ephy-session.h" -#include "ephy-debug.h" -#include "ephy-profile-utils.h" - -#include <string.h> - -enum { - PROP_0, - PROP_PRIVATE_INSTANCE, - N_PROPERTIES -}; - -static GParamSpec *object_properties[N_PROPERTIES] = { NULL, }; - -#define EPHY_APPLICATION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_APPLICATION, EphyApplicationPrivate)) - -struct _EphyApplicationPrivate { - EphyApplicationStartupContext *startup_context; - gboolean private_instance; -}; - -G_DEFINE_TYPE (EphyApplication, ephy_application, GTK_TYPE_APPLICATION); - -static void ephy_application_finalize (GObject *object); - -/** - * ephy_application_startup_context_new: - * @bookmarks_filename: A bookmarks file to import. - * @session_filename: A session to restore. - * @bookmark_url: A URL to be added to the bookmarks. - * @arguments: A %NULL-terminated array of URLs and file URIs to be opened. - * @user_time: The user time when the EphyApplication startup was invoked. - * - * Creates a new startup context. All string parameters, including - * @arguments, are copied. - * - * Returns: a newly allocated #EphyApplicationStartupContext - **/ -EphyApplicationStartupContext * -ephy_application_startup_context_new (EphyStartupFlags startup_flags, - char *bookmarks_filename, - char *session_filename, - char *bookmark_url, - char **arguments, - guint32 user_time) -{ - EphyApplicationStartupContext *ctx = g_slice_new0 (EphyApplicationStartupContext); - - ctx->startup_flags = startup_flags; - - ctx->bookmarks_filename = g_strdup (bookmarks_filename); - ctx->session_filename = g_strdup (session_filename); - ctx->bookmark_url = g_strdup (bookmark_url); - - ctx->arguments = g_strdupv (arguments); - - ctx->user_time = user_time; - - return ctx; -} - -static void -ephy_application_free_startup_context (EphyApplication *application) -{ - EphyApplicationStartupContext *ctx = application->priv->startup_context; - - g_assert (ctx != NULL); - - g_free (ctx->bookmarks_filename); - g_free (ctx->session_filename); - g_free (ctx->bookmark_url); - - g_strfreev (ctx->arguments); - - g_slice_free (EphyApplicationStartupContext, ctx); - - application->priv->startup_context = NULL; -} - -static void -queue_commands (EphyApplication *application) -{ - EphyApplicationStartupContext *ctx; - EphyShell *shell; - EphySession *session; - - shell = ephy_shell_get_default (); - g_assert (shell != NULL); - session = EPHY_SESSION (ephy_shell_get_session (shell)); - g_assert (session != NULL); - - ctx = application->priv->startup_context; - - /* We only get here when starting a new instance, so we first need - to autoresume! */ - ephy_session_queue_command (EPHY_SESSION (ephy_shell_get_session (shell)), - EPHY_SESSION_CMD_RESUME_SESSION, - NULL, NULL, ctx->user_time, TRUE); - - if (ctx->startup_flags & EPHY_STARTUP_BOOKMARKS_EDITOR) - ephy_session_queue_command (session, - EPHY_SESSION_CMD_OPEN_BOOKMARKS_EDITOR, - NULL, NULL, ctx->user_time, FALSE); - - else if (ctx->session_filename != NULL) { - ephy_session_queue_command (session, - EPHY_SESSION_CMD_LOAD_SESSION, - (const char *)ctx->session_filename, NULL, - ctx->user_time, FALSE); - } else if (ctx->arguments != NULL) { - /* Don't queue any window openings if no extra arguments given, */ - /* since session autoresume will open one for us. */ - GString *options; - - options = g_string_sized_new (64); - - if (ctx->startup_flags & EPHY_STARTUP_NEW_WINDOW) { - g_string_append (options, "new-window,"); - } - if (ctx->startup_flags & EPHY_STARTUP_NEW_TAB) { - g_string_append (options, "new-tab,external,"); - } - - ephy_session_queue_command (session, - EPHY_SESSION_CMD_OPEN_URIS, - (const char*)options->str, - (const char **)ctx->arguments, - ctx->user_time, FALSE); - } -} - -static void -ephy_application_startup (GApplication* application) -{ - /* We're not remoting; start our services */ - /* Migrate profile if we are not running a private instance */ - if (!ephy_application_is_private_instance (EPHY_APPLICATION (application)) && - ephy_profile_utils_get_migration_version () < EPHY_PROFILE_MIGRATION_VERSION) { - GError *error = NULL; - char *argv[1] = { "ephy-profile-migrator" }; - char *envp[1] = { "EPHY_LOG_MODULES=ephy-profile" }; - - g_spawn_sync (NULL, argv, envp, G_SPAWN_SEARCH_PATH, - NULL, NULL, NULL, NULL, - NULL, &error); - - if (error) { - LOG ("Failed to run migrator: %s", error->message); - g_error_free (error); - } - } -} - -static void -ephy_application_activate (GApplication *application) -{ - /* - * We get here on each new instance (remote or not). Queue the - * commands. - */ - queue_commands (EPHY_APPLICATION (application)); -} - -/* - * We use this enumeration to conveniently fill and read from the - * dictionary variant that is sent from the remote to the primary - * instance. - */ -typedef enum { - CTX_STARTUP_FLAGS, - CTX_BOOKMARKS_FILENAME, - CTX_SESSION_FILENAME, - CTX_BOOKMARK_URL, - CTX_ARGUMENTS, - CTX_USER_TIME -}CtxEnum; - -static void -ephy_application_add_platform_data (GApplication *application, - GVariantBuilder *builder) -{ - EphyApplication *app; - EphyApplicationStartupContext *ctx; - GVariantBuilder *ctx_builder; - - app = EPHY_APPLICATION (application); - - G_APPLICATION_CLASS (ephy_application_parent_class)->add_platform_data (application, - builder); - - if (app->priv->startup_context) { - /* - * We create an array variant that contains only the elements in - * ctx that are non-NULL. - */ - ctx_builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY); - ctx = app->priv->startup_context; - - if (ctx->startup_flags) { - g_variant_builder_add (ctx_builder, "{iv}", - CTX_STARTUP_FLAGS, - g_variant_new_byte (ctx->startup_flags)); - } - if (ctx->bookmarks_filename) { - g_variant_builder_add (ctx_builder, "{iv}", - CTX_BOOKMARKS_FILENAME, - g_variant_new_string (ctx->bookmarks_filename)); - } - if (ctx->session_filename) { - g_variant_builder_add (ctx_builder, "{iv}", - CTX_SESSION_FILENAME, - g_variant_new_string (ctx->session_filename)); - } - if (ctx->bookmark_url) { - g_variant_builder_add (ctx_builder, "{iv}", - CTX_BOOKMARK_URL, - g_variant_new_string (ctx->bookmark_url)); - } - if (ctx->arguments) { - g_variant_builder_add (ctx_builder, "{iv}", - CTX_ARGUMENTS, - g_variant_new_strv ((const gchar * const *)ctx->arguments, -1)); - } - - g_variant_builder_add (ctx_builder, "{iv}", - CTX_USER_TIME, - g_variant_new_uint32 (ctx->user_time)); - - g_variant_builder_add (builder, "{sv}", - "ephy-application-startup-context", - g_variant_builder_end (ctx_builder)); - - g_variant_builder_unref (ctx_builder); - } -} - -static void -ephy_application_before_emit (GApplication *application, - GVariant *platform_data) -{ - GVariantIter iter, ctx_iter; - const char *key; - CtxEnum ctx_key; - GVariant *value, *ctx_value; - EphyApplicationStartupContext *ctx = NULL; - - EphyApplication *app = EPHY_APPLICATION (application); - - g_variant_iter_init (&iter, platform_data); - while (g_variant_iter_loop (&iter, "{&sv}", &key, &value)) { - if (strcmp (key, "ephy-application-startup-context") == 0) { - ctx = g_slice_new0 (EphyApplicationStartupContext); - - /* - * Iterate over the startup context variant and fill the members - * that were wired. Everything else is just NULL. - */ - g_variant_iter_init (&ctx_iter, value); - while (g_variant_iter_loop (&ctx_iter, "{iv}", &ctx_key, &ctx_value)) { - switch (ctx_key) { - case CTX_STARTUP_FLAGS: - ctx->startup_flags = g_variant_get_byte (ctx_value); - break; - case CTX_BOOKMARKS_FILENAME: - ctx->bookmarks_filename = g_variant_dup_string (ctx_value, NULL); - break; - case CTX_SESSION_FILENAME: - ctx->session_filename = g_variant_dup_string (ctx_value, NULL); - break; - case CTX_BOOKMARK_URL: - ctx->bookmark_url = g_variant_dup_string (ctx_value, NULL); - break; - case CTX_ARGUMENTS: - ctx->arguments = g_variant_dup_strv (ctx_value, NULL); - break; - case CTX_USER_TIME: - ctx->user_time = g_variant_get_uint32 (ctx_value); - break; - default: - g_assert_not_reached (); - break; - } - } - } - } - - if (app->priv->startup_context) - ephy_application_free_startup_context (app); - app->priv->startup_context = ctx; - - G_APPLICATION_CLASS (ephy_application_parent_class)->before_emit (application, - platform_data); -} - -static void -ephy_application_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EphyApplication *application = EPHY_APPLICATION (object); - - switch (prop_id) { - case PROP_PRIVATE_INSTANCE: - application->priv->private_instance = g_value_get_boolean (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -ephy_application_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EphyApplication *application = EPHY_APPLICATION (object); - - switch (prop_id) { - case PROP_PRIVATE_INSTANCE: - g_value_set_boolean (value, application->priv->private_instance); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -ephy_application_class_init (EphyApplicationClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS(class); - GApplicationClass *application_class = G_APPLICATION_CLASS (class); - - object_class->finalize = ephy_application_finalize; - object_class->set_property = ephy_application_set_property; - object_class->get_property = ephy_application_get_property; - - application_class->startup = ephy_application_startup; - application_class->activate = ephy_application_activate; - application_class->before_emit = ephy_application_before_emit; - application_class->add_platform_data = ephy_application_add_platform_data; - - object_properties[PROP_PRIVATE_INSTANCE] = - g_param_spec_boolean ("private-instance", - "Private instance", - "Whether this Epiphany instance is private.", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY); - - g_object_class_install_properties (object_class, - N_PROPERTIES, - object_properties); - - g_type_class_add_private (class, sizeof (EphyApplicationPrivate)); -} - -static void -ephy_application_init (EphyApplication *application) -{ - application->priv = EPHY_APPLICATION_GET_PRIVATE(application); - application->priv->startup_context = NULL; -} - -static void -ephy_application_finalize (GObject *object) -{ - EphyApplication *application = EPHY_APPLICATION (object); - - if (application->priv->startup_context) - ephy_application_free_startup_context (application); - - G_OBJECT_CLASS (ephy_application_parent_class)->finalize (object); -} - -EphyApplication * -ephy_application_new (gboolean private_instance) -{ - GApplicationFlags flags = G_APPLICATION_FLAGS_NONE; - - if (private_instance) - flags |= G_APPLICATION_NON_UNIQUE; - - return g_object_new (EPHY_TYPE_APPLICATION, - "application-id", "org.gnome.Epiphany", - "flags", flags, - "private-instance", private_instance, - NULL); -} - -/** - * ephy_application_set_startup_context: - * @application: A #EphyApplication - * @ctx: (transfer full): a #EphyApplicationStartupContext - * - * Sets the startup context to be used during activation of a new instance. - * See ephy_application_set_startup_new(). - **/ -void -ephy_application_set_startup_context (EphyApplication *application, - EphyApplicationStartupContext *ctx) -{ - g_return_if_fail (EPHY_IS_APPLICATION (application)); - - if (application->priv->startup_context) - ephy_application_free_startup_context (application); - - application->priv->startup_context = ctx; -} - -/** - * ephy_application_is_private_instance: - * @application: an #EphyApplication - * - * Returns: whether @application is a private instance - **/ -gboolean -ephy_application_is_private_instance (EphyApplication *application) -{ - g_return_val_if_fail (EPHY_IS_APPLICATION (application), FALSE); - - return application->priv->private_instance; -} diff --git a/src/ephy-application.h b/src/ephy-application.h deleted file mode 100644 index 2bc8cbaf3..000000000 --- a/src/ephy-application.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * Copyright © 2011 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 - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#if !defined (__EPHY_EPIPHANY_H_INSIDE__) && !defined (EPIPHANY_COMPILATION) -#error "Only <epiphany/epiphany.h> can be included directly." -#endif - -#ifndef __EPHY_APPLICATION_H__ -#define __EPHY_APPLICATION_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define EPHY_TYPE_APPLICATION (ephy_application_get_type ()) -#define EPHY_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),EPHY_TYPE_APPLICATION, EphyApplication)) -#define EPHY_APPLICATION_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_APPLICATION, EphyApplication const)) -#define EPHY_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_APPLICATION, EphyApplicationClass)) -#define EPHY_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_APPLICATION)) -#define EPHY_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_APPLICATION)) -#define EPHY_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_APPLICATION, EphyApplicationClass)) - -typedef struct _EphyApplication EphyApplication; -typedef struct _EphyApplicationPrivate EphyApplicationPrivate; -typedef struct _EphyApplicationClass EphyApplicationClass; - -extern EphyApplication *application; - -struct _EphyApplication { - GtkApplication parent; - - EphyApplicationPrivate *priv; -}; - -struct _EphyApplicationClass { - GtkApplicationClass parent_class; -}; - -typedef enum { - EPHY_STARTUP_NEW_TAB = 1 << 0, - EPHY_STARTUP_NEW_WINDOW = 1 << 1, - EPHY_STARTUP_BOOKMARKS_EDITOR = 1 << 2 -} EphyStartupFlags; - -typedef struct { - EphyStartupFlags startup_flags; - - char *bookmarks_filename; - char *session_filename; - char *bookmark_url; - - char **arguments; - - guint32 user_time; -} EphyApplicationStartupContext; - -GType ephy_application_get_type (void) G_GNUC_CONST; - -EphyApplication *ephy_application_new (gboolean private_instance); - -void ephy_application_set_startup_context (EphyApplication *application, - EphyApplicationStartupContext *ctx); - -EphyApplicationStartupContext *ephy_application_startup_context_new (EphyStartupFlags startup_flags, - char *bookmarks_filename, - char *session_filename, - char *bookmark_url, - char **arguments, - guint32 user_time); - -gboolean ephy_application_is_private_instance (EphyApplication *application); - -G_END_DECLS - -#endif diff --git a/src/ephy-main.c b/src/ephy-main.c index 323389467..2b5f10261 100644 --- a/src/ephy-main.c +++ b/src/ephy-main.c @@ -22,7 +22,6 @@ #include "config.h" -#include "ephy-application.h" #include "ephy-settings.h" #include "ephy-shell.h" #include "ephy-file-helpers.h" @@ -239,8 +238,7 @@ main (int argc, GError *error = NULL; guint32 user_time; gboolean arbitrary_url; - EphyApplication *application; - EphyApplicationStartupContext *ctx; + EphyShellStartupContext *ctx; EphyStartupFlags startup_flags; int status; @@ -417,20 +415,18 @@ main (int argc, g_setenv ("XLIB_SKIP_ARGB_VISUALS", "1", FALSE); /* Now create the shell */ - application = ephy_application_new (private_instance); - _ephy_shell_create_instance (application); - g_object_unref (application); + _ephy_shell_create_instance (private_instance); startup_flags = get_startup_flags (); - ctx = ephy_application_startup_context_new (startup_flags, - bookmarks_file, - session_filename, - bookmark_url, - arguments, - user_time); + ctx = ephy_shell_startup_context_new (startup_flags, + bookmarks_file, + session_filename, + bookmark_url, + arguments, + user_time); g_strfreev (arguments); - ephy_application_set_startup_context (application, ctx); - status = g_application_run (G_APPLICATION (application), argc, argv); + ephy_shell_set_startup_context (ephy_shell, ctx); + status = g_application_run (G_APPLICATION (ephy_shell), argc, argv); /* Shutdown */ g_object_unref (ephy_shell); diff --git a/src/ephy-session.c b/src/ephy-session.c index 9aadb1189..af2ec68a0 100644 --- a/src/ephy-session.c +++ b/src/ephy-session.c @@ -816,7 +816,7 @@ session_command_dispatch (EphySession *session) run_again = FALSE; } - g_application_release (G_APPLICATION (ephy_shell_get_application (ephy_shell_get_default ()))); + g_application_release (G_APPLICATION (ephy_shell_get_default ())); /* This unrefs the shell! */ session_command_free (cmd); @@ -1676,7 +1676,7 @@ ephy_session_add_window (EphySession *session, session->priv->tool_windows = g_list_append (session->priv->tool_windows, window); - gtk_application_add_window (GTK_APPLICATION (ephy_shell_get_application (ephy_shell_get_default ())), window); + gtk_application_add_window (GTK_APPLICATION (ephy_shell_get_default ()), window); ephy_session_save (session, SESSION_CRASHED); } @@ -1697,7 +1697,7 @@ ephy_session_remove_window (EphySession *session, session->priv->tool_windows = g_list_remove (session->priv->tool_windows, window); - gtk_application_remove_window (GTK_APPLICATION (ephy_shell_get_application (ephy_shell_get_default ())), window); + gtk_application_remove_window (GTK_APPLICATION (ephy_shell_get_default ()), window); ephy_session_save (session, SESSION_CRASHED); } @@ -1804,7 +1804,7 @@ ephy_session_queue_command (EphySession *session, session_command_queue_next (session); - g_application_hold (G_APPLICATION (ephy_shell_get_application (ephy_shell_get_default ()))); + g_application_hold (G_APPLICATION (ephy_shell_get_default ())); if (priv->resume_window != NULL) { diff --git a/src/ephy-shell.c b/src/ephy-shell.c index c978f1b5e..e3f3c98ba 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -58,6 +58,7 @@ #include "ephy-web-view.h" #include "ephy-network-manager.h" #include "ephy-network-manager-defines.h" +#include "ephy-profile-utils.h" #define EPHY_SHELL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_SHELL, EphyShellPrivate)) @@ -69,14 +70,13 @@ struct _EphyShellPrivate EggToolbarsModel *toolbars_model; EggToolbarsModel *fs_toolbars_model; EphyExtensionsManager *extensions_manager; - EphyApplication *application; EphyNetworkManager *nm_proxy; GtkWidget *bme; GtkWidget *history_window; GObject *pdm_dialog; GObject *prefs_dialog; GList *del_on_exit; - + EphyShellStartupContext *startup_context; guint embed_single_connected : 1; }; @@ -90,15 +90,293 @@ static GObject *impl_get_embed_single (EphyEmbedShell *embed_shell); G_DEFINE_TYPE (EphyShell, ephy_shell, EPHY_TYPE_EMBED_SHELL) +/** + * ephy_shell_startup_context_new: + * @bookmarks_filename: A bookmarks file to import. + * @session_filename: A session to restore. + * @bookmark_url: A URL to be added to the bookmarks. + * @arguments: A %NULL-terminated array of URLs and file URIs to be opened. + * @user_time: The user time when the EphyShell startup was invoked. + * + * Creates a new startup context. All string parameters, including + * @arguments, are copied. + * + * Returns: a newly allocated #EphyShellStartupContext + **/ +EphyShellStartupContext * +ephy_shell_startup_context_new (EphyStartupFlags startup_flags, + char *bookmarks_filename, + char *session_filename, + char *bookmark_url, + char **arguments, + guint32 user_time) +{ + EphyShellStartupContext *ctx = g_slice_new0 (EphyShellStartupContext); + + ctx->startup_flags = startup_flags; + + ctx->bookmarks_filename = g_strdup (bookmarks_filename); + ctx->session_filename = g_strdup (session_filename); + ctx->bookmark_url = g_strdup (bookmark_url); + + ctx->arguments = g_strdupv (arguments); + + ctx->user_time = user_time; + + return ctx; +} + +static void +queue_commands (EphyShell *shell) +{ + EphyShellStartupContext *ctx; + EphySession *session; + + session = EPHY_SESSION (ephy_shell_get_session (shell)); + g_assert (session != NULL); + + ctx = shell->priv->startup_context; + + /* We only get here when starting a new instance, so we first need + to autoresume! */ + ephy_session_queue_command (session, + EPHY_SESSION_CMD_RESUME_SESSION, + NULL, NULL, ctx->user_time, TRUE); + + if (ctx->startup_flags & EPHY_STARTUP_BOOKMARKS_EDITOR) + ephy_session_queue_command (session, + EPHY_SESSION_CMD_OPEN_BOOKMARKS_EDITOR, + NULL, NULL, ctx->user_time, FALSE); + else if (ctx->session_filename != NULL) + ephy_session_queue_command (session, + EPHY_SESSION_CMD_LOAD_SESSION, + (const char *)ctx->session_filename, NULL, + ctx->user_time, FALSE); + else if (ctx->arguments != NULL) + { + /* Don't queue any window openings if no extra arguments given, */ + /* since session autoresume will open one for us. */ + GString *options; + + options = g_string_sized_new (64); + + if (ctx->startup_flags & EPHY_STARTUP_NEW_WINDOW) + g_string_append (options, "new-window,"); + + if (ctx->startup_flags & EPHY_STARTUP_NEW_TAB) + g_string_append (options, "new-tab,external,"); + + ephy_session_queue_command (session, + EPHY_SESSION_CMD_OPEN_URIS, + (const char*)options->str, + (const char **)ctx->arguments, + ctx->user_time, FALSE); + } +} + +static void +ephy_shell_startup (GApplication* application) +{ + /* We're not remoting; start our services */ + /* Migrate profile if we are not running a private instance */ + if (!ephy_embed_shell_is_private_instance (EPHY_EMBED_SHELL (application)) && + ephy_profile_utils_get_migration_version () < EPHY_PROFILE_MIGRATION_VERSION) + { + GError *error = NULL; + char *argv[1] = { "ephy-profile-migrator" }; + char *envp[1] = { "EPHY_LOG_MODULES=ephy-profile" }; + + g_spawn_sync (NULL, argv, envp, G_SPAWN_SEARCH_PATH, + NULL, NULL, NULL, NULL, + NULL, &error); + + if (error) + { + LOG ("Failed to run migrator: %s", error->message); + g_error_free (error); + } + } +} + +static void +ephy_shell_activate (GApplication *application) +{ + /* + * We get here on each new instance (remote or not). Queue the + * commands. + */ + queue_commands (EPHY_SHELL (application)); +} + +/* + * We use this enumeration to conveniently fill and read from the + * dictionary variant that is sent from the remote to the primary + * instance. + */ +typedef enum +{ + CTX_STARTUP_FLAGS, + CTX_BOOKMARKS_FILENAME, + CTX_SESSION_FILENAME, + CTX_BOOKMARK_URL, + CTX_ARGUMENTS, + CTX_USER_TIME +} CtxEnum; + +static void +ephy_shell_add_platform_data (GApplication *application, + GVariantBuilder *builder) +{ + EphyShell *app; + EphyShellStartupContext *ctx; + GVariantBuilder *ctx_builder; + + app = EPHY_SHELL (application); + + G_APPLICATION_CLASS (ephy_shell_parent_class)->add_platform_data (application, + builder); + + if (app->priv->startup_context) + { + /* + * We create an array variant that contains only the elements in + * ctx that are non-NULL. + */ + ctx_builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY); + ctx = app->priv->startup_context; + + if (ctx->startup_flags) + g_variant_builder_add (ctx_builder, "{iv}", + CTX_STARTUP_FLAGS, + g_variant_new_byte (ctx->startup_flags)); + + if (ctx->bookmarks_filename) + g_variant_builder_add (ctx_builder, "{iv}", + CTX_BOOKMARKS_FILENAME, + g_variant_new_string (ctx->bookmarks_filename)); + + if (ctx->session_filename) + g_variant_builder_add (ctx_builder, "{iv}", + CTX_SESSION_FILENAME, + g_variant_new_string (ctx->session_filename)); + + if (ctx->bookmark_url) + g_variant_builder_add (ctx_builder, "{iv}", + CTX_BOOKMARK_URL, + g_variant_new_string (ctx->bookmark_url)); + + if (ctx->arguments) + g_variant_builder_add (ctx_builder, "{iv}", + CTX_ARGUMENTS, + g_variant_new_strv ((const gchar * const *)ctx->arguments, -1)); + + g_variant_builder_add (ctx_builder, "{iv}", + CTX_USER_TIME, + g_variant_new_uint32 (ctx->user_time)); + + g_variant_builder_add (builder, "{sv}", + "ephy-shell-startup-context", + g_variant_builder_end (ctx_builder)); + + g_variant_builder_unref (ctx_builder); + } +} + +static void +ephy_shell_free_startup_context (EphyShell *shell) +{ + EphyShellStartupContext *ctx = shell->priv->startup_context; + + g_assert (ctx != NULL); + + g_free (ctx->bookmarks_filename); + g_free (ctx->session_filename); + g_free (ctx->bookmark_url); + + g_strfreev (ctx->arguments); + + g_slice_free (EphyShellStartupContext, ctx); + + shell->priv->startup_context = NULL; +} + +static void +ephy_shell_before_emit (GApplication *application, + GVariant *platform_data) +{ + GVariantIter iter, ctx_iter; + const char *key; + CtxEnum ctx_key; + GVariant *value, *ctx_value; + EphyShellStartupContext *ctx = NULL; + + EphyShell *shell = EPHY_SHELL (application); + + g_variant_iter_init (&iter, platform_data); + while (g_variant_iter_loop (&iter, "{&sv}", &key, &value)) + { + if (strcmp (key, "ephy-shell-startup-context") == 0) + { + ctx = g_slice_new0 (EphyShellStartupContext); + + /* + * Iterate over the startup context variant and fill the members + * that were wired. Everything else is just NULL. + */ + g_variant_iter_init (&ctx_iter, value); + while (g_variant_iter_loop (&ctx_iter, "{iv}", &ctx_key, &ctx_value)) + { + switch (ctx_key) + { + case CTX_STARTUP_FLAGS: + ctx->startup_flags = g_variant_get_byte (ctx_value); + break; + case CTX_BOOKMARKS_FILENAME: + ctx->bookmarks_filename = g_variant_dup_string (ctx_value, NULL); + break; + case CTX_SESSION_FILENAME: + ctx->session_filename = g_variant_dup_string (ctx_value, NULL); + break; + case CTX_BOOKMARK_URL: + ctx->bookmark_url = g_variant_dup_string (ctx_value, NULL); + break; + case CTX_ARGUMENTS: + ctx->arguments = g_variant_dup_strv (ctx_value, NULL); + break; + case CTX_USER_TIME: + ctx->user_time = g_variant_get_uint32 (ctx_value); + break; + default: + g_assert_not_reached (); + break; + } + } + } + } + + if (shell->priv->startup_context) + ephy_shell_free_startup_context (shell); + shell->priv->startup_context = ctx; + + G_APPLICATION_CLASS (ephy_shell_parent_class)->before_emit (application, + platform_data); +} + static void ephy_shell_class_init (EphyShellClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GApplicationClass *application_class = G_APPLICATION_CLASS (klass); EphyEmbedShellClass *embed_shell_class = EPHY_EMBED_SHELL_CLASS (klass); object_class->dispose = ephy_shell_dispose; object_class->finalize = ephy_shell_finalize; + application_class->startup = ephy_shell_startup; + application_class->activate = ephy_shell_activate; + application_class->before_emit = ephy_shell_before_emit; + application_class->add_platform_data = ephy_shell_add_platform_data; + embed_shell_class->get_embed_single = impl_get_embed_single; g_type_class_add_private (object_class, sizeof(EphyShellPrivate)); @@ -292,19 +570,17 @@ ephy_shell_dispose (GObject *object) priv->nm_proxy = NULL; } - if (priv->application != NULL) - { - LOG ("Unref application"); - g_object_unref (priv->application); - priv->application = NULL; - } - G_OBJECT_CLASS (ephy_shell_parent_class)->dispose (object); } static void ephy_shell_finalize (GObject *object) { + EphyShell *shell = EPHY_SHELL (object); + + if (shell->priv->startup_context) + ephy_shell_free_startup_context (shell); + G_OBJECT_CLASS (ephy_shell_parent_class)->finalize (object); LOG ("Ephy shell finalised"); @@ -796,34 +1072,42 @@ ephy_shell_get_prefs_dialog (EphyShell *shell) return shell->priv->prefs_dialog; } -/** - * ephy_shell_get_application: - * @shell: A #EphyApplication - * - * Gets the #EphyApplication for @shell - * - * Returns: (transfer none): a #EphyApplication - **/ -EphyApplication * -ephy_shell_get_application (EphyShell *shell) +void +_ephy_shell_create_instance (gboolean private_instance) { - g_return_val_if_fail (EPHY_IS_SHELL (shell), NULL); + GApplicationFlags flags = G_APPLICATION_FLAGS_NONE; + + g_assert (ephy_shell == NULL); + + if (private_instance) + flags |= G_APPLICATION_NON_UNIQUE; - return shell->priv->application; + ephy_shell = EPHY_SHELL (g_object_new (EPHY_TYPE_SHELL, + "application-id", "org.gnome.Epiphany", + "flags", flags, + "private-instance", private_instance, + NULL)); + /* FIXME weak ref */ + g_assert (ephy_shell != NULL); } +/** + * ephy_shell_set_startup_context: + * @shell: A #EphyShell + * @ctx: (transfer full): a #EphyShellStartupContext + * + * Sets the startup context to be used during activation of a new instance. + * See ephy_shell_set_startup_new(). + **/ void -_ephy_shell_create_instance (EphyApplication *application) +ephy_shell_set_startup_context (EphyShell *shell, + EphyShellStartupContext *ctx) { - g_assert (ephy_shell == NULL); - - ephy_shell = EPHY_SHELL (g_object_new (EPHY_TYPE_SHELL, NULL)); - /* FIXME weak ref */ + g_return_if_fail (EPHY_IS_SHELL (shell)); - g_assert (ephy_shell != NULL); + if (shell->priv->startup_context) + ephy_shell_free_startup_context (shell); - if (application) - ephy_shell->priv->application = g_object_ref (application); - else - ephy_shell->priv->application = ephy_application_new (FALSE); + shell->priv->startup_context = ctx; } + diff --git a/src/ephy-shell.h b/src/ephy-shell.h index 100356443..bd49a0fd9 100644 --- a/src/ephy-shell.h +++ b/src/ephy-shell.h @@ -1,6 +1,9 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + /* * Copyright © 2000-2004 Marco Pesenti Gritti * Copyright © 2003, 2004, 2006 Christian Persch + * Copyright © 2011 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 @@ -29,7 +32,6 @@ #include "ephy-bookmarks.h" #include "ephy-window.h" #include "ephy-embed.h" -#include "ephy-application.h" #include <webkit/webkit.h> #include <glib-object.h> @@ -74,6 +76,26 @@ typedef enum } EphyNewTabFlags; +typedef enum +{ + EPHY_STARTUP_NEW_TAB = 1 << 0, + EPHY_STARTUP_NEW_WINDOW = 1 << 1, + EPHY_STARTUP_BOOKMARKS_EDITOR = 1 << 2 +} EphyStartupFlags; + +typedef struct +{ + EphyStartupFlags startup_flags; + + char *bookmarks_filename; + char *session_filename; + char *bookmark_url; + + char **arguments; + + guint32 user_time; +} EphyShellStartupContext; + struct _EphyShell { EphyEmbedShell parent; @@ -127,10 +149,18 @@ GObject *ephy_shell_get_pdm_dialog (EphyShell *shell); GObject *ephy_shell_get_prefs_dialog (EphyShell *shell); -EphyApplication *ephy_shell_get_application (EphyShell *shell); +void ephy_shell_set_startup_context (EphyShell *shell, + EphyShellStartupContext *ctx); + +EphyShellStartupContext *ephy_shell_startup_context_new (EphyStartupFlags startup_flags, + char *bookmarks_filename, + char *session_filename, + char *bookmark_url, + char **arguments, + guint32 user_time); /* private API */ -void _ephy_shell_create_instance (EphyApplication *application); +void _ephy_shell_create_instance (gboolean private_instance); G_END_DECLS diff --git a/src/ephy-window.c b/src/ephy-window.c index 67bd63e39..a10b81034 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -3837,7 +3837,7 @@ ephy_window_constructor (GType type, proxy = GTK_WIDGET (proxies->data); priv->entry = ephy_location_entry_get_entry (EPHY_LOCATION_ENTRY (proxy)); gtk_window_set_application (GTK_WINDOW (window), - GTK_APPLICATION (ephy_shell_get_application (ephy_shell_get_default ()))); + GTK_APPLICATION (ephy_shell_get_default ())); } return object; diff --git a/tests/ephy-download.c b/tests/ephy-download.c index ed9144ed7..94445feaf 100644 --- a/tests/ephy-download.c +++ b/tests/ephy-download.c @@ -173,7 +173,7 @@ main (int argc, char *argv[]) ephy_debug_init (); ephy_embed_prefs_init (); - _ephy_shell_create_instance (NULL); + _ephy_shell_create_instance (FALSE); if (!ephy_file_helpers_init (NULL, TRUE, FALSE, NULL)) { g_debug ("Something wrong happened with ephy_file_helpers_init()"); diff --git a/tests/ephy-embed-single.c b/tests/ephy-embed-single.c index 9e15e9ae3..555723c2a 100644 --- a/tests/ephy-embed-single.c +++ b/tests/ephy-embed-single.c @@ -101,7 +101,7 @@ main (int argc, char *argv[]) ephy_debug_init (); ephy_embed_prefs_init (); - _ephy_shell_create_instance (NULL); + _ephy_shell_create_instance (FALSE); if (!ephy_file_helpers_init (NULL, TRUE, FALSE, NULL)) { g_debug ("Something wrong happened with ephy_file_helpers_init()"); |