Bug 1254091 - part 2: fix focus messaging from SpecialPowers to refer to the right window, r?enndeakin
MozReview-Commit-ID: DMnK23GoerQ
--- a/testing/specialpowers/content/specialpowersAPI.js
+++ b/testing/specialpowers/content/specialpowersAPI.js
@@ -2,16 +2,18 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* This code is loaded in every child process that is started by mochitest in
* order to be used as a replacement for UniversalXPConnect
*/
"use strict";
+var global = this;
+
var Ci = Components.interfaces;
var Cc = Components.classes;
var Cu = Components.utils;
Cu.import("chrome://specialpowers/content/MockFilePicker.jsm");
Cu.import("chrome://specialpowers/content/MockColorPicker.jsm");
Cu.import("chrome://specialpowers/content/MockPermissionPrompt.jsm");
Cu.import("resource://gre/modules/Services.jsm");
@@ -1619,17 +1621,24 @@ SpecialPowersAPI.prototype = {
return this.focusManager.focusedWindow;
},
focus: function(aWindow) {
// This is called inside TestRunner._makeIframe without aWindow, because of assertions in oop mochitests
// With aWindow, it is called in SimpleTest.waitForFocus to allow popup window opener focus switching
if (aWindow)
aWindow.focus();
- sendAsyncMessage("SpecialPowers.Focus", {});
+ var mm = global;
+ if (aWindow) {
+ mm = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDocShell)
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIContentFrameMessageManager);
+ }
+ mm.sendAsyncMessage("SpecialPowers.Focus", {});
},
getClipboardData: function(flavor, whichClipboard) {
if (this._cb == null)
this._cb = Components.classes["@mozilla.org/widget/clipboard;1"].
getService(Components.interfaces.nsIClipboard);
if (whichClipboard === undefined)
whichClipboard = this._cb.kGlobalClipboard;