diff --git a/mozilla/browser/base/content/browser.js b/mozilla/browser/base/content/browser.js index 92237acad9c..34765774611 100644 --- a/mozilla/browser/base/content/browser.js +++ b/mozilla/browser/base/content/browser.js @@ -895,7 +895,33 @@ function delayedStartup() gClickSelectsAll = gPrefService.getBoolPref("browser.urlbar.clickSelectsAll"); #ifdef HAVE_SHELL_SERVICE - if (!getShellService()) { + // Perform default browser checking (after window opens). + var shell = getShellService(); + if (shell) { + var shouldCheck = shell.shouldCheckDefaultBrowser; + if (shouldCheck && !shell.isDefaultBrowser(true)) { + var brandBundle = document.getElementById("bundle_brand"); + var shellBundle = document.getElementById("bundle_shell"); + + var brandShortName = brandBundle.getString("brandShortName"); + var promptTitle = shellBundle.getString("setDefaultBrowserTitle"); + var promptMessage = shellBundle.getFormattedString("setDefaultBrowserMessage", + [brandShortName]); + var checkboxLabel = shellBundle.getFormattedString("setDefaultBrowserDontAsk", + [brandShortName]); + const IPS = Components.interfaces.nsIPromptService; + var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] + .getService(IPS); + var checkEveryTime = { value: shouldCheck }; + var rv = ps.confirmEx(window, promptTitle, promptMessage, + (IPS.BUTTON_TITLE_YES * IPS.BUTTON_POS_0) + + (IPS.BUTTON_TITLE_NO * IPS.BUTTON_POS_1), + null, null, null, checkboxLabel, checkEveryTime); + if (rv == 0) + shell.setDefaultBrowser(true, false); + shell.shouldCheckDefaultBrowser = checkEveryTime.value; + } + } else { // We couldn't get the shell service; go hide the mail toolbar button. var mailbutton = document.getElementById("mail-button"); if (mailbutton) diff --git a/mozilla/browser/components/nsBrowserGlue.js b/mozilla/browser/components/nsBrowserGlue.js index 7fb96498426..ab1efa93dd8 100644 --- a/mozilla/browser/components/nsBrowserGlue.js +++ b/mozilla/browser/components/nsBrowserGlue.js @@ -35,6 +35,8 @@ * * ***** END LICENSE BLOCK ***** */ + + // Constructor function BrowserGlue() { @@ -42,17 +44,14 @@ function BrowserGlue() { } BrowserGlue.prototype = { - - mPrefService: null, - - QueryInterface: function nsBG_QI(iid) + QueryInterface: function(iid) { xpcomCheckInterfaces(iid, kServiceIIds, Components.results.NS_ERROR_NO_INTERFACE); return this; - }, - + } +, // nsIObserver implementation - observe: function nsBG_observe(subject, topic, data) + observe: function(subject, topic, data) { switch(topic) { case "xpcom-shutdown": @@ -65,10 +64,10 @@ BrowserGlue.prototype = { this._onProfileStartup(); break; } - }, - + } +, // initialization (called on application startup) - _init: function nsBG_init() + _init: function() { // observer registration const osvr = Components.classes['@mozilla.org/observer-service;1'] @@ -79,7 +78,7 @@ BrowserGlue.prototype = { }, // cleanup (called on application shutdown) - _dispose: function nsBG_dispose() + _dispose: function() { // observer removal const osvr = Components.classes['@mozilla.org/observer-service;1'] @@ -90,16 +89,11 @@ BrowserGlue.prototype = { }, // profile startup handler (contains profile initialization routines) - _onProfileStartup: function nsBG_onProfileStartup() + _onProfileStartup: function() { - if (this.prefService.getBoolPref("browser.shell.checkDefaultBrowser")) - this.checkDefaultBrowser(); - this.Sanitizer.onStartup(); - // check if we're in safe mode - var app = Components.classes["@mozilla.org/xre/app-info;1"] - .getService(Components.interfaces.nsIXULAppInfo) + var app = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo) .QueryInterface(Components.interfaces.nsIXULRuntime); if (app.inSafeMode) { var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] @@ -110,7 +104,7 @@ BrowserGlue.prototype = { }, // profile shutdown handler (contains profile cleanup routines) - _onProfileShutdown: function nsBG_onProfileShutdown() + _onProfileShutdown: function() { // here we enter last survival area, in order to avoid multiple // "quit-application" notifications caused by late window closings @@ -137,92 +131,19 @@ BrowserGlue.prototype = { } return Sanitizer; }, - - get prefService() - { - if (!this.mPrefService) - this.mPrefService = - Components.classes["@mozilla.org/preferences-service;1"] - .getService(Components.interfaces.nsIPrefBranch2); - - return this.mPrefService; - }, - + // ------------------------------ // public nsIBrowserGlue members // ------------------------------ - - sanitize: function nsBG_sanitize(aParentWindow) + + sanitize: function(aParentWindow) { this.Sanitizer.sanitize(aParentWindow); - }, - - checkDefaultBrowser: function nsBG_checkDefaultBrowser(aUserInitiated, - aParentWindow) - { - var shell; - try { - shell = Components.classes["@mozilla.org/browser/shell-service;1"] - .getService(Components.interfaces.nsIShellService); - } catch (ex) { } - - if (!shell) - return; - - const cID = "@mozilla.org/intl/stringbundle;1"; - const nsISBS = Components.interfaces.nsIStringBundleService; - var bundleSvc = Components.classes[cID].getService(nsISBS); - - const brandURL = "chrome://branding/locale/brand.properties"; - var brandBundle = bundleSvc.createBundle(brandURL); - const shellURL = "chrome://browser/locale/shellservice.properties"; - var shellBundle = bundleSvc.createBundle(shellURL); - - var brandShortName = brandBundle.GetStringFromName("brandShortName"); - - var promptTitle = shellBundle.GetStringFromName("setDefaultBrowserTitle"); - var promptMessage = - shellBundle.formatStringFromName("setDefaultBrowserMessage", - [brandShortName], 1); - var checkboxLabel = - shellBundle.formatStringFromName("setDefaultBrowserDontAsk", - [brandShortName], 1); - var checkEveryTime = { value: true }; - - const nsIPS = Components.interfaces.nsIPromptService; - var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] - .getService(nsIPS); - - var parentWindow = aParentWindow || null; - - if (!shell.isDefaultBrowser()) { - - if (aUserInitiated) { - // Don't show the checkbox - checkboxLabel = null; - checkEveryTime = {}; - } - - var rv = ps.confirmEx(parentWindow, promptTitle, promptMessage, - (nsIPS.BUTTON_TITLE_YES * nsIPS.BUTTON_POS_0) + - (nsIPS.BUTTON_TITLE_NO * nsIPS.BUTTON_POS_1), - null, null, null, checkboxLabel, checkEveryTime); - - if (rv == 0) - shell.setDefaultBrowser(true, false); - - if (!aUserInitiated) - this.prefService.setBoolPref("browser.shell.checkDefaultBrowser", - checkEveryTime.value); - - } else if (aUserInitiated) { - promptMessage = shellBundle.formatStringFromName("alreadyDefaultBrowser", - [brandShortName], 1); - ps.alert(parentWindow, promptTitle, promptMessage); - } } + } + // XPCOM Scaffolding code // component defined in this file @@ -270,7 +191,7 @@ function xpcomCheckInterfaces(iid, iids, ex) { var Module = { registered: false, - + registerSelf: function(compMgr, fileSpec, location, type) { if (!this.registered) { @@ -291,7 +212,7 @@ var Module = { this.registered = true; } }, - + unregisterSelf: function(compMgr, fileSpec, location) { compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar) @@ -303,7 +224,7 @@ var Module = { catman.deleteCategoryEntry(kServiceCats[j], kServiceCtrId, true); } }, - + getClassObject: function(compMgr, cid, iid) { if(cid.equals(kServiceCId)) @@ -316,7 +237,7 @@ var Module = { ]; }, - + canUnload: function(compMgr) { return true; diff --git a/mozilla/browser/components/nsIBrowserGlue.idl b/mozilla/browser/components/nsIBrowserGlue.idl index 4026b0fd088..c0663778740 100644 --- a/mozilla/browser/components/nsIBrowserGlue.idl +++ b/mozilla/browser/components/nsIBrowserGlue.idl @@ -56,29 +56,15 @@ interface nsIDOMWindow; * */ -[scriptable, uuid(7bef1130-e2ca-4721-8272-6e6e5e7fc994)] +[scriptable, uuid(6d340848-9bc1-49a3-9073-99932bbc2a11)] interface nsIBrowserGlue : nsISupports { /** * Deletes privacy sensitive data according to user preferences * - * @param aParentWindow Optional: a window to be used as the parent of the + * @param aParentWindow an optionally null window which is the parent of the * sanitization dialog (if it has to be shown per user preferences) * */ void sanitize(in nsIDOMWindow aParentWindow); - - /** - * Checks whether the browser is set as the system default, and if not, - * prompts the user to make it the default. - * - * @param aUserInitiated a boolean value indicating whether an alert should be - * displayed if the browser is already registered as the system - * default. Also controls whether or not the "Should check at startup" - * checkbox appears in the confirmation prompt. - * @param aParentWindow Optional: a window to be used as the parent of the - * prompts and alerts - * - */ - void checkDefaultBrowser(in boolean aUserInitiated, in nsIDOMWindow aParentWindow); }; diff --git a/mozilla/browser/components/preferences/general.js b/mozilla/browser/components/preferences/general.js index 06beff70495..258318a4f4a 100644 --- a/mozilla/browser/components/preferences/general.js +++ b/mozilla/browser/components/preferences/general.js @@ -163,10 +163,34 @@ var gGeneralPane = { "", null); }, +#ifdef HAVE_SHELL_SERVICE checkNow: function () { - var browserGlue = Components.classes["@mozilla.org/browser/browserglue;1"] - .getService(Components.interfaces.nsIBrowserGlue); - browserGlue.checkDefaultBrowser(true, window); + var shellSvc = Components.classes["@mozilla.org/browser/shell-service;1"] + .getService(Components.interfaces.nsIShellService); + var brandBundle = document.getElementById("bundleBrand"); + var shellBundle = document.getElementById("bundleShell"); + var brandShortName = brandBundle.getString("brandShortName"); + var promptTitle = shellBundle.getString("setDefaultBrowserTitle"); + var promptMessage; + const IPS = Components.interfaces.nsIPromptService; + var psvc = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] + .getService(IPS); + if (!shellSvc.isDefaultBrowser(false)) { + promptMessage = shellBundle.getFormattedString("setDefaultBrowserMessage", + [brandShortName]); + var rv = psvc.confirmEx(window, promptTitle, promptMessage, + (IPS.BUTTON_TITLE_YES * IPS.BUTTON_POS_0) + + (IPS.BUTTON_TITLE_NO * IPS.BUTTON_POS_1), + null, null, null, null, { }); + if (rv == 0) + shellSvc.setDefaultBrowser(true, false); + } + else { + promptMessage = shellBundle.getFormattedString("alreadyDefaultBrowser", + [brandShortName]); + psvc.alert(window, promptTitle, promptMessage); + } } +#endif }; diff --git a/mozilla/browser/components/shell/public/nsIShellService.idl b/mozilla/browser/components/shell/public/nsIShellService.idl index 6ac3341c160..f3d15f22a0d 100644 --- a/mozilla/browser/components/shell/public/nsIShellService.idl +++ b/mozilla/browser/components/shell/public/nsIShellService.idl @@ -39,15 +39,19 @@ interface nsIDOMElement; -[scriptable, uuid(f0a0e17d-87bb-4a44-8f6a-11908927b647)] +[scriptable, uuid(d6f62053-3769-46f6-bd2b-0a1440d6c394)] interface nsIShellService : nsISupports { /** * Determines whether or not Firefox is the "Default Browser." * This is simply whether or not Firefox is registered to handle * http links. + * + * @param aStartupCheck true if this is the check being performed + * by the first browser window at startup, + * false otherwise. */ - boolean isDefaultBrowser(); + boolean isDefaultBrowser(in boolean aStartupCheck); /** * Registers Firefox as the "Default Browser." @@ -61,6 +65,14 @@ interface nsIShellService : nsISupports */ void setDefaultBrowser(in boolean aClaimAllTypes, in boolean aForAllUsers); + /** + * Used to determine whether or not to show a "Set Default Browser" + * query dialog. This attribute is true if the application is starting + * up and "browser.shell.checkDefaultBrowser" is true, otherwise it + * is false. + */ + attribute boolean shouldCheckDefaultBrowser; + /** * Flags for positioning/sizing of the Desktop Background image. */ diff --git a/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp b/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp index e2377c8f65c..a66fd3b2126 100644 --- a/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp +++ b/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp @@ -164,9 +164,12 @@ nsGNOMEShellService::KeyMatchesAppName(const char *aKeyValue) const } NS_IMETHODIMP -nsGNOMEShellService::IsDefaultBrowser(PRBool* aIsDefaultBrowser) +nsGNOMEShellService::IsDefaultBrowser(PRBool aStartupCheck, + PRBool* aIsDefaultBrowser) { *aIsDefaultBrowser = PR_FALSE; + if (aStartupCheck) + mCheckedThisSession = PR_TRUE; nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); @@ -307,6 +310,39 @@ nsGNOMEShellService::SetDefaultBrowser(PRBool aClaimAllTypes, return NS_OK; } +NS_IMETHODIMP +nsGNOMEShellService::GetShouldCheckDefaultBrowser(PRBool* aResult) +{ + // If we've already checked, the browser has been started and this is a + // new window open, and we don't want to check again. + if (mCheckedThisSession) { + *aResult = PR_FALSE; + return NS_OK; + } + + nsCOMPtr prefs; + nsCOMPtr pserve(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (pserve) + pserve->GetBranch("", getter_AddRefs(prefs)); + + prefs->GetBoolPref(PREF_CHECKDEFAULTBROWSER, aResult); + + return NS_OK; +} + +NS_IMETHODIMP +nsGNOMEShellService::SetShouldCheckDefaultBrowser(PRBool aShouldCheck) +{ + nsCOMPtr prefs; + nsCOMPtr pserve(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (pserve) + pserve->GetBranch("", getter_AddRefs(prefs)); + + prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheck); + + return NS_OK; +} + static nsresult WriteImage(const nsCString& aPath, gfxIImageFrame* aImage) { diff --git a/mozilla/browser/components/shell/src/nsGNOMEShellService.h b/mozilla/browser/components/shell/src/nsGNOMEShellService.h index 1640dc42e5e..7b98433c80f 100644 --- a/mozilla/browser/components/shell/src/nsGNOMEShellService.h +++ b/mozilla/browser/components/shell/src/nsGNOMEShellService.h @@ -43,7 +43,7 @@ class nsGNOMEShellService : public nsIShellService { public: - nsGNOMEShellService() { } + nsGNOMEShellService() : mCheckedThisSession(PR_FALSE) { } NS_DECL_ISUPPORTS NS_DECL_NSISHELLSERVICE @@ -55,7 +55,8 @@ private: NS_HIDDEN_(PRBool) KeyMatchesAppName(const char *aKeyValue) const; - PRBool mUseLocaleFilenames; + PRPackedBool mCheckedThisSession; + PRPackedBool mUseLocaleFilenames; nsCString mAppPath; }; diff --git a/mozilla/browser/components/shell/src/nsMacShellService.cpp b/mozilla/browser/components/shell/src/nsMacShellService.cpp index a715a8df119..5803992d638 100644 --- a/mozilla/browser/components/shell/src/nsMacShellService.cpp +++ b/mozilla/browser/components/shell/src/nsMacShellService.cpp @@ -79,7 +79,7 @@ extern "C" { NS_IMPL_ISUPPORTS3(nsMacShellService, nsIMacShellService, nsIShellService, nsIWebProgressListener) NS_IMETHODIMP -nsMacShellService::IsDefaultBrowser(PRBool* aIsDefaultBrowser) +nsMacShellService::IsDefaultBrowser(PRBool aStartupCheck, PRBool* aIsDefaultBrowser) { *aIsDefaultBrowser = PR_TRUE; @@ -134,6 +134,12 @@ nsMacShellService::IsDefaultBrowser(PRBool* aIsDefaultBrowser) // release the idetifiers strings ::CFRelease(firefoxID); + // If this is the first browser window, maintain internal state that we've + // checked this session (so that subsequent window opens don't show the + // default browser dialog). + if (aStartupCheck) + mCheckedThisSession = PR_TRUE; + return rv; } @@ -164,6 +170,39 @@ nsMacShellService::SetDefaultBrowser(PRBool aClaimAllTypes, PRBool aForAllUsers) return NS_OK; } +NS_IMETHODIMP +nsMacShellService::GetShouldCheckDefaultBrowser(PRBool* aResult) +{ + // If we've already checked, the browser has been started and this is a + // new window open, and we don't want to check again. + if (mCheckedThisSession) { + *aResult = PR_FALSE; + return NS_OK; + } + + nsCOMPtr prefs; + nsCOMPtr pserve(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (pserve) + pserve->GetBranch("", getter_AddRefs(prefs)); + + prefs->GetBoolPref(PREF_CHECKDEFAULTBROWSER, aResult); + + return NS_OK; +} + +NS_IMETHODIMP +nsMacShellService::SetShouldCheckDefaultBrowser(PRBool aShouldCheck) +{ + nsCOMPtr prefs; + nsCOMPtr pserve(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (pserve) + pserve->GetBranch("", getter_AddRefs(prefs)); + + prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheck); + + return NS_OK; +} + NS_IMETHODIMP nsMacShellService::SetDesktopBackground(nsIDOMElement* aElement, PRInt32 aPosition) diff --git a/mozilla/browser/components/shell/src/nsMacShellService.h b/mozilla/browser/components/shell/src/nsMacShellService.h index f884e9a7672..3d0a9d3d029 100644 --- a/mozilla/browser/components/shell/src/nsMacShellService.h +++ b/mozilla/browser/components/shell/src/nsMacShellService.h @@ -46,7 +46,7 @@ class nsMacShellService : public nsIMacShellService, public nsIWebProgressListener { public: - nsMacShellService() {}; + nsMacShellService() : mCheckedThisSession(PR_FALSE) {}; virtual ~nsMacShellService() {}; NS_DECL_ISUPPORTS @@ -58,6 +58,8 @@ protected: private: nsCOMPtr mBackgroundFile; + + PRBool mCheckedThisSession; }; #endif // nsmacshellservice_h____ diff --git a/mozilla/browser/components/shell/src/nsShellService.h b/mozilla/browser/components/shell/src/nsShellService.h index 6db640fc51a..58e7eb68f76 100644 --- a/mozilla/browser/components/shell/src/nsShellService.h +++ b/mozilla/browser/components/shell/src/nsShellService.h @@ -34,5 +34,8 @@ * * ***** END LICENSE BLOCK ***** */ +#define PREF_CHECKDEFAULTBROWSER "browser.shell.checkDefaultBrowser" + #define SHELLSERVICE_PROPERTIES "chrome://browser/locale/shellservice.properties" #define BRAND_PROPERTIES "chrome://branding/locale/brand.properties" + diff --git a/mozilla/browser/components/shell/src/nsWindowsShellService.cpp b/mozilla/browser/components/shell/src/nsWindowsShellService.cpp index 595eca52a4b..8dc3981faf1 100644 --- a/mozilla/browser/components/shell/src/nsWindowsShellService.cpp +++ b/mozilla/browser/components/shell/src/nsWindowsShellService.cpp @@ -291,6 +291,7 @@ nsWindowsShellService::Register(nsIComponentManager *aCompMgr, nsIFile *aPath, c } nsWindowsShellService::nsWindowsShellService() +:mCheckedThisSession(PR_FALSE) { nsCOMPtr obsServ (do_GetService("@mozilla.org/observer-service;1")); obsServ->AddObserver(this, "quit-application", PR_FALSE); @@ -322,7 +323,7 @@ nsWindowsShellService::UnregisterDDESupport() } NS_IMETHODIMP -nsWindowsShellService::IsDefaultBrowser(PRBool* aIsDefaultBrowser) +nsWindowsShellService::IsDefaultBrowser(PRBool aStartupCheck, PRBool* aIsDefaultBrowser) { SETTING* settings; SETTING* end = gSettings + sizeof(gSettings)/sizeof(SETTING); @@ -378,6 +379,12 @@ nsWindowsShellService::IsDefaultBrowser(PRBool* aIsDefaultBrowser) } } + // If this is the first browser window, maintain internal state that we've + // checked this session (so that subsequent window opens don't show the + // default browser dialog). + if (aStartupCheck) + mCheckedThisSession = PR_TRUE; + return NS_OK; } @@ -601,6 +608,39 @@ nsWindowsShellService::SetRegKey(const char* aKeyName, const char* aValueName, ::RegCloseKey(theKey); } +NS_IMETHODIMP +nsWindowsShellService::GetShouldCheckDefaultBrowser(PRBool* aResult) +{ + // If we've already checked, the browser has been started and this is a + // new window open, and we don't want to check again. + if (mCheckedThisSession) { + *aResult = PR_FALSE; + return NS_OK; + } + + nsCOMPtr prefs; + nsCOMPtr pserve(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (pserve) + pserve->GetBranch("", getter_AddRefs(prefs)); + + prefs->GetBoolPref(PREF_CHECKDEFAULTBROWSER, aResult); + + return NS_OK; +} + +NS_IMETHODIMP +nsWindowsShellService::SetShouldCheckDefaultBrowser(PRBool aShouldCheck) +{ + nsCOMPtr prefs; + nsCOMPtr pserve(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (pserve) + pserve->GetBranch("", getter_AddRefs(prefs)); + + prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheck); + + return NS_OK; +} + static nsresult WriteBitmap(nsIFile* aFile, gfxIImageFrame* aImage) { @@ -978,7 +1018,7 @@ nsWindowsShellService::Observe(nsISupports* aObject, const char* aTopic, const P { if (!nsCRT::strcmp("app-startup", aTopic)) { PRBool isDefault; - IsDefaultBrowser(&isDefault); + IsDefaultBrowser(PR_FALSE, &isDefault); if (!isDefault) return NS_OK; @@ -986,7 +1026,7 @@ nsWindowsShellService::Observe(nsISupports* aObject, const char* aTopic, const P } else if (!nsCRT::strcmp("quit-application", aTopic)) { PRBool isDefault; - IsDefaultBrowser(&isDefault); + IsDefaultBrowser(PR_FALSE, &isDefault); if (!isDefault) return NS_OK; diff --git a/mozilla/browser/components/shell/src/nsWindowsShellService.h b/mozilla/browser/components/shell/src/nsWindowsShellService.h index 857147b3550..e8905d53613 100644 --- a/mozilla/browser/components/shell/src/nsWindowsShellService.h +++ b/mozilla/browser/components/shell/src/nsWindowsShellService.h @@ -71,6 +71,8 @@ protected: nsresult RegisterDDESupport(); nsresult UnregisterDDESupport(); +private: + PRBool mCheckedThisSession; }; #endif // nswindowsshellservice_h____