Bug 1718082 - move hasSiblings from BrowserChild to BC and update as a synced field, r=nika

Differential Revision: https://phabricator.services.mozilla.com/D171645
This commit is contained in:
Gijs Kruitbosch 2023-03-13 17:32:08 +00:00
Родитель 5fb3c80f03
Коммит 9e0531a790
13 изменённых файлов: 37 добавлений и 91 удалений

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

@ -29,16 +29,6 @@ export class BrowserTabChild extends JSWindowActorChild {
let docShell = context.docShell;
switch (message.name) {
case "Browser:HasSiblings":
try {
let browserChild = docShell
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIBrowserChild);
let hasSiblings = message.data;
browserChild.hasSiblings = hasSiblings;
} catch (e) {}
break;
// XXX(nika): Should we try to call this in the parent process instead?
case "Browser:Reload":
/* First, we'll try to use the session history object to reload so

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

@ -2056,12 +2056,6 @@
this.getCachedFindBar(tab).browser = aBrowser;
}
tab.linkedBrowser.sendMessageToActor(
"Browser:HasSiblings",
this.tabs.length > 1,
"BrowserTab"
);
evt = document.createEvent("Events");
evt.initEvent("TabRemotenessChange", true, false);
tab.dispatchEvent(evt);
@ -2420,22 +2414,10 @@
// If we transitioned from one browser to two browsers, we need to set
// hasSiblings=false on both the existing browser and the new browser.
if (this.tabs.length == 2) {
this.tabs[0].linkedBrowser.sendMessageToActor(
"Browser:HasSiblings",
true,
"BrowserTab"
);
this.tabs[1].linkedBrowser.sendMessageToActor(
"Browser:HasSiblings",
true,
"BrowserTab"
);
this.tabs[0].linkedBrowser.browsingContext.hasSiblings = true;
this.tabs[1].linkedBrowser.browsingContext.hasSiblings = true;
} else {
aTab.linkedBrowser.sendMessageToActor(
"Browser:HasSiblings",
this.tabs.length > 1,
"BrowserTab"
);
aTab.linkedBrowser.browsingContext.hasSiblings = this.tabs.length > 1;
}
if (aTab.userContextId) {
@ -4085,16 +4067,12 @@
if (this.tabs.length == 2) {
// We're closing one of our two open tabs, inform the other tab that its
// sibling is going away.
this.tabs[0].linkedBrowser.sendMessageToActor(
"Browser:HasSiblings",
false,
"BrowserTab"
);
this.tabs[1].linkedBrowser.sendMessageToActor(
"Browser:HasSiblings",
false,
"BrowserTab"
);
for (let tab of this.tabs) {
let bc = tab.linkedBrowser.browsingContext;
if (bc) {
bc.hasSiblings = false;
}
}
}
let notificationBox = this.readNotificationBox(browser);
@ -6262,12 +6240,6 @@
this.getCachedFindBar(tab).browser = browser;
}
browser.sendMessageToActor(
"Browser:HasSiblings",
this.tabs.length > 1,
"BrowserTab"
);
evt = document.createEvent("Events");
evt.initEvent("TabRemotenessChange", true, false);
tab.dispatchEvent(evt);

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

@ -2904,6 +2904,11 @@ bool BrowsingContext::CanSet(FieldIndex<IDX_IsAppTab>, const bool& aValue,
return XRE_IsParentProcess() && !aSource && IsTop();
}
bool BrowsingContext::CanSet(FieldIndex<IDX_HasSiblings>, const bool& aValue,
ContentParent* aSource) {
return XRE_IsParentProcess() && !aSource && IsTop();
}
bool BrowsingContext::CanSet(FieldIndex<IDX_ShouldDelayMediaFromStart>,
const bool& aValue, ContentParent* aSource) {
return IsTop();

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

@ -139,6 +139,10 @@ struct EmbedderColorSchemes {
/* Hold the pinned/app-tab state and should be used on top level browsing \
* contexts only */ \
FIELD(IsAppTab, bool) \
/* Whether there's more than 1 tab / toplevel browsing context in this \
* parent window. Used to determine if a given BC is allowed to resize \
* and/or move the window or not. */ \
FIELD(HasSiblings, bool) \
/* Indicate that whether we should delay media playback, which would only \
be done on an unvisited tab. And this should only be used on the top \
level browsing contexts */ \
@ -943,6 +947,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
void AddDiscardListener(std::function<void(uint64_t)>&& aListener);
bool IsAppTab() { return GetIsAppTab(); }
bool HasSiblings() { return GetHasSiblings(); }
protected:
virtual ~BrowsingContext();
@ -1119,6 +1124,9 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
bool CanSet(FieldIndex<IDX_IsAppTab>, const bool& aValue,
ContentParent* aSource);
bool CanSet(FieldIndex<IDX_HasSiblings>, const bool& aValue,
ContentParent* aSource);
bool CanSet(FieldIndex<IDX_ShouldDelayMediaFromStart>, const bool& aValue,
ContentParent* aSource);
void DidSet(FieldIndex<IDX_ShouldDelayMediaFromStart>, bool aOldValue);

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

@ -313,6 +313,7 @@ void CanonicalBrowsingContext::ReplacedBy(
Transaction txn;
txn.SetBrowserId(GetBrowserId());
txn.SetIsAppTab(GetIsAppTab());
txn.SetHasSiblings(GetHasSiblings());
txn.SetHistoryID(GetHistoryID());
txn.SetExplicitActive(GetExplicitActive());
txn.SetEmbedderColorSchemes(GetEmbedderColorSchemes());

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

@ -4757,23 +4757,8 @@ bool nsGlobalWindowOuter::CanMoveResizeWindows(CallerType aCallerType) {
}
// Ignore the request if we have more than one tab in the window.
if (XRE_IsContentProcess()) {
nsCOMPtr<nsIDocShell> docShell = GetDocShell();
if (docShell) {
nsCOMPtr<nsIBrowserChild> child = docShell->GetBrowserChild();
bool hasSiblings = true;
if (child && NS_SUCCEEDED(child->GetHasSiblings(&hasSiblings)) &&
hasSiblings) {
return false;
}
}
} else {
nsCOMPtr<nsIDocShellTreeOwner> treeOwner = GetTreeOwner();
uint32_t itemCount = 0;
if (treeOwner && NS_SUCCEEDED(treeOwner->GetTabCount(&itemCount)) &&
itemCount > 1) {
return false;
}
if (mBrowsingContext->Top()->HasSiblings()) {
return false;
}
}

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

@ -137,6 +137,13 @@ interface BrowsingContext {
*/
[SetterThrows] attribute boolean isAppTab;
/**
* Sets whether this is BC has siblings **at the toplevel** (e.g. in a tabbed
* browser environment). Used to determine if web content can resize the top
* window. Never set correctly for non-top BCs.
*/
[SetterThrows] attribute boolean hasSiblings;
// The inRDMPane flag indicates whether or not Responsive Design Mode is
// active for the browsing context.
[SetterThrows] attribute boolean inRDMPane;

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

@ -32,11 +32,6 @@ interface nsIBrowserChild : nsISupports
readonly attribute uint64_t tabId;
/*
* Indicates whether or not there are other tabs in this tab's window.
*/
attribute boolean hasSiblings;
/**
* Send a message from the BrowserChild to the BrowserParent that a
* nsIWebNavigation navigation finished in the child.

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

@ -309,7 +309,6 @@ BrowserChild::BrowserChild(ContentChild* aManager, const TabId& aTabId,
mHasValidInnerSize(false),
mDestroyed(false),
mIsTopLevel(aIsTopLevel),
mHasSiblings(false),
mIsTransparent(false),
mIPCOpen(false),
mDidSetRealShowInfo(false),
@ -3395,16 +3394,6 @@ nsresult BrowserChild::CanCancelContentJS(
return NS_OK;
}
nsresult BrowserChild::GetHasSiblings(bool* aHasSiblings) {
*aHasSiblings = mHasSiblings;
return NS_OK;
}
nsresult BrowserChild::SetHasSiblings(bool aHasSiblings) {
mHasSiblings = aHasSiblings;
return NS_OK;
}
NS_IMETHODIMP BrowserChild::OnStateChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
uint32_t aStateFlags,

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

@ -801,11 +801,6 @@ class BrowserChild final : public nsMessageManagerScriptExecutor,
// actor in a remote browser.
bool mIsTopLevel : 1;
// Whether or not this tab has siblings (other tabs in the same window).
// This is one factor used when choosing to allow or deny a non-system
// script's attempt to resize the window.
bool mHasSiblings : 1;
bool mIsTransparent : 1;
bool mIPCOpen : 1;

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

@ -1154,7 +1154,6 @@ nsresult ContentChild::ProvideWindowCommon(
nsTArray<FrameScriptInfo> frameScripts(std::move(info.frameScripts()));
uint32_t maxTouchPoints = info.maxTouchPoints();
DimensionInfo dimensionInfo = std::move(info.dimensions());
bool hasSiblings = info.hasSiblings();
// Once this function exits, we should try to exit the nested event loop.
ready = true;
@ -1187,7 +1186,6 @@ nsresult ContentChild::ProvideWindowCommon(
newChild->WebWidget()->GetDefaultScale().scale);
newChild->SetMaxTouchPoints(maxTouchPoints);
newChild->SetHasSiblings(hasSiblings);
if (aForceNoOpener || !parent) {
MOZ_DIAGNOSTIC_ASSERT(!browsingContext->HadOriginalOpener());

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

@ -5790,7 +5790,6 @@ mozilla::ipc::IPCResult ContentParent::RecvCreateWindow(
// We always expect to open a new window here. If we don't, it's an error.
cwi.windowOpened() = true;
cwi.maxTouchPoints() = 0;
cwi.hasSiblings() = false;
// Make sure to resolve the resolver when this function exits, even if we
// failed to generate a valid response.
@ -5852,7 +5851,6 @@ mozilla::ipc::IPCResult ContentParent::RecvCreateWindow(
return IPC_FAIL(this, "New BrowsingContext has mismatched LoadContext");
}
}
BrowserParent::AutoUseNewTab aunt(newTab);
nsCOMPtr<nsIRemoteTab> newRemoteTab;
@ -5874,6 +5872,11 @@ mozilla::ipc::IPCResult ContentParent::RecvCreateWindow(
MOZ_ASSERT(BrowserHost::GetFrom(newRemoteTab.get()) ==
newTab->GetBrowserHost());
// This used to happen in the child - there may now be a better place to
// do this work.
MOZ_ALWAYS_SUCCEEDS(
newBC->SetHasSiblings(openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB));
newTab->SwapFrameScriptsFrom(cwi.frameScripts());
newTab->MaybeShowFrame();
@ -5883,7 +5886,6 @@ mozilla::ipc::IPCResult ContentParent::RecvCreateWindow(
}
cwi.maxTouchPoints() = newTab->GetMaxTouchPoints();
cwi.hasSiblings() = (openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB);
return IPC_OK();
}

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

@ -207,7 +207,6 @@ struct CreatedWindowInfo
FrameScriptInfo[] frameScripts;
uint32_t maxTouchPoints;
DimensionInfo dimensions;
bool hasSiblings;
};