Bug 1318472 - Remove inactive hidden tabs when removing the primary tab, r=ehsan

MozReview-Commit-ID: KiMsKOljNpE
This commit is contained in:
Michael Layzell 2016-12-14 01:55:00 +08:00
Родитель 3583928097
Коммит d24aef4068
5 изменённых файлов: 79 добавлений и 0 удалений

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

@ -2525,6 +2525,13 @@
var browser = this.getBrowserForTab(aTab); var browser = this.getBrowserForTab(aTab);
// Start closing the FrameLoaderOwners which are inactive, so that
// they are cleaned up as well.
let frameLoader = browser.frameLoader;
if (frameLoader && frameLoader.groupedSessionHistory) {
frameLoader.groupedSessionHistory.closeInactiveFrameLoaderOwners();
}
if (!aTab._pendingPermitUnload && !aAdoptedByTab && !aSkipPermitUnload) { if (!aTab._pendingPermitUnload && !aAdoptedByTab && !aSkipPermitUnload) {
// We need to block while calling permitUnload() because it // We need to block while calling permitUnload() because it
// processes the event queue and may lead to another removeTab() // processes the event queue and may lead to another removeTab()

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

@ -492,3 +492,5 @@ tags = mcb
[browser_newwindow_focus.js] [browser_newwindow_focus.js]
skip-if = (os == "linux" && !e10s) # Bug 1263254 - Perma fails on Linux without e10s for some reason. skip-if = (os == "linux" && !e10s) # Bug 1263254 - Perma fails on Linux without e10s for some reason.
[browser_bug1299667.js] [browser_bug1299667.js]
[browser_close_dependent_tabs.js]
skip-if = !e10s # GroupedSHistory is e10s-only

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

@ -0,0 +1,51 @@
add_task(function* () {
yield SpecialPowers.pushPrefEnv({
set: [["browser.groupedhistory.enabled", true]]
});
// Wait for a process change and then fulfil the promise.
function awaitProcessChange(browser) {
return new Promise(resolve => {
browser.addEventListener("BrowserChangedProcess", function bcp(e) {
browser.removeEventListener("BrowserChangedProcess", bcp);
ok(true, "The browser changed process!");
resolve();
});
});
}
let tab2;
// Test 1: Create prerendered browser, and don't switch to it, then close the tab
yield BrowserTestUtils.withNewTab({ gBrowser, url: "data:text/html,a" }, function* (browser1) {
// Set up the grouped SHEntry setup
tab2 = gBrowser.loadOneTab("data:text/html,b", {
referrerPolicy: Ci.nsIHttpChannel.REFERRER_POLICY_DEFAULT,
allowThirdPartyFixup: true,
relatedToCurrent: true,
isPrerendered: true,
});
});
// At this point tab2 should be closed
todo(!tab2.linkedBrowser, "The new tab should be closed");
yield BrowserTestUtils.removeTab(tab2); // XXX: Shouldn't be needed once the todo is fixed
// Test 2: Create prerendered browser, switch to it, then close the tab
yield BrowserTestUtils.withNewTab({ gBrowser, url: "data:text/html,a" }, function* (browser1) {
// Set up the grouped SHEntry setup
tab2 = gBrowser.loadOneTab("data:text/html,b", {
referrerPolicy: Ci.nsIHttpChannel.REFERRER_POLICY_DEFAULT,
allowThirdPartyFixup: true,
relatedToCurrent: true,
isPrerendered: true,
});
yield BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
browser1.frameLoader.appendPartialSessionHistoryAndSwap(
tab2.linkedBrowser.frameLoader);
yield awaitProcessChange(browser1);
});
// At this point tab2 should be closed
ok(!tab2.linkedBrowser, "The new tab should be closed");
});

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

@ -44,4 +44,10 @@ interface nsIGroupedSHistory : nsISupports
* partial session history. * partial session history.
*/ */
void gotoIndex(in unsigned long aGlobalIndex, out nsIFrameLoader aTargetLoaderToSwap); void gotoIndex(in unsigned long aGlobalIndex, out nsIFrameLoader aTargetLoaderToSwap);
/**
* Close the FrameLoaderOwners of the inactive PartialSHistories in this GlobalSHistory.
* This does not remove the PartialSHistories from the GroupedSHistory.
*/
void closeInactiveFrameLoaderOwners();
}; };

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

@ -168,5 +168,18 @@ GroupedSHistory::GroupedHistoryEnabled() {
return Preferences::GetBool("browser.groupedhistory.enabled", false); return Preferences::GetBool("browser.groupedhistory.enabled", false);
} }
NS_IMETHODIMP
GroupedSHistory::CloseInactiveFrameLoaderOwners()
{
for (int32_t i = 0; i < mPartialHistories.Count(); ++i) {
if (i != mIndexOfActivePartialHistory) {
nsCOMPtr<nsIFrameLoader> loader;
mPartialHistories[i]->GetOwnerFrameLoader(getter_AddRefs(loader));
loader->RequestFrameLoaderClose();
}
}
return NS_OK;
}
} // namespace dom } // namespace dom
} // namespace mozilla } // namespace mozilla