[Pale-Moon] Issue #1737 - Part 7: Tidy components/*.js

pull/24/head
Pale Moon 2 years ago committed by Roy Tam
parent 94e0c368a5
commit 500d51dfc4
  1. 248
      application/palemoon/components/distribution.js
  2. 8
      application/palemoon/components/nsAboutRedirector.js
  3. 277
      application/palemoon/components/nsBrowserContentHandler.js
  4. 335
      application/palemoon/components/nsBrowserGlue.js

@ -17,22 +17,23 @@ XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
this.DistributionCustomizer = function DistributionCustomizer() {
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
let dirSvc = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties);
let iniFile = dirSvc.get("XREExeF", Ci.nsIFile);
iniFile.leafName = "distribution";
iniFile.append("distribution.ini");
if (iniFile.exists())
if (iniFile.exists()) {
this._iniFile = iniFile;
}
}
DistributionCustomizer.prototype = {
_iniFile: null,
get _ini() {
let ini = Cc["@mozilla.org/xpcom/ini-parser-factory;1"].
getService(Ci.nsIINIParserFactory).
createINIParser(this._iniFile);
let ini = Cc["@mozilla.org/xpcom/ini-parser-factory;1"]
.getService(Ci.nsIINIParserFactory)
.createINIParser(this._iniFile);
this.__defineGetter__("_ini", function() ini);
return this._ini;
},
@ -44,8 +45,8 @@ DistributionCustomizer.prototype = {
},
get _prefSvc() {
let svc = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService);
let svc = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService);
this.__defineGetter__("_prefSvc", function() svc);
return this._prefSvc;
},
@ -57,8 +58,8 @@ DistributionCustomizer.prototype = {
},
get _ioSvc() {
let svc = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
let svc = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
this.__defineGetter__("_ioSvc", function() svc);
return this._ioSvc;
},
@ -70,11 +71,12 @@ DistributionCustomizer.prototype = {
_parseBookmarksSection:
function(parentId, section) {
let keys = [];
for (let i in enumerate(this._ini.getKeys(section)))
for (let i in enumerate(this._ini.getKeys(section))) {
keys.push(i);
}
keys.sort();
let items = {};
let items = { };
let defaultItemId = -1;
let maxItemId = -1;
@ -84,11 +86,13 @@ DistributionCustomizer.prototype = {
let [foo, iid, iprop, ilocale] = m;
iid = parseInt(iid);
if (ilocale)
if (ilocale) {
continue;
}
if (!items[iid])
items[iid] = {};
if (!items[iid]) {
items[iid] = { };
}
if (keys.indexOf(keys[i] + "." + this._locale) >= 0) {
items[iid][iprop] = this._ini.getString(section, keys[i] + "." +
this._locale);
@ -96,11 +100,13 @@ DistributionCustomizer.prototype = {
items[iid][iprop] = this._ini.getString(section, keys[i]);
}
if (iprop == "type" && items[iid]["type"] == "default")
if (iprop == "type" && items[iid]["type"] == "default") {
defaultItemId = iid;
}
if (maxItemId < iid)
if (maxItemId < iid) {
maxItemId = iid;
}
} else {
dump("Key did not match: " + keys[i] + "\n");
}
@ -108,70 +114,76 @@ DistributionCustomizer.prototype = {
let prependIndex = 0;
for (let iid = 0; iid <= maxItemId; iid++) {
if (!items[iid])
if (!items[iid]) {
continue;
}
let index = PlacesUtils.bookmarks.DEFAULT_INDEX;
let newId;
switch (items[iid]["type"]) {
case "default":
break;
case "folder":
if (iid < defaultItemId)
index = prependIndex++;
newId = PlacesUtils.bookmarks.createFolder(parentId,
items[iid]["title"],
index);
this._parseBookmarksSection(newId, "BookmarksFolder-" +
items[iid]["folderId"]);
if (items[iid]["description"])
PlacesUtils.annotations.setItemAnnotation(newId,
"bookmarkProperties/description",
items[iid]["description"], 0,
PlacesUtils.annotations.EXPIRE_NEVER);
break;
case "separator":
if (iid < defaultItemId)
index = prependIndex++;
PlacesUtils.bookmarks.insertSeparator(parentId, index);
break;
case "livemark":
if (iid < defaultItemId)
index = prependIndex++;
// Don't bother updating the livemark contents on creation.
PlacesUtils.livemarks.addLivemark({ title: items[iid]["title"]
, parentId: parentId
, index: index
, feedURI: this._makeURI(items[iid]["feedLink"])
, siteURI: this._makeURI(items[iid]["siteLink"])
}).then(null, Cu.reportError);
break;
case "bookmark":
default:
if (iid < defaultItemId)
index = prependIndex++;
newId = PlacesUtils.bookmarks.insertBookmark(parentId,
this._makeURI(items[iid]["link"]),
index, items[iid]["title"]);
if (items[iid]["description"])
PlacesUtils.annotations.setItemAnnotation(newId,
"bookmarkProperties/description",
items[iid]["description"], 0,
PlacesUtils.annotations.EXPIRE_NEVER);
break;
case "default":
break;
case "folder":
if (iid < defaultItemId) {
index = prependIndex++;
}
newId = PlacesUtils.bookmarks.createFolder(parentId,
items[iid]["title"],
index);
this._parseBookmarksSection(newId, "BookmarksFolder-" +
items[iid]["folderId"]);
if (items[iid]["description"])
PlacesUtils.annotations.setItemAnnotation(newId,
"bookmarkProperties/description",
items[iid]["description"], 0,
PlacesUtils.annotations.EXPIRE_NEVER);
break;
case "separator":
if (iid < defaultItemId) {
index = prependIndex++;
}
PlacesUtils.bookmarks.insertSeparator(parentId, index);
break;
case "livemark":
if (iid < defaultItemId) {
index = prependIndex++;
}
// Don't bother updating the livemark contents on creation.
PlacesUtils.livemarks.addLivemark({ title: items[iid]["title"],
parentId: parentId,
index: index,
feedURI: this._makeURI(items[iid]["feedLink"]),
siteURI: this._makeURI(items[iid]["siteLink"])
}).then(null, Cu.reportError);
break;
case "bookmark":
// Fallthrough
default:
if (iid < defaultItemId) {
index = prependIndex++;
}
newId = PlacesUtils.bookmarks.insertBookmark(parentId,
this._makeURI(items[iid]["link"]),
index, items[iid]["title"]);
if (items[iid]["description"]) {
PlacesUtils.annotations.setItemAnnotation(newId, "bookmarkProperties/description",
items[iid]["description"], 0,
PlacesUtils.annotations.EXPIRE_NEVER);
}
break;
}
}
},
@ -179,8 +191,9 @@ DistributionCustomizer.prototype = {
_customizationsApplied: false,
applyCustomizations: function() {
this._customizationsApplied = true;
if (!this._iniFile)
if (!this._iniFile) {
return this._checkCustomizationComplete();
}
// nsPrefService loads very early. Reload prefs so we can set
// distribution defaults during the prefservice:after-app-defaults
@ -192,25 +205,27 @@ DistributionCustomizer.prototype = {
_bookmarksApplied: false,
applyBookmarks: function() {
this._bookmarksApplied = true;
if (!this._iniFile)
if (!this._iniFile) {
return this._checkCustomizationComplete();
}
let sections = enumToObject(this._ini.getSections());
// The global section, and several of its fields, is required
// (we also check here to be consistent with applyPrefDefaults below)
if (!sections["Global"])
if (!sections["Global"]) {
return this._checkCustomizationComplete();
}
let globalPrefs = enumToObject(this._ini.getKeys("Global"));
if (!(globalPrefs["id"] && globalPrefs["version"] && globalPrefs["about"]))
if (!(globalPrefs["id"] && globalPrefs["version"] && globalPrefs["about"])) {
return this._checkCustomizationComplete();
}
let bmProcessedPref;
try {
bmProcessedPref = this._ini.getString("Global",
"bookmarks.initialized.pref");
}
catch (e) {
} catch(e) {
bmProcessedPref = "distribution." +
this._ini.getString("Global", "id") + ".bookmarksProcessed";
}
@ -218,12 +233,14 @@ DistributionCustomizer.prototype = {
let bmProcessed = this._prefs.getBoolPref(bmProcessedPref, false);
if (!bmProcessed) {
if (sections["BookmarksMenu"])
if (sections["BookmarksMenu"]) {
this._parseBookmarksSection(PlacesUtils.bookmarksMenuFolderId,
"BookmarksMenu");
if (sections["BookmarksToolbar"])
}
if (sections["BookmarksToolbar"]) {
this._parseBookmarksSection(PlacesUtils.toolbarFolderId,
"BookmarksToolbar");
}
this._prefs.setBoolPref(bmProcessedPref, true);
}
return this._checkCustomizationComplete();
@ -232,17 +249,20 @@ DistributionCustomizer.prototype = {
_prefDefaultsApplied: false,
applyPrefDefaults: function() {
this._prefDefaultsApplied = true;
if (!this._iniFile)
if (!this._iniFile) {
return this._checkCustomizationComplete();
}
let sections = enumToObject(this._ini.getSections());
// The global section, and several of its fields, is required
if (!sections["Global"])
if (!sections["Global"]) {
return this._checkCustomizationComplete();
}
let globalPrefs = enumToObject(this._ini.getKeys("Global"));
if (!(globalPrefs["id"] && globalPrefs["version"] && globalPrefs["about"]))
if (!(globalPrefs["id"] && globalPrefs["version"] && globalPrefs["about"])) {
return this._checkCustomizationComplete();
}
let defaults = this._prefSvc.getDefaultBranch(null);
@ -253,8 +273,8 @@ DistributionCustomizer.prototype = {
defaults.setCharPref("distribution.version",
this._ini.getString("Global", "version"));
let partnerAbout = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString);
let partnerAbout = Cc["@mozilla.org/supports-string;1"]
.createInstance(Ci.nsISupportsString);
try {
if (globalPrefs["about." + this._locale]) {
partnerAbout.data = this._ini.getString("Global", "about." + this._locale);
@ -273,20 +293,22 @@ DistributionCustomizer.prototype = {
try {
let value = eval(this._ini.getString("Preferences", key));
switch (typeof value) {
case "boolean":
defaults.setBoolPref(key, value);
break;
case "number":
defaults.setIntPref(key, value);
break;
case "string":
defaults.setCharPref(key, value);
break;
case "undefined":
defaults.setCharPref(key, value);
break;
case "boolean":
defaults.setBoolPref(key, value);
break;
case "number":
defaults.setIntPref(key, value);
break;
case "string":
defaults.setCharPref(key, value);
break;
case "undefined":
defaults.setCharPref(key, value);
break;
}
} catch (e) { /* ignore bad prefs and move on */ }
} catch(e) {
/* ignore bad prefs and move on */
}
}
}
@ -294,8 +316,8 @@ DistributionCustomizer.prototype = {
// always get set as a string) to keep the INI format consistent:
// string prefs always need to be in quotes
let localizedStr = Cc["@mozilla.org/pref-localizedstring;1"].
createInstance(Ci.nsIPrefLocalizedString);
let localizedStr = Cc["@mozilla.org/pref-localizedstring;1"]
.createInstance(Ci.nsIPrefLocalizedString);
if (sections["LocalizablePreferences"]) {
for (let key in enumerate(this._ini.getKeys("LocalizablePreferences"))) {
@ -304,7 +326,9 @@ DistributionCustomizer.prototype = {
value = value.replace("%LOCALE%", this._locale, "g");
localizedStr.data = "data:text/plain," + key + "=" + value;
defaults.setComplexValue(key, Ci.nsIPrefLocalizedString, localizedStr);
} catch (e) { /* ignore bad prefs and move on */ }
} catch(e) {
/* ignore bad prefs and move on */
}
}
}
@ -314,7 +338,9 @@ DistributionCustomizer.prototype = {
let value = eval(this._ini.getString("LocalizablePreferences-" + this._locale, key));
localizedStr.data = "data:text/plain," + key + "=" + value;
defaults.setComplexValue(key, Ci.nsIPrefLocalizedString, localizedStr);
} catch (e) { /* ignore bad prefs and move on */ }
} catch(e) {
/* ignore bad prefs and move on */
}
}
}
@ -325,21 +351,23 @@ DistributionCustomizer.prototype = {
let prefDefaultsApplied = this._prefDefaultsApplied || !this._iniFile;
if (this._customizationsApplied && this._bookmarksApplied &&
prefDefaultsApplied) {
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let os = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
os.notifyObservers(null, DISTRIBUTION_CUSTOMIZATION_COMPLETE_TOPIC, null);
}
}
};
function enumerate(UTF8Enumerator) {
while (UTF8Enumerator.hasMore())
while (UTF8Enumerator.hasMore()) {
yield UTF8Enumerator.getNext();
}
}
function enumToObject(UTF8Enumerator) {
let ret = {};
for (let i in enumerate(UTF8Enumerator))
let ret = { };
for (let i in enumerate(UTF8Enumerator)) {
ret[i] = 1;
}
return ret;
}

@ -15,7 +15,7 @@ const ALLOW_SCRIPT = Ci.nsIAboutModule.ALLOW_SCRIPT;
const HIDE_FROM_ABOUTABOUT = Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT;
const MAKE_LINKABLE = Ci.nsIAboutModule.MAKE_LINKABLE;
function AboutRedirector() {}
function AboutRedirector() { }
AboutRedirector.prototype = {
classDescription: "Browser about: Redirector",
classID: Components.ID("{8cc51368-6aa0-43e8-b762-bde9b9fd828c}"),
@ -88,15 +88,17 @@ AboutRedirector.prototype = {
getURIFlags: function(aURI) {
let name = this._getModuleName(aURI);
if (!(name in this._redirMap))
if (!(name in this._redirMap)) {
throw Cr.NS_ERROR_ILLEGAL_VALUE;
}
return this._redirMap[name].flags;
},
newChannel: function(aURI, aLoadInfo) {
let name = this._getModuleName(aURI);
if (!(name in this._redirMap))
if (!(name in this._redirMap)) {
throw Cr.NS_ERROR_ILLEGAL_VALUE;
}
let newURI = Services.io.newURI(this._redirMap[name].url, null, null);
let channel = Services.io.newChannelFromURIWithLoadInfo(newURI, aLoadInfo);

@ -41,11 +41,12 @@ const NS_ERROR_WONT_HANDLE_CONTENT = 0x805d0001;
const NS_ERROR_ABORT = Components.results.NS_ERROR_ABORT;
const URI_INHERITS_SECURITY_CONTEXT = Components.interfaces.nsIHttpProtocolHandler
.URI_INHERITS_SECURITY_CONTEXT;
.URI_INHERITS_SECURITY_CONTEXT;
function shouldLoadURI(aURI) {
if (aURI && !aURI.schemeIs("chrome"))
if (aURI && !aURI.schemeIs("chrome")) {
return true;
}
dump("*** Preventing external load of chrome: URI into browser window\n");
dump(" Use -chrome <uri> instead\n");
@ -63,10 +64,10 @@ function resolveURIInternal(aCmdLine, aArgument) {
}
try {
if (uri.file.exists())
if (uri.file.exists()) {
return uri;
}
catch (e) {
}
} catch(e) {
Components.utils.reportError(e);
}
@ -75,8 +76,7 @@ function resolveURIInternal(aCmdLine, aArgument) {
try {
uri = urifixup.createFixupURI(aArgument, 0);
}
catch (e) {
} catch(e) {
Components.utils.reportError(e);
}
@ -102,8 +102,9 @@ const OVERRIDE_NEW_BUILD_ID = 3;
function needHomepageOverride(prefb) {
var savedmstone = prefb.getCharPref("browser.startup.homepage_override.mstone", "");
if (savedmstone == "ignore")
if (savedmstone == "ignore") {
return OVERRIDE_NONE;
}
var mstone = Services.appinfo.platformVersion;
@ -116,8 +117,9 @@ function needHomepageOverride(prefb) {
// agreement if the platform's installer had already shown one. Now with
// about:rights we've removed the EULA stuff and default pref, but we need
// a way to make existing profiles retain the default that we removed.
if (savedmstone)
if (savedmstone) {
prefb.setBoolPref("browser.rights.3.shown", true);
}
prefb.setCharPref("browser.startup.homepage_override.mstone", mstone);
prefb.setCharPref("browser.startup.homepage_override.buildID", buildID);
@ -146,7 +148,7 @@ function getPostUpdateOverridePage(defaultOverridePage) {
// If the updates.xml file is deleted then getUpdateAt will throw.
var update = um.getUpdateAt(0)
.QueryInterface(Components.interfaces.nsIPropertyBag);
} catch (e) {
} catch(e) {
// This should never happen.
Components.utils.reportError("Unable to find update: " + e);
return defaultOverridePage;
@ -155,13 +157,15 @@ function getPostUpdateOverridePage(defaultOverridePage) {
let actions = update.getProperty("actions");
// When the update doesn't specify actions fallback to the original behavior
// of displaying the default override page.
if (!actions)
if (!actions) {
return defaultOverridePage;
}
// The existence of silent or the non-existence of showURL in the actions both
// mean that an override page should not be displayed.
if (actions.indexOf("silent") != -1 || actions.indexOf("showURL") == -1)
if (actions.indexOf("silent") != -1 || actions.indexOf("showURL") == -1) {
return "";
}
return update.getProperty("openURL") || defaultOverridePage;
}
@ -187,19 +191,22 @@ function openWindow(parent, url, target, features, args, noExternalArgs) {
// Pass an array to avoid the browser "|"-splitting behavior.
var argArray = Components.classes["@mozilla.org/supports-array;1"]
.createInstance(Components.interfaces.nsISupportsArray);
.createInstance(Components.interfaces.nsISupportsArray);
// add args to the arguments array
var stringArgs = null;
if (args instanceof Array) // array
if (args instanceof Array) {
// array
stringArgs = args;
else if (args) // string
} else if (args) {
// string
stringArgs = [args];
}
if (stringArgs) {
// put the URIs into argArray
var uriArray = Components.classes["@mozilla.org/supports-array;1"]
.createInstance(Components.interfaces.nsISupportsArray);
.createInstance(Components.interfaces.nsISupportsArray);
stringArgs.forEach(function(uri) {
var sstring = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(nsISupportsString);
@ -272,22 +279,22 @@ function doSearch(searchTerm, cmdLine) {
sa);
}
function nsBrowserContentHandler() {
}
function nsBrowserContentHandler() { }
nsBrowserContentHandler.prototype = {
classID: Components.ID("{5d0ce354-df01-421a-83fb-7ead0990c24e}"),
_xpcom_factory: {
createInstance: function(outer, iid) {
if (outer)
if (outer) {
throw Components.results.NS_ERROR_NO_AGGREGATION;
}
return gBrowserContentHandler.QueryInterface(iid);
}
},
/* helper functions */
mChromeURL : null,
mChromeURL: null,
get chromeURL() {
if (this.mChromeURL) {
@ -302,13 +309,13 @@ nsBrowserContentHandler.prototype = {
},
/* nsISupports */
QueryInterface : XPCOMUtils.generateQI([nsICommandLineHandler,
QueryInterface: XPCOMUtils.generateQI([ nsICommandLineHandler,
nsIBrowserHandler,
nsIContentHandler,
nsICommandLineValidator]),
nsICommandLineValidator ]),
/* nsICommandLineHandler */
handle : function(cmdLine) {
handle: function(cmdLine) {
if (cmdLine.handleFlag("browser", false)) {
// Passing defaultArgs, so use NO_EXTERNAL_URIS
openWindow(null, this.chromeURL, "_blank",
@ -319,8 +326,7 @@ nsBrowserContentHandler.prototype = {
try {
var remoteCommand = cmdLine.handleFlagWithParam("remote", true);
}
catch (e) {
} catch(e) {
throw NS_ERROR_ABORT;
}
@ -332,63 +338,63 @@ nsBrowserContentHandler.prototype = {
remoteVerb = a[1].toLowerCase();
var remoteParams = [];
var sepIndex = a[2].lastIndexOf(",");
if (sepIndex == -1)
if (sepIndex == -1) {
remoteParams[0] = a[2];
else {
} else {
remoteParams[0] = a[2].substring(0, sepIndex);
remoteParams[1] = a[2].substring(sepIndex + 1);
}
}
switch (remoteVerb) {
case "openurl":
case "openfile":
// openURL(<url>)
// openURL(<url>,new-window)
// openURL(<url>,new-tab)
// First param is the URL, second param (if present) is the "target"
// (tab, window)
var url = remoteParams[0];
var target = nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW;
if (remoteParams[1]) {
var targetParam = remoteParams[1].toLowerCase()
.replace(/^\s*|\s*$/g, "");
if (targetParam == "new-tab")
target = nsIBrowserDOMWindow.OPEN_NEWTAB;
else if (targetParam == "new-window")
target = nsIBrowserDOMWindow.OPEN_NEWWINDOW;
else {
// The "target" param isn't one of our supported values, so
// assume it's part of a URL that contains commas.
url += "," + remoteParams[1];
case "openurl":
case "openfile":
// openURL(<url>)
// openURL(<url>,new-window)
// openURL(<url>,new-tab)
// First param is the URL, second param (if present) is the "target"
// (tab, window)
var url = remoteParams[0];
var target = nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW;
if (remoteParams[1]) {
var targetParam = remoteParams[1].toLowerCase()
.replace(/^\s*|\s*$/g, "");
if (targetParam == "new-tab") {
target = nsIBrowserDOMWindow.OPEN_NEWTAB;
} else if (targetParam == "new-window") {
target = nsIBrowserDOMWindow.OPEN_NEWWINDOW;
} else {
// The "target" param isn't one of our supported values, so
// assume it's part of a URL that contains commas.
url += "," + remoteParams[1];
}
}
}
var uri = resolveURIInternal(cmdLine, url);
handURIToExistingBrowser(uri, target, cmdLine);
break;
case "xfedocommand":
// xfeDoCommand(openBrowser)
if (remoteParams[0].toLowerCase() != "openbrowser")
throw NS_ERROR_ABORT;
// Passing defaultArgs, so use NO_EXTERNAL_URIS
openWindow(null, this.chromeURL, "_blank",
"chrome,dialog=no,all" + this.getFeatures(cmdLine),
this.defaultArgs, NO_EXTERNAL_URIS);
break;
default:
// Somebody sent us a remote command we don't know how to process:
// just abort.
throw "Unknown remote command.";
var uri = resolveURIInternal(cmdLine, url);
handURIToExistingBrowser(uri, target, cmdLine);
break;
case "xfedocommand":
// xfeDoCommand(openBrowser)
if (remoteParams[0].toLowerCase() != "openbrowser") {
throw NS_ERROR_ABORT;
}
// Passing defaultArgs, so use NO_EXTERNAL_URIS
openWindow(null, this.chromeURL, "_blank",
"chrome,dialog=no,all" + this.getFeatures(cmdLine),
this.defaultArgs, NO_EXTERNAL_URIS);
break;
default:
// Somebody sent us a remote command we don't know how to process:
// just abort.
throw "Unknown remote command.";
}
cmdLine.preventDefault = true;
}
catch (e) {
} catch (e) {
Components.utils.reportError(e);
// If we had a -remote flag but failed to process it, throw
// NS_ERROR_ABORT so that the xremote code knows to return a failure
@ -401,15 +407,15 @@ nsBrowserContentHandler.prototype = {
try {
while ((uriparam = cmdLine.handleFlagWithParam("new-window", false))) {
var uri = resolveURIInternal(cmdLine, uriparam);
if (!shouldLoadURI(uri))
if (!shouldLoadURI(uri)) {
continue;
}
openWindow(null, this.chromeURL, "_blank",
"chrome,dialog=no,all" + this.getFeatures(cmdLine),
uri.spec);
cmdLine.preventDefault = true;
}
}
catch (e) {
} catch(e) {
Components.utils.reportError(e);
}
@ -419,8 +425,7 @@ nsBrowserContentHandler.prototype = {
handURIToExistingBrowser(uri, nsIBrowserDOMWindow.OPEN_NEWTAB, cmdLine);
cmdLine.preventDefault = true;
}
}
catch (e) {
} catch(e) {
Components.utils.reportError(e);
}
@ -431,27 +436,29 @@ nsBrowserContentHandler.prototype = {
if (chromeParam == "chrome://browser/content/pref/pref.xul") {
openPreferences();
cmdLine.preventDefault = true;
} else try {
// only load URIs which do not inherit chrome privs
var features = "chrome,dialog=no,all" + this.getFeatures(cmdLine);
var uri = resolveURIInternal(cmdLine, chromeParam);
var netutil = Components.classes["@mozilla.org/network/util;1"]
.getService(nsINetUtil);
if (!netutil.URIChainHasFlags(uri, URI_INHERITS_SECURITY_CONTEXT)) {
openWindow(null, uri.spec, "_blank", features);
cmdLine.preventDefault = true;
}
}
catch (e) {
} else {
try {
// only load URIs which do not inherit chrome privs
var features = "chrome,dialog=no,all" + this.getFeatures(cmdLine);
var uri = resolveURIInternal(cmdLine, chromeParam);
var netutil = Components.classes["@mozilla.org/network/util;1"]
.getService(nsINetUtil);
if (!netutil.URIChainHasFlags(uri, URI_INHERITS_SECURITY_CONTEXT)) {
openWindow(null, uri.spec, "_blank", features);
cmdLine.preventDefault = true;
}
} catch(e) {
Components.utils.reportError(e);
}
}
}
if (cmdLine.handleFlag("preferences", false)) {
openPreferences();
cmdLine.preventDefault = true;
}
if (cmdLine.handleFlag("silent", false))
if (cmdLine.handleFlag("silent", false)) {
cmdLine.preventDefault = true;
}
try {
var privateWindowParam = cmdLine.handleFlagWithParam("private-window", false);
@ -460,15 +467,15 @@ nsBrowserContentHandler.prototype = {
handURIToExistingBrowser(resolvedURI, nsIBrowserDOMWindow.OPEN_NEWTAB, cmdLine, true);
cmdLine.preventDefault = true;
}
} catch (e) {
} catch(e) {
if (e.result != Components.results.NS_ERROR_INVALID_ARG) {
throw e;
}
// NS_ERROR_INVALID_ARG is thrown when flag exists, but has no param.
if (cmdLine.handleFlag("private-window", false)) {
openWindow(null, this.chromeURL, "_blank",
"chrome,dialog=no,private,all" + this.getFeatures(cmdLine),
"about:privatebrowsing");
"chrome,dialog=no,private,all" + this.getFeatures(cmdLine),
"about:privatebrowsing");
cmdLine.preventDefault = true;
}
}
@ -512,16 +519,12 @@ nsBrowserContentHandler.prototype = {
#endif
},
helpInfo : " --browser Open a browser window.\n" +
" --new-window <url> Open <url> in a new window.\n" +
" --new-tab <url> Open <url> in a new tab.\n" +
" --private-window <url> Open <url> in a new private window.\n" +
#ifdef XP_WIN
" --preferences Open Options dialog.\n" +
#else
" --preferences Open Preferences dialog.\n" +
#endif
" --search <term> Search <term> with your default search engine.\n",
helpInfo: " --browser Open a browser window.\n" +
" --new-window <url> Open <url> in a new window.\n" +
" --new-tab <url> Open <url> in a new tab.\n" +
" --private-window <url> Open <url> in a new private window.\n" +
" --preferences Open Preferences dialog.\n" +
" --search <term> Search <term> with your default search engine.\n",
/* nsIBrowserHandler */
@ -559,31 +562,36 @@ nsBrowserContentHandler.prototype = {
.getService(Components.interfaces.nsISessionStartup);
haveUpdateSession = ss.doRestore();
overridePage = Services.urlFormatter.formatURLPref("startup.homepage_override_url");
if (prefb.prefHasUserValue("app.update.postupdate"))
if (prefb.prefHasUserValue("app.update.postupdate")) {
overridePage = getPostUpdateOverridePage(overridePage);
}
overridePage = overridePage.replace("%OLD_VERSION%", old_mstone);
break;
}
}
} catch (ex) {}
} catch(ex) {
}
// formatURLPref might return "about:blank" if getting the pref fails
if (overridePage == "about:blank")
if (overridePage == "about:blank") {
overridePage = "";
}
var startPage = "";
try {
var choice = prefb.getIntPref("browser.startup.page");
if (choice == 1 || choice == 3)
if (choice == 1 || choice == 3) {
startPage = this.startPage;
} catch (e) {
}
} catch(e) {
Components.utils.reportError(e);
}
// Only show the startPage if we're not restoring an update session.
if (overridePage && startPage && !haveUpdateSession)
if (overridePage && startPage && !haveUpdateSession) {
return overridePage + "|" + startPage;
}
return overridePage || startPage || "about:logopage";
},
@ -599,9 +607,9 @@ nsBrowserContentHandler.prototype = {
return uri;
},
mFeatures : null,
mFeatures: null,
getFeatures : function(cmdLine) {
getFeatures: function(cmdLine) {
if (this.mFeatures === null) {
this.mFeatures = "";
@ -609,12 +617,13 @@ nsBrowserContentHandler.prototype = {
var width = cmdLine.handleFlagWithParam("width", false);
var height = cmdLine.handleFlagWithParam("height", false);
if (width)
if (width) {
this.mFeatures += ",width=" + width;
if (height)
}
if (height) {
this.mFeatures += ",height=" + height;
}
catch (e) {
}
} catch(e) {
}
// The global PB Service consumes this flag, so only eat it in per-window
@ -629,25 +638,24 @@ nsBrowserContentHandler.prototype = {
/* nsIContentHandler */
handleContent : function(contentType, context, request) {
handleContent: function(contentType, context, request) {
try {
var webNavInfo = Components.classes["@mozilla.org/webnavigation-info;1"]
.getService(nsIWebNavigationInfo);
if (!webNavInfo.isTypeSupported(contentType, null)) {
throw NS_ERROR_WONT_HANDLE_CONTENT;
}
} catch (e) {
} catch(e) {
throw NS_ERROR_WONT_HANDLE_CONTENT;
}
request.QueryInterface(nsIChannel);
handURIToExistingBrowser(request.URI,
nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW, null);
handURIToExistingBrowser(request.URI, nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW, null);
request.cancel(NS_BINDING_ABORTED);
},
/* nsICommandLineValidator */
validate : function(cmdLine) {
validate: function(cmdLine) {
// Other handlers may use osint so only handle the osint flag if the url
// flag is also present and the command line is valid.
var osintFlagIdx = cmdLine.findFlag("osint", false);
@ -655,18 +663,20 @@ nsBrowserContentHandler.prototype = {
if (urlFlagIdx > -1 && (osintFlagIdx > -1 ||
cmdLine.state == nsICommandLine.STATE_REMOTE_EXPLICIT)) {
var urlParam = cmdLine.getArgument(urlFlagIdx + 1);
if (cmdLine.length != urlFlagIdx + 2 || /firefoxurl:/.test(urlParam))
if (cmdLine.length != urlFlagIdx + 2 || /firefoxurl:/.test(urlParam)) {
throw NS_ERROR_ABORT;
}
cmdLine.handleFlag("osint", false)
}
},
};
var gBrowserContentHandler = new nsBrowserContentHandler();
function handURIToExistingBrowser(uri, location, cmdLine, forcePrivate)
{
if (!shouldLoadURI(uri))
function handURIToExistingBrowser(uri, location, cmdLine, forcePrivate) {
if (!shouldLoadURI(uri)) {
return;
}
// Unless using a private window is forced, open external links in private
// windows only if we're in perma-private mode.
@ -692,14 +702,12 @@ function handURIToExistingBrowser(uri, location, cmdLine, forcePrivate)
nsIBrowserDOMWindow.OPEN_EXTERNAL);
}
function nsDefaultCommandLineHandler() {
}
function nsDefaultCommandLineHandler() { }
nsDefaultCommandLineHandler.prototype = {
classID: Components.ID("{47cd0651-b1be-4a0f-b5c4-10e5a573ef71}"),
/* nsISupports */
QueryInterface : function(iid) {
QueryInterface: function(iid) {
if (!iid.equals(nsISupports) &&
!iid.equals(nsICommandLineHandler))
throw Components.results.NS_ERROR_NO_INTERFACE;
@ -712,7 +720,7 @@ nsDefaultCommandLineHandler.prototype = {
#endif
/* nsICommandLineHandler */
handle : function(cmdLine) {
handle: function(cmdLine) {
var urilist = [];
#ifdef XP_WIN
@ -729,8 +737,7 @@ nsDefaultCommandLineHandler.prototype = {
.getService(Components.interfaces.nsIProperties);
var dir = fl.get("ProfD", Components.interfaces.nsILocalFile);
this._haveProfile = true;
}
catch (e) {
} catch(e) {
while ((ar = cmdLine.handleFlagWithParam("url", false))) { }
cmdLine.preventDefault = true;
}
@ -743,8 +750,7 @@ nsDefaultCommandLineHandler.prototype = {
var uri = resolveURIInternal(cmdLine, ar);
urilist.push(uri);
}
}
catch (e) {
} catch(e) {
Components.utils.reportError(e);
}
@ -760,8 +766,7 @@ nsDefaultCommandLineHandler.prototype = {
} else {
try {
urilist.push(resolveURIInternal(cmdLine, curarg));
}
catch (e) {
} catch(e) {
Components.utils.reportError("Error opening URI '" + curarg + "' from the command line: " + e + "\n");
}
}
@ -775,8 +780,7 @@ nsDefaultCommandLineHandler.prototype = {
try {
handURIToExistingBrowser(urilist[0], nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW, cmdLine);
return;
}
catch (e) {
} catch(e) {
}
}
@ -787,8 +791,7 @@ nsDefaultCommandLineHandler.prototype = {
URLlist);
}
}
else if (!cmdLine.preventDefault) {
} else if (!cmdLine.preventDefault) {
// Passing defaultArgs, so use NO_EXTERNAL_URIS
openWindow(null, gBrowserContentHandler.chromeURL, "_blank",
"chrome,dialog=no,all" + gBrowserContentHandler.getFeatures(cmdLine),

@ -69,10 +69,12 @@ const BOOKMARKS_BACKUP_MAX_BACKUPS = 10;
const BrowserGlueServiceFactory = {
_instance: null,
createInstance: function(outer, iid) {
if (outer != null)
if (outer != null) {
throw Components.results.NS_ERROR_NO_AGGREGATION;
}
return this._instance == null ?
this._instance = new BrowserGlue() : this._instance;
this._instance = new BrowserGlue() :
this._instance;
}
};
@ -90,7 +92,7 @@ function BrowserGlue() {
XPCOMUtils.defineLazyGetter(this, "_sanitizer",
function() {
let sanitizerScope = {};
let sanitizerScope = { };
Services.scriptloader.loadSubScript("chrome://browser/content/sanitize.js", sanitizerScope);
return sanitizerScope.Sanitizer;
});
@ -114,8 +116,9 @@ BrowserGlue.prototype = {
_migrationImportsDefaultBookmarks: false,
_setPrefToSaveSession: function(aForce) {
if (!this._saveSession && !aForce)
if (!this._saveSession && !aForce) {
return;
}
Services.prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
@ -131,8 +134,9 @@ BrowserGlue.prototype = {
if (Services.prefs.prefHasUserValue("services.sync.autoconnectDelay")) {
let prefDelay = Services.prefs.getIntPref("services.sync.autoconnectDelay");
if (prefDelay > 0)
if (prefDelay > 0) {
return;
}
}
// delays are in seconds
@ -184,7 +188,7 @@ BrowserGlue.prototype = {
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].
getService(Ci.nsIAppStartup);
appStartup.trackStartupCrashEnd();
} catch (e) {
} catch(e) {
Cu.reportError("Could not end startup crash tracking in quit-application-granted: " + e);
}
DateTimePickerHelper.uninit();
@ -213,8 +217,9 @@ BrowserGlue.prototype = {
subject.data = true;
break;
case "places-init-complete":
if (!this._migrationImportsDefaultBookmarks)
if (!this._migrationImportsDefaultBookmarks) {
this._initPlaces(false);
}
Services.obs.removeObserver(this, "places-init-complete");
this._isPlacesInitObserver = false;
@ -249,18 +254,16 @@ BrowserGlue.prototype = {
break;
case "browser-glue-test": // used by tests
if (data == "post-update-notification") {
if (Services.prefs.prefHasUserValue("app.update.postupdate"))
if (Services.prefs.prefHasUserValue("app.update.postupdate")) {
this._showUpdateNotification();
}
else if (data == "force-ui-migration") {
}
} else if (data == "force-ui-migration") {
this._migrateUI();
}
else if (data == "force-distribution-customization") {
} else if (data == "force-distribution-customization") {
this._distributionCustomizer.applyPrefDefaults();
this._distributionCustomizer.applyCustomizations();
// To apply distribution bookmarks use "places-init-complete".
}
else if (data == "force-places-init") {
} else if (data == "force-places-init") {
this._initPlaces(false);
}
break;
@ -296,16 +299,19 @@ BrowserGlue.prototype = {
// No need to initialize the search service, since it's guaranteed to be
// initialized already when this notification fires.
let ss = Services.search;
if (ss.currentEngine.name == ss.defaultEngine.name)
if (ss.currentEngine.name == ss.defaultEngine.name) {
return;
if (data == "engine-current")
}
if (data == "engine-current") {
ss.defaultEngine = ss.currentEngine;
else
} else {
ss.currentEngine = ss.defaultEngine;
}
break;
case "browser-search-service":
if (data != "init-complete")
if (data != "init-complete") {
return;
}
Services.obs.removeObserver(this, "browser-search-service");
this._syncSearchEngines();
break;
@ -374,21 +380,26 @@ BrowserGlue.prototype = {
os.removeObserver(this, "weave:engine:clients:display-uri");
#endif
os.removeObserver(this, "session-save");
if (this._isIdleObserver)
if (this._isIdleObserver) {
this._idleService.removeIdleObserver(this, BOOKMARKS_BACKUP_IDLE_TIME);
if (this._isPlacesInitObserver)
}
if (this._isPlacesInitObserver) {
os.removeObserver(this, "places-init-complete");
if (this._isPlacesLockedObserver)
}
if (this._isPlacesLockedObserver) {
os.removeObserver(this, "places-database-locked");
if (this._isPlacesShutdownObserver)
}
if (this._isPlacesShutdownObserver) {
os.removeObserver(this, "places-shutdown");
}
os.removeObserver(this, "handle-xul-text-link");
os.removeObserver(this, "profile-before-change");
os.removeObserver(this, "browser-search-engine-modified");
try {
os.removeObserver(this, "browser-search-service");
} catch(ex) {
// may have already been removed by the observer
} catch (ex) {}
}
},
_onAppDefaults: function() {
@ -441,9 +452,12 @@ BrowserGlue.prototype = {
let cookies;
try {
cookies = aHttpChannel.getRequestHeader("Cookie");
} catch (e) { /* no cookie sent */ }
if (cookies && cookies.indexOf("MoodleSession") > -1)
} catch(e) {
// no cookie sent
}
if (cookies && cookies.indexOf("MoodleSession") > -1) {
return aOriginalUA.replace(/Goanna\/[^ ]*/, "Goanna/20100101");
}
return null;
});
}
@ -451,8 +465,9 @@ BrowserGlue.prototype = {
_trackSlowStartup: function() {
if (Services.startup.interrupted ||
Services.prefs.getBoolPref("browser.slowStartup.notificationDisabled"))
Services.prefs.getBoolPref("browser.slowStartup.notificationDisabled")) {
return;
}
let currentTime = Date.now() - Services.startup.getStartupInfo().process;
let averageTime = 0;
@ -460,13 +475,15 @@ BrowserGlue.prototype = {
try {
averageTime = Services.prefs.getIntPref("browser.slowStartup.averageTime");
samples = Services.prefs.getIntPref("browser.slowStartup.samples");
} catch (e) { }
} catch(e) {
}
averageTime = (averageTime * samples + currentTime) / ++samples;
if (samples >= Services.prefs.getIntPref("browser.slowStartup.maxSamples")) {
if (averageTime > Services.prefs.getIntPref("browser.slowStartup.timeThreshold"))
if (averageTime > Services.prefs.getIntPref("browser.slowStartup.timeThreshold")) {
this._showSlowStartupNotification();
}
averageTime = 0;
samples = 0;
}
@ -477,8 +494,9 @@ BrowserGlue.prototype = {
_showSlowStartupNotification: function() {
let win = this.getMostRecentBrowserWindow();
if (!win)
if (!win) {
return;
}
let productName = gBrandBundle.GetStringFromName("brandFullName");
let message = win.gNavigatorBundle.getFormattedString("slowStartup.message", [productName]);
@ -509,7 +527,7 @@ BrowserGlue.prototype = {
// the first browser window has finished initializing
_onFirstWindowLoaded: function() {
#ifdef XP_WIN
// For windows seven, initialize the jump list module.
// For Windows, initialize the jump list module.
const WINTASKBAR_CONTRACTID = "@mozilla.org/windows-taskbar;1";
if (WINTASKBAR_CONTRACTID in Cc &&
Cc[WINTASKBAR_CONTRACTID].getService(Ci.nsIWinTaskbar).available) {
@ -543,8 +561,9 @@ BrowserGlue.prototype = {
// All initial windows have opened.
_onWindowsRestored: function() {
// Show update notification, if needed.
if (Services.prefs.prefHasUserValue("app.update.postupdate"))