Bug 1134518 - Use the globalMM for ContentTask's frame script to prevent it from being loaded twice into a docShell swapped to another browser window r=bustage

This commit is contained in:
Tim Taubert 2015-04-24 11:06:27 +02:00
parent 6d9ebde0b8
commit 08f3961c3b

View File

@ -15,6 +15,14 @@ Cu.import("resource://gre/modules/Promise.jsm");
const FRAME_SCRIPT = "chrome://mochikit/content/tests/BrowserTestUtils/content-task.js";
const globalMM = Cc["@mozilla.org/globalmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager);
/**
* Keeps track of whether the frame script was already loaded.
*/
let gFrameScriptLoaded = false;
/**
* Mapping from message id to associated promise.
*/
@ -47,12 +55,10 @@ this.ContentTask = {
* @rejects An error message if execution fails.
*/
spawn: function ContentTask_spawn(browser, arg, task) {
let mm = browser.ownerDocument.defaultView.messageManager;
let scripts = mm.getDelayedFrameScripts();
// Load the frame script if needed.
if (!scripts.find(script => script[0] == FRAME_SCRIPT)) {
mm.loadFrameScript(FRAME_SCRIPT, true);
if (!gFrameScriptLoaded) {
globalMM.loadFrameScript(FRAME_SCRIPT, true);
gFrameScriptLoaded = true;
}
let deferred = {};