Bug 311605: default browser checking should be done nsBrowserBlue, not in delayed startup, r=mano

This commit is contained in:
gavin%gavinsharp.com 2005-12-04 18:34:12 +00:00
parent 92df6d61be
commit b05089efa8
12 changed files with 131 additions and 223 deletions

View File

@ -895,33 +895,7 @@ function delayedStartup()
gClickSelectsAll = gPrefService.getBoolPref("browser.urlbar.clickSelectsAll");
#ifdef HAVE_SHELL_SERVICE
// 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 {
if (!getShellService()) {
// We couldn't get the shell service; go hide the mail toolbar button.
var mailbutton = document.getElementById("mail-button");
if (mailbutton)

View File

@ -35,8 +35,6 @@
*
* ***** END LICENSE BLOCK ***** */
// Constructor
function BrowserGlue() {
@ -44,14 +42,17 @@ function BrowserGlue() {
}
BrowserGlue.prototype = {
QueryInterface: function(iid)
mPrefService: null,
QueryInterface: function nsBG_QI(iid)
{
xpcomCheckInterfaces(iid, kServiceIIds, Components.results.NS_ERROR_NO_INTERFACE);
return this;
}
,
},
// nsIObserver implementation
observe: function(subject, topic, data)
observe: function nsBG_observe(subject, topic, data)
{
switch(topic) {
case "xpcom-shutdown":
@ -64,10 +65,10 @@ BrowserGlue.prototype = {
this._onProfileStartup();
break;
}
}
,
},
// initialization (called on application startup)
_init: function()
_init: function nsBG_init()
{
// observer registration
const osvr = Components.classes['@mozilla.org/observer-service;1']
@ -78,7 +79,7 @@ BrowserGlue.prototype = {
},
// cleanup (called on application shutdown)
_dispose: function()
_dispose: function nsBG_dispose()
{
// observer removal
const osvr = Components.classes['@mozilla.org/observer-service;1']
@ -89,11 +90,16 @@ BrowserGlue.prototype = {
},
// profile startup handler (contains profile initialization routines)
_onProfileStartup: function()
_onProfileStartup: function nsBG_onProfileStartup()
{
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"]
@ -104,7 +110,7 @@ BrowserGlue.prototype = {
},
// profile shutdown handler (contains profile cleanup routines)
_onProfileShutdown: function()
_onProfileShutdown: function nsBG_onProfileShutdown()
{
// here we enter last survival area, in order to avoid multiple
// "quit-application" notifications caused by late window closings
@ -131,19 +137,92 @@ 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(aParentWindow)
sanitize: function nsBG_sanitize(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 if this dialog is forced
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
@ -191,7 +270,7 @@ function xpcomCheckInterfaces(iid, iids, ex) {
var Module = {
registered: false,
registerSelf: function(compMgr, fileSpec, location, type)
{
if (!this.registered) {
@ -212,7 +291,7 @@ var Module = {
this.registered = true;
}
},
unregisterSelf: function(compMgr, fileSpec, location)
{
compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar)
@ -224,7 +303,7 @@ var Module = {
catman.deleteCategoryEntry(kServiceCats[j], kServiceCtrId, true);
}
},
getClassObject: function(compMgr, cid, iid)
{
if(cid.equals(kServiceCId))
@ -237,7 +316,7 @@ var Module = {
];
},
canUnload: function(compMgr)
{
return true;

View File

@ -56,15 +56,29 @@ interface nsIDOMWindow;
*
*/
[scriptable, uuid(6d340848-9bc1-49a3-9073-99932bbc2a11)]
[scriptable, uuid(7bef1130-e2ca-4721-8272-6e6e5e7fc994)]
interface nsIBrowserGlue : nsISupports
{
/**
* Deletes privacy sensitive data according to user preferences
*
* @param aParentWindow an optionally null window which is the parent of the
* @param aParentWindow Optional: a window to be used as 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);
};

View File

@ -163,34 +163,10 @@ var gGeneralPane = {
"", null);
},
#ifdef HAVE_SHELL_SERVICE
checkNow: function ()
{
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);
}
var browserGlue = Components.classes["@mozilla.org/browser/browserglue;1"]
.getService(Components.interfaces.nsIBrowserGlue);
browserGlue.checkDefaultBrowser(true, window);
}
#endif
};

View File

@ -39,19 +39,15 @@
interface nsIDOMElement;
[scriptable, uuid(d6f62053-3769-46f6-bd2b-0a1440d6c394)]
[scriptable, uuid(f0a0e17d-87bb-4a44-8f6a-11908927b647)]
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(in boolean aStartupCheck);
boolean isDefaultBrowser();
/**
* Registers Firefox as the "Default Browser."
@ -65,14 +61,6 @@ 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.
*/

View File

@ -164,12 +164,9 @@ nsGNOMEShellService::KeyMatchesAppName(const char *aKeyValue) const
}
NS_IMETHODIMP
nsGNOMEShellService::IsDefaultBrowser(PRBool aStartupCheck,
PRBool* aIsDefaultBrowser)
nsGNOMEShellService::IsDefaultBrowser(PRBool* aIsDefaultBrowser)
{
*aIsDefaultBrowser = PR_FALSE;
if (aStartupCheck)
mCheckedThisSession = PR_TRUE;
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
@ -310,39 +307,6 @@ 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<nsIPrefBranch> prefs;
nsCOMPtr<nsIPrefService> 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<nsIPrefBranch> prefs;
nsCOMPtr<nsIPrefService> 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)
{

View File

@ -43,7 +43,7 @@
class nsGNOMEShellService : public nsIShellService
{
public:
nsGNOMEShellService() : mCheckedThisSession(PR_FALSE) { }
nsGNOMEShellService() { }
NS_DECL_ISUPPORTS
NS_DECL_NSISHELLSERVICE
@ -55,8 +55,7 @@ private:
NS_HIDDEN_(PRBool) KeyMatchesAppName(const char *aKeyValue) const;
PRPackedBool mCheckedThisSession;
PRPackedBool mUseLocaleFilenames;
PRBool mUseLocaleFilenames;
nsCString mAppPath;
};

View File

@ -79,7 +79,7 @@ extern "C" {
NS_IMPL_ISUPPORTS3(nsMacShellService, nsIMacShellService, nsIShellService, nsIWebProgressListener)
NS_IMETHODIMP
nsMacShellService::IsDefaultBrowser(PRBool aStartupCheck, PRBool* aIsDefaultBrowser)
nsMacShellService::IsDefaultBrowser(PRBool* aIsDefaultBrowser)
{
*aIsDefaultBrowser = PR_TRUE;
@ -134,12 +134,6 @@ nsMacShellService::IsDefaultBrowser(PRBool aStartupCheck, PRBool* aIsDefaultBrow
// 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;
}
@ -170,39 +164,6 @@ 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<nsIPrefBranch> prefs;
nsCOMPtr<nsIPrefService> 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<nsIPrefBranch> prefs;
nsCOMPtr<nsIPrefService> 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)

View File

@ -46,7 +46,7 @@ class nsMacShellService : public nsIMacShellService,
public nsIWebProgressListener
{
public:
nsMacShellService() : mCheckedThisSession(PR_FALSE) {};
nsMacShellService() {};
virtual ~nsMacShellService() {};
NS_DECL_ISUPPORTS
@ -58,8 +58,6 @@ protected:
private:
nsCOMPtr<nsILocalFile> mBackgroundFile;
PRBool mCheckedThisSession;
};
#endif // nsmacshellservice_h____

View File

@ -34,8 +34,5 @@
*
* ***** 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"

View File

@ -291,7 +291,6 @@ nsWindowsShellService::Register(nsIComponentManager *aCompMgr, nsIFile *aPath, c
}
nsWindowsShellService::nsWindowsShellService()
:mCheckedThisSession(PR_FALSE)
{
nsCOMPtr<nsIObserverService> obsServ (do_GetService("@mozilla.org/observer-service;1"));
obsServ->AddObserver(this, "quit-application", PR_FALSE);
@ -323,7 +322,7 @@ nsWindowsShellService::UnregisterDDESupport()
}
NS_IMETHODIMP
nsWindowsShellService::IsDefaultBrowser(PRBool aStartupCheck, PRBool* aIsDefaultBrowser)
nsWindowsShellService::IsDefaultBrowser(PRBool* aIsDefaultBrowser)
{
SETTING* settings;
SETTING* end = gSettings + sizeof(gSettings)/sizeof(SETTING);
@ -379,12 +378,6 @@ nsWindowsShellService::IsDefaultBrowser(PRBool aStartupCheck, PRBool* aIsDefault
}
}
// 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;
}
@ -608,39 +601,6 @@ 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<nsIPrefBranch> prefs;
nsCOMPtr<nsIPrefService> 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<nsIPrefBranch> prefs;
nsCOMPtr<nsIPrefService> 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)
{
@ -1018,7 +978,7 @@ nsWindowsShellService::Observe(nsISupports* aObject, const char* aTopic, const P
{
if (!nsCRT::strcmp("app-startup", aTopic)) {
PRBool isDefault;
IsDefaultBrowser(PR_FALSE, &isDefault);
IsDefaultBrowser(&isDefault);
if (!isDefault)
return NS_OK;
@ -1026,7 +986,7 @@ nsWindowsShellService::Observe(nsISupports* aObject, const char* aTopic, const P
}
else if (!nsCRT::strcmp("quit-application", aTopic)) {
PRBool isDefault;
IsDefaultBrowser(PR_FALSE, &isDefault);
IsDefaultBrowser(&isDefault);
if (!isDefault)
return NS_OK;

View File

@ -71,8 +71,6 @@ protected:
nsresult RegisterDDESupport();
nsresult UnregisterDDESupport();
private:
PRBool mCheckedThisSession;
};
#endif // nswindowsshellservice_h____