Bug 1350642 - Keep the tabCountResizable property in sync; r=dao

Differential Revision: https://phabricator.services.mozilla.com/D2197

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Haik Aftandilian 2018-07-19 18:05:35 +00:00
Родитель e2f970d134
Коммит 59a99c8595
9 изменённых файлов: 73 добавлений и 17 удалений

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

@ -52,6 +52,14 @@ addMessageListener("Browser:HideSessionRestoreButton", function(message) {
}
});
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
addMessageListener("Browser:HasSiblings", function(message) {
let tabChild = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsITabChild);
let hasSiblings = message.data;
tabChild.hasSiblings = hasSiblings;
});
}
// XXX(nika): Should we try to call this in the parent process instead?
addMessageListener("Browser:Reload", function(message) {

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

@ -1666,6 +1666,10 @@ window._gBrowser = {
this.getCachedFindBar(tab).browser = aBrowser;
}
tab.linkedBrowser
.messageManager
.sendAsyncMessage("Browser:HasSiblings", this.tabs.length > 1);
evt = document.createEvent("Events");
evt.initEvent("TabRemotenessChange", true, false);
tab.dispatchEvent(evt);
@ -2043,6 +2047,17 @@ window._gBrowser = {
this._outerWindowIDBrowserMap.set(browser.outerWindowID, browser);
}
// 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) {
window.messageManager
.broadcastAsyncMessage("Browser:HasSiblings", true);
} else {
aTab.linkedBrowser
.messageManager
.sendAsyncMessage("Browser:HasSiblings", this.tabs.length > 1);
}
var evt = new CustomEvent("TabBrowserInserted", { bubbles: true, detail: { insertedOnTabCreation: aInsertedOnTabCreation } });
aTab.dispatchEvent(evt);
},
@ -2815,6 +2830,13 @@ window._gBrowser = {
aTab.dispatchEvent(evt);
Services.telemetry.recordEvent("savant", "tab", "close", null, { subcategory: "frame" });
if (this.tabs.length == 2) {
// We're closing one of our two open tabs, inform the other tab that its
// sibling is going away.
window.messageManager
.broadcastAsyncMessage("Browser:HasSiblings", false);
}
if (aTab.linkedPanel) {
if (!aAdoptedByTab && !gMultiProcessBrowser) {
// Prevent this tab from showing further dialogs, since we're closing it

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

@ -4516,7 +4516,7 @@ nsGlobalWindowOuter::CanMoveResizeWindows(CallerType aCallerType)
if (child &&
NS_SUCCEEDED(child->GetHasSiblings(&hasSiblings)) &&
hasSiblings) {
child->SendGetTabCount(&itemCount);
return false;
}
}
} else {

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

@ -988,6 +988,7 @@ ContentChild::ProvideWindowCommon(TabChild* aTabOpener,
CompositorOptions compositorOptions = info.compositorOptions();
uint32_t maxTouchPoints = info.maxTouchPoints();
DimensionInfo dimensionInfo = info.dimensions();
bool hasSiblings = info.hasSiblings();
// Once this function exits, we should try to exit the nested event loop.
ready = true;
@ -1030,6 +1031,7 @@ ContentChild::ProvideWindowCommon(TabChild* aTabOpener,
}
newChild->SetMaxTouchPoints(maxTouchPoints);
newChild->SetHasSiblings(hasSiblings);
// Set the opener window for this window before we start loading the document
// inside of it. We have to do this before loading the remote scripts, because

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

@ -4719,6 +4719,7 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
nsresult& aResult,
nsCOMPtr<nsITabParent>& aNewTabParent,
bool* aWindowIsNew,
int32_t& aOpenLocation,
nsIPrincipal* aTriggeringPrincipal,
uint32_t aReferrerPolicy,
bool aLoadURI)
@ -4775,11 +4776,11 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
}
}
int32_t openLocation = nsWindowWatcher::GetWindowOpenLocation(
aOpenLocation = nsWindowWatcher::GetWindowOpenLocation(
outerWin, aChromeFlags, aCalledFromJS, aPositionSpecified, aSizeSpecified);
MOZ_ASSERT(openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB ||
openLocation == nsIBrowserDOMWindow::OPEN_NEWWINDOW);
MOZ_ASSERT(aOpenLocation == nsIBrowserDOMWindow::OPEN_NEWTAB ||
aOpenLocation == nsIBrowserDOMWindow::OPEN_NEWWINDOW);
// Read the origin attributes for the tab from the opener tabParent.
OriginAttributes openerOriginAttributes;
@ -4790,7 +4791,7 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
openerOriginAttributes.mPrivateBrowsingId = 1;
}
if (openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB) {
if (aOpenLocation == nsIBrowserDOMWindow::OPEN_NEWTAB) {
if (NS_WARN_IF(!browserDOMWin)) {
aResult = NS_ERROR_ABORT;
return IPC_OK();
@ -4808,13 +4809,13 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
nsCOMPtr<nsIFrameLoaderOwner> frameLoaderOwner;
if (aLoadURI) {
aResult = browserDOMWin->OpenURIInFrame(aURIToLoad,
params, openLocation,
params, aOpenLocation,
nsIBrowserDOMWindow::OPEN_NEW,
aNextTabParentId, aName,
getter_AddRefs(frameLoaderOwner));
} else {
aResult = browserDOMWin->CreateContentWindowInFrame(aURIToLoad,
params, openLocation,
params, aOpenLocation,
nsIBrowserDOMWindow::OPEN_NEW,
aNextTabParentId, aName,
getter_AddRefs(frameLoaderOwner));
@ -4833,13 +4834,13 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
} else if (NS_SUCCEEDED(aResult) && !frameLoaderOwner) {
// Fall through to the normal window opening code path when there is no
// window which we can open a new tab in.
openLocation = nsIBrowserDOMWindow::OPEN_NEWWINDOW;
aOpenLocation = nsIBrowserDOMWindow::OPEN_NEWWINDOW;
} else {
*aWindowIsNew = false;
}
// If we didn't retarget our window open into a new window, we should return now.
if (openLocation != nsIBrowserDOMWindow::OPEN_NEWWINDOW) {
if (aOpenLocation != nsIBrowserDOMWindow::OPEN_NEWWINDOW) {
return IPC_OK();
}
}
@ -4941,6 +4942,7 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab,
cwi.windowOpened() = true;
cwi.layersId() = LayersId{0};
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.
@ -4973,12 +4975,13 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab,
const nsCOMPtr<nsIURI> uriToLoad = DeserializeURI(aURIToLoad);
nsCOMPtr<nsITabParent> newRemoteTab;
int32_t openLocation = nsIBrowserDOMWindow::OPEN_NEWWINDOW;
mozilla::ipc::IPCResult ipcResult =
CommonCreateWindow(aThisTab, /* aSetOpener = */ true, aChromeFlags,
aCalledFromJS, aPositionSpecified, aSizeSpecified,
uriToLoad, aFeatures, aBaseURI, aFullZoom,
nextTabParentId, VoidString(), rv,
newRemoteTab, &cwi.windowOpened(),
newRemoteTab, &cwi.windowOpened(), openLocation,
aTriggeringPrincipal, aReferrerPolicy,
/* aLoadUri = */ false);
if (!ipcResult) {
@ -5009,6 +5012,8 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab,
cwi.dimensions() = newTab->GetDimensionInfo();
}
cwi.hasSiblings() = (openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB);
return IPC_OK();
}
@ -5030,14 +5035,16 @@ ContentParent::RecvCreateWindowInDifferentProcess(
nsCOMPtr<nsITabParent> newRemoteTab;
bool windowIsNew;
nsCOMPtr<nsIURI> uriToLoad = DeserializeURI(aURIToLoad);
int32_t openLocation = nsIBrowserDOMWindow::OPEN_NEWWINDOW;
nsresult rv;
mozilla::ipc::IPCResult ipcResult =
CommonCreateWindow(aThisTab, /* aSetOpener = */ false, aChromeFlags,
aCalledFromJS, aPositionSpecified, aSizeSpecified,
uriToLoad, aFeatures, aBaseURI, aFullZoom,
/* aNextTabParentId = */ 0, aName, rv,
newRemoteTab, &windowIsNew, aTriggeringPrincipal,
aReferrerPolicy, /* aLoadUri = */ true);
newRemoteTab, &windowIsNew, openLocation,
aTriggeringPrincipal, aReferrerPolicy,
/* aLoadUri = */ true);
if (!ipcResult) {
return ipcResult;
}

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

@ -736,6 +736,7 @@ private:
nsresult& aResult,
nsCOMPtr<nsITabParent>& aNewTabParent,
bool* aWindowIsNew,
int32_t& aOpenLocation,
nsIPrincipal* aTriggeringPrincipal,
uint32_t aReferrerPolicy,
bool aLoadUri);

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

@ -125,6 +125,7 @@ struct CreatedWindowInfo
CompositorOptions compositorOptions;
uint32_t maxTouchPoints;
DimensionInfo dimensions;
bool hasSiblings;
};

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

