aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/mozilla-embed-single.cpp
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2006-01-17 07:51:41 +0800
committerChristian Persch <chpe@src.gnome.org>2006-01-17 07:51:41 +0800
commit5a9945adda3cd770a0d72f13e55f11950fd66015 (patch)
tree5290aba17884b7d98a754aab198b597380b7fd0d /embed/mozilla/mozilla-embed-single.cpp
parente469aef9ea4efd1098ad6982f0da77fed594faf1 (diff)
downloadgsoc2013-epiphany-5a9945adda3cd770a0d72f13e55f11950fd66015.tar.gz
gsoc2013-epiphany-5a9945adda3cd770a0d72f13e55f11950fd66015.tar.zst
gsoc2013-epiphany-5a9945adda3cd770a0d72f13e55f11950fd66015.zip
Fix number of /'s in URI.
2006-01-17 Christian Persch <chpe@cvs.gnome.org> * data/chrome/epiphany.manifest.in: Fix number of /'s in URI. * data/epiphany.schemas.in: Add new entries. * embed/mozilla/EphyAboutModule.cpp: Fix title. * data/glade/prefs-dialog.glade: * embed/ephy-embed-prefs.h: * embed/mozilla/mozilla-embed-single.cpp: * embed/mozilla/mozilla-notifiers.cpp: * embed/mozilla/mozilla-notifiers.h: * lib/eel-gconf-extensions.c: (eel_gconf_unset_key), (eel_gconf_notify): * lib/eel-gconf-extensions.h: * lib/egg/egg-editable-toolbar.c: (popup_context_menu_cb), (button_press_event_cb), (egg_editable_toolbar_set_ui_manager), (egg_editable_toolbar_set_selected): * lib/ephy-dialog.c: (set_value_from_pref), (set_pref_from_value), (set_value_from_togglebutton), (strcmp_with_null), (get_index_from_value), (compare_values), (set_togglebutton_from_value), (set_pref_from_info_and_emit), (spinbutton_changed_cb), (save_info): * lib/ephy-dialog.h: * lib/ephy-file-helpers.c: (ephy_file_monitor_timeout_cb), (ephy_file_monitor_cb), (ephy_file_monitor_add), (ephy_file_monitor_cancel): * lib/ephy-file-helpers.h: * src/ephy-extensions-manager.c: (ephy_extensions_manager_load_file): * src/ephy-window.c: * src/popup-commands.c: (popup_cmd_bookmark_link): * src/prefs-dialog.c: (prefs_dialog_finalize), (setup_font_combo), (fonts_language_changed_cb), (font_prefs_dialog_response_cb), (row_is_separator), (setup_fonts_dialog), (font_prefs_button_clicked_cb), (css_checkbox_toggled), (css_edit_button_clicked_cb), (prefs_dialog_init): Rework font prefs, and add user stylesheet setting. * src/bookmarks/ephy-bookmark-action-group.c: (node_added_cb): * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_get_local): * src/window-commands.c: (window_cmd_file_bookmark_page): Some build fixes.
Diffstat (limited to 'embed/mozilla/mozilla-embed-single.cpp')
-rw-r--r--embed/mozilla/mozilla-embed-single.cpp178
1 files changed, 173 insertions, 5 deletions
diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp
index d542dc20c..21b9d7462 100644
--- a/embed/mozilla/mozilla-embed-single.cpp
+++ b/embed/mozilla/mozilla-embed-single.cpp
@@ -102,22 +102,26 @@
#include <nsIIDNService.h>
#endif /* ALLOW_PRIVATE_API */
-#ifdef HAVE_GECKO_1_8
-#include <nsIStyleSheetService.h>
-#include "EphyUtils.h"
-#endif
-
#include <stdlib.h>
#ifdef ENABLE_NETWORK_MANAGER
#include <libnm_glib.h>
#endif
+#ifdef HAVE_GECKO_1_8
+#include <nsIURI.h>
+#include <nsIStyleSheetService.h>
+#include "EphyUtils.h"
+#include "ephy-file-helpers.h"
+#endif
+
#define MOZILLA_PROFILE_DIR "/mozilla"
#define MOZILLA_PROFILE_NAME "epiphany"
#define MOZILLA_PROFILE_FILE "prefs.js"
#define DEFAULT_PROFILE_FILE SHARE_DIR"/default-prefs.js"
+#define USER_CSS_LOAD_DELAY 500 /* ms */
+
#define MOZILLA_EMBED_SINGLE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), MOZILLA_TYPE_EMBED_SINGLE, MozillaEmbedSinglePrivate))
struct MozillaEmbedSinglePrivate
@@ -133,6 +137,12 @@ struct MozillaEmbedSinglePrivate
libnm_glib_ctx *nm_context;
guint nm_callback_id;
#endif
+#ifdef HAVE_GECKO_1_8
+ char *user_css_uri;
+ guint user_css_enabled_notifier_id;
+ EphyFileMonitor *user_css_file_monitor;
+ guint user_css_enabled : 1;
+#endif
guint online : 1;
};
@@ -592,6 +602,156 @@ mozilla_init_network_manager (MozillaEmbedSingle *single)
#endif /* ENABLE_NETWORK_MANAGER */
+#ifdef HAVE_GECKO_1_8
+
+static void
+user_css_register (MozillaEmbedSingle *single)
+{
+ MozillaEmbedSinglePrivate *priv = single->priv;
+
+ nsresult rv;
+ nsCOMPtr<nsIURI> uri;
+ rv = EphyUtils::NewURI (getter_AddRefs (uri),
+ nsDependentCString (priv->user_css_uri));
+ NS_ENSURE_SUCCESS (rv, );
+
+ nsCOMPtr<nsIStyleSheetService> service
+ (do_GetService ("@mozilla.org/content/style-sheet-service;1", &rv));
+ NS_ENSURE_SUCCESS (rv, );
+
+ rv = service->LoadAndRegisterSheet (uri, nsIStyleSheetService::AGENT_SHEET);
+ if (NS_FAILED (rv))
+ {
+ g_warning ("Registering the user stylesheet failed (rv=%x)!\n", rv);
+ }
+}
+
+static void
+user_css_unregister (MozillaEmbedSingle *single)
+{
+ MozillaEmbedSinglePrivate *priv = single->priv;
+
+ nsresult rv;
+ nsCOMPtr<nsIURI> uri;
+ rv = EphyUtils::NewURI (getter_AddRefs (uri),
+ nsDependentCString (priv->user_css_uri));
+ NS_ENSURE_SUCCESS (rv, );
+
+ nsCOMPtr<nsIStyleSheetService> service
+ (do_GetService ("@mozilla.org/content/style-sheet-service;1", &rv));
+ NS_ENSURE_SUCCESS (rv, );
+
+ PRBool isRegistered = PR_FALSE;
+ rv = service->SheetRegistered (uri, nsIStyleSheetService::USER_SHEET,
+ &isRegistered);
+ if (NS_SUCCEEDED (rv) && isRegistered)
+ {
+ rv = service->UnregisterSheet (uri, nsIStyleSheetService::USER_SHEET);
+ }
+ if (NS_FAILED (rv))
+ {
+ g_warning ("Unregistering the user stylesheet failed (rv=%x)!\n", rv);
+ }
+}
+
+static void
+user_css_file_monitor_func (EphyFileMonitor *,
+ const char *,
+ MozillaEmbedSingle *single)
+{
+ LOG ("Reregistering the user style sheet");
+
+ user_css_unregister (single);
+ user_css_register (single);
+}
+
+static void
+user_css_enabled_notify (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ MozillaEmbedSingle *single)
+{
+ MozillaEmbedSinglePrivate *priv = single->priv;
+ guint enabled;
+
+ enabled = eel_gconf_get_boolean (CONF_USER_CSS_ENABLED) != FALSE;
+ if (priv->user_css_enabled == enabled) return;
+
+ LOG ("User stylesheet enabled: %s", enabled ? "t" : "f");
+
+ priv->user_css_enabled = enabled;
+
+ if (enabled)
+ {
+ user_css_register (single);
+
+ g_assert (priv->user_css_file_monitor == NULL);
+ priv->user_css_file_monitor =
+ ephy_file_monitor_add (priv->user_css_uri,
+ GNOME_VFS_MONITOR_FILE,
+ USER_CSS_LOAD_DELAY,
+ (EphyFileMonitorFunc) user_css_file_monitor_func,
+ NULL,
+ single);
+ }
+ else
+ {
+ if (priv->user_css_file_monitor != NULL)
+ {
+ ephy_file_monitor_cancel (priv->user_css_file_monitor);
+ priv->user_css_file_monitor = NULL;
+ }
+
+ user_css_unregister (single);
+ }
+}
+
+static void
+mozilla_stylesheet_init (MozillaEmbedSingle *single)
+{
+ MozillaEmbedSinglePrivate *priv = single->priv;
+ char *user_css_file;
+
+ user_css_file = g_build_filename (ephy_dot_dir (),
+ USER_STYLESHEET_FILENAME,
+ NULL);
+ priv->user_css_uri = gnome_vfs_get_uri_from_local_path (user_css_file);
+ g_free (user_css_file);
+
+ user_css_enabled_notify (NULL, 0, NULL, single);
+ priv->user_css_enabled_notifier_id =
+ eel_gconf_notification_add
+ (CONF_USER_CSS_ENABLED,
+ (GConfClientNotifyFunc) user_css_enabled_notify,
+ single);
+}
+
+static void
+mozilla_stylesheet_shutdown (MozillaEmbedSingle *single)
+{
+ MozillaEmbedSinglePrivate *priv = single->priv;
+
+ if (priv->user_css_enabled_notifier_id != 0)
+ {
+ eel_gconf_notification_remove (priv->user_css_enabled_notifier_id);
+ priv->user_css_enabled_notifier_id = 0;
+ }
+
+ if (priv->user_css_file_monitor != NULL)
+ {
+ ephy_file_monitor_cancel (priv->user_css_file_monitor);
+ priv->user_css_file_monitor = NULL;
+ }
+
+ if (priv->user_css_uri != NULL)
+ {
+ g_free (priv->user_css_uri);
+ priv->user_css_uri = NULL;
+ }
+}
+
+#endif /* HAVE_GECKO_1_8 */
+
static gboolean
init_services (MozillaEmbedSingle *single)
{
@@ -641,6 +801,10 @@ init_services (MozillaEmbedSingle *single)
mozilla_init_network_manager (single);
#endif
+#ifdef HAVE_GECKO_1_8
+ mozilla_stylesheet_init (single);
+#endif
+
return TRUE;
}
@@ -697,6 +861,10 @@ mozilla_embed_single_dispose (GObject *object)
MozillaEmbedSingle *single = MOZILLA_EMBED_SINGLE (object);
MozillaEmbedSinglePrivate *priv = single->priv;
+#ifdef HAVE_GECKO_1_8
+ mozilla_stylesheet_shutdown (single);
+#endif
+
if (priv->mSingleObserver)
{
priv->mSingleObserver->Detach ();