2005-08-23 20:38:28 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Firefox Browser Glue Service.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Giorgio Maone
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Giorgio Maone <g.maone@informaction.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
|
|
|
|
function BrowserGlue() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserGlue.prototype = {
|
2005-12-04 21:34:12 +03:00
|
|
|
|
|
|
|
mPrefService: null,
|
|
|
|
|
|
|
|
QueryInterface: function nsBG_QI(iid)
|
2005-08-23 20:38:28 +04:00
|
|
|
{
|
|
|
|
xpcomCheckInterfaces(iid, kServiceIIds, Components.results.NS_ERROR_NO_INTERFACE);
|
|
|
|
return this;
|
2005-12-04 21:34:12 +03:00
|
|
|
},
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// nsIObserver implementation
|
2005-12-04 21:34:12 +03:00
|
|
|
observe: function nsBG_observe(subject, topic, data)
|
2005-08-23 20:38:28 +04:00
|
|
|
{
|
|
|
|
switch(topic) {
|
|
|
|
case "xpcom-shutdown":
|
|
|
|
this._dispose();
|
|
|
|
break;
|
2005-09-19 21:40:48 +04:00
|
|
|
case "profile-change-teardown":
|
2005-08-23 20:38:28 +04:00
|
|
|
this._onProfileShutdown();
|
|
|
|
break;
|
2005-10-07 19:15:21 +04:00
|
|
|
case "final-ui-startup":
|
2005-08-23 20:38:28 +04:00
|
|
|
this._onProfileStartup();
|
|
|
|
break;
|
|
|
|
}
|
2005-12-04 21:34:12 +03:00
|
|
|
},
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// initialization (called on application startup)
|
2005-12-04 21:34:12 +03:00
|
|
|
_init: function nsBG_init()
|
2005-08-23 20:38:28 +04:00
|
|
|
{
|
|
|
|
// observer registration
|
|
|
|
const osvr = Components.classes['@mozilla.org/observer-service;1']
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
2005-09-19 21:40:48 +04:00
|
|
|
osvr.addObserver(this, "profile-change-teardown", false);
|
2005-08-23 20:38:28 +04:00
|
|
|
osvr.addObserver(this, "xpcom-shutdown", false);
|
2005-10-07 19:15:21 +04:00
|
|
|
osvr.addObserver(this, "final-ui-startup", false);
|
2005-08-23 20:38:28 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// cleanup (called on application shutdown)
|
2005-12-04 21:34:12 +03:00
|
|
|
_dispose: function nsBG_dispose()
|
2005-08-23 20:38:28 +04:00
|
|
|
{
|
|
|
|
// observer removal
|
|
|
|
const osvr = Components.classes['@mozilla.org/observer-service;1']
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
2005-09-19 21:40:48 +04:00
|
|
|
osvr.removeObserver(this, "profile-change-teardown");
|
2005-08-23 20:38:28 +04:00
|
|
|
osvr.removeObserver(this, "xpcom-shutdown");
|
2005-10-07 19:15:21 +04:00
|
|
|
osvr.removeObserver(this, "final-ui-startup");
|
2005-08-23 20:38:28 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// profile startup handler (contains profile initialization routines)
|
2005-12-04 21:34:12 +03:00
|
|
|
_onProfileStartup: function nsBG_onProfileStartup()
|
2005-08-23 20:38:28 +04:00
|
|
|
{
|
2005-12-04 21:34:12 +03:00
|
|
|
if (this.prefService.getBoolPref("browser.shell.checkDefaultBrowser"))
|
|
|
|
this.checkDefaultBrowser();
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
this.Sanitizer.onStartup();
|
2005-12-04 21:34:12 +03:00
|
|
|
|
2005-10-04 09:02:47 +04:00
|
|
|
// check if we're in safe mode
|
2005-12-04 21:34:12 +03:00
|
|
|
var app = Components.classes["@mozilla.org/xre/app-info;1"]
|
|
|
|
.getService(Components.interfaces.nsIXULAppInfo)
|
2005-10-04 09:02:47 +04:00
|
|
|
.QueryInterface(Components.interfaces.nsIXULRuntime);
|
|
|
|
if (app.inSafeMode) {
|
|
|
|
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
|
|
|
|
.getService(Components.interfaces.nsIWindowWatcher);
|
|
|
|
ww.openWindow(null, "chrome://browser/content/safeMode.xul",
|
|
|
|
"_blank", "chrome,centerscreen,modal,resizable=no", null);
|
|
|
|
}
|
2005-08-23 20:38:28 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// profile shutdown handler (contains profile cleanup routines)
|
2005-12-04 21:34:12 +03:00
|
|
|
_onProfileShutdown: function nsBG_onProfileShutdown()
|
2005-08-23 20:38:28 +04:00
|
|
|
{
|
2005-10-11 01:53:40 +04:00
|
|
|
// here we enter last survival area, in order to avoid multiple
|
|
|
|
// "quit-application" notifications caused by late window closings
|
|
|
|
const appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1']
|
|
|
|
.getService(Components.interfaces.nsIAppStartup);
|
|
|
|
try {
|
|
|
|
appStartup.enterLastWindowClosingSurvivalArea();
|
|
|
|
|
|
|
|
this.Sanitizer.onShutdown();
|
|
|
|
|
|
|
|
} catch(ex) {
|
|
|
|
} finally {
|
|
|
|
appStartup.exitLastWindowClosingSurvivalArea();
|
|
|
|
}
|
2005-08-23 20:38:28 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// returns the (cached) Sanitizer constructor
|
|
|
|
get Sanitizer()
|
|
|
|
{
|
|
|
|
if(typeof(Sanitizer) != "function") { // we should dynamically load the script
|
|
|
|
Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Components.interfaces.mozIJSSubScriptLoader)
|
|
|
|
.loadSubScript("chrome://browser/content/sanitize.js", null);
|
|
|
|
}
|
|
|
|
return Sanitizer;
|
|
|
|
},
|
2005-12-04 21:34:12 +03:00
|
|
|
|
|
|
|
get prefService()
|
|
|
|
{
|
|
|
|
if (!this.mPrefService)
|
|
|
|
this.mPrefService =
|
|
|
|
Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch2);
|
|
|
|
|
|
|
|
return this.mPrefService;
|
|
|
|
},
|
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
// ------------------------------
|
|
|
|
// public nsIBrowserGlue members
|
|
|
|
// ------------------------------
|
2005-12-04 21:34:12 +03:00
|
|
|
|
|
|
|
sanitize: function nsBG_sanitize(aParentWindow)
|
2005-08-23 20:38:28 +04:00
|
|
|
{
|
|
|
|
this.Sanitizer.sanitize(aParentWindow);
|
2005-12-04 21:34:12 +03:00
|
|
|
},
|
2005-08-23 20:38:28 +04:00
|
|
|
|
2005-12-04 21:34:12 +03:00
|
|
|
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) {
|
2005-12-04 21:42:48 +03:00
|
|
|
// Don't show the checkbox
|
2005-12-04 21:34:12 +03:00
|
|
|
checkboxLabel = null;
|
|
|
|
checkEveryTime = {};
|
|
|
|
}
|
2005-08-23 20:38:28 +04:00
|
|
|
|
2005-12-04 21:34:12 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-08-23 20:38:28 +04:00
|
|
|
|
|
|
|
// XPCOM Scaffolding code
|
|
|
|
|
|
|
|
// component defined in this file
|
|
|
|
|
|
|
|
const kServiceName = "Firefox Browser Glue Service";
|
|
|
|
const kServiceId = "{eab9012e-5f74-4cbc-b2b5-a590235513cc}";
|
|
|
|
const kServiceCtrId = "@mozilla.org/browser/browserglue;1";
|
|
|
|
const kServiceConstructor = BrowserGlue;
|
|
|
|
|
|
|
|
const kServiceCId = Components.ID(kServiceId);
|
|
|
|
|
|
|
|
// interfaces implemented by this component
|
|
|
|
const kServiceIIds = [
|
|
|
|
Components.interfaces.nsIObserver,
|
|
|
|
Components.interfaces.nsISupports,
|
|
|
|
Components.interfaces.nsISupportsWeakReference,
|
|
|
|
Components.interfaces.nsIBrowserGlue
|
|
|
|
];
|
|
|
|
|
|
|
|
// categories which this component is registered in
|
|
|
|
const kServiceCats = ["app-startup"];
|
|
|
|
|
|
|
|
// Factory object
|
|
|
|
const kServiceFactory = {
|
|
|
|
_instance: null,
|
|
|
|
createInstance: function (outer, iid)
|
|
|
|
{
|
|
|
|
if (outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
xpcomCheckInterfaces(iid, kServiceIIds,
|
|
|
|
Components.results.NS_ERROR_INVALID_ARG);
|
|
|
|
return this._instance == null ?
|
|
|
|
this._instance = new kServiceConstructor() : this._instance;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function xpcomCheckInterfaces(iid, iids, ex) {
|
|
|
|
for (var j = iids.length; j-- >0;) {
|
|
|
|
if (iid.equals(iids[j])) return true;
|
|
|
|
}
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module
|
|
|
|
|
|
|
|
var Module = {
|
|
|
|
registered: false,
|
2005-12-04 21:34:12 +03:00
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
registerSelf: function(compMgr, fileSpec, location, type)
|
|
|
|
{
|
|
|
|
if (!this.registered) {
|
|
|
|
compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar)
|
|
|
|
.registerFactoryLocation(kServiceCId,
|
|
|
|
kServiceName,
|
|
|
|
kServiceCtrId,
|
|
|
|
fileSpec,
|
|
|
|
location,
|
|
|
|
type);
|
|
|
|
const catman = Components.classes['@mozilla.org/categorymanager;1']
|
|
|
|
.getService(Components.interfaces.nsICategoryManager);
|
|
|
|
var len = kServiceCats.length;
|
|
|
|
for (var j = 0; j < len; j++) {
|
|
|
|
catman.addCategoryEntry(kServiceCats[j],
|
|
|
|
kServiceCtrId, kServiceCtrId, true, true, null);
|
|
|
|
}
|
|
|
|
this.registered = true;
|
|
|
|
}
|
|
|
|
},
|
2005-12-04 21:34:12 +03:00
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
unregisterSelf: function(compMgr, fileSpec, location)
|
|
|
|
{
|
|
|
|
compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar)
|
|
|
|
.unregisterFactoryLocation(kServiceCId, fileSpec);
|
|
|
|
const catman = Components.classes['@mozilla.org/categorymanager;1']
|
|
|
|
.getService(Components.interfaces.nsICategoryManager);
|
2005-08-23 20:47:17 +04:00
|
|
|
var len = kServiceCats.length;
|
2005-08-23 20:49:21 +04:00
|
|
|
for (var j = 0; j < len; j++) {
|
2005-08-23 20:38:28 +04:00
|
|
|
catman.deleteCategoryEntry(kServiceCats[j], kServiceCtrId, true);
|
|
|
|
}
|
|
|
|
},
|
2005-12-04 21:34:12 +03:00
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
getClassObject: function(compMgr, cid, iid)
|
|
|
|
{
|
|
|
|
if(cid.equals(kServiceCId))
|
|
|
|
return kServiceFactory;
|
|
|
|
|
|
|
|
throw Components.results[
|
|
|
|
iid.equals(Components.interfaces.nsIFactory)
|
|
|
|
? "NS_ERROR_NO_INTERFACE"
|
|
|
|
: "NS_ERROR_NOT_IMPLEMENTED"
|
|
|
|
];
|
|
|
|
|
|
|
|
},
|
2005-12-04 21:34:12 +03:00
|
|
|
|
2005-08-23 20:38:28 +04:00
|
|
|
canUnload: function(compMgr)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// entrypoint
|
|
|
|
function NSGetModule(compMgr, fileSpec) {
|
|
|
|
return Module;
|
|
|
|
}
|