@ -411,7 +411,7 @@ TabChild::TabChild(nsIContentChild* aManager,
, mHasValidInnerSize(false)
, mDestroyed(false)
, mUniqueId(aTabId)
, mHasSiblings(true)
, mHasSiblings(false)
, mIsTransparent(false)
, mIPCOpen(false)
, mParentIsActive(false)
@ -3492,6 +3492,20 @@ TabChild::TabGroup()
return mTabGroup;
}
nsresult
TabChild::GetHasSiblings(bool* aHasSiblings)
{
*aHasSiblings = mHasSiblings;
return NS_OK;
}
nsresult
TabChild::SetHasSiblings(bool aHasSiblings)
{
mHasSiblings = aHasSiblings;
return NS_OK;
}
TabChildGlobal::TabChildGlobal(TabChild* aTabChild)
: ContentFrameMessageManager(new nsFrameMessageManager(aTabChild)),
mTabChild(aTabChild)

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

@ -29,8 +29,9 @@
let linkclick = () => {
clicky.removeEventListener('click', linkclick);
let popup = window.open("about:blank", "_blank", "width=500,height=500");
is(popup.innerHeight, 500);
is(popup.innerWidth, 500);
is(popup.innerHeight, 500, "starting width is 500");
is(popup.innerWidth, 500, "starting height in 500");
popup.resizeBy(50, 0);
// We resized synchronously. If this happened, we sometimes won't fire
@ -52,8 +53,8 @@
synthesizeMouseAtCenter(clicky, {}, window);
let popup = await popupPromise;
is(popup.innerHeight, 500);
is(popup.innerWidth, 550);
is(popup.innerHeight, 500, "ending height is 500");
is(popup.innerWidth, 550, "ending width is 550");
popup.close();
});
</script>