Esempio n. 1
0
static gboolean
session_command_dispatch (EphySession *session)
{
	EphySessionPrivate *priv = session->priv;
	SessionCommand *cmd;
	gboolean run_again = TRUE;

	cmd = g_queue_pop_head (priv->queue);
	g_assert (cmd != NULL);

	LOG ("dispatching queue cmd:%d", cmd->command);

	switch (cmd->command)
	{
		case EPHY_SESSION_CMD_RESUME_SESSION:
			session_command_autoresume (session, cmd->user_time);
			break;
		case EPHY_SESSION_CMD_LOAD_SESSION:
			ephy_session_load (session, cmd->arg, cmd->user_time);
			break;
		case EPHY_SESSION_CMD_OPEN_BOOKMARKS_EDITOR:
			session_command_open_bookmarks_editor (session, cmd->user_time);
			break;
		case EPHY_SESSION_CMD_OPEN_URIS:
			session_command_open_uris (session, cmd->args, cmd->arg, cmd->user_time);
			break;
		case EPHY_SESSION_CMD_MAYBE_OPEN_WINDOW:
			/* FIXME: maybe just check for normal windows? */
			if (priv->windows == NULL &&
			    priv->tool_windows == NULL)
			{
				ephy_shell_new_tab_full (ephy_shell_get_default (),
							 NULL /* window */, NULL /* tab */,
							 NULL /* NetworkRequest */,
							 EPHY_NEW_TAB_IN_NEW_WINDOW |
							 EPHY_NEW_TAB_HOME_PAGE,
							 EPHY_WEB_VIEW_CHROME_ALL,
							 FALSE /* is popup? */,
							 cmd->user_time);
			}
			break;
		default:
			g_assert_not_reached ();
			break;
	}

	/* Look if there's anything else to dispatch */
	if (g_queue_is_empty (priv->queue))
	{
		priv->queue_idle_id = 0;
		run_again = FALSE;
	}

	g_application_release (G_APPLICATION (ephy_shell_get_default ()));

	/* This unrefs the shell! */
	session_command_free (cmd);

	return run_again;
}
Esempio n. 2
0
/*
 * update_tabs_visibility: Hide tabs if there is only one tab
 * and the pref is not set or when in application mode.
 */
