Bug 1476145 part 4. Stop using getInterface(nsIDOMWindowUtils) in devtools. r=bgrins

This commit is contained in:
Boris Zbarsky 2018-07-24 19:47:41 -04:00
parent 270fa12c79
commit 0e54dc6661
37 changed files with 59 additions and 131 deletions

View File

@ -37,7 +37,5 @@ function whenDelayedStartupFinished(aWindow, aCallback) {
* Bug 774619 is an example.
*/
registerCleanupFunction(function tearDown() {
window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.garbageCollect();
window.windowUtils.garbageCollect();
});

View File

@ -192,9 +192,7 @@ function test() {
// Flush the layout for the iframe.
info("rect " + iframe.contentDocument.documentElement.getBoundingClientRect());
let utils = testWin
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
let utils = testWin.windowUtils;
let coords = gEditor.getCoordsFromPosition({ line: 4, ch: 0 });
let rect = iframe.getBoundingClientRect();

View File

@ -113,8 +113,7 @@ class ToolboxTabs extends Component {
*/
updateCachedToolTabsWidthMap() {
const thisNode = findDOMNode(this);
const utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const utils = window.windowUtils;
// Force a reflow before calling getBoundingWithoutFlushing on each tab.
thisNode.clientWidth;

View File

@ -525,8 +525,7 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = {
// Don't return from the interrupt handler until the debugger is brought
// up; no reason to continue executing the slow script.
const utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const utils = window.windowUtils;
utils.enterModalState();
Services.tm.spinEventLoopUntil(() => {
return setupFinished;

View File

@ -37,9 +37,7 @@ add_task(async function() {
}
info("Test browser window");
let windowId = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
let windowId = window.windowUtils.outerWindowID;
target = await targetFromURL(new URL("http://foo?type=window&id=" + windowId));
is(target.url, window.location.href);
is(target.isLocalTab, false);

View File

@ -49,7 +49,5 @@ function sendZoomKey(shortcut, times) {
}
function getCurrentZoom(toolbox) {
const windowUtils = toolbox.win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
return windowUtils.fullZoom;
return toolbox.win.windowUtils.fullZoom;
}

View File

@ -28,8 +28,7 @@ add_task(async function() {
const hostWindow = toolbox.win.parent;
const originWidth = hostWindow.outerWidth;
const originHeight = hostWindow.outerHeight;
const windowUtils = toolbox.win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const windowUtils = toolbox.win.windowUtils;
info("Waiting for the toolbox window will to be rendered with zoom x1.4");
await waitUntil(() => {

View File

@ -65,9 +65,7 @@ function checkGetTab() {
if (gTab1.linkedBrowser.frameLoader.tabParent) {
filter.tabId = gTab1.linkedBrowser.frameLoader.tabParent.tabId;
} else {
const windowUtils = gTab1.linkedBrowser.contentWindow
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const windowUtils = gTab1.linkedBrowser.contentWindow.windowUtils;
filter.outerWindowID = windowUtils.outerWindowID;
}
return gClient.getTab(filter);

View File

@ -22,9 +22,7 @@ if (url.search.length > 1) {
const { DebuggerClient } = require("devtools/shared/client/debugger-client");
// `host` is the frame element loading the toolbox.
let host = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.containerElement;
let host = window.windowUtils.containerElement;
// If there's no containerElement (which happens when loading about:devtools-toolbox as
// a top level document), use the current window.

View File

@ -3028,9 +3028,7 @@ Toolbox.prototype = {
// Force GC to prevent long GC pauses when running tests and to free up
// memory in general when the toolbox is closed.
if (flags.testing) {
win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.garbageCollect();
win.windowUtils.garbageCollect();
}
}).catch(console.error));
});

View File

@ -14,9 +14,7 @@
"use strict";
var style = "data:text/css,a { background-color: seagreen; }";
var uri = SpecialPowers.Services.io.newURI(style);
var windowUtils = SpecialPowers.wrap(window)
.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
.getInterface(SpecialPowers.Ci.nsIDOMWindowUtils);
var windowUtils = SpecialPowers.getDOMWindowUtils(window);
windowUtils.loadSheet(uri, windowUtils.AUTHOR_SHEET);
</script>

View File

@ -12,9 +12,7 @@
"use strict";
var style = "data:text/css,div { background-color: seagreen; }";
var uri = SpecialPowers.Services.io.newURI(style);
var windowUtils = SpecialPowers.wrap(window)
.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
.getInterface(SpecialPowers.Ci.nsIDOMWindowUtils);
var windowUtils = SpecialPowers.getDOMWindowUtils(window);
windowUtils.loadSheet(uri, windowUtils.AUTHOR_SHEET);
</script>
</head>

View File

@ -127,8 +127,7 @@ var global = this;
for (const d of allDocShells) {
const win = d.contentViewer.DOMDocument.defaultView;
const winUtils = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const winUtils = win.windowUtils;
try {
winUtils.loadSheet(gFloatingScrollbarsStylesheet, win.AGENT_SHEET);
} catch (e) { }
@ -144,8 +143,7 @@ var global = this;
}
for (const d of allDocShells) {
const win = d.contentViewer.DOMDocument.defaultView;
const winUtils = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const winUtils = win.windowUtils;
try {
winUtils.removeSheet(gFloatingScrollbarsStylesheet, win.AGENT_SHEET);
} catch (e) { }

View File

@ -21,8 +21,7 @@ function getToplevelWindow(window) {
exports.getToplevelWindow = getToplevelWindow;
function getDOMWindowUtils(window) {
return window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
return window.windowUtils;
}
exports.getDOMWindowUtils = getDOMWindowUtils;

View File

@ -1597,8 +1597,7 @@ var Scratchpad = {
* the inner window ID
*/
getInnerWindowId: function SP_getInnerWindowId(aWindow) {
return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
return aWindow.windowUtils.currentInnerWindowID;
},
updateStatusBar: function SP_updateStatusBar(aEventType) {

View File

@ -22,8 +22,7 @@ function test() {
function runTests() {
const sp = gScratchpadWindow.Scratchpad;
const doc = gScratchpadWindow.document;
const winUtils = gScratchpadWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const winUtils = gScratchpadWindow.windowUtils;
const OS = Services.appinfo.OS;
info("will test the Edit menu");

View File

@ -236,7 +236,7 @@ AbstractTreeItem.prototype = {
*/
get bounds() {
const win = this.document.defaultView;
const utils = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
const utils = win.windowUtils;
return utils.getBoundsWithoutFlushing(this._containerNode);
},
@ -486,8 +486,7 @@ AbstractTreeItem.prototype = {
_getHeight: function(elem) {
const win = this.document.defaultView;
const utils = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const utils = win.windowUtils;
return utils.getBoundsWithoutFlushing(elem).height;
},

View File

@ -117,8 +117,7 @@ SideMenuWidget.prototype = {
*/
isScrolledToBottom: function() {
if (this._list.lastElementChild) {
const utils = this.window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const utils = this.window.windowUtils;
const childRect = utils.getBoundsWithoutFlushing(this._list.lastElementChild);
const listRect = utils.getBoundsWithoutFlushing(this._list);

View File

@ -119,8 +119,7 @@ async function getScrollbarSize() {
gBrowser.selectedBrowser,
{},
function() {
const winUtils = content.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const winUtils = content.windowUtils;
const scrollbarHeight = {};
const scrollbarWidth = {};
winUtils.getScrollbarSize(true, scrollbarWidth, scrollbarHeight);

View File

@ -70,8 +70,7 @@ function logAccessDeniedWarning(window, callerInfo, extensionPolicy) {
const msg = `The extension "${name}" is not allowed to access ${reportedURI.spec}`;
const innerWindowId = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
const innerWindowId = window.windowUtils;
const errorFlag = 0;

View File

@ -25,7 +25,7 @@
* /dom/webidl/Animation*.webidl
*/
const {Cu, Ci} = require("chrome");
const {Cu} = require("chrome");
const protocol = require("devtools/shared/protocol");
const {Actor} = protocol;
const {animationPlayerSpec, animationsSpec} = require("devtools/shared/specs/animation");
@ -496,9 +496,7 @@ var AnimationPlayerActor = protocol.ActorClassWithSpec(animationPlayerSpec, {
return {name: property.property, values: property.values};
});
const DOMWindowUtils =
this.window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const DOMWindowUtils = this.window.windowUtils;
// Fill missing keyframe with computed value.
for (const property of properties) {

View File

@ -6,7 +6,7 @@
"use strict";
const { Ci, Cu } = require("chrome");
const { Cu } = require("chrome");
const { Services } = require("resource://gre/modules/Services.jsm");
var systemAppOrigin = (function() {
@ -220,8 +220,7 @@ TouchSimulator.prototype = {
fireMouseEvent(type, evt) {
const content = this.getContent(evt.target);
const utils = content.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const utils = content.windowUtils;
utils.sendMouseEvent(type, evt.clientX, evt.clientY, 0, 1, 0, true, 0,
evt.MOZ_SOURCE_TOUCH);
},
@ -330,8 +329,7 @@ TouchSimulator.prototype = {
return 0;
}
const utils = content.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const utils = content.windowUtils;
const allowZoom = {};
const minZoom = {};

View File

@ -2687,9 +2687,7 @@ const StorageActor = protocol.ActorClassWithSpec(specs.storageSpec, {
getWindowFromInnerWindowID(innerID) {
innerID = innerID.QueryInterface(Ci.nsISupportsPRUint64).data;
for (const win of this.childWindowPool.values()) {
const id = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.currentInnerWindowID;
const id = win.windowUtils.currentInnerWindowID;
if (id == innerID) {
return win;
}

View File

@ -188,8 +188,7 @@ AddonTargetActor.prototype = {
const e = Services.wm.getEnumerator(null);
while (e.hasMoreElements()) {
const win = e.getNext();
const windowUtils = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const windowUtils = win.windowUtils;
windowUtils.suppressEventHandling(true);
windowUtils.suspendTimeouts();
}
@ -199,8 +198,7 @@ AddonTargetActor.prototype = {
const e = Services.wm.getEnumerator(null);
while (e.hasMoreElements()) {
const win = e.getNext();
const windowUtils = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const windowUtils = win.windowUtils;
windowUtils.resumeTimeouts();
windowUtils.suppressEventHandling(false);
}

View File

@ -51,9 +51,7 @@ loader.lazyRequireGetter(this, "StyleSheetActor", "devtools/server/actors/styles
loader.lazyRequireGetter(this, "getSheetText", "devtools/server/actors/stylesheets", true);
function getWindowID(window) {
return window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.currentInnerWindowID;
return window.windowUtils.currentInnerWindowID;
}
function getDocShellChromeEventHandler(docShell) {
@ -94,8 +92,7 @@ exports.getChildDocShells = getChildDocShells;
*/
function getInnerId(window) {
return window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
return window.windowUtils.currentInnerWindowID;
}
const browsingContextTargetPrototype = {
@ -347,9 +344,7 @@ const browsingContextTargetPrototype = {
get outerWindowID() {
if (this.window) {
return this.window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
return this.window.windowUtils.outerWindowID;
}
return null;
},
@ -782,9 +777,7 @@ const browsingContextTargetPrototype = {
const webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebProgress);
const window = webProgress.DOMWindow;
const id = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
const id = window.windowUtils.outerWindowID;
let parentID = undefined;
// Ignore the parent of the original document on non-e10s firefox,
// as we get the xul window as parent and don't care about it.
@ -792,10 +785,7 @@ const browsingContextTargetPrototype = {
// current window in order to deal with front end. e.g. toolbox will be fall
// into infinite loop due to recursive search with by using parent id.
if (window.parent && window.parent != window && window != this._originalWindow) {
parentID = window.parent
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
parentID = window.parent.windowUtils.outerWindowID;
}
return {
@ -830,10 +820,7 @@ const browsingContextTargetPrototype = {
_notifyDocShellDestroy(webProgress) {
webProgress = webProgress.QueryInterface(Ci.nsIWebProgress);
const id = webProgress.DOMWindow
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
const id = webProgress.DOMWindow.windowUtils.outerWindowID;
this.emit("frameUpdate", {
frames: [{
id,
@ -1138,8 +1125,7 @@ const browsingContextTargetPrototype = {
* Disable or enable the service workers testing features.
*/
_setServiceWorkersTestingEnabled(enabled) {
const windowUtils = this.window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const windowUtils = this.window.windowUtils;
windowUtils.serviceWorkersTestingEnabled = enabled;
},
@ -1166,8 +1152,7 @@ const browsingContextTargetPrototype = {
return null;
}
const windowUtils = this.window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const windowUtils = this.window.windowUtils;
return windowUtils.serviceWorkersTestingEnabled;
},
@ -1179,9 +1164,7 @@ const browsingContextTargetPrototype = {
// The browsing context is already closed.
return;
}
const windowUtils = this.window
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const windowUtils = this.window.windowUtils;
windowUtils.suppressEventHandling(true);
windowUtils.suspendTimeouts();
},
@ -1194,9 +1177,7 @@ const browsingContextTargetPrototype = {
// The browsing context is already closed.
return;
}
const windowUtils = this.window
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const windowUtils = this.window.windowUtils;
windowUtils.resumeTimeouts();
windowUtils.suppressEventHandling(false);
},

View File

@ -184,8 +184,7 @@ parentProcessTargetPrototype.preNest = function() {
const e = Services.wm.getEnumerator(null);
while (e.hasMoreElements()) {
const win = e.getNext();
const windowUtils = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const windowUtils = win.windowUtils;
windowUtils.suppressEventHandling(true);
windowUtils.suspendTimeouts();
}
@ -199,8 +198,7 @@ parentProcessTargetPrototype.postNest = function(nestData) {
const e = Services.wm.getEnumerator(null);
while (e.hasMoreElements()) {
const win = e.getNext();
const windowUtils = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const windowUtils = win.windowUtils;
windowUtils.resumeTimeouts();
windowUtils.suppressEventHandling(false);
}

View File

@ -335,9 +335,7 @@ BrowserTabList.prototype.getTab = function({ outerWindowID, tabId }) {
});
}
if (window) {
const iframe = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.containerElement;
const iframe = window.windowUtils.containerElement;
if (iframe) {
return this._getActorForBrowser(iframe);
}

View File

@ -4,7 +4,7 @@
"use strict";
const { Ci, Cu } = require("chrome");
const { Cu } = require("chrome");
const { getRect } = require("devtools/shared/layout/utils");
const { LocalizationHelper } = require("devtools/shared/l10n");
@ -78,8 +78,7 @@ function createScreenshotData(document, args) {
// Only adjust for scrollbars when considering the full window
if (!args.selector) {
const winUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const winUtils = window.windowUtils;
const scrollbarHeight = {};
const scrollbarWidth = {};
winUtils.getScrollbarSize(false, scrollbarWidth, scrollbarHeight);

View File

@ -85,8 +85,7 @@ var WebConsoleUtils = {
* Inner ID for the given window.
*/
getInnerWindowId: function(window) {
return window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
return window.windowUtils.currentInnerWindowID;
},
/**

View File

@ -34,8 +34,7 @@ window.onload = function() {
let desc;
const appInfo = Services.appinfo;
const utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const utils = window.windowUtils;
const localDesc = {
appid: appInfo.ID,

View File

@ -225,9 +225,7 @@ RootClient.prototype = {
packet.outerWindowID = browser.outerWindowID;
} else {
// <iframe mozbrowser> tabs in parent process
const windowUtils = browser.contentWindow
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const windowUtils = browser.contentWindow.windowUtils;
packet.outerWindowID = windowUtils.outerWindowID;
}
} else {

View File

@ -64,8 +64,5 @@ ContentObserver.prototype = {
// Utility functions.
ContentObserver.GetInnerWindowID = function(window) {
return window
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.currentInnerWindowID;
return window.windowUtils.currentInnerWindowID;
};

View File

@ -4,8 +4,6 @@
"use strict";
const { Ci } = require("chrome");
loader.lazyRequireGetter(this, "CommandState",
"devtools/shared/gcli/command-state", true);
@ -59,8 +57,7 @@ function onPaintFlashingChanged(target, flashing) {
* @return The new value of the window.paintFlashing flag
*/
function setPaintFlashing(window, state) {
const winUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const winUtils = window.windowUtils;
if (!["on", "off", "toggle", "query"].includes(state)) {
throw new Error(`Unsupported state: ${state}`);

View File

@ -300,8 +300,7 @@ function createScreenshotData(document, args) {
// Only adjust for scrollbars when considering the full window
if (!args.selector) {
const winUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const winUtils = window.windowUtils;
const scrollbarHeight = {};
const scrollbarWidth = {};
winUtils.getScrollbarSize(false, scrollbarWidth, scrollbarHeight);

View File

@ -26,9 +26,10 @@ exports.setIgnoreLayoutChanges = (...args) =>
*/
const utilsCache = new WeakMap();
function utilsFor(win) {
// XXXbz Given that we now have a direct getter for the DOMWindowUtils, is
// this weakmap cache path any faster than just calling the getter?
if (!utilsCache.has(win)) {
utilsCache.set(win, win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils));
utilsCache.set(win, win.windowUtils);
}
return utilsCache.get(win);
}
@ -674,6 +675,9 @@ exports.isAfterPseudoElement = isAfterPseudoElement;
* Container windows are used as a weakmap key to store the corresponding
* nsIDOMWindowUtils instance to avoid querying it every time.
*
* XXXbz Given that we now have a direct getter for the DOMWindowUtils, is
* this weakmap cache path any faster than just calling the getter?
*
* @param {DOMNode|DOMWindow}
* The node for which the zoom factor should be calculated, or its
* owner window.

View File

@ -72,8 +72,7 @@ async function getSystemInfo() {
}
if (win) {
const utils = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
const utils = win.windowUtils;
dpi = utils.displayDPI;
useragent = win.navigator.userAgent;
width = win.screen.width;

View File

@ -20,9 +20,7 @@ function doConsoleCalls(aState)
{
let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm", {});
let console = new ConsoleAPI({
innerID: window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.currentInnerWindowID
innerID: window.windowUtils.currentInnerWindowID
});
let longString = (new Array(DebuggerServer.LONG_STRING_LENGTH + 2)).join("a");