Bug 1651519: Remove nsIDOMWindowUtils::currentInnerWindowID. r=nika,remote-protocol-reviewers,webcompat-reviewers,whimboo

It has some properties which make it footgunny, especially in the face of
Fission. Callers should use WindowGlobalChild.innerWindowId instead.

Differential Revision: https://phabricator.services.mozilla.com/D82801
This commit is contained in:
Kris Maglione 2020-07-21 16:59:28 +00:00
Родитель 56d5bde110
Коммит 9c2c147159
44 изменённых файлов: 67 добавлений и 87 удалений

Просмотреть файл

@ -504,7 +504,7 @@ function getTabStateForContentWindow(aContentWindow, aForRemove = false) {
}
function getInnerWindowIDForWindow(aContentWindow) {
return aContentWindow.windowUtils.currentInnerWindowID;
return aContentWindow.windowGlobalChild.innerWindowId;
}
function getMessageManagerForWindow(aContentWindow) {

Просмотреть файл

@ -102,7 +102,7 @@ async function promiseBrowserContentUnloaded(browser) {
browser,
MSG_WINDOW_DESTROYED,
MSG_WINDOW_DESTROYED => {
let innerWindowId = this.content.windowUtils.currentInnerWindowID;
let innerWindowId = this.content.windowGlobalChild.innerWindowId;
let observer = subject => {
if (
innerWindowId === subject.QueryInterface(Ci.nsISupportsPRUint64).data

Просмотреть файл

@ -135,7 +135,7 @@ class ReportSiteIssueHelperChild extends JSWindowActorChild {
}
_getLoggedMessages(includePrivate = false) {
const windowId = this.contentWindow.windowUtils.currentInnerWindowID;
const windowId = this.contentWindow.windowGlobalChild.innerWindowId;
return this._getConsoleMessages(windowId).concat(
this._getScriptErrors(windowId, includePrivate)
);

Просмотреть файл

@ -71,7 +71,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=995943
var gGoCount = 0;
function go() {
debug("Invoking go for window with id: " + window.windowUtils.currentInnerWindowID);
debug("Invoking go for window with id: " + window.windowGlobalChild.innerWindowId);
is(++gGoCount, 1, "Should only call go once!");
checkLoadFileURI('http://example.com', false).then(
pushPrefs.bind(null, [['capability.policy.policynames', ' somepolicy '],

Просмотреть файл

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

Просмотреть файл

@ -46,7 +46,7 @@ const EventSourceActor = ActorClassWithSpec(eventSourceSpec, {
startListening: function() {
this.stopListening();
this.innerWindowID = this.targetActor.window.windowUtils.currentInnerWindowID;
this.innerWindowID = this.targetActor.window.windowGlobalChild.innerWindowId;
eventSourceEventService.addListener(this.innerWindowID, this);
},

Просмотреть файл

@ -50,7 +50,7 @@ const WebSocketActor = ActorClassWithSpec(webSocketSpec, {
startListening: function() {
this.stopListening();
this.innerWindowID = this.targetActor.window.windowUtils.currentInnerWindowID;
this.innerWindowID = this.targetActor.window.windowGlobalChild.innerWindowId;
webSocketEventService.addListener(this.innerWindowID, this);
},

Просмотреть файл

@ -3519,7 +3519,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.windowUtils.currentInnerWindowID;
const id = win.windowGlobalChild.innerWindowId;
if (id == innerID) {
return win;
}

Просмотреть файл

@ -83,7 +83,7 @@ loader.lazyRequireGetter(
);
function getWindowID(window) {
return window.windowUtils.currentInnerWindowID;
return window.windowGlobalChild.innerWindowId;
}
function getDocShellChromeEventHandler(docShell) {
@ -123,7 +123,7 @@ exports.getChildDocShells = getChildDocShells;
*/
function getInnerId(window) {
return window.windowUtils.currentInnerWindowID;
return window.windowGlobalChild.innerWindowId;
}
const browsingContextTargetPrototype = {

Просмотреть файл

@ -88,10 +88,10 @@ var WebConsoleUtils = {
* Inner ID for the given window, null if we can't access it.
*/
getInnerWindowId: function(window) {
// Might throw with SecurityError: Permission denied to access property "windowUtils"
// on cross-origin object.
// Might throw with SecurityError: Permission denied to access property
// "windowGlobalChild" on cross-origin object.
try {
return window.windowUtils.currentInnerWindowID;
return window.windowGlobalChild.innerWindowId;
} catch (e) {
return null;
}
@ -546,7 +546,7 @@ WebConsoleCommands._registerOriginal("cd", function(owner, window) {
0,
1,
"content javascript",
owner.window.windowUtils.currentInnerWindowID
owner.window.windowGlobalChild.innerWindowId
);
const Services = require("Services");
Services.console.logMessage(scriptError);

Просмотреть файл

@ -72,5 +72,5 @@ ContentObserver.prototype = {
// Utility functions.
ContentObserver.GetInnerWindowID = function(window) {
return window.windowUtils.currentInnerWindowID;
return window.windowGlobalChild.innerWindowId;
};

Просмотреть файл

@ -201,7 +201,7 @@ function logInPage(text, flags, window) {
0,
flags,
"screenshot",
window.windowUtils.currentInnerWindowID
window.windowGlobalChild.innerWindowId
);
Services.console.logMessage(scriptError);
}

Просмотреть файл

@ -22,7 +22,7 @@ function doConsoleCalls(aState)
{
const { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm");
const console = new ConsoleAPI({
innerID: window.windowUtils.currentInnerWindowID
innerID: window.windowGlobalChild.innerWindowId
});
const longString = (new Array(DevToolsServer.LONG_STRING_LENGTH + 2)).join("a");

Просмотреть файл

@ -123,7 +123,7 @@ add_task(async function test() {
let { testFns } = this.content.wrappedJSObject;
this.content.onbeforeunload = testFns[testIdx];
this.content.location = url;
return this.content.windowUtils.currentInnerWindowID;
return this.content.windowGlobalChild.innerWindowId;
}
);
@ -142,7 +142,7 @@ add_task(async function test() {
"Page should have navigated to the correct URL"
);
Assert.notEqual(
this.content.windowUtils.currentInnerWindowID,
this.content.windowGlobalChild.innerWindowId,
winID,
"Page should have a new inner window"
);
@ -157,7 +157,7 @@ add_task(async function test() {
"Page should have the same URL"
);
Assert.equal(
this.content.windowUtils.currentInnerWindowID,
this.content.windowGlobalChild.innerWindowId,
winID,
"Page should have the same inner window"
);

Просмотреть файл

@ -157,8 +157,7 @@ DOMRequestIpcHelper.prototype = {
this._window = aWindow;
if (this._window) {
// We don't use this.innerWindowID, but other classes rely on it.
let util = this._window.windowUtils;
this.innerWindowID = util.currentInnerWindowID;
this.innerWindowID = this._window.windowGlobalChild.innerWindowId;
}
this._destroyed = false;

Просмотреть файл

@ -2146,20 +2146,6 @@ nsDOMWindowUtils::GetOuterWindowID(uint64_t* aWindowID) {
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetCurrentInnerWindowID(uint64_t* aWindowID) {
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
NS_ENSURE_TRUE(window, NS_ERROR_NOT_AVAILABLE);
nsGlobalWindowInner* inner =
nsGlobalWindowOuter::Cast(window)->GetCurrentInnerWindowInternal();
if (!inner) {
return NS_ERROR_NOT_AVAILABLE;
}
*aWindowID = inner->WindowID();
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::SuspendTimeouts() {
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);

Просмотреть файл

@ -14,7 +14,7 @@ var service = SpecialPowers.Cc["@mozilla.org/eventsourceevent/service;1"]
.getService(SpecialPowers.Ci.nsIEventSourceEventService);
ok(!!service, "We have the nsIEventSourceEventService");
var innerId = SpecialPowers.getDOMWindowUtils(window).currentInnerWindowID;
var innerId = SpecialPowers.wrap(window).windowGlobalChild.innerWindowId;
ok(innerId, "We have a valid innerWindowID: " + innerId);
var channelId = null;
@ -66,4 +66,4 @@ SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>
</html>

Просмотреть файл

@ -14,7 +14,7 @@ var service = SpecialPowers.Cc["@mozilla.org/eventsourceevent/service;1"]
.getService(SpecialPowers.Ci.nsIEventSourceEventService);
ok(!!service, "We have the nsIEventSourceEventService");
var innerId = SpecialPowers.getDOMWindowUtils(window).currentInnerWindowID;
var innerId = SpecialPowers.wrap(window).windowGlobalChild.innerWindowId;
ok(innerId, "We have a valid innerWindowID: " + innerId);
var channelId;
@ -69,4 +69,4 @@ function checkCallsCount() {
</script>
</pre>
</body>
</html>
</html>

Просмотреть файл

@ -14,7 +14,7 @@ var service = SpecialPowers.Cc["@mozilla.org/eventsourceevent/service;1"]
.getService(SpecialPowers.Ci.nsIEventSourceEventService);
ok(!!service, "We have the nsIEventSourceEventService");
var innerId = SpecialPowers.getDOMWindowUtils(window).currentInnerWindowID;
var innerId = SpecialPowers.wrap(window).windowGlobalChild.innerWindowId;
ok(innerId, "We have a valid innerWindowID: " + innerId);
var listener = {
@ -64,4 +64,4 @@ function doTest(status) {
</script>
</pre>
</body>
</html>
</html>

Просмотреть файл

@ -14,7 +14,7 @@ var service = SpecialPowers.Cc["@mozilla.org/eventsourceevent/service;1"]
.getService(SpecialPowers.Ci.nsIEventSourceEventService);
ok(!!service, "We have the nsIEventSourceEventService");
var innerId = SpecialPowers.getDOMWindowUtils(window).currentInnerWindowID;
var innerId = SpecialPowers.wrap(window).windowGlobalChild.innerWindowId;
ok(innerId, "We have a valid innerWindowID: " + innerId);
var channelId = null;
@ -58,4 +58,4 @@ SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>
</html>

Просмотреть файл

@ -134,9 +134,8 @@ BrowserElementChild.prototype = {
},
_tryGetInnerWindowID(win) {
let utils = win.windowUtils;
try {
return utils.currentInnerWindowID;
return win.windowGlobalChild.innerWindowId;
} catch (e) {
return null;
}

Просмотреть файл

@ -1298,12 +1298,6 @@ interface nsIDOMWindowUtils : nsISupports {
*/
readonly attribute unsigned long long outerWindowID;
/**
* Get the id of the current inner window of this window. If there
* is no current inner window, throws NS_ERROR_NOT_AVAILABLE.
*/
readonly attribute unsigned long long currentInnerWindowID;
/**
* Put the window into a state where scripts are frozen and events
* suppressed, for use when the window has launched a modal prompt.

Просмотреть файл

@ -257,7 +257,7 @@ IdpSandbox.prototype = {
// can't rethrow anything else because that could leak information about the
// internal workings of the IdP across origins.
_logError(e) {
let winID = this.window.windowUtils.currentInnerWindowID;
let winID = this.window.windowGlobalChild.innerWindowId;
let scriptError = Cc["@mozilla.org/scripterror;1"].createInstance(
Ci.nsIScriptError
);

Просмотреть файл

@ -253,7 +253,7 @@ setupPrototype(RTCIceCandidate, {
class RTCSessionDescription {
init(win) {
this._win = win;
this._winID = this._win.windowUtils.currentInnerWindowID;
this._winID = this._win.windowGlobalChild.innerWindowId;
}
__init({ type, sdp }) {
@ -389,7 +389,7 @@ class RTCPeerConnection {
}
__init(rtcConfig) {
this._winID = this._win.windowUtils.currentInnerWindowID;
this._winID = this._win.windowGlobalChild.innerWindowId;
// TODO: Update this code once we support pc.setConfiguration, to track
// setting from content independently from pref (Bug 1181768).
if (
@ -2020,7 +2020,7 @@ setupPrototype(PeerConnectionObserver, {
class RTCPeerConnectionStatic {
init(win) {
this._winID = win.windowUtils.currentInnerWindowID;
this._winID = win.windowGlobalChild.innerWindowId;
}
registerPeerConnectionLifecycleCallback(cb) {

Просмотреть файл

@ -216,8 +216,8 @@ function injectControlledFrame(target = document.body) {
: Promise.reject(new Error("Frame removed from document"));
},
innerWindowId() {
var utils = SpecialPowers.getDOMWindowUtils(iframe.contentWindow);
return utils.currentInnerWindowID;
return SpecialPowers.wrap(iframe).browsingContext.currentWindowContext
.innerWindowId;
},
};

Просмотреть файл

@ -40,7 +40,7 @@ add_task(async function() {
if (aTopic == "console-storage-cache-event") {
apiCallCount++;
if (apiCallCount == 4) {
let windowId = content.window.windowUtils.currentInnerWindowID;
let windowId = content.windowGlobalChild.innerWindowId;
Services.obs.removeObserver(this, "console-storage-cache-event");
ok(

Просмотреть файл

@ -17,7 +17,7 @@ function test() {
);
function getInnerWindowId(aWindow) {
return aWindow.windowUtils.currentInnerWindowID;
return aWindow.windowGlobalChild.innerWindowId;
}
function whenNewWindowLoaded(aOptions, aCallback) {

Просмотреть файл

@ -2,7 +2,7 @@
<script>
dump("Content running top level script " + window.location.href + "\n");
var winID = SpecialPowers.getDOMWindowUtils(this).currentInnerWindowID;
var winID = SpecialPowers.wrap(this).windowGlobalChild.innerWindowId;
var observer = {
observe(subject, topic) {

Просмотреть файл

@ -23,8 +23,10 @@ function getIDs(iframe) {
// Force inner creation
win.document;
var util = SpecialPowers.getDOMWindowUtils(win);
return [util.outerWindowID, util.currentInnerWindowID];
return [
SpecialPowers.getDOMWindowUtils(win).outerWindowID,
SpecialPowers.wrap(win).windowGlobalChild.innerWindowId,
];
}
var i1 = document.createElement("iframe");

Просмотреть файл

@ -26,7 +26,7 @@ var tests = [
{ payload: (function() { var buffer = ""; for (var i = 0; i < 120; ++i) buffer += i; return buffer; }()) },
]
var innerId = window.top.windowUtils.currentInnerWindowID;
var innerId = window.top.windowGlobalChild.innerWindowId;
ok(innerId, "We have a valid innerWindowID: " + innerId);
var service = Cc["@mozilla.org/websocketevent/service;1"]

Просмотреть файл

@ -38,7 +38,7 @@ function hasExpectedProperties(message, exception) {
is(message.sourceName, location.href, "has correct sourceName/filename");
ok(message.lineNumber > 0, "has lineNumber");
is(message.innerWindowID, window.windowUtils.currentInnerWindowID,
is(message.innerWindowID, window.windowGlobalChild.innerWindowId,
"correct innerWindowID");
}

Просмотреть файл

@ -1439,12 +1439,11 @@ NS_IMETHODIMP HttpBaseChannel::GetTopLevelContentWindowId(uint64_t* aWindowId) {
if (loadContext) {
nsCOMPtr<mozIDOMWindowProxy> topWindow;
loadContext->GetTopWindow(getter_AddRefs(topWindow));
nsCOMPtr<nsIDOMWindowUtils> windowUtils;
if (topWindow) {
windowUtils = nsGlobalWindowOuter::Cast(topWindow)->WindowUtils();
}
if (windowUtils) {
windowUtils->GetCurrentInnerWindowID(&mContentWindowId);
if (nsPIDOMWindowInner* inner =
nsPIDOMWindowOuter::From(topWindow)->GetCurrentInnerWindow()) {
mContentWindowId = inner->WindowID();
}
}
}
}

Просмотреть файл

@ -241,7 +241,7 @@ class Page extends ContentProcessDomain {
const window = defaultContext.window;
const executionContextId = Runtime._onContextCreated("context-created", {
windowId: window.windowUtils.currentInnerWindowID,
windowId: window.windowGlobalChild.innerWindowId,
window,
isDefault: false,
contextName: worldName,

Просмотреть файл

@ -89,7 +89,7 @@ class Runtime extends ContentProcessDomain {
// after we replied to `enable` request.
executeSoon(() => {
this._onContextCreated("context-created", {
windowId: this.content.windowUtils.currentInnerWindowID,
windowId: this.content.windowGlobalChild.innerWindowId,
window: this.content,
isDefault: true,
});
@ -325,8 +325,7 @@ class Runtime extends ContentProcessDomain {
_getDefaultContextForWindow(innerWindowId) {
if (!innerWindowId) {
const { windowUtils } = this.content;
innerWindowId = windowUtils.currentInnerWindowID;
innerWindowId = this.content.windowGlobalChild.innerWindowId;
}
const curContexts = this.innerWindowIdToContexts.get(innerWindowId);
if (curContexts) {

Просмотреть файл

@ -48,7 +48,7 @@ class ExecutionContext {
// Here, we assume that debuggee is a window object and we will propably have
// to adapt that once we cover workers or contexts that aren't a document.
this.window = debuggee;
this.windowId = debuggee.windowUtils.currentInnerWindowID;
this.windowId = debuggee.windowGlobalChild.innerWindowId;
this.id = id;
this.frameId = debuggee.docShell.browsingContext.id.toString();
this.isDefault = isDefault;

Просмотреть файл

@ -74,8 +74,8 @@ class ContextObserver {
handleEvent({ type, target, persisted }) {
const window = target.defaultView;
const frameId = window.docShell.browsingContext.id;
const id = window.windowUtils.currentInnerWindowID;
const frameId = window.browsingContext.id;
const id = window.windowGlobalChild.innerWindowId;
switch (type) {
case "DOMWindowCreated":

Просмотреть файл

@ -231,7 +231,7 @@ class SpecialPowersChild extends JSWindowActorChild {
let window = this.contentWindow;
// We should not invoke the getter.
if (!("SpecialPowers" in window.wrappedJSObject)) {
this._windowID = window.windowUtils.currentInnerWindowID;
this._windowID = window.windowGlobalChild.innerWindowId;
defineSpecialPowers(this);
if (this.IsInNestedFrame) {

Просмотреть файл

@ -132,7 +132,9 @@ function wrapPrivileged(obj, win) {
let { windowID, proxies, handler } = perWindowInfo.get(win) || {};
// |windowUtils| is undefined if |win| is a non-window object
// such as a sandbox.
let currentID = win.windowUtils ? win.windowUtils.currentInnerWindowID : 0;
let currentID = win.windowGlobalChild
? win.windowGlobalChild.innerWindowId
: 0;
// Values are dead objects if the inner window is changed.
if (windowID !== currentID) {
windowID = currentID;

Просмотреть файл

@ -109,7 +109,7 @@ class DefaultMap extends Map {
}
function getInnerWindowID(window) {
return window.windowUtils.currentInnerWindowID;
return window.windowGlobalChild?.innerWindowId;
}
/**

Просмотреть файл

@ -48,7 +48,7 @@ add_task(async function test_contentscript_devtools_sandbox_metadata() {
let win = window.open("file_sample.html");
let innerWindowID = SpecialPowers.getDOMWindowUtils(win).currentInnerWindowID;
let innerWindowID = SpecialPowers.wrap(win).windowGlobalChild.innerWindowId;
await extension.awaitFinish("contentScript.executed");

Просмотреть файл

@ -191,7 +191,8 @@ add_task(async function test_ExtensionPageContextChild_in_child_frame() {
let frame = this.content.document.querySelector(
"iframe[src*='iframe.html']"
);
let innerWindowID = frame.contentWindow.windowUtils.currentInnerWindowID;
let innerWindowID =
frame.browsingContext.currentWindowContext.innerWindowId;
let context = ExtensionPageChild.extensionContexts.get(innerWindowID);
Assert.ok(context, "Got extension page context for child frame");
@ -237,7 +238,7 @@ add_task(async function test_ExtensionPageContextChild_in_toplevel() {
"resource://gre/modules/ExtensionPageChild.jsm"
);
let innerWindowID = this.content.windowUtils.currentInnerWindowID;
let innerWindowID = this.content.windowGlobalChild.innerWindowId;
let context = ExtensionPageChild.extensionContexts.get(innerWindowID);
Assert.ok(context, "Got extension page context for top-level document");

Просмотреть файл

@ -51,7 +51,7 @@ this.InsecurePasswordUtils = {
* Inner ID for the given window.
*/
_getInnerWindowId(window) {
return window.windowUtils.currentInnerWindowID;
return window.windowGlobalChild.innerWindowId;
},
_sendWebConsoleMessage(messageTag, domDoc) {

Просмотреть файл

@ -69,7 +69,7 @@ var AboutReader = function(actor, articlePromise) {
this._docRef = Cu.getWeakReference(doc);
this._winRef = Cu.getWeakReference(win);
this._innerWindowId = win.windowUtils.currentInnerWindowID;
this._innerWindowId = win.windowGlobalChild.innerWindowId;
this._article = null;
this._languagePromise = new Promise(resolve => {

Просмотреть файл

@ -37,8 +37,7 @@ function CallbackObject(id, callback, mediator) {
}
function RemoteMediator(window) {
let utils = window.windowUtils;
this._windowID = utils.currentInnerWindowID;
this._windowID = window.windowGlobalChild.innerWindowId;
this.mm = window.docShell.messageManager;
this.mm.addWeakMessageListener(MSG_INSTALL_CALLBACK, this);