aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2013-01-08 18:30:38 +0800
committerCarlos Garcia Campos <cgarcia@igalia.com>2013-01-09 00:49:28 +0800
commitaff7854dd623643a1d76676508dbb9265a4c3bc1 (patch)
treee3164dd4e200ee5d7658e91274500dca2c4b5e8d /src
parent5a570470ebdd1f3ed5aa2977a40bb85623b336e6 (diff)
downloadgsoc2013-epiphany-aff7854dd623643a1d76676508dbb9265a4c3bc1.tar
gsoc2013-epiphany-aff7854dd623643a1d76676508dbb9265a4c3bc1.tar.gz
gsoc2013-epiphany-aff7854dd623643a1d76676508dbb9265a4c3bc1.tar.bz2
gsoc2013-epiphany-aff7854dd623643a1d76676508dbb9265a4c3bc1.tar.lz
gsoc2013-epiphany-aff7854dd623643a1d76676508dbb9265a4c3bc1.tar.xz
gsoc2013-epiphany-aff7854dd623643a1d76676508dbb9265a4c3bc1.tar.zst
gsoc2013-epiphany-aff7854dd623643a1d76676508dbb9265a4c3bc1.zip
ephy-session: Remove EPHY_SESSION_CMD_OPEN_URIS
Add ephy_session_open_uris() instead and use it from EphyShell instead of scheduling a command. https://bugzilla.gnome.org/show_bug.cgi?id=641739
Diffstat (limited to 'src')
-rw-r--r--src/ephy-session.c172
-rw-r--r--src/ephy-session.h8
-rw-r--r--src/ephy-shell.c26
3 files changed, 123 insertions, 83 deletions
diff --git a/src/ephy-session.c b/src/ephy-session.c
index bfe09c5b1..1d13ac168 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -32,7 +32,6 @@
#include "ephy-gui.h"
#include "ephy-prefs.h"
#include "ephy-settings.h"
-#include "ephy-shell.h"
#include "ephy-string.h"
#include "ephy-window.h"
@@ -56,6 +55,7 @@ struct _EphySessionPrivate
GQueue *queue;
guint queue_idle_id;
+ guint open_uris_idle_id;
guint dont_save : 1;
};
@@ -192,92 +192,142 @@ session_command_free (SessionCommand *cmd)
g_object_unref (ephy_shell_get_default ());
}
-static void
-session_command_open_uris (EphySession *session,
- char **uris,
- const char *options,
- guint32 user_time)
+typedef struct {
+ EphySession *session;
+ EphyWindow *window;
+ char **uris;
+ EphyNewTabFlags flags;
+ guint32 user_time;
+ guint current_uri;
+} OpenURIsData;
+
+static OpenURIsData *
+open_uris_data_new (EphySession *session,
+ const char **uris,
+ EphyStartupFlags startup_flags,
+ guint32 user_time)
{
+ OpenURIsData *data;
EphyShell *shell;
- EphyWindow *window;
- EphyEmbed *embed;
- EphyNewTabFlags flags = 0;
- guint i;
gboolean new_windows_in_tabs;
gboolean have_uris;
shell = ephy_shell_get_default ();
- g_object_ref (shell);
+ data = g_slice_new0 (OpenURIsData);
+ data->session = g_object_ref (session);
+ data->uris = g_strdupv ((char **)uris);
+ data->user_time = user_time;
- window = ephy_shell_get_main_window (shell);
+ data->window = ephy_shell_get_main_window (shell);
new_windows_in_tabs = g_settings_get_boolean (EPHY_SETTINGS_MAIN,
EPHY_PREFS_NEW_WINDOWS_IN_TABS);
- have_uris = ! (g_strv_length (uris) == 1 && g_str_equal (uris[0], ""));
+ have_uris = ! (g_strv_length ((char **)uris) == 1 && g_str_equal (uris[0], ""));
- if (options != NULL && strstr (options, "external") != NULL)
+ if (startup_flags & EPHY_STARTUP_NEW_TAB)
{
- flags |= EPHY_NEW_TAB_FROM_EXTERNAL;
+ data->flags |= EPHY_NEW_TAB_FROM_EXTERNAL;
}
- if (options != NULL && strstr (options, "new-window") != NULL)
+ if (startup_flags & EPHY_STARTUP_NEW_WINDOW)
{
- window = NULL;
- flags |= EPHY_NEW_TAB_IN_NEW_WINDOW;
+ data->window = NULL;
+ data->flags |= EPHY_NEW_TAB_IN_NEW_WINDOW;
}
- else if ((options != NULL && strstr (options, "new-tab") != NULL) ||
- (new_windows_in_tabs && have_uris))
+ else if (startup_flags & EPHY_STARTUP_NEW_TAB || (new_windows_in_tabs && have_uris))
{
- flags |= EPHY_NEW_TAB_IN_EXISTING_WINDOW |
- EPHY_NEW_TAB_JUMP |
- EPHY_NEW_TAB_PRESENT_WINDOW;
+ data->flags |= EPHY_NEW_TAB_IN_EXISTING_WINDOW | EPHY_NEW_TAB_JUMP | EPHY_NEW_TAB_PRESENT_WINDOW;
}
else if (!have_uris)
{
- window = NULL;
- flags |= EPHY_NEW_TAB_IN_NEW_WINDOW;
+ data->window = NULL;
+ data->flags |= EPHY_NEW_TAB_IN_NEW_WINDOW;
}
- for (i = 0; uris[i] != NULL; ++i)
- {
- const char *url = uris[i];
- EphyNewTabFlags page_flags;
+ g_application_hold (G_APPLICATION (shell));
+
+ return data;
+}
+
+static void
+open_uris_data_free (OpenURIsData *data)
+{
+ g_application_release (G_APPLICATION (ephy_shell_get_default ()));
+ g_object_unref (data->session);
+ g_strfreev (data->uris);
+
+ g_slice_free (OpenURIsData, data);
+}
+
+static gboolean
+ephy_session_open_uris_idle (OpenURIsData *data)
+{
+ EphyEmbed *embed;
+ EphyNewTabFlags page_flags;
+ const char *url;
#ifdef HAVE_WEBKIT2
- WebKitURIRequest *request = NULL;
+ WebKitURIRequest *request = NULL;
#else
- WebKitNetworkRequest *request = NULL;
+ WebKitNetworkRequest *request = NULL;
#endif
- if (url[0] == '\0')
- {
- page_flags = EPHY_NEW_TAB_HOME_PAGE;
- }
- else
- {
- page_flags = EPHY_NEW_TAB_OPEN_PAGE;
+ url = data->uris[data->current_uri];
+ if (url[0] == '\0')
+ {
+ page_flags = EPHY_NEW_TAB_HOME_PAGE;
+ }
+ else
+ {
+ page_flags = EPHY_NEW_TAB_OPEN_PAGE;
#ifdef HAVE_WEBKIT2
- request = webkit_uri_request_new (url);
+ request = webkit_uri_request_new (url);
#else
- request = webkit_network_request_new (url);
+ request = webkit_network_request_new (url);
#endif
- }
-
- embed = ephy_shell_new_tab_full (shell, window,
- NULL /* parent tab */,
- request,
- flags | page_flags,
- EPHY_WEB_VIEW_CHROME_ALL,
- FALSE /* is popup? */,
- user_time);
+ }
- if (request)
- g_object_unref (request);
+ embed = ephy_shell_new_tab_full (ephy_shell_get_default (),
+ data->window,
+ NULL /* parent tab */,
+ request,
+ data->flags | page_flags,
+ EPHY_WEB_VIEW_CHROME_ALL,
+ FALSE /* is popup? */,
+ data->user_time);
- window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (embed)));
+ if (request)
+ {
+ g_object_unref (request);
}
- g_object_unref (shell);
+ data->window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (embed)));
+ data->current_uri++;
+
+ return data->uris[data->current_uri] != NULL;
+}
+
+static void
+ephy_session_open_uris_idle_done (OpenURIsData *data)
+{
+ data->session->priv->open_uris_idle_id = 0;
+ open_uris_data_free (data);
+}
+
+void
+ephy_session_open_uris (EphySession *session,
+ const char **uris,
+ EphyStartupFlags startup_flags,
+ guint32 user_time)
+{
+ if (session->priv->open_uris_idle_id == 0)
+ {
+ session->priv->open_uris_idle_id =
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+ (GSourceFunc)ephy_session_open_uris_idle,
+ open_uris_data_new (session, uris, startup_flags, user_time),
+ (GDestroyNotify)ephy_session_open_uris_idle_done);
+ }
}
static void
@@ -314,9 +364,6 @@ session_command_dispatch (EphySession *session)
switch (cmd->command)
{
- case EPHY_SESSION_CMD_OPEN_URIS:
- session_command_open_uris (session, cmd->args, cmd->arg, cmd->user_time);
- break;
default:
g_assert_not_reached ();
break;
@@ -429,14 +476,12 @@ window_removed_cb (GtkApplication *application,
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 ();
+ session->priv = EPHY_SESSION_GET_PRIVATE (session);
+ session->priv->queue = g_queue_new ();
shell = ephy_shell_get_default ();
g_signal_connect (shell, "window-added",
@@ -452,6 +497,12 @@ ephy_session_dispose (GObject *object)
LOG ("EphySession disposing");
+ if (session->priv->open_uris_idle_id > 0)
+ {
+ g_source_remove (session->priv->open_uris_idle_id);
+ session->priv->open_uris_idle_id = 0;
+ }
+
session_command_queue_clear (session);
G_OBJECT_CLASS (ephy_session_parent_class)->dispose (object);
@@ -1396,7 +1447,6 @@ ephy_session_queue_command (EphySession *session,
LOG ("queue_command command:%d", command);
g_return_if_fail (EPHY_IS_SESSION (session));
- g_return_if_fail (command != EPHY_SESSION_CMD_OPEN_URIS || args != NULL);
priv = session->priv;
diff --git a/src/ephy-session.h b/src/ephy-session.h
index 62f07690e..afdf398e9 100644
--- a/src/ephy-session.h
+++ b/src/ephy-session.h
@@ -26,6 +26,7 @@
#ifndef EPHY_SESSION_H
#define EPHY_SESSION_H
+#include "ephy-shell.h"
#include "ephy-window.h"
#include <gtk/gtk.h>
@@ -45,8 +46,7 @@ typedef struct _EphySessionClass EphySessionClass;
typedef enum
{
- EPHY_SESSION_CMD_OPEN_URIS,
- EPHY_SESSION_CMD_LAST
+ EPHY_SESSION_CMD_LAST
} EphySessionCommand;
struct _EphySession
@@ -64,6 +64,10 @@ struct _EphySessionClass
GType ephy_session_get_type (void);
+void ephy_session_open_uris (EphySession *session,
+ const char **uris,
+ EphyStartupFlags startup_flags,
+ guint32 user_time);
gboolean ephy_session_save (EphySession *session,
const char *filename);
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index ee947ff97..42209bd5c 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -113,7 +113,7 @@ ephy_shell_startup_context_new (EphyStartupFlags startup_flags,
}
static void
-queue_commands (EphyShell *shell)
+ephy_shell_startup_continue (EphyShell *shell)
{
EphyShellStartupContext *ctx;
EphySession *session;
@@ -129,21 +129,8 @@ queue_commands (EphyShell *shell)
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);
+ ephy_session_open_uris (session, (const char **)ctx->arguments,
+ ctx->startup_flags, ctx->user_time);
}
}
@@ -262,7 +249,7 @@ session_load_cb (GObject *object,
EphyShell *shell = EPHY_SHELL (user_data);
ephy_session_resume_finish (session, result, NULL);
- queue_commands (shell);
+ ephy_shell_startup_continue (shell);
}
static void
@@ -281,9 +268,8 @@ ephy_shell_activate (GApplication *application)
ctx = shell->priv->startup_context;
ephy_session_resume (EPHY_SESSION (ephy_shell_get_session (shell)),
ctx->user_time, NULL, session_load_cb, shell);
- }
- else
- queue_commands (shell);
+ } else
+ ephy_shell_startup_continue (shell);
}
/*