Bug 1670134, remove message manager reference from LightweightThemeChild.jsm, by getting chromeOuterWindowId from BrowserChild instead, r=mconley

Differential Revision: https://phabricator.services.mozilla.com/D93043
This commit is contained in:
Neil Deakin 2020-10-09 17:36:22 +00:00
parent 52d04941c0
commit af842b5083
9 changed files with 30 additions and 46 deletions

View File

@ -25,12 +25,17 @@ class LightweightThemeChild extends JSWindowActorChild {
}
_getChromeOuterWindowID() {
if (this.docShell.messageManager) {
return this.docShell.messageManager.chromeOuterWindowID;
try {
// Getting the browserChild throws an exception when it is null.
let browserChild = this.docShell.browserChild;
if (browserChild) {
return browserChild.chromeOuterWindowID;
}
} catch (ex) {}
// We don't have a message manager, so presumable we're running in a sidebar
// in the parent process.
return this.contentWindow.top.docShell.outerWindowID;
return this.contentWindow.top.docShell?.outerWindowID;
}
/**

View File

@ -40,7 +40,6 @@ class ContentFrameMessageManager : public DOMEventTargetHelper,
virtual Nullable<WindowProxyHolder> GetContent(ErrorResult& aError) = 0;
virtual already_AddRefed<nsIDocShell> GetDocShell(ErrorResult& aError) = 0;
virtual already_AddRefed<nsIEventTarget> GetTabEventTarget() = 0;
virtual uint64_t ChromeOuterWindowID() = 0;
nsFrameMessageManager* GetMessageManager() { return mMessageManager; }
void DisconnectMessageManager() {

View File

@ -186,25 +186,6 @@ InProcessBrowserChildMessageManager::GetTabEventTarget() {
return target.forget();
}
uint64_t InProcessBrowserChildMessageManager::ChromeOuterWindowID() {
if (!mDocShell) {
return 0;
}
nsCOMPtr<nsIDocShellTreeItem> root;
nsresult rv = mDocShell->GetInProcessRootTreeItem(getter_AddRefs(root));
if (NS_WARN_IF(NS_FAILED(rv))) {
return 0;
}
nsPIDOMWindowOuter* topWin = root->GetWindow();
if (!topWin) {
return 0;
}
return topWin->WindowID();
}
void InProcessBrowserChildMessageManager::FireUnloadEvent() {
// We're called from Document::MaybeInitializeFinalizeFrameLoaders, so it
// should be safe to run script.

View File

@ -62,7 +62,6 @@ class InProcessBrowserChildMessageManager final
return do_AddRef(mDocShell);
}
virtual already_AddRefed<nsIEventTarget> GetTabEventTarget() override;
virtual uint64_t ChromeOuterWindowID() override;
NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)

View File

@ -41,13 +41,17 @@ windows.
"Both browsers should belong to the same document.");
let winID = getOuterWindowID(browser1.ownerGlobal);
let browser1ID = await ContentTask.spawn(browser1, null, () => {
return chromeOuterWindowID;
});
let getChildRootOuterId = browser => {
try {
return docShell.browserChild?.chromeOuterWindowID;
} catch(ex) { }
let browser2ID = await ContentTask.spawn(browser2, null, () => {
return chromeOuterWindowID;
});
// Not a remote tab
return content.top.windowRoot.ownerGlobal.docShell.outerWindowID;
};
let browser1ID = await SpecialPowers.spawn(browser1, [], getChildRootOuterId);
let browser2ID = await SpecialPowers.spawn(browser2, [], getChildRootOuterId);
is(browser1ID, winID,
"Browser 1 frame script environment should have the correct chromeOuterWindowID");

View File

@ -473,13 +473,6 @@ interface ContentFrameMessageManager : EventTarget
*/
readonly attribute nsIEventTarget? tabEventTarget;
/**
* Returns the outerWindowID of the browser window hosting the frame.
* If, for some reason, the frameloader can't be resolved to a browser
* window, this will return 0.
*/
readonly attribute long long chromeOuterWindowID;
};
ContentFrameMessageManager includes MessageManagerGlobal;
ContentFrameMessageManager includes SyncMessageSenderMixin;

View File

@ -50,4 +50,9 @@ interface nsIBrowserChild : nsISupports
* nsIWebNavigation navigation finished in the child.
*/
void notifyNavigationFinished();
/**
* Id of the chrome window the tab is within.
*/
readonly attribute uint64_t chromeOuterWindowID;
};

View File

@ -2993,6 +2993,12 @@ void BrowserChild::SetTabId(const TabId& aTabId) {
NestedBrowserChildMap()[mUniqueId] = this;
}
NS_IMETHODIMP
BrowserChild::GetChromeOuterWindowID(uint64_t* aId) {
*aId = ChromeOuterWindowID();
return NS_OK;
}
bool BrowserChild::DoSendBlockingMessage(
const nsAString& aMessage, StructuredCloneData& aData,
nsTArray<StructuredCloneData>* aRetVal) {
@ -4024,13 +4030,6 @@ BrowserChildMessageManager::GetTabEventTarget() {
return target.forget();
}
uint64_t BrowserChildMessageManager::ChromeOuterWindowID() {
if (!mBrowserChild) {
return 0;
}
return mBrowserChild->ChromeOuterWindowID();
}
nsresult BrowserChildMessageManager::Dispatch(
TaskCategory aCategory, already_AddRefed<nsIRunnable>&& aRunnable) {
return DispatcherTrait::Dispatch(aCategory, std::move(aRunnable));

View File

@ -106,7 +106,6 @@ class BrowserChildMessageManager : public ContentFrameMessageManager,
virtual already_AddRefed<nsIDocShell> GetDocShell(
ErrorResult& aError) override;
virtual already_AddRefed<nsIEventTarget> GetTabEventTarget() override;
virtual uint64_t ChromeOuterWindowID() override;
NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)