From eca7ff9596e54159941f2788c2e6be59ddf26259 Mon Sep 17 00:00:00 2001 From: "law%netscape.com" Date: Wed, 24 Apr 2002 00:14:18 +0000 Subject: [PATCH] Bug 134754; add scriptiable API to get Win32 registry value; r=sgehani, sr=dveditz --- xpfe/components/winhooks/nsIWindowsHooks.idl | 23 +++++++++++ xpfe/components/winhooks/nsWindowsHooks.cpp | 43 ++++++++++++++++---- xpfe/components/winhooks/nsWindowsHooks.h | 3 +- 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/xpfe/components/winhooks/nsIWindowsHooks.idl b/xpfe/components/winhooks/nsIWindowsHooks.idl index 6fb26f9de3f7..c4f693cba0f6 100644 --- a/xpfe/components/winhooks/nsIWindowsHooks.idl +++ b/xpfe/components/winhooks/nsIWindowsHooks.idl @@ -200,6 +200,29 @@ interface nsIWindowsHooks : nsISupports { void setImageAsWallpaper(in nsIDOMElement aImageElement, in boolean useBackground); }; +/* nsIWindowsRegistry + * + * This interface describes the service that you can use to + * get/set Win32 registry entries. + * + * Notice: This interface is incomplete and should be used at your own risk! + */ +[scriptable, uuid(e07e7430-8d11-417c-83ee-c994400c452f)] +interface nsIWindowsRegistry : nsISupports { + /** + * Returns a Win32 registry entry value. The returned string will be truncated + * at 4096 bytes. The constants define the set of valid starting keys. You + * pass in the subkey name and a value identifier (an empty string returns + * the "default" value for that subkey). + */ + const long HKCR = 0; // HKEY_CLASSES_ROOT + const long HKCC = 1; // HKEY_CURRENT_CONFIG + const long HKCU = 2; // HKEY_CURRENT_USER + const long HKLM = 3; // HKEY_LOCAL_MACHINE + const long HKU = 4; // HKEY_USERS + string getRegistryEntry( in long aHKeyConstant, in string aSubKeyName, in string aValueName ); +}; + %{C++ #define NS_IWINDOWSHOOKS_CONTRACTID "@mozilla.org/winhooks;1" #define NS_IWINDOWSHOOKS_CLASSNAME "Mozilla Windows Integration Hooks" diff --git a/xpfe/components/winhooks/nsWindowsHooks.cpp b/xpfe/components/winhooks/nsWindowsHooks.cpp index 0ba7b76f4180..f425a1b7427b 100644 --- a/xpfe/components/winhooks/nsWindowsHooks.cpp +++ b/xpfe/components/winhooks/nsWindowsHooks.cpp @@ -172,7 +172,7 @@ DEFINE_GETTER_AND_SETTER( HaveBeenSet, mHaveBeenSet ) // Implementation of the nsIWindowsHooks interface. // Use standard implementation of nsISupports stuff. -NS_IMPL_ISUPPORTS1( nsWindowsHooks, nsIWindowsHooks ); +NS_IMPL_ISUPPORTS2( nsWindowsHooks, nsIWindowsHooks, nsIWindowsRegistry ); nsWindowsHooks::nsWindowsHooks() { NS_INIT_ISUPPORTS(); @@ -647,6 +647,40 @@ nsWindowsHooks::SetRegistry() { return NS_OK; } +NS_IMETHODIMP nsWindowsHooks::GetRegistryEntry( PRInt32 aHKEYConstant, const char *aSubKeyName, const char *aValueName, char **aResult ) { + NS_ENSURE_ARG( aResult ); + *aResult = 0; + // Calculate HKEY_* starting point based on input nsIWindowsHooks constant. + HKEY hKey; + switch ( aHKEYConstant ) { + case HKCR: + hKey = HKEY_CLASSES_ROOT; + break; + case HKCC: + hKey = HKEY_CURRENT_CONFIG; + break; + case HKCU: + hKey = HKEY_CURRENT_USER; + break; + case HKLM: + hKey = HKEY_LOCAL_MACHINE; + break; + case HKU: + hKey = HKEY_USERS; + break; + default: + return NS_ERROR_INVALID_ARG; + } + + // Get requested registry entry. + nsCAutoString entry( RegistryEntry( hKey, aSubKeyName, aValueName, 0 ).currentSetting() ); + + // Copy to result. + *aResult = PL_strdup( entry.get() ); + + return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY; +} + // nsIWindowsHooks.idl for documentation /* @@ -742,6 +776,7 @@ NS_IMETHODIMP nsWindowsHooks::StartupAddOption(const char* option) { newsetting.Append(option); startup.setting = newsetting; startup.set(); + return NS_OK; } /* @@ -944,9 +979,3 @@ nsWindowsHooks::SetImageAsWallpaper(nsIDOMElement* aElement, PRBool aUseBackgrou return rv; } - -#if (_MSC_VER == 1100) -#define INITGUID -#include "objbase.h" -DEFINE_OLEGUID(IID_IPersistFile, 0x0000010BL, 0, 0); -#endif diff --git a/xpfe/components/winhooks/nsWindowsHooks.h b/xpfe/components/winhooks/nsWindowsHooks.h index 853e68644a25..40e80ca2891c 100644 --- a/xpfe/components/winhooks/nsWindowsHooks.h +++ b/xpfe/components/winhooks/nsWindowsHooks.h @@ -102,7 +102,7 @@ private: friend class nsWindowsHooks; }; // nsWindowsHooksSettings -class nsWindowsHooks : public nsIWindowsHooks { +class nsWindowsHooks : public nsIWindowsHooks, public nsIWindowsRegistry { public: // ctor/dtor nsWindowsHooks(); @@ -111,6 +111,7 @@ public: // Declare all interface methods we must implement. NS_DECL_ISUPPORTS NS_DECL_NSIWINDOWSHOOKS + NS_DECL_NSIWINDOWSREGISTRY protected: // Internal flavor of GetPreferences.