diff --git a/docshell/base/nsDocShellTreeOwner.cpp b/docshell/base/nsDocShellTreeOwner.cpp index 4acfdc755301..e5787bc423f6 100644 --- a/docshell/base/nsDocShellTreeOwner.cpp +++ b/docshell/base/nsDocShellTreeOwner.cpp @@ -398,6 +398,25 @@ nsDocShellTreeOwner::GetPrimaryRemoteTab(nsIRemoteTab** aTab) { return NS_OK; } +NS_IMETHODIMP +nsDocShellTreeOwner::GetPrimaryContentBrowsingContext( + mozilla::dom::BrowsingContext** aBc) { + if (mTreeOwner) { + return mTreeOwner->GetPrimaryContentBrowsingContext(aBc); + } + if (mPrimaryRemoteTab) { + return mPrimaryRemoteTab->GetBrowsingContext(aBc); + } + if (mPrimaryContentShell) { + return mPrimaryContentShell->GetBrowsingContextXPCOM(aBc); + } + if (mWebBrowser->mDocShell) { + return mWebBrowser->mDocShell->GetBrowsingContextXPCOM(aBc); + } + *aBc = nullptr; + return NS_OK; +} + NS_IMETHODIMP nsDocShellTreeOwner::GetPrimaryContentSize(int32_t* aWidth, int32_t* aHeight) { return NS_ERROR_NOT_IMPLEMENTED; diff --git a/docshell/base/nsIDocShellTreeOwner.idl b/docshell/base/nsIDocShellTreeOwner.idl index 7e8aed5910a1..5d54172739f0 100644 --- a/docshell/base/nsIDocShellTreeOwner.idl +++ b/docshell/base/nsIDocShellTreeOwner.idl @@ -12,6 +12,7 @@ interface nsIDocShellTreeItem; interface nsIRemoteTab; +webidl BrowsingContext; [scriptable, uuid(0e3dc4b1-4cea-4a37-af71-79f0afd07574)] interface nsIDocShellTreeOwner : nsISupports @@ -51,6 +52,12 @@ interface nsIDocShellTreeOwner : nsISupports */ readonly attribute nsIRemoteTab primaryRemoteTab; + /* + Get the BrowsingContext associated with either the primary content shell or + primary remote tab, depending on which is available. + */ + readonly attribute BrowsingContext primaryContentBrowsingContext; + /* Tells the tree owner to size its window or parent window in such a way that the shell passed along will be the size specified. diff --git a/dom/base/test/chrome/file_bug1209621.xhtml b/dom/base/test/chrome/file_bug1209621.xhtml index 36f81a13c06b..3ba58975bda7 100644 --- a/dom/base/test/chrome/file_bug1209621.xhtml +++ b/dom/base/test/chrome/file_bug1209621.xhtml @@ -29,6 +29,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1209621 "There shouldn't be primaryContentShell because no browser has primary=true."); is(treeOwner.primaryRemoteTab, null, "There shouldn't be primaryRemoteTab because no remote browser has primary=true."); + is(treeOwner.primaryContentBrowsingContext, null, + "There shouldn't be primaryContentBrowsingContext because no browser has primary=true."); var ip = document.getElementById("inprocess"); var remote = document.getElementById("remote"); @@ -40,6 +42,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1209621 "primary browser should be the primaryContentShell."); is(treeOwner.primaryRemoteTab, null, "There shouldn't be primaryRemoteTab because no remote browser has primary=true."); + is(treeOwner.primaryContentBrowsingContext, ip.browsingContext, + "primary browsing context should be the primaryContentBrowsingContext."); ip.removeAttribute("primary"); remote.setAttribute("primary", "true"); @@ -49,12 +53,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1209621 ok(tp, "Remote browsers should have a remoteTab."); is(treeOwner.primaryRemoteTab, tp, "primary remote browser should be the primaryRemoteTab."); + is(treeOwner.primaryContentBrowsingContext, remote.browsingContext, + "primary remote browser should be the primaryContentBrowsingContext."); remote.removeAttribute("primary"); is(treeOwner.primaryContentShell, null, "There shouldn't be primaryContentShell because no browser has primary=true."); is(treeOwner.primaryRemoteTab, null, "There shouldn't be primaryRemoteTab because no remote browser has primary=true."); + is(treeOwner.primaryContentBrowsingContext, null, + "There shouldn't be primaryContentBrowsingContext because no browser has primary=true."); remote2.setAttribute("primary", "true"); var tp2 = remote2.frameLoader.remoteTab; @@ -63,6 +71,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1209621 "primary remote browser should be the primaryRemoteTab."); is(treeOwner.primaryContentShell, null, "There shouldn't be primaryContentShell because no browser has primary=true."); + is(treeOwner.primaryContentBrowsingContext, remote2.browsingContext, + "primary remote browser should be the primaryContentBrowsingContext."); window.arguments[0].setTimeout(function() { this.done(); }, 0); window.close(); diff --git a/dom/interfaces/base/nsIRemoteTab.idl b/dom/interfaces/base/nsIRemoteTab.idl index 15ce25511bdf..7995fe263a01 100644 --- a/dom/interfaces/base/nsIRemoteTab.idl +++ b/dom/interfaces/base/nsIRemoteTab.idl @@ -8,6 +8,7 @@ interface nsIPrincipal; webidl Element; webidl WindowGlobalParent; +webidl BrowsingContext; [builtinclass, scriptable, uuid(8e49f7b0-1f98-4939-bf91-e9c39cd56434)] interface nsIRemoteTab : nsISupports @@ -55,6 +56,11 @@ interface nsIRemoteTab : nsISupports */ readonly attribute int32_t osPid; + /** + * The toplevel BrowsingContext loaded in this remote tab. + */ + readonly attribute BrowsingContext browsingContext; + /** * True if we've previously received layers for this tab when switching to * it. diff --git a/dom/ipc/BrowserHost.cpp b/dom/ipc/BrowserHost.cpp index 3cf33d66b240..91843ea768c1 100644 --- a/dom/ipc/BrowserHost.cpp +++ b/dom/ipc/BrowserHost.cpp @@ -228,6 +228,18 @@ BrowserHost::GetOsPid(int32_t* aOsPid) { return NS_OK; } +/* readonly attribute BrowsingContext browsingContext; */ +NS_IMETHODIMP +BrowserHost::GetBrowsingContext(BrowsingContext** aBc) { + if (!mRoot) { + *aBc = nullptr; + return NS_OK; + } + RefPtr bc = mRoot->GetBrowsingContext(); + bc.forget(aBc); + return NS_OK; +} + /* readonly attribute boolean hasPresented; */ NS_IMETHODIMP BrowserHost::GetHasPresented(bool* aHasPresented) { diff --git a/xpfe/appshell/AppWindow.cpp b/xpfe/appshell/AppWindow.cpp index df2801539f3f..70bb3a762641 100644 --- a/xpfe/appshell/AppWindow.cpp +++ b/xpfe/appshell/AppWindow.cpp @@ -450,6 +450,19 @@ AppWindow::GetPrimaryRemoteTab(nsIRemoteTab** aTab) { return NS_OK; } +NS_IMETHODIMP +AppWindow::GetPrimaryContentBrowsingContext( + mozilla::dom::BrowsingContext** aBc) { + if (mPrimaryBrowserParent) { + return mPrimaryBrowserParent->GetBrowsingContext(aBc); + } + if (mPrimaryContentShell) { + return mPrimaryContentShell->GetBrowsingContextXPCOM(aBc); + } + *aBc = nullptr; + return NS_OK; +} + static LayoutDeviceIntSize GetOuterToInnerSizeDifference(nsIWidget* aWindow) { if (!aWindow) { return LayoutDeviceIntSize(); diff --git a/xpfe/appshell/nsChromeTreeOwner.cpp b/xpfe/appshell/nsChromeTreeOwner.cpp index b63c90f122cf..e400c1c482a8 100644 --- a/xpfe/appshell/nsChromeTreeOwner.cpp +++ b/xpfe/appshell/nsChromeTreeOwner.cpp @@ -130,6 +130,13 @@ nsChromeTreeOwner::GetPrimaryRemoteTab(nsIRemoteTab** aTab) { return mAppWindow->GetPrimaryRemoteTab(aTab); } +NS_IMETHODIMP +nsChromeTreeOwner::GetPrimaryContentBrowsingContext( + mozilla::dom::BrowsingContext** aBc) { + NS_ENSURE_STATE(mAppWindow); + return mAppWindow->GetPrimaryContentBrowsingContext(aBc); +} + NS_IMETHODIMP nsChromeTreeOwner::GetPrimaryContentSize(int32_t* aWidth, int32_t* aHeight) { NS_ENSURE_STATE(mAppWindow); diff --git a/xpfe/appshell/nsContentTreeOwner.cpp b/xpfe/appshell/nsContentTreeOwner.cpp index d8e5e0877d72..e98baac37001 100644 --- a/xpfe/appshell/nsContentTreeOwner.cpp +++ b/xpfe/appshell/nsContentTreeOwner.cpp @@ -191,6 +191,13 @@ nsContentTreeOwner::GetPrimaryRemoteTab(nsIRemoteTab** aTab) { return mAppWindow->GetPrimaryRemoteTab(aTab); } +NS_IMETHODIMP +nsContentTreeOwner::GetPrimaryContentBrowsingContext( + mozilla::dom::BrowsingContext** aBc) { + NS_ENSURE_STATE(mAppWindow); + return mAppWindow->GetPrimaryContentBrowsingContext(aBc); +} + NS_IMETHODIMP nsContentTreeOwner::GetPrimaryContentSize(int32_t* aWidth, int32_t* aHeight) { NS_ENSURE_STATE(mAppWindow); diff --git a/xpfe/appshell/nsIAppWindow.idl b/xpfe/appshell/nsIAppWindow.idl index bbb018b9b5be..ca9a17e2dc66 100644 --- a/xpfe/appshell/nsIAppWindow.idl +++ b/xpfe/appshell/nsIAppWindow.idl @@ -24,6 +24,7 @@ interface nsIXULBrowserWindow; interface nsIRemoteTab; interface mozIDOMWindowProxy; interface nsIOpenWindowInfo; +webidl BrowsingContext; native LiveResizeListenerArray(nsTArray>); @@ -56,6 +57,12 @@ interface nsIAppWindow : nsISupports */ readonly attribute nsIRemoteTab primaryRemoteTab; + /** + * Helper for getting the BrowsingContext from either `primaryContentShell` or + * `primaryRemoteTab` depending on which is available. + */ + readonly attribute BrowsingContext primaryContentBrowsingContext; + void remoteTabAdded(in nsIRemoteTab aTab, in boolean aPrimary); void remoteTabRemoved(in nsIRemoteTab aTab);