static void
update_tabs_visibility (EphyNotebook *nb,
                        gboolean      before_inserting)
{
  EphyEmbedShellMode mode;
  gboolean show_tabs = FALSE;
  guint num;
  EphyPrefsUITabsBarVisibilityPolicy policy;

  mode = ephy_embed_shell_get_mode (EPHY_EMBED_SHELL (ephy_shell_get_default ()));
  num = gtk_notebook_get_n_pages (GTK_NOTEBOOK (nb));

  if (before_inserting)
    num++;

  policy = g_settings_get_enum (EPHY_SETTINGS_UI,
                                EPHY_PREFS_UI_TABS_BAR_VISIBILITY_POLICY);

  if (mode != EPHY_EMBED_SHELL_MODE_APPLICATION &&
      nb->adaptive_mode != EPHY_ADAPTIVE_MODE_NARROW &&
      ((policy == EPHY_PREFS_UI_TABS_BAR_VISIBILITY_POLICY_MORE_THAN_ONE && num > 1) ||
        policy == EPHY_PREFS_UI_TABS_BAR_VISIBILITY_POLICY_ALWAYS))
    show_tabs = TRUE;

  /* Only show the tabs when the "tabs-allowed" property is TRUE. */
  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), nb->tabs_allowed && show_tabs);
}
static void
test_ephy_completion_model_create (void)
{
  EphyCompletionModel *model;
  model = ephy_completion_model_new (ephy_embed_shell_get_global_history_service (ephy_embed_shell_get_default ()),
                                     ephy_shell_get_bookmarks_manager (ephy_shell_get_default ()));
  g_assert (model);
  g_object_unref (model);
}
static void
test_ephy_completion_model_create (void)
{
    EphyCompletionModel *model;
    model = ephy_completion_model_new (EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service (ephy_embed_shell_get_default ())),
                                       ephy_shell_get_bookmarks (ephy_shell_get_default ()), TRUE);
    g_assert (model);
    g_object_unref (model);
}
Esempio n. 5
0
static void
session_command_open_bookmarks_editor (EphySession *session,
				       guint32 user_time)
{
	GtkWidget *editor;

	editor = ephy_shell_get_bookmarks_editor (ephy_shell_get_default ());
	
	gtk_window_present_with_time (GTK_WINDOW (editor), user_time);
}
static void
ephy_completion_model_init (EphyCompletionModel *model)
{
  EphyCompletionModelPrivate *priv;
  EphyBookmarks *bookmarks_service;

  model->priv = priv = EPHY_COMPLETION_MODEL_GET_PRIVATE (model);

  priv->history_service = EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service (ephy_embed_shell_get_default ()));

  bookmarks_service = ephy_shell_get_bookmarks (ephy_shell_get_default ());
  priv->bookmarks = ephy_bookmarks_get_bookmarks (bookmarks_service);
}
Esempio n. 7
0
static void
session_command_free (SessionCommand *cmd)
{
	g_assert (cmd != NULL);

	g_free (cmd->arg);
	if (cmd->args)
	{
		g_strfreev (cmd->args);
	}

	g_slice_free (SessionCommand, cmd);

	g_object_unref (ephy_shell_get_default ());
}
Esempio n. 8
0
static void
ephy_session_init (EphySession *session)
{
	EphyShell *shell;

	LOG ("EphySession initialising");

	session->priv = EPHY_SESSION_GET_PRIVATE (session);

	session->priv->closed_tabs = 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);
}
Esempio n. 9
0
static void
session_maybe_open_window (EphySession *session,
			   guint32 user_time)
{
	EphyShell *shell = ephy_shell_get_default ();

	/* FIXME: maybe just check for normal windows? */
	if (ephy_shell_get_n_windows (shell) == 0)
	{
		ephy_shell_new_tab_full (shell,
					 NULL /* window */, NULL /* tab */,
					 NULL /* NetworkRequest */,
					 EPHY_NEW_TAB_IN_NEW_WINDOW |
					 EPHY_NEW_TAB_HOME_PAGE,
					 EPHY_WEB_VIEW_CHROME_ALL,
					 FALSE /* is popup? */,
					 user_time);
	}
}
Esempio n. 10
0
static void
test_ephy_completion_model_update_empty (void)
{
  EphyCompletionModel *model;
  GMainLoop *loop = NULL;

  model = ephy_completion_model_new (ephy_embed_shell_get_global_history_service (ephy_embed_shell_get_default ()),
                                     ephy_shell_get_bookmarks_manager (ephy_shell_get_default ()));
  g_assert (model);

  loop = g_main_loop_new (NULL, FALSE);

  ephy_completion_model_update_for_string (model, "hello",
                                           (EphyHistoryJobCallback)update_empty_cb,
                                           loop);

  g_main_loop_run (loop);

  g_object_unref (model);
  g_main_loop_unref (loop);
}
Esempio n. 11
0
void
ephy_session_undo_close_tab (EphySession *session)
{
	EphySessionPrivate *priv;
	EphyEmbed *embed, *new_tab;
	ClosedTab *tab;
#ifndef HAVE_WEBKIT2
	WebKitWebBackForwardList *dest;
	GList *i;
#endif
	EphyNewTabFlags flags = EPHY_NEW_TAB_OPEN_PAGE
		| EPHY_NEW_TAB_PRESENT_WINDOW
		| EPHY_NEW_TAB_JUMP
		| EPHY_NEW_TAB_DONT_COPY_HISTORY;

	g_return_if_fail (EPHY_IS_SESSION (session));

	priv = session->priv;

	tab = g_queue_pop_head (priv->closed_tabs);
	if (tab == NULL)
		return;

	LOG ("UNDO CLOSE TAB: %s", tab->url);
	if (*tab->parent_location != NULL)
	{
		GtkWidget *window;

		flags |= EPHY_NEW_TAB_IN_EXISTING_WINDOW;

		if (tab->position > 0)
		{
			/* Append in the n-th position. */
			embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (*tab->parent_location),
								       tab->position - 1));
			flags |= EPHY_NEW_TAB_APPEND_AFTER;
		}
		else
		{
			/* Just prepend in the first position. */
			embed = NULL;
			flags |= EPHY_NEW_TAB_FIRST;
		}

		window = gtk_widget_get_toplevel (GTK_WIDGET (*tab->parent_location));
		new_tab = ephy_shell_new_tab (ephy_shell_get_default (),
					      EPHY_WINDOW (window), embed, tab->url,
					      flags);
		post_restore_cleanup (priv->closed_tabs, tab, FALSE);
	}
	else
	{
		EphyNotebook *notebook;
		flags |=  EPHY_NEW_TAB_IN_NEW_WINDOW;
		new_tab = ephy_shell_new_tab (ephy_shell_get_default (),
					      NULL, NULL, tab->url, flags);

		/* FIXME: This makes the assumption that the notebook
		   is the parent of the returned EphyEmbed. */
		notebook = EPHY_NOTEBOOK (gtk_widget_get_parent (GTK_WIDGET (new_tab)));
		*tab->parent_location = notebook;
		post_restore_cleanup (priv->closed_tabs, tab, TRUE);
	}

	/* This is deficient: we need to recreate the whole
	 * BackForward list. Also, WebKit2 doesn't have this API. */
