diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks/ephy-bookmarks-editor.c | 6 | ||||
-rw-r--r-- | src/ephy-history-window.c | 5 | ||||
-rw-r--r-- | src/ephy-session.c | 255 | ||||
-rw-r--r-- | src/ephy-session.h | 4 | ||||
-rw-r--r-- | src/ephy-shell.c | 131 | ||||
-rw-r--r-- | src/ephy-shell.h | 8 | ||||
-rw-r--r-- | src/ephy-window.c | 13 | ||||
-rw-r--r-- | src/window-commands.c | 2 |
8 files changed, 177 insertions, 247 deletions
diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c index 221ab9aeb..8ffd89dcb 100644 --- a/src/bookmarks/ephy-bookmarks-editor.c +++ b/src/bookmarks/ephy-bookmarks-editor.c @@ -291,11 +291,7 @@ get_target_window (EphyBookmarksEditor *editor) } else { - EphySession *session; - - session = EPHY_SESSION (ephy_shell_get_session (ephy_shell)); - - return GTK_WIDGET (ephy_session_get_active_window (session)); + return GTK_WIDGET (ephy_shell_get_active_window (ephy_shell)); } } diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c index 8b03b69b8..a344060ab 100644 --- a/src/ephy-history-window.c +++ b/src/ephy-history-window.c @@ -304,10 +304,7 @@ get_target_window (EphyHistoryWindow *editor) } else { - EphySession *session; - - session = EPHY_SESSION (ephy_shell_get_session (ephy_shell)); - return GTK_WIDGET (ephy_session_get_active_window (session)); + return GTK_WIDGET (ephy_shell_get_active_window (ephy_shell)); } } diff --git a/src/ephy-session.c b/src/ephy-session.c index 9f44d7e0f..e7d1e3438 100644 --- a/src/ephy-session.c +++ b/src/ephy-session.c @@ -56,7 +56,6 @@ typedef struct struct _EphySessionPrivate { - GList *windows; GtkWidget *resume_window; GQueue *queue; @@ -67,17 +66,7 @@ struct _EphySessionPrivate #define SESSION_STATE "type:session_state" -static void ephy_session_iface_init (EphyExtensionIface *iface); - -enum -{ - PROP_0, - PROP_ACTIVE_WINDOW -}; - -G_DEFINE_TYPE_WITH_CODE (EphySession, ephy_session, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (EPHY_TYPE_EXTENSION, - ephy_session_iface_init)) +G_DEFINE_TYPE (EphySession, ephy_session, G_TYPE_OBJECT) /* Helper functions */ @@ -190,25 +179,6 @@ notebook_page_reordered_cb (GtkWidget *notebook, ephy_session_save (session, SESSION_STATE); } -static gboolean -window_focus_in_event_cb (EphyWindow *window, - GdkEventFocus *event, - EphySession *session) -{ - LOG ("focus-in-event for window %p", window); - - g_return_val_if_fail (g_list_find (session->priv->windows, window) != NULL, FALSE); - - /* move the active window to the front of the list */ - session->priv->windows = g_list_remove (session->priv->windows, window); - session->priv->windows = g_list_prepend (session->priv->windows, window); - - g_object_notify (G_OBJECT (session), "active-window"); - - /* propagate event */ - return FALSE; -} - /* Queue worker */ static void @@ -245,6 +215,7 @@ session_command_autoresume (EphySession *session, char *saved_session_file_path; gboolean crashed_session; EphyPrefsRestoreSessionPolicy policy; + EphyShell *shell; LOG ("ephy_session_autoresume"); @@ -258,9 +229,11 @@ session_command_autoresume (EphySession *session, policy = g_settings_get_enum (EPHY_SETTINGS_MAIN, EPHY_PREFS_RESTORE_SESSION_POLICY); + shell = ephy_shell_get_default (); + if (crashed_session == FALSE || policy == EPHY_PREFS_RESTORE_SESSION_POLICY_NEVER || - priv->windows != NULL) + ephy_shell_get_n_windows (shell) > 0) { /* If we are auto-resuming, and we never want to * restore the session, clobber the session state @@ -319,7 +292,7 @@ session_command_open_uris (EphySession *session, g_object_ref (shell); - window = ephy_session_get_active_window (session); + window = ephy_shell_get_active_window (shell); new_windows_in_tabs = g_settings_get_boolean (EPHY_SETTINGS_MAIN, EPHY_PREFS_NEW_WINDOWS_IN_TABS); @@ -403,6 +376,7 @@ session_command_dispatch (EphySession *session) { EphySessionPrivate *priv = session->priv; SessionCommand *cmd; + EphyShell *shell = ephy_shell_get_default (); gboolean run_again = TRUE; cmd = g_queue_pop_head (priv->queue); @@ -426,9 +400,9 @@ session_command_dispatch (EphySession *session) break; case EPHY_SESSION_CMD_MAYBE_OPEN_WINDOW: /* FIXME: maybe just check for normal windows? */ - if (priv->windows == NULL) + if (ephy_shell_get_n_windows (shell) == 0) { - ephy_shell_new_tab_full (ephy_shell_get_default (), + ephy_shell_new_tab_full (shell, NULL /* window */, NULL /* tab */, NULL /* NetworkRequest */, EPHY_NEW_TAB_IN_NEW_WINDOW | @@ -493,24 +467,22 @@ session_command_queue_clear (EphySession *session) } } -/* EphyExtensionIface implementation */ - static void -impl_attach_window (EphyExtension *extension, - EphyWindow *window) +window_added_cb (GtkApplication *application, + GtkWindow *window, + EphySession *session) { - EphySession *session = EPHY_SESSION (extension); GtkWidget *notebook; + EphyWindow *ephy_window; - LOG ("impl_attach_window"); - - session->priv->windows = g_list_append (session->priv->windows, window); ephy_session_save (session, SESSION_STATE); - g_signal_connect (window, "focus-in-event", - G_CALLBACK (window_focus_in_event_cb), session); + if (!EPHY_IS_WINDOW (window)) + return; - notebook = ephy_window_get_notebook (window); + ephy_window = EPHY_WINDOW (window); + + notebook = ephy_window_get_notebook (ephy_window); g_signal_connect (notebook, "page-added", G_CALLBACK (notebook_page_added_cb), session); g_signal_connect (notebook, "page-removed", @@ -522,7 +494,7 @@ impl_attach_window (EphyExtension *extension, * place the window on the right workspace */ - if (gtk_window_get_role (GTK_WINDOW (window)) == NULL) + if (gtk_window_get_role (window) == NULL) { /* I guess rand() is unique enough, otherwise we could use * time + pid or something @@ -530,20 +502,16 @@ impl_attach_window (EphyExtension *extension, char *role; role = g_strdup_printf ("epiphany-window-%x", rand()); - gtk_window_set_role (GTK_WINDOW (window), role); + gtk_window_set_role (window, role); g_free (role); } } static void -impl_detach_window (EphyExtension *extension, - EphyWindow *window) +window_removed_cb (GtkApplication *application, + GtkWindow *window, + EphySession *session) { - EphySession *session = EPHY_SESSION (extension); - - LOG ("impl_detach_window"); - - session->priv->windows = g_list_remove (session->priv->windows, window); ephy_session_save (session, SESSION_STATE); /* NOTE: since the window will be destroyed anyway, we don't need to @@ -557,12 +525,19 @@ static void ephy_session_init (EphySession *session) { EphySessionPrivate *priv; + EphyShell *shell; LOG ("EphySession initialising"); priv = session->priv = EPHY_SESSION_GET_PRIVATE (session); priv->queue = g_queue_new (); + + shell = ephy_shell_get_default (); + g_signal_connect (shell, "window-added", + G_CALLBACK (window_added_cb), session); + g_signal_connect (shell, "window-removed", + G_CALLBACK (window_removed_cb), session); } static void @@ -578,71 +553,11 @@ ephy_session_dispose (GObject *object) } static void -ephy_session_finalize (GObject *object) -{ - EphySession *session = EPHY_SESSION (object); - - LOG ("EphySession finalising"); - - /* FIXME: those should be NULL already!? */ - g_list_free (session->priv->windows); - - G_OBJECT_CLASS (ephy_session_parent_class)->finalize (object); -} - -static void -ephy_session_iface_init (EphyExtensionIface *iface) -{ - iface->attach_window = impl_attach_window; - iface->detach_window = impl_detach_window; -} - -static void -ephy_session_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - /* no writeable properties */ - g_return_if_reached (); -} - -static void -ephy_session_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EphySession *session = EPHY_SESSION (object); - - switch (prop_id) - { - case PROP_ACTIVE_WINDOW: - g_value_set_object (value, ephy_session_get_active_window (session)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void ephy_session_class_init (EphySessionClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); object_class->dispose = ephy_session_dispose; - object_class->finalize = ephy_session_finalize; - object_class->get_property = ephy_session_get_property; - object_class->set_property = ephy_session_set_property; - - g_object_class_install_property - (object_class, - PROP_ACTIVE_WINDOW, - g_param_spec_object ("active-window", - "Active Window", - "The active window", - EPHY_TYPE_WINDOW, - G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); g_type_class_add_private (object_class, sizeof (EphySessionPrivate)); } @@ -803,8 +718,10 @@ ephy_session_save (EphySession *session, const char *filename) { EphySessionPrivate *priv; + EphyShell *shell; xmlTextWriterPtr writer; GList *w; + GList *windows; GFile *save_to_file, *tmp_file; char *tmp_file_path, *save_to_file_path; int ret; @@ -820,7 +737,9 @@ ephy_session_save (EphySession *session, LOG ("ephy_sesion_save %s", filename); - if (priv->windows == NULL) + shell = ephy_shell_get_default (); + + if (ephy_shell_get_n_windows (shell) == 0) { session_delete (session, filename); return TRUE; @@ -856,11 +775,13 @@ ephy_session_save (EphySession *session, ret = xmlTextWriterStartElement (writer, (const xmlChar *) "session"); if (ret < 0) goto out; - /* iterate through all the windows */ - for (w = session->priv->windows; w != NULL && ret >= 0; w = w->next) + /* iterate through all the windows */ + windows = ephy_shell_get_windows (shell); + for (w = windows; w != NULL && ret >= 0; w = w->next) { ret = write_ephy_window (writer, EPHY_WINDOW (w->data)); } + g_list_free (windows); if (ret < 0) goto out; ret = xmlTextWriterEndElement (writer); /* session */ @@ -1037,12 +958,14 @@ ephy_session_load_from_string (EphySession *session, guint32 user_time) { EphySessionPrivate *priv; + EphyShell *shell; xmlDocPtr doc; xmlNodePtr child; EphyWindow *window; GtkWidget *widget = NULL; gboolean first_window_created = FALSE; - + gboolean retval; + g_return_val_if_fail (EPHY_IS_SESSION (session), FALSE); g_return_val_if_fail (session_data, FALSE); @@ -1066,7 +989,7 @@ ephy_session_load_from_string (EphySession *session, return FALSE; } - g_object_ref (ephy_shell_get_default ()); + shell = g_object_ref (ephy_shell_get_default ()); priv->dont_save = TRUE; @@ -1133,9 +1056,11 @@ ephy_session_load_from_string (EphySession *session, ephy_session_save (session, SESSION_STATE); - g_object_unref (ephy_shell_get_default ()); + retval = ephy_shell_get_n_windows (shell) > 0; + + g_object_unref (shell); - return priv->windows != NULL; + return retval; } /** @@ -1187,92 +1112,6 @@ ephy_session_load (EphySession *session, } /** - * ephy_session_get_windows: - * @session: the #EphySession - * - * Returns: (element-type EphyWindow) (transfer container): the list of - * open #EphyWindow:s. - **/ -GList * -ephy_session_get_windows (EphySession *session) -{ - g_return_val_if_fail (EPHY_IS_SESSION (session), NULL); - - return g_list_copy (session->priv->windows); -} - -/** - * ephy_session_get_active_window: - * @session: a #EphySession - * - * Get the current active browser window. Use it when you - * need to take an action (like opening an url) on - * a window but you dont have a target window. - * - * Return value: (transfer none): the current active non-popup browser - * window, or NULL of there is none. - **/ -EphyWindow * -ephy_session_get_active_window (EphySession *session) -{ - EphyWindow *window = NULL; - EphyEmbedContainer *w; - GList *l; - - g_return_val_if_fail (EPHY_IS_SESSION (session), NULL); - - for (l = session->priv->windows; l != NULL; l = l->next) - { - w = EPHY_EMBED_CONTAINER (l->data); - - if (ephy_embed_container_get_is_popup (w) == FALSE) - { - window = EPHY_WINDOW (w); - break; - } - } - - return window; -} - -/** - * ephy_session_close_all_windows: - * @session: a #EphySession - * - * Try to close all browser windows. A window might refuse to - * close if there are ongoing download operations or unsubmitted - * modifed forms. - * - * Returns: %TRUE if all windows were closed, or %FALSE otherwise - **/ -gboolean -ephy_session_close_all_windows (EphySession *session) -{ - GList *l; - gboolean retval = TRUE; - - g_return_val_if_fail (EPHY_IS_SESSION (session), FALSE); - - ephy_session_close (session); - - for (l = session->priv->windows; l != NULL; l = l->next) - { - EphyWindow *window = EPHY_WINDOW (l->data); - - if (ephy_window_close (window)) - { - gtk_widget_destroy (GTK_WIDGET (window)); - } - else - { - retval = FALSE; - } - } - - return retval; -} - -/** * ephy_session_queue_command: * @session: a #EphySession **/ diff --git a/src/ephy-session.h b/src/ephy-session.h index 392c0612b..fc754126f 100644 --- a/src/ephy-session.h +++ b/src/ephy-session.h @@ -86,10 +86,6 @@ gboolean ephy_session_load_from_string (EphySession *session, void ephy_session_close (EphySession *session); -GList *ephy_session_get_windows (EphySession *session); - -gboolean ephy_session_close_all_windows (EphySession *session); - void ephy_session_queue_command (EphySession *session, EphySessionCommand op, const char *arg, diff --git a/src/ephy-shell.c b/src/ephy-shell.c index 9fa31bacf..f8ad2f8ed 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -54,6 +54,7 @@ struct _EphyShellPrivate { EphySession *session; + GList *windows; GObject *lockdown; EphyBookmarks *bookmarks; EphyExtensionsManager *extensions_manager; @@ -206,11 +207,9 @@ show_about (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - EphySession *session; EphyWindow *window; - session = EPHY_SESSION (ephy_shell_get_session (ephy_shell)); - window = ephy_session_get_active_window (session); + window = ephy_shell_get_active_window (ephy_shell); window_cmd_help_about (NULL, GTK_WIDGET (window)); } @@ -428,6 +427,50 @@ ephy_shell_before_emit (GApplication *application, platform_data); } +static gboolean +window_focus_in_event_cb (EphyWindow *window, + GdkEventFocus *event, + EphyShell *shell) +{ + LOG ("focus-in-event for window %p", window); + + g_return_val_if_fail (g_list_find (shell->priv->windows, window) != NULL, FALSE); + + /* move the active window to the front of the list */ + shell->priv->windows = g_list_remove (shell->priv->windows, window); + shell->priv->windows = g_list_prepend (shell->priv->windows, window); + + return GDK_EVENT_PROPAGATE; +} + +static void +ephy_shell_window_added (GtkApplication *application, + GtkWindow *window) +{ + EphyShell *shell = EPHY_SHELL (application); + + if (EPHY_IS_WINDOW (window)) { + shell->priv->windows = g_list_append (shell->priv->windows, window); + g_signal_connect (window, "focus-in-event", + G_CALLBACK (window_focus_in_event_cb), + shell); + } + + GTK_APPLICATION_CLASS (ephy_shell_parent_class)->window_added (application, window); +} + +static void +ephy_shell_window_removed (GtkApplication *application, + GtkWindow *window) +{ + EphyShell *shell = EPHY_SHELL (application); + + if (EPHY_IS_WINDOW (window)) + shell->priv->windows = g_list_remove (shell->priv->windows, window); + + GTK_APPLICATION_CLASS (ephy_shell_parent_class)->window_removed (application, window); +} + static void ephy_shell_constructed (GObject *object) { @@ -448,6 +491,7 @@ ephy_shell_class_init (EphyShellClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GApplicationClass *application_class = G_APPLICATION_CLASS (klass); + GtkApplicationClass *gtk_application_class = GTK_APPLICATION_CLASS (klass); EphyEmbedShellClass *embed_shell_class = EPHY_EMBED_SHELL_CLASS (klass); object_class->dispose = ephy_shell_dispose; @@ -459,6 +503,9 @@ ephy_shell_class_init (EphyShellClass *klass) application_class->before_emit = ephy_shell_before_emit; application_class->add_platform_data = ephy_shell_add_platform_data; + gtk_application_class->window_added = ephy_shell_window_added; + gtk_application_class->window_removed = ephy_shell_window_removed; + embed_shell_class->get_embed_single = impl_get_embed_single; g_type_class_add_private (object_class, sizeof(EphyShellPrivate)); @@ -529,7 +576,6 @@ download_started_cb (WebKitWebContext *web_context, EphyShell *shell) { EphyDownload *ed; - EphySession *session; EphyWindow *window; /* Is download locked down? */ @@ -539,8 +585,7 @@ download_started_cb (WebKitWebContext *web_context, return; } - session = EPHY_SESSION (ephy_shell_get_session (shell)); - window = ephy_session_get_active_window (session); + window = ephy_shell_get_active_window (shell); ed = ephy_download_new_for_download (download); ephy_download_set_window (ed, GTK_WIDGET (window)); @@ -586,6 +631,12 @@ ephy_shell_dispose (GObject *object) g_clear_object (&priv->bookmarks); g_clear_object (&priv->network_monitor); + if (priv->windows != NULL) { + LOG ("Free browser window list"); + g_list_free (priv->windows); + priv->windows = NULL; + } + G_OBJECT_CLASS (ephy_shell_parent_class)->dispose (object); } @@ -810,17 +861,9 @@ ephy_shell_get_session (EphyShell *shell) { g_return_val_if_fail (EPHY_IS_SHELL (shell), NULL); - if (shell->priv->session == NULL) { - EphyExtensionsManager *manager; - + if (shell->priv->session == NULL) shell->priv->session = g_object_new (EPHY_TYPE_SESSION, NULL); - manager = EPHY_EXTENSIONS_MANAGER - (ephy_shell_get_extensions_manager (shell)); - ephy_extensions_manager_register (manager, - G_OBJECT (shell->priv->session)); - } - return G_OBJECT (shell->priv->session); } @@ -1013,3 +1056,61 @@ ephy_shell_set_startup_context (EphyShell *shell, shell->priv->startup_context = ctx; } + +GList * +ephy_shell_get_windows (EphyShell *shell) +{ + g_return_val_if_fail (EPHY_IS_SHELL (shell), NULL); + + return g_list_copy (shell->priv->windows); +} + +guint +ephy_shell_get_n_windows (EphyShell *shell) +{ + g_return_val_if_fail (EPHY_IS_SHELL (shell), 0); + + return g_list_length (shell->priv->windows); +} + +EphyWindow * +ephy_shell_get_active_window (EphyShell *shell) +{ + GList *l; + + g_return_val_if_fail (EPHY_IS_SHELL (shell), NULL); + + for (l = shell->priv->windows; l != NULL; l = l->next) { + EphyEmbedContainer *window = EPHY_EMBED_CONTAINER (l->data); + + if (!ephy_embed_container_get_is_popup (window)) + return EPHY_WINDOW (window); + } + + return NULL; +} + +gboolean +ephy_shell_close_all_windows (EphyShell *shell) +{ + GList *windows; + gboolean retval = TRUE; + + g_return_val_if_fail (EPHY_IS_SHELL (shell), FALSE); + + ephy_session_close (EPHY_SESSION (ephy_shell_get_session (shell))); + + windows = shell->priv->windows; + while (windows) { + EphyWindow *window = EPHY_WINDOW (windows->data); + + windows = windows->next; + + if (ephy_window_close (window)) + gtk_widget_destroy (GTK_WIDGET (window)); + else + retval = FALSE; + } + + return retval; +} diff --git a/src/ephy-shell.h b/src/ephy-shell.h index 42b83e18b..9e0a4c7de 100644 --- a/src/ephy-shell.h +++ b/src/ephy-shell.h @@ -177,6 +177,14 @@ GObject *ephy_shell_get_pdm_dialog (EphyShell *shell); GObject *ephy_shell_get_prefs_dialog (EphyShell *shell); +GList *ephy_shell_get_windows (EphyShell *shell); + +guint ephy_shell_get_n_windows (EphyShell *shell); + +EphyWindow *ephy_shell_get_active_window (EphyShell *shell); + +gboolean ephy_shell_close_all_windows (EphyShell *shell); + G_END_DECLS #endif diff --git a/src/ephy-window.c b/src/ephy-window.c index dd85df737..c84d0c6a2 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -4183,10 +4183,8 @@ ephy_window_get_location_controller (EphyWindow *window) gboolean ephy_window_close (EphyWindow *window) { - EphySession *session; EphyEmbed *modified_embed = NULL; - GList *tabs, *l, *windows; - guint number_windows; + GList *tabs, *l; gboolean modified = FALSE; /* We ignore the delete_event if the disable_quit lockdown has been set @@ -4231,14 +4229,9 @@ ephy_window_close (EphyWindow *window) } /* If this is the last window, save its state in the session. */ - session = EPHY_SESSION (ephy_shell_get_session (ephy_shell)); - windows = ephy_session_get_windows (session); - number_windows = g_list_length (windows); - g_list_free (windows); - - if (number_windows == 1) + if (ephy_shell_get_n_windows (ephy_shell) == 1) { - ephy_session_close (session); + ephy_session_close (EPHY_SESSION (ephy_shell_get_session (ephy_shell))); } /* See bug #114689 */ diff --git a/src/window-commands.c b/src/window-commands.c index 81ba0f0bb..a38557d72 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -722,7 +722,7 @@ void window_cmd_file_quit (GtkAction *action, EphyWindow *window) { - if (ephy_session_close_all_windows (EPHY_SESSION (ephy_shell_get_session (ephy_shell)))) + if (ephy_shell_close_all_windows (ephy_shell)) g_application_quit (g_application_get_default ()); } |