diff options
author | Xan Lopez <xan@igalia.com> | 2013-03-24 03:57:31 +0800 |
---|---|---|
committer | Xan Lopez <xan@igalia.com> | 2013-03-24 03:58:43 +0800 |
commit | a06498057762d695d044584d76fb388650a10e12 (patch) | |
tree | 7f62a3c31871bcc94c13e21068001e63af304c5a /embed | |
parent | 35b2a8970c28e322bad1ee2c67ee1ba7a4824e95 (diff) | |
download | gsoc2013-epiphany-a06498057762d695d044584d76fb388650a10e12.tar gsoc2013-epiphany-a06498057762d695d044584d76fb388650a10e12.tar.gz gsoc2013-epiphany-a06498057762d695d044584d76fb388650a10e12.tar.bz2 gsoc2013-epiphany-a06498057762d695d044584d76fb388650a10e12.tar.lz gsoc2013-epiphany-a06498057762d695d044584d76fb388650a10e12.tar.xz gsoc2013-epiphany-a06498057762d695d044584d76fb388650a10e12.tar.zst gsoc2013-epiphany-a06498057762d695d044584d76fb388650a10e12.zip |
Get rid of EphyEmbedSingle
Move the remaining initialization code to EphyEmbedShell
https://bugzilla.gnome.org/show_bug.cgi?id=693703
Diffstat (limited to 'embed')
-rw-r--r-- | embed/Makefile.am | 2 | ||||
-rw-r--r-- | embed/ephy-embed-shell.c | 147 | ||||
-rw-r--r-- | embed/ephy-embed-shell.h | 4 | ||||
-rw-r--r-- | embed/ephy-embed-single.c | 149 | ||||
-rw-r--r-- | embed/ephy-embed-single.h | 58 | ||||
-rw-r--r-- | embed/ephy-web-view.c | 1 |
6 files changed, 88 insertions, 273 deletions
diff --git a/embed/Makefile.am b/embed/Makefile.am index 1d1ea0899..44aa8b11b 100644 --- a/embed/Makefile.am +++ b/embed/Makefile.am @@ -19,7 +19,6 @@ INST_H_FILES = \ ephy-embed-container.h \ ephy-embed-event.h \ ephy-embed-prefs.h \ - ephy-embed-single.h \ ephy-embed-shell.h \ ephy-embed-utils.h \ ephy-overview.h \ @@ -37,7 +36,6 @@ libephyembed_la_SOURCES = \ ephy-embed-container.c \ ephy-embed-dialog.c \ ephy-embed-event.c \ - ephy-embed-single.c \ ephy-embed-shell.c \ ephy-embed-utils.c \ ephy-encoding.c \ diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c index ba6c840e3..ab7341906 100644 --- a/embed/ephy-embed-shell.c +++ b/embed/ephy-embed-shell.c @@ -22,15 +22,18 @@ #include <config.h> #include "ephy-embed-shell.h" +#include "ephy-about-handler.h" #include "ephy-debug.h" #include "ephy-download.h" +#include "ephy-embed-prefs.h" #include "ephy-embed-private.h" -#include "ephy-embed-single.h" #include "ephy-embed-type-builtins.h" #include "ephy-encodings.h" #include "ephy-file-helpers.h" #include "ephy-history-service.h" #include "ephy-profile-utils.h" +#include "ephy-request-about.h" +#include "ephy-settings.h" #include "ephy-snapshot-service.h" #include "ephy-web-extension.h" @@ -40,6 +43,7 @@ #define PAGE_SETUP_FILENAME "page-setup-gtk.ini" #define PRINT_SETTINGS_FILENAME "print-settings.ini" +#define NSPLUGINWRAPPER_SETUP "/usr/bin/mozilla-plugin-config" #define EPHY_EMBED_SHELL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_EMBED_SHELL, EphyEmbedShellPrivate)) @@ -47,13 +51,11 @@ struct _EphyEmbedShellPrivate { EphyHistoryService *global_history_service; GList *downloads; - EphyEmbedSingle *embed_single; EphyEncodings *encodings; GtkPageSetup *page_setup; GtkPrintSettings *print_settings; EphyEmbedShellMode mode; EphyFrecentStore *frecent_store; - guint single_initialised : 1; GDBusProxy *web_extension; guint web_extension_watch_name_id; guint web_extension_form_auth_save_signal_id; @@ -96,7 +98,6 @@ ephy_embed_shell_dispose (GObject *object) g_clear_object (&priv->print_settings); g_clear_object (&priv->frecent_store); g_clear_object (&priv->global_history_service); - g_clear_object (&priv->embed_single); if (priv->web_extension_watch_name_id > 0) { g_bus_unwatch_name (priv->web_extension_watch_name_id); priv->web_extension_watch_name_id = 0; @@ -290,59 +291,6 @@ ephy_embed_shell_get_frecent_store (EphyEmbedShell *shell) return shell->priv->frecent_store; } -static GObject * -impl_get_embed_single (EphyEmbedShell *shell) -{ - EphyEmbedShellPrivate *priv; - - g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL); - - priv = shell->priv; - - if (priv->embed_single != NULL && - !priv->single_initialised) { - g_warning ("ephy_embed_shell_get_embed_single called while the single is being initialised!\n"); - return G_OBJECT (priv->embed_single); - } - - if (priv->embed_single == NULL) { - priv->embed_single = EPHY_EMBED_SINGLE (g_object_new (EPHY_TYPE_EMBED_SINGLE, NULL)); - g_assert (priv->embed_single != NULL); - - if (!ephy_embed_single_initialize (priv->embed_single)) { - GtkWidget *dialog; - - dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - _("Epiphany can't be used now. " - "Initialization failed.")); - gtk_dialog_run (GTK_DIALOG (dialog)); - - exit (0); - } - - priv->single_initialised = TRUE; - } - - return G_OBJECT (shell->priv->embed_single); -} - -/** - * ephy_embed_shell_get_embed_single: - * @shell: the #EphyEmbedShell - * - * Return value: (transfer none): - **/ -GObject * -ephy_embed_shell_get_embed_single (EphyEmbedShell *shell) -{ - EphyEmbedShellClass *klass = EPHY_EMBED_SHELL_GET_CLASS (shell); - - return klass->get_embed_single (shell); -} - /** * ephy_embed_shell_get_encodings: * @shell: the #EphyEmbedShell @@ -407,8 +355,67 @@ ephy_embed_shell_get_property (GObject *object, } static void +complete_about_request_for_contents (WebKitURISchemeRequest *request, + gchar *data, + gsize data_length) +{ + GInputStream *stream; + + stream = g_memory_input_stream_new_from_data (data, data_length, g_free); + webkit_uri_scheme_request_finish (request, stream, data_length, "text/html"); + g_object_unref (stream); +} + +static void +get_plugins_cb (WebKitWebContext *web_context, + GAsyncResult *result, + WebKitURISchemeRequest *request) +{ + GList *plugins; + GString *data_str; + gsize data_length; + + data_str = g_string_new("<html>"); + plugins = webkit_web_context_get_plugins_finish (web_context, result, NULL); + _ephy_about_handler_handle_plugins (data_str, plugins); + g_string_append (data_str, "</html>"); + + data_length = data_str->len; + complete_about_request_for_contents (request, g_string_free (data_str, FALSE), data_length); + g_object_unref (request); +} + +static void +about_request_cb (WebKitURISchemeRequest *request, + gpointer user_data) +{ + const gchar *path; + + path = webkit_uri_scheme_request_get_path (request); + if (!g_strcmp0 (path, "plugins")) { + /* Plugins API is async in WebKit2 */ + webkit_web_context_get_plugins (webkit_web_context_get_default (), + NULL, + (GAsyncReadyCallback)get_plugins_cb, + g_object_ref (request)); + } else { + GString *contents; + gsize data_length; + + contents = ephy_about_handler_handle (path); + data_length = contents->len; + complete_about_request_for_contents (request, g_string_free (contents, FALSE), data_length); + } +} + +static void ephy_embed_shell_init (EphyEmbedShell *shell) { + WebKitWebContext *web_context; + WebKitCookieManager *cookie_manager; + char *filename; + char *cookie_policy; + shell->priv = EPHY_EMBED_SHELL_GET_PRIVATE (shell); /* globally accessible singleton */ @@ -417,6 +424,30 @@ ephy_embed_shell_init (EphyEmbedShell *shell) shell->priv->downloads = NULL; + /* Initialise nspluginwrapper's plugins if available. */ + if (g_file_test (NSPLUGINWRAPPER_SETUP, G_FILE_TEST_EXISTS) != FALSE) + g_spawn_command_line_sync (NSPLUGINWRAPPER_SETUP, NULL, NULL, NULL, NULL); + + web_context = webkit_web_context_get_default (); + + /* Store cookies in moz-compatible SQLite format */ + cookie_manager = webkit_web_context_get_cookie_manager (web_context); + filename = g_build_filename (ephy_dot_dir (), "cookies.sqlite", NULL); + webkit_cookie_manager_set_persistent_storage (cookie_manager, filename, + WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE); + g_free (filename); + + cookie_policy = g_settings_get_string (EPHY_SETTINGS_WEB, + EPHY_PREFS_WEB_COOKIES_POLICY); + ephy_embed_prefs_set_cookie_accept_policy (cookie_manager, cookie_policy); + g_free (cookie_policy); + + /* about: URIs handler */ + webkit_web_context_register_uri_scheme (web_context, + EPHY_ABOUT_SCHEME, + about_request_cb, + NULL, NULL); + ephy_embed_shell_watch_web_extension (shell); } @@ -430,8 +461,6 @@ ephy_embed_shell_class_init (EphyEmbedShellClass *klass) 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_MODE] = g_param_spec_enum ("mode", "Mode", diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h index 169d8757c..37bcb9c9e 100644 --- a/embed/ephy-embed-shell.h +++ b/embed/ephy-embed-shell.h @@ -73,16 +73,12 @@ struct _EphyEmbedShellClass void (* prepare_close) (EphyEmbedShell *shell); void (* restored_window) (EphyEmbedShell *shell); - - /*< private >*/ - GObject * (* get_embed_single) (EphyEmbedShell *shell); }; GType ephy_embed_shell_get_type (void); EphyEmbedShell *ephy_embed_shell_get_default (void); GObject *ephy_embed_shell_get_global_history_service (EphyEmbedShell *shell); GObject *ephy_embed_shell_get_encodings (EphyEmbedShell *shell); -GObject *ephy_embed_shell_get_embed_single (EphyEmbedShell *shell); void ephy_embed_shell_prepare_close (EphyEmbedShell *shell); void ephy_embed_shell_restored_window (EphyEmbedShell *shell); void ephy_embed_shell_set_page_setup (EphyEmbedShell *shell, diff --git a/embed/ephy-embed-single.c b/embed/ephy-embed-single.c deleted file mode 100644 index f9f8bc7c4..000000000 --- a/embed/ephy-embed-single.c +++ /dev/null @@ -1,149 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ -/* - * Copyright © 2000-2003 Marco Pesenti Gritti - * - * 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-embed-single.h" - -#include "ephy-about-handler.h" -#include "ephy-debug.h" -#include "ephy-embed-prefs.h" -#include "ephy-embed-shell.h" -#include "ephy-embed-type-builtins.h" -#include "ephy-file-helpers.h" -#include "ephy-prefs.h" -#include "ephy-request-about.h" -#include "ephy-settings.h" -#include "ephy-signal-accumulator.h" -#include "ephy-string.h" - -#include <glib/gi18n.h> -#include <libsoup/soup.h> -#include <webkit2/webkit2.h> - -#define NSPLUGINWRAPPER_SETUP "/usr/bin/mozilla-plugin-config" - -G_DEFINE_TYPE (EphyEmbedSingle, ephy_embed_single, G_TYPE_OBJECT) - -static void -ephy_embed_single_init (EphyEmbedSingle *single) -{ -} - -static void -ephy_embed_single_class_init (EphyEmbedSingleClass *klass) -{ -} - - -static void -complete_about_request_for_contents (WebKitURISchemeRequest *request, - gchar *data, - gsize data_length) -{ - GInputStream *stream; - - stream = g_memory_input_stream_new_from_data (data, data_length, g_free); - webkit_uri_scheme_request_finish (request, stream, data_length, "text/html"); - g_object_unref (stream); -} - -static void -get_plugins_cb (WebKitWebContext *web_context, - GAsyncResult *result, - WebKitURISchemeRequest *request) -{ - GList *plugins; - GString *data_str; - gsize data_length; - - data_str = g_string_new("<html>"); - plugins = webkit_web_context_get_plugins_finish (web_context, result, NULL); - _ephy_about_handler_handle_plugins (data_str, plugins); - g_string_append (data_str, "</html>"); - - data_length = data_str->len; - complete_about_request_for_contents (request, g_string_free (data_str, FALSE), data_length); - g_object_unref (request); -} - -static void -about_request_cb (WebKitURISchemeRequest *request, - gpointer user_data) -{ - const gchar *path; - - path = webkit_uri_scheme_request_get_path (request); - if (!g_strcmp0 (path, "plugins")) { - /* Plugins API is async in WebKit2 */ - webkit_web_context_get_plugins (webkit_web_context_get_default (), - NULL, - (GAsyncReadyCallback) get_plugins_cb, - g_object_ref (request)); - } else { - GString *contents; - gsize data_length; - - contents = ephy_about_handler_handle (path); - data_length = contents->len; - complete_about_request_for_contents (request, g_string_free (contents, FALSE), data_length); - } -} - -/** - * ephy_embed_single_initialize: - * @single: the #EphyEmbedSingle - * - * Performs startup initialisations. Must be called before calling - * any other methods. - **/ -gboolean -ephy_embed_single_initialize (EphyEmbedSingle *single) -{ - WebKitWebContext *web_context; - WebKitCookieManager *cookie_manager; - char *filename; - char *cookie_policy; - - /* Initialise nspluginwrapper's plugins if available. */ - if (g_file_test (NSPLUGINWRAPPER_SETUP, G_FILE_TEST_EXISTS) != FALSE) - g_spawn_command_line_sync (NSPLUGINWRAPPER_SETUP, NULL, NULL, NULL, NULL); - - web_context = webkit_web_context_get_default (); - - /* Store cookies in moz-compatible SQLite format */ - cookie_manager = webkit_web_context_get_cookie_manager (web_context); - filename = g_build_filename (ephy_dot_dir (), "cookies.sqlite", NULL); - webkit_cookie_manager_set_persistent_storage (cookie_manager, filename, - WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE); - g_free (filename); - - cookie_policy = g_settings_get_string (EPHY_SETTINGS_WEB, - EPHY_PREFS_WEB_COOKIES_POLICY); - ephy_embed_prefs_set_cookie_accept_policy (cookie_manager, cookie_policy); - g_free (cookie_policy); - - /* about: URIs handler */ - webkit_web_context_register_uri_scheme (web_context, - EPHY_ABOUT_SCHEME, - about_request_cb, - NULL, NULL); - return TRUE; -} - diff --git a/embed/ephy-embed-single.h b/embed/ephy-embed-single.h deleted file mode 100644 index 517a0b09b..000000000 --- a/embed/ephy-embed-single.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ -/* - * Copyright © 2000-2003 Marco Pesenti Gritti - * - * 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_EMBED_SINGLE_H -#define EPHY_EMBED_SINGLE_H - -#include "ephy-embed.h" -#include "ephy-web-view.h" - -G_BEGIN_DECLS - -#define EPHY_TYPE_EMBED_SINGLE (ephy_embed_single_get_type ()) -#define EPHY_EMBED_SINGLE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_EMBED_SINGLE, EphyEmbedSingle)) -#define EPHY_EMBED_SINGLE_IFACE(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_EMBED_SINGLE, EphyEmbedSingleIface)) -#define EPHY_IS_EMBED_SINGLE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_EMBED_SINGLE)) -#define EPHY_IS_EMBED_SINGLE_IFACE(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_EMBED_SINGLE)) -#define EPHY_EMBED_SINGLE_GET_IFACE(i) (G_TYPE_INSTANCE_GET_INTERFACE ((i), EPHY_TYPE_EMBED_SINGLE, EphyEmbedSingleIface)) - -typedef struct _EphyEmbedSingle EphyEmbedSingle; -typedef struct _EphyEmbedSingleClass EphyEmbedSingleClass; - -struct _EphyEmbedSingle { - GObject parent; -}; - -struct _EphyEmbedSingleClass -{ - GObjectClass parent_class; -}; - -GType ephy_embed_single_get_type (void); - -gboolean ephy_embed_single_initialize (EphyEmbedSingle *single); - -G_END_DECLS - -#endif diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c index 7ce358e42..8307a0617 100644 --- a/embed/ephy-web-view.c +++ b/embed/ephy-web-view.c @@ -29,7 +29,6 @@ #include "ephy-embed-prefs.h" #include "ephy-embed-private.h" #include "ephy-embed-shell.h" -#include "ephy-embed-single.h" #include "ephy-embed-type-builtins.h" #include "ephy-embed-utils.h" #include "ephy-embed.h" |