[epiphany] Get rid of EphyEmbedSingle



commit a06498057762d695d044584d76fb388650a10e12
Author: Xan Lopez <xan igalia com>
Date:   Sat Mar 23 20:57:31 2013 +0100

    Get rid of EphyEmbedSingle
    
    Move the remaining initialization code to EphyEmbedShell
    
    https://bugzilla.gnome.org/show_bug.cgi?id=693703

 embed/Makefile.am              |    2 -
 embed/ephy-embed-shell.c       |  147 +++++++++++++++++++++++----------------
 embed/ephy-embed-shell.h       |    4 -
 embed/ephy-embed-single.c      |  149 ----------------------------------------
 embed/ephy-embed-single.h      |   58 ----------------
 embed/ephy-web-view.c          |    1 -
 src/ephy-shell.c               |    1 -
 src/ephy-window.c              |    1 -
 src/pdm-dialog.c               |    6 --
 src/prefs-dialog.c             |    1 -
 src/window-commands.c          |    1 -
 tests/Makefile.am              |    4 -
 tests/ephy-embed-single-test.c |  115 -------------------------------
 13 files changed, 88 insertions(+), 402 deletions(-)
---
diff --git a/embed/Makefile.am b/embed/Makefile.am
index 1d1ea08..44aa8b1 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 ba6c840..ab73419 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 169d875..37bcb9c 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-web-view.c b/embed/ephy-web-view.c
index 7ce358e..8307a06 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"
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index c53270b..9b3a901 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -28,7 +28,6 @@
 #include "ephy-debug.h"
 #include "ephy-embed-container.h"
 #include "ephy-embed-prefs.h"
-#include "ephy-embed-single.h"
 #include "ephy-embed-utils.h"
 #include "ephy-file-helpers.h"
 #include "ephy-gui.h"
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 5b2b664..210588b 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -33,7 +33,6 @@
 #include "ephy-embed-container.h"
 #include "ephy-embed-prefs.h"
 #include "ephy-embed-shell.h"
-#include "ephy-embed-single.h"
 #include "ephy-embed-type-builtins.h"
 #include "ephy-embed-utils.h"
 #include "ephy-encoding-menu.h"
diff --git a/src/pdm-dialog.c b/src/pdm-dialog.c
index d6a3279..4a09260 100644
--- a/src/pdm-dialog.c
+++ b/src/pdm-dialog.c
@@ -1594,12 +1594,6 @@ static void
 pdm_dialog_finalize (GObject *object)
 {
        PdmDialog *dialog = EPHY_PDM_DIALOG (object);
-       GObject *single;
-
-       single = ephy_embed_shell_get_embed_single (ephy_embed_shell_get_default ());
-
-       g_signal_handlers_disconnect_matched
-               (single, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, object);
 
 #ifdef HAVE_WEBKIT2
        g_signal_handlers_disconnect_by_func (get_cookie_manager (), cookie_changed_cb, object);
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 8910cd7..7a6b77d 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -28,7 +28,6 @@
 #include "ephy-embed-container.h"
 #include "ephy-embed-prefs.h"
 #include "ephy-embed-shell.h"
-#include "ephy-embed-single.h"
 #include "ephy-embed-utils.h"
 #include "ephy-encodings.h"
 #include "ephy-file-chooser.h"
diff --git a/src/window-commands.c b/src/window-commands.c
index 265582f..9f61c27 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -31,7 +31,6 @@
 #include "ephy-embed-container.h"
 #include "ephy-embed-prefs.h"
 #include "ephy-embed-shell.h"
-#include "ephy-embed-single.h"
 #include "ephy-embed-utils.h"
 #include "ephy-embed.h"
 #include "ephy-favicon-helpers.h"
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6236ad3..b69d602 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,7 +5,6 @@ noinst_PROGRAMS = \
        test-ephy-completion-model \
        test-ephy-download \
        test-ephy-embed-shell \
-       test-ephy-embed-single \
        test-ephy-embed-utils \
        test-ephy-encodings \
        test-ephy-file-helpers \
@@ -130,9 +129,6 @@ test_ephy_download_SOURCES = \
 test_ephy_embed_shell_SOURCES = \
        ephy-embed-shell-test.c
 
-test_ephy_embed_single_SOURCES = \
-       ephy-embed-single-test.c
-
 test_ephy_embed_utils_SOURCES = \
        ephy-embed-utils-test.c
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]