#ifndef HAVE_WEBKIT2
	dest = webkit_web_view_get_back_forward_list (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (new_tab));
	for (i = tab->bflist; i; i = i->next)
	{
		LOG ("ADDING TO BF: %s",
		     webkit_web_history_item_get_title ((WebKitWebHistoryItem*) i->data));
		webkit_web_back_forward_list_add_item (dest,
						       webkit_web_history_item_copy ((WebKitWebHistoryItem*) i->data));
	}
#endif
	closed_tab_free (tab);

	if (g_queue_is_empty (priv->closed_tabs))
		g_object_notify (G_OBJECT (session), "can-undo-tab-closed");
}
Esempio n. 12
0
static void
session_command_open_uris (EphySession *session,
			   char **uris,
			   const char *options,
			   guint32 user_time)
{
	EphyShell *shell;
	EphyWindow *window;
	EphyEmbed *embed;
	EphySessionPrivate *priv;
	EphyNewTabFlags flags = 0;
	guint i;

	priv = session->priv;

	shell = ephy_shell_get_default ();

	g_object_ref (shell);

	window = ephy_session_get_active_window (session);

	if (options != NULL && strstr (options, "external") != NULL)
	{
		flags |= EPHY_NEW_TAB_FROM_EXTERNAL;
	}
	if (options != NULL && strstr (options, "new-window") != NULL)
	{
		window = NULL;
		flags |= EPHY_NEW_TAB_IN_NEW_WINDOW;
	}
	else if (options != NULL && strstr (options, "new-tab") != NULL)
	{
		flags |= EPHY_NEW_TAB_IN_EXISTING_WINDOW |
			 EPHY_NEW_TAB_JUMP;
	}

	for (i = 0; uris[i] != NULL; ++i)
	{
		const char *url = uris[i];
		EphyNewTabFlags page_flags;
#ifdef HAVE_WEBKIT2
		WebKitURIRequest *request = NULL;
#else
		WebKitNetworkRequest *request = NULL;
#endif

		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);
#else
			request = webkit_network_request_new (url);
#endif
		}

		/* For the first URI, if we have a valid recovery
		 * window, reuse the already existing embed instead of
		 * creating a new one, except if we still want to
		 * present the option to resume a crashed session, in
		 * that case use a new tab in the same window */
		if (i == 0 && priv->resume_window != NULL)
		{
			EphyWebView *web_view;
			
			embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (priv->resume_window));
			web_view = ephy_embed_get_web_view (embed);
			ephy_web_view_load_url (web_view, url);
		}
		else
		{
			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);

		window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (embed)));
	}

	g_object_unref (shell);
}