Skip to content

Commit

Permalink
Remove Firefox 3.x specific calls to compareFirefoxVersion().
Browse files Browse the repository at this point in the history
  • Loading branch information
arantius committed Jun 15, 2012
1 parent 80a07f1 commit 50da6eb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 67 deletions.
40 changes: 6 additions & 34 deletions components/greasemonkey.js
Expand Up @@ -27,7 +27,7 @@ var gExtensionPath = (function() {
})();

// Only a particular set of strings are allowed. See: http://goo.gl/ex2LJ
var gMaxJSVersion = "1.8";
var gMaxJSVersion = "ECMAv5";
var gGreasemonkeyVersion = 'unknown';

var gMenuCommands = [];
Expand Down Expand Up @@ -93,13 +93,7 @@ function createSandbox(
}

var unsafeWin = aContentWin.wrappedJSObject;
sandbox = new Components.utils.Sandbox(aContentWin);

if (GM_util.compareFirefoxVersion("4.0") < 0) {
// Fixes .. something confusing. Must be before __proto__ assignment.
// See #1192
sandbox.document = aContentWin.document;
}
var sandbox = new Components.utils.Sandbox(aContentWin);

sandbox.__proto__ = aContentWin;
sandbox.unsafeWindow = unsafeWin;
Expand Down Expand Up @@ -234,22 +228,10 @@ function isTempScript(uri) {
}

function loadGreasemonkeyVersion() {
// Find the new version, and call the continuation when ready. (Firefox 4+
// gives us only an async API, requiring this cumbersome setup.)
if (GM_util.compareFirefoxVersion("4.0") < 0) {
// This is too early for Firefox 3. Sloppy timeout workaround.
GM_util.timeout(function() {
var extMan = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
var item = extMan.getItemForID(GM_GUID);
gGreasemonkeyVersion = new String(item.version);
}, 0);
} else {
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID(GM_GUID, function(addon) {
gGreasemonkeyVersion = new String(addon.version);
});
}
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID(GM_GUID, function(addon) {
gGreasemonkeyVersion = new String(addon.version);
});
}

function openInTab(safeContentWin, chromeWin, url, aLoadInBackground) {
Expand Down Expand Up @@ -364,16 +346,6 @@ function startup() {
loader.loadSubScript("chrome://greasemonkey/content/xmlhttprequester.js");
loader.loadSubScript("chrome://greasemonkey/content/third-party/mpl-utils.js");

if (GM_util.compareFirefoxVersion("4.0") >= 0) {
gMaxJSVersion = "ECMAv5";
}

// Firefox <4 reports a different stack.fileName for the module.
if (GM_util.compareFirefoxVersion("4.0") < 0) {
// Pull the name out of the variable the module exports.
gmRunScriptFilename = GM_runScript_filename;
}

loadGreasemonkeyVersion();
}

Expand Down
11 changes: 1 addition & 10 deletions content/browser.js
Expand Up @@ -70,16 +70,7 @@ GM_BrowserUI.chromeLoad = function(e) {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(GM_BrowserUI, "install-userscript", true);

// Since Firefox 3 does not give us inner-window-destroyed, which is exactly
// what we want, instead we listen for dom-window-destroyed, which comes
// pretty close (at least it doesn't leak memory). But: listening for dom-
// in Firefox 4 causes breakage, so we just do either-or.
if (GM_util.compareFirefoxVersion("4.0") >= 0) {
observerService.addObserver(GM_BrowserUI, "inner-window-destroyed", true);
} else {
observerService.addObserver(GM_BrowserUI, "dom-window-destroyed", true);
}
observerService.addObserver(GM_BrowserUI, "inner-window-destroyed", true);

// we use this to determine if we are the active window sometimes
GM_BrowserUI.winWat = Components
Expand Down
8 changes: 3 additions & 5 deletions content/config.js
Expand Up @@ -152,11 +152,9 @@ Config.prototype.install = function(script, oldScript) {
}

if (oldScript) {
if (GM_util.compareFirefoxVersion('4.0') >= 0) {
var scope = {};
Components.utils.import('resource://greasemonkey/addons4.js', scope);
scope.ScriptAddonReplaceScript(script);
}
var scope = {};
Components.utils.import('resource://greasemonkey/addons4.js', scope);
scope.ScriptAddonReplaceScript(script);
this._changed(script, 'modified', oldScript.id);
} else {
this._changed(script, 'install', existingIndex);
Expand Down
32 changes: 14 additions & 18 deletions modules/script.js
Expand Up @@ -683,26 +683,22 @@ Script.prototype.checkRemoteVersionErr = function(lastCheck, aCallback) {
};

Script.prototype.handleRemoteUpdate = function(aAvailable, aListener) {
if (GM_util.compareFirefoxVersion("4.0") < 0) {
if (aAvailable) this.installUpdate();
} else {
var addons4 = {};
Components.utils.import('resource://greasemonkey/addons4.js', addons4);
var addon = addons4.ScriptAddonFactoryByScript(this);
var scriptInstall = addons4.ScriptInstallFactoryByAddon(addon);
if (aListener) {
// When in the add-ons manager, listeners are passed around to keep
// the UI up to date.
if (aAvailable) {
AddonManagerPrivate.callAddonListeners("onNewInstall", scriptInstall);
aListener.onUpdateAvailable(addon, scriptInstall);
} else {
aListener.onNoUpdateAvailable(addon);
}
var addons4 = {};
Components.utils.import('resource://greasemonkey/addons4.js', addons4);
var addon = addons4.ScriptAddonFactoryByScript(this);
var scriptInstall = addons4.ScriptInstallFactoryByAddon(addon);
if (aListener) {
// When in the add-ons manager, listeners are passed around to keep
// the UI up to date.
if (aAvailable) {
AddonManagerPrivate.callAddonListeners("onNewInstall", scriptInstall);
aListener.onUpdateAvailable(addon, scriptInstall);
} else {
// Otherwise, just install.
if (aAvailable) scriptInstall.install();
aListener.onNoUpdateAvailable(addon);
}
} else {
// Otherwise, just install.
if (aAvailable) scriptInstall.install();
}
}

Expand Down

0 comments on commit 50da6eb

Please sign in to comment.