From ef00d72ca806e53063a7834679833a906e12bcb0 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 15 May 2007 12:22:26 +0200 Subject: [PATCH] Put compreg.dat in the profile. --- browser/GeckoDirectoryProvider.cpp | 32 +++++++++++++--- browser/GeckoDirectoryProvider.h | 4 +- browser/sugar-browser.cpp | 60 ++++++++++++++++++------------ 3 files changed, 65 insertions(+), 31 deletions(-) diff --git a/browser/GeckoDirectoryProvider.cpp b/browser/GeckoDirectoryProvider.cpp index c94a7cf0..f59d26a6 100644 --- a/browser/GeckoDirectoryProvider.cpp +++ b/browser/GeckoDirectoryProvider.cpp @@ -16,23 +16,43 @@ NS_IMPL_ISUPPORTS2 (GeckoDirectoryProvider, nsIDirectoryServiceProvider, nsIDirectoryServiceProvider2) -GeckoDirectoryProvider::GeckoDirectoryProvider(const char *sugar_path) +GeckoDirectoryProvider::GeckoDirectoryProvider(const char *sugar_path, + const char *profile_path) { - mComponentPath = g_strconcat(sugar_path, "/mozilla/components", NULL); + mComponentPath = g_build_filename + (sugar_path, "mozilla", "components", NULL); + mCompregPath = g_build_filename + (profile_path, "compreg.dat", NULL); } GeckoDirectoryProvider::~GeckoDirectoryProvider() { if(mComponentPath) g_free(mComponentPath); + if(mCompregPath) + g_free(mCompregPath); } /* nsIFile getFile (in string prop, out PRBool persistent); */ NS_IMETHODIMP GeckoDirectoryProvider::GetFile (const char *prop, - PRBool *persistent, - nsIFile **_retval) + PRBool *persistent, + nsIFile **_retval) { + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr file; + + if (!strcmp(prop, NS_XPCOM_COMPONENT_REGISTRY_FILE)) { + rv = NS_NewNativeLocalFile(nsDependentCString(mCompregPath), + PR_TRUE, + getter_AddRefs(file)); + } + + if (NS_SUCCEEDED(rv) && file) { + NS_ADDREF(*_retval = file); + return NS_OK; + } + return NS_ERROR_FAILURE; } @@ -47,7 +67,7 @@ GeckoDirectoryProvider::GetFiles (const char *aProperty, nsISimpleEnumerator **a nsCOMPtr componentDir; rv = NS_NewNativeLocalFile(nsDependentCString(mComponentPath), PR_TRUE, - getter_AddRefs (componentDir)); + getter_AddRefs(componentDir)); NS_ENSURE_SUCCESS (rv, rv); nsCOMArray array; @@ -61,6 +81,6 @@ GeckoDirectoryProvider::GetFiles (const char *aProperty, nsISimpleEnumerator **a rv = NS_SUCCESS_AGGREGATE_RESULT; } } - + return rv; } diff --git a/browser/GeckoDirectoryProvider.h b/browser/GeckoDirectoryProvider.h index 5b74169f..db6ccc92 100644 --- a/browser/GeckoDirectoryProvider.h +++ b/browser/GeckoDirectoryProvider.h @@ -28,11 +28,13 @@ class GeckoDirectoryProvider : public nsIDirectoryServiceProvider2 NS_DECL_NSIDIRECTORYSERVICEPROVIDER NS_DECL_NSIDIRECTORYSERVICEPROVIDER2 - GeckoDirectoryProvider(const char *sugar_path); + GeckoDirectoryProvider(const char *sugar_path, + const char *profile_path); virtual ~GeckoDirectoryProvider(); private: char *mComponentPath; + char *mCompregPath; }; #endif /* GECKO_DIRECTORY_PROVIDER_H */ diff --git a/browser/sugar-browser.cpp b/browser/sugar-browser.cpp index d5644da3..2cee6d26 100644 --- a/browser/sugar-browser.cpp +++ b/browser/sugar-browser.cpp @@ -148,6 +148,39 @@ setup_plugin_path () g_free (new_path); } +static gboolean +setup_directory_provider(const char *full_prof_path) +{ + const char *prefix = g_getenv("SUGAR_PREFIX"); + if (prefix == NULL) { + g_print("The SUGAR_PREFIX environment variable is not set."); + exit(1); + } + + char *components_path = g_build_filename(prefix, "share/sugar", NULL); + + GeckoDirectoryProvider *dirProvider = + new GeckoDirectoryProvider(components_path, full_prof_path); + if (!dirProvider) { + g_warning ("failed to create GeckoDirectoryProvider"); + return FALSE; + } + + g_free(components_path); + + NS_ADDREF (dirProvider); + + nsCOMPtr dp (do_QueryInterface (dirProvider)); + NS_RELEASE (dirProvider); + dirProvider = nsnull; + + if (!dp) return FALSE; + + gtk_moz_embed_set_directory_service_provider(dp); + + return TRUE; +} + gboolean sugar_browser_startup(const char *profile_path, const char *profile_name) { @@ -159,32 +192,11 @@ sugar_browser_startup(const char *profile_path, const char *profile_name) old_handler = XSetErrorHandler(error_handler); - const char *prefix = g_getenv("SUGAR_PREFIX"); - if (prefix == NULL) { - g_print("The SUGAR_PREFIX environment variable is not set."); - exit(1); - } - - char *components_path = g_build_filename(prefix, "share/sugar", NULL); - - GeckoDirectoryProvider *dirProvider = - new GeckoDirectoryProvider(components_path); - if (!dirProvider) { - g_warning ("failed to create GeckoDirectoryProvider"); + char *full_prof_path = g_build_filename(profile_path, profile_name, NULL); + if (!setup_directory_provider(full_prof_path)) { return FALSE; } - - g_free(components_path); - - NS_ADDREF (dirProvider); - - nsCOMPtr dp (do_QueryInterface (dirProvider)); - NS_RELEASE (dirProvider); - dirProvider = nsnull; - - if (!dp) return FALSE; - - gtk_moz_embed_set_directory_service_provider(dp); + g_free(full_prof_path); gtk_moz_embed_push_startup();