From 055dda3e6a9cf7d71ccdee5e890c67fa38933e0d Mon Sep 17 00:00:00 2001 From: "dougt%meer.net" Date: Tue, 25 Apr 2006 00:20:06 +0000 Subject: [PATCH] Adding methods for querying and setting default browser application --- minimo/chrome/content/minimo.js | 8 ++ minimo/components/device/nsDeviceSupport.cpp | 106 ++++++++++++++++++ minimo/components/device/nsIDeviceSupport.idl | 6 + minimo/customization/all.js | 2 + 4 files changed, 122 insertions(+) diff --git a/minimo/chrome/content/minimo.js b/minimo/chrome/content/minimo.js index 3b3375626d6c..570706290d89 100755 --- a/minimo/chrome/content/minimo.js +++ b/minimo/chrome/content/minimo.js @@ -437,6 +437,14 @@ function MiniNavStartup() gMinimoBundle = document.getElementById("minimo_properties"); + /* + * Check to see if we should set ourselves as the default + * app. no annoying dialog -- just do it if the pref is + * set. + */ + var device = Components.classes["@mozilla.org/device/support;1"].getService(nsIDeviceSupport); + if (!device.isDefaultBrowser() && device.shouldCheckDefaultBrowser) + device.setDefaultBrowser(); } function HomebarHandler(e) { diff --git a/minimo/components/device/nsDeviceSupport.cpp b/minimo/components/device/nsDeviceSupport.cpp index 2e85ad5f354b..df7209bda5bf 100755 --- a/minimo/components/device/nsDeviceSupport.cpp +++ b/minimo/components/device/nsDeviceSupport.cpp @@ -40,6 +40,9 @@ #include "nsCOMPtr.h" #include "nsIServiceManager.h" #include "nsIGenericFactory.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" + #include "string.h" #include "nsMemory.h" @@ -123,7 +126,110 @@ NS_IMETHODIMP nsDeviceSupport::Has(const char* aProperty, char **aValue) return NS_OK; } +#ifdef XP_WIN +static void SetRegistryKey(HKEY root, char *key, char *set) +{ + HKEY hResult; + LONG nResult = RegOpenKeyEx(root, key, 0, KEY_WRITE, &hResult); + if(nResult != ERROR_SUCCESS) + return; + + RegSetValueEx(hResult, + NULL, + 0, + REG_SZ, + (CONST BYTE*)set, + strlen(set)); + RegCloseKey(hResult); +} + +static void GetRegistryKey(HKEY root, char *key, char *get) +{ + HKEY hResult; + LONG nResult = RegOpenKeyEx(root, key, 0, KEY_READ, &hResult); + if(nResult != ERROR_SUCCESS) + return; + + DWORD length = MAX_PATH; + RegQueryValueEx(hResult, + NULL, + 0, + NULL, + (BYTE*)get, + (LPDWORD)&length); + + RegCloseKey(hResult); +} + +#endif + +NS_IMETHODIMP nsDeviceSupport::IsDefaultBrowser(PRBool *_retval) +{ + *_retval = PR_FALSE; + +#ifdef XP_WIN + + char buffer[MAX_PATH]; + GetRegistryKey(HKEY_CLASSES_ROOT, "http\\Shell\\Open\\Command", (char*)&buffer); + + if (strstr( buffer, "minimo_runner")) + *_retval = PR_TRUE; + +#endif + return NS_OK; +} + +NS_IMETHODIMP nsDeviceSupport::SetDefaultBrowser() +{ +#ifdef XP_WIN + char *cp; + char exe[MAX_PATH]; + char cmdline[MAX_PATH]; + GetModuleFileName(GetModuleHandle(NULL), exe, sizeof(exe)); + cp = strrchr(exe,'\\'); + if (cp != NULL) + { + cp++; // pass the \ char. + *cp = 0; + } + + strcpy(cmdline, "\""); + strcat(cmdline, exe); + strcat(cmdline, "minimo_runner.exe\" -url %1"); + + SetRegistryKey(HKEY_CLASSES_ROOT, "http\\Shell\\Open\\Command", cmdline); + SetRegistryKey(HKEY_CLASSES_ROOT, "https\\Shell\\Open\\Command", cmdline); + SetRegistryKey(HKEY_CLASSES_ROOT, "ftp\\Shell\\Open\\Command", cmdline); + SetRegistryKey(HKEY_CLASSES_ROOT, "file\\Shell\\Open\\Command", cmdline); +#endif + + return NS_OK; +} + +#define PREF_CHECKDEFAULTBROWSER "browser.shell.checkDefaultBrowser" + +NS_IMETHODIMP nsDeviceSupport::GetShouldCheckDefaultBrowser(PRBool *aShouldCheckDefaultBrowser) +{ + nsCOMPtr prefs; + nsCOMPtr pserve(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (pserve) + pserve->GetBranch("", getter_AddRefs(prefs)); + + prefs->GetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheckDefaultBrowser); + return NS_OK; +} + +NS_IMETHODIMP nsDeviceSupport::SetShouldCheckDefaultBrowser(PRBool aShouldCheckDefaultBrowser) +{ + nsCOMPtr prefs; + nsCOMPtr pserve(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (pserve) + pserve->GetBranch("", getter_AddRefs(prefs)); + + prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheckDefaultBrowser); + return NS_OK; +} //------------------------------------------------------------------------------ // XPCOM REGISTRATION BELOW diff --git a/minimo/components/device/nsIDeviceSupport.idl b/minimo/components/device/nsIDeviceSupport.idl index b32f4891605a..3b6049cf8670 100755 --- a/minimo/components/device/nsIDeviceSupport.idl +++ b/minimo/components/device/nsIDeviceSupport.idl @@ -44,4 +44,10 @@ interface nsIDeviceSupport : nsISupports void rotateScreen(in boolean aLandscapeMode); string has(in string property); + + boolean isDefaultBrowser(); + void setDefaultBrowser(); + + attribute boolean shouldCheckDefaultBrowser; + }; diff --git a/minimo/customization/all.js b/minimo/customization/all.js index 83aa5da760c9..522e2f0feb81 100755 --- a/minimo/customization/all.js +++ b/minimo/customization/all.js @@ -673,3 +673,5 @@ pref("browser.cache.disk.enable",false); pref("signon.rememberSignons", true); pref("signon.SignonFileName", "signons.txt"); + +