aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/mozilla-embed-single.cpp
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2006-01-17 21:58:21 +0800
committerChristian Persch <chpe@src.gnome.org>2006-01-17 21:58:21 +0800
commitf220f9282e63ca352def47b86ec5f9c5c5c57696 (patch)
tree131d1dff90041138a058eaa8e3844f19f5293f3e /embed/mozilla/mozilla-embed-single.cpp
parentb89fb9d5a5860e5349115717d48b240cf9715f4b (diff)
downloadgsoc2013-epiphany-f220f9282e63ca352def47b86ec5f9c5c5c57696.tar
gsoc2013-epiphany-f220f9282e63ca352def47b86ec5f9c5c5c57696.tar.gz
gsoc2013-epiphany-f220f9282e63ca352def47b86ec5f9c5c5c57696.tar.bz2
gsoc2013-epiphany-f220f9282e63ca352def47b86ec5f9c5c5c57696.tar.lz
gsoc2013-epiphany-f220f9282e63ca352def47b86ec5f9c5c5c57696.tar.xz
gsoc2013-epiphany-f220f9282e63ca352def47b86ec5f9c5c5c57696.tar.zst
gsoc2013-epiphany-f220f9282e63ca352def47b86ec5f9c5c5c57696.zip
Add event type to the callback.
2006-01-17 Christian Persch <chpe@cvs.gnome.org> * lib/ephy-file-helpers.c: (ephy_file_monitor_timeout_cb), (ephy_file_monitor_cb): * lib/ephy-file-helpers.h: Add event type to the callback. * embed/mozilla/EphyUtils.cpp: * embed/mozilla/EphyUtils.h: New function, like NS_NewFileURI (which we can't use since nsNetUtil.h conflicts with embed strings). * embed/mozilla/mozilla-embed-single.cpp: * embed/mozilla/mozilla-notifiers.cpp: Check that the user CSS file exists before registering it. Also handle file-deleted events. * src/bookmarks/ephy-bookmarks-menu.c: (ephy_bookmarks_menu_build): * src/bookmarks/ephy-topics-palette.c: (ephy_topics_palette_constructor), (ephy_topics_palette_class_init): Build fixes.
Diffstat (limited to 'embed/mozilla/mozilla-embed-single.cpp')
-rw-r--r--embed/mozilla/mozilla-embed-single.cpp74
1 files changed, 52 insertions, 22 deletions
diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp
index 21b9d7462..0c7d04e0a 100644
--- a/embed/mozilla/mozilla-embed-single.cpp
+++ b/embed/mozilla/mozilla-embed-single.cpp
@@ -70,6 +70,7 @@
#include <nsCPasswordManager.h>
#include <nsIPermission.h>
#include <nsIPermissionManager.h>
+#include <nsIFile.h>
#include <nsILocalFile.h>
#include <nsIURI.h>
@@ -138,7 +139,7 @@ struct MozillaEmbedSinglePrivate
guint nm_callback_id;
#endif
#ifdef HAVE_GECKO_1_8
- char *user_css_uri;
+ char *user_css_file;
guint user_css_enabled_notifier_id;
EphyFileMonitor *user_css_file_monitor;
guint user_css_enabled : 1;
@@ -610,15 +611,31 @@ user_css_register (MozillaEmbedSingle *single)
MozillaEmbedSinglePrivate *priv = single->priv;
nsresult rv;
+ nsCOMPtr<nsILocalFile> file;
+ rv = NS_NewNativeLocalFile (nsDependentCString (priv->user_css_file),
+ PR_TRUE, getter_AddRefs (file));
+ NS_ENSURE_SUCCESS (rv, );
+
+ PRBool exists = PR_FALSE;
+ rv = file->Exists (&exists);
+ if (NS_FAILED (rv) || !exists) return;
+
nsCOMPtr<nsIURI> uri;
- rv = EphyUtils::NewURI (getter_AddRefs (uri),
- nsDependentCString (priv->user_css_uri));
+ rv = EphyUtils::NewFileURI (getter_AddRefs (uri), file);
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);
+ }
+
rv = service->LoadAndRegisterSheet (uri, nsIStyleSheetService::AGENT_SHEET);
if (NS_FAILED (rv))
{
@@ -632,9 +649,13 @@ user_css_unregister (MozillaEmbedSingle *single)
MozillaEmbedSinglePrivate *priv = single->priv;
nsresult rv;
+ nsCOMPtr<nsILocalFile> file;
+ rv = NS_NewNativeLocalFile (nsDependentCString (priv->user_css_file),
+ PR_TRUE, getter_AddRefs (file));
+ NS_ENSURE_SUCCESS (rv, );
+
nsCOMPtr<nsIURI> uri;
- rv = EphyUtils::NewURI (getter_AddRefs (uri),
- nsDependentCString (priv->user_css_uri));
+ rv = EphyUtils::NewFileURI (getter_AddRefs (uri), file);
NS_ENSURE_SUCCESS (rv, );
nsCOMPtr<nsIStyleSheetService> service
@@ -657,12 +678,19 @@ user_css_unregister (MozillaEmbedSingle *single)
static void
user_css_file_monitor_func (EphyFileMonitor *,
const char *,
+ GnomeVFSMonitorEventType event_type,
MozillaEmbedSingle *single)
{
LOG ("Reregistering the user style sheet");
- user_css_unregister (single);
- user_css_register (single);
+ if (event_type == GNOME_VFS_MONITOR_EVENT_DELETED)
+ {
+ user_css_unregister (single);
+ }
+ else
+ {
+ user_css_register (single);
+ }
}
static void
@@ -683,16 +711,21 @@ user_css_enabled_notify (GConfClient *client,
if (enabled)
{
+ char *uri;
+
user_css_register (single);
+ uri = gnome_vfs_get_uri_from_local_path (priv->user_css_file);
+
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);
+ ephy_file_monitor_add (uri,
+ GNOME_VFS_MONITOR_FILE,
+ USER_CSS_LOAD_DELAY,
+ (EphyFileMonitorFunc) user_css_file_monitor_func,
+ NULL,
+ single);
+ g_free (uri);
}
else
{
@@ -710,13 +743,10 @@ 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);
+ priv->user_css_file = g_build_filename (ephy_dot_dir (),
+ USER_STYLESHEET_FILENAME,
+ NULL);
user_css_enabled_notify (NULL, 0, NULL, single);
priv->user_css_enabled_notifier_id =
@@ -743,10 +773,10 @@ mozilla_stylesheet_shutdown (MozillaEmbedSingle *single)
priv->user_css_file_monitor = NULL;
}
- if (priv->user_css_uri != NULL)
+ if (priv->user_css_file != NULL)
{
- g_free (priv->user_css_uri);
- priv->user_css_uri = NULL;
+ g_free (priv->user_css_file);
+ priv->user_css_file = NULL;
}
}