Bug 1310771 - Part 1: Add an aFlags argument to nsIBrowser::SwapBrowsers, r=mconley

This adds a single flag, SWAP_KEEP_PERMANENT_KEY, which tells the
browser that when it performs the swap, the permanent key should stick
with the browser, rather than following the frameLoader.

This patch also adds the implementation of tabbrowser.swapBrowsers,
which was previously absent, despite being referenced.

MozReview-Commit-ID: CLwJYzpY8Pp
This commit is contained in:
Michael Layzell 2016-11-09 14:47:45 -05:00
Родитель 368a498322
Коммит faee358314
4 изменённых файлов: 45 добавлений и 14 удалений

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

@ -2860,7 +2860,7 @@
this.mIsBusy = true;
}
this._swapBrowserDocShells(aOurTab, otherBrowser);
this._swapBrowserDocShells(aOurTab, otherBrowser, Ci.nsIBrowser.SWAP_DEFAULT);
}
// Handle findbar data (if any)
@ -2893,9 +2893,21 @@
</body>
</method>
<method name="swapBrowsers">
<parameter name="aOurTab"/>
<parameter name="aOtherBrowser"/>
<parameter name="aFlags"/>
<body>
<![CDATA[
this._swapBrowserDocShells(aOurTab, aOtherBrowser, aFlags);
]]>
</body>
</method>
<method name="_swapBrowserDocShells">
<parameter name="aOurTab"/>
<parameter name="aOtherBrowser"/>
<parameter name="aFlags"/>
<body>
<![CDATA[
// Unhook our progress listener
@ -2937,15 +2949,17 @@
remoteBrowser._outerWindowIDBrowserMap.set(aOtherBrowser.outerWindowID, aOtherBrowser);
}
// Swap permanentKey properties.
let ourPermanentKey = ourBrowser.permanentKey;
ourBrowser.permanentKey = aOtherBrowser.permanentKey;
aOtherBrowser.permanentKey = ourPermanentKey;
aOurTab.permanentKey = ourBrowser.permanentKey;
if (remoteBrowser) {
let otherTab = remoteBrowser.getTabForBrowser(aOtherBrowser);
if (otherTab) {
otherTab.permanentKey = aOtherBrowser.permanentKey;
if (!(aFlags & Ci.nsIBrowser.SWAP_KEEP_PERMANENT_KEY)) {
// Swap permanentKey properties.
let ourPermanentKey = ourBrowser.permanentKey;
ourBrowser.permanentKey = aOtherBrowser.permanentKey;
aOtherBrowser.permanentKey = ourPermanentKey;
aOurTab.permanentKey = ourBrowser.permanentKey;
if (remoteBrowser) {
let otherTab = remoteBrowser.getTabForBrowser(aOtherBrowser);
if (otherTab) {
otherTab.permanentKey = aOtherBrowser.permanentKey;
}
}
}

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

@ -426,7 +426,7 @@ nsFrameLoader::AppendPartialSessionHistoryAndSwap(nsIFrameLoader* aOther)
if (!ourBrowser || !otherBrowser) {
return NS_ERROR_FAILURE;
}
if (NS_FAILED(ourBrowser->SwapBrowsers(otherBrowser))) {
if (NS_FAILED(ourBrowser->SwapBrowsers(otherBrowser, nsIBrowser::SWAP_KEEP_PERMANENT_KEY))) {
return NS_ERROR_FAILURE;
}
mGroupedSessionHistory.swap(otherLoader->mGroupedSessionHistory);
@ -462,7 +462,7 @@ nsFrameLoader::RequestGroupedHistoryNavigation(uint32_t aGlobalIndex)
if (!ourBrowser || !otherBrowser) {
return NS_ERROR_FAILURE;
}
if (NS_FAILED(ourBrowser->SwapBrowsers(otherBrowser))) {
if (NS_FAILED(ourBrowser->SwapBrowsers(otherBrowser, nsIBrowser::SWAP_KEEP_PERMANENT_KEY))) {
return NS_ERROR_FAILURE;
}
mGroupedSessionHistory.swap(otherLoader->mGroupedSessionHistory);

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

@ -25,6 +25,22 @@ interface nsIBrowser : nsISupports
void dropLinks(in unsigned long linksCount,
[array, size_is(linksCount)] in wstring links);
/**
* Flags for controlling the behavior of swapBrowsers
*/
/**
* The default options. This is used for swapping browsers between windows
*/
const unsigned long SWAP_DEFAULT = 0;
/**
* If this bit is set, swapping the browsers will not swap the permanentKey of
* the browsers. This is used when performing cross process loads by swapping
* browsers.
*/
const unsigned long SWAP_KEEP_PERMANENT_KEY = 0x1;
/**
* Swapping of frameloaders are usually initiated from a frameloader owner
* or other components operating on frameloader owners. This is done by calling
@ -37,7 +53,7 @@ interface nsIBrowser : nsISupports
* frameloader owners such as <xul:browser> can setup their properties and /
* or listeners properly on swapping.
*/
void swapBrowsers(in nsIBrowser aOtherBrowser);
void swapBrowsers(in nsIBrowser aOtherBrowser, in unsigned long aFlags);
/**
* Close the browser (usually means to remove a tab).

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

@ -1255,6 +1255,7 @@
<method name="swapBrowsers">
<parameter name="aOtherBrowser"/>
<parameter name="aFlags"/>
<body>
<![CDATA[
// The request comes from a XPCOM component, we'd want to redirect
@ -1264,7 +1265,7 @@
if (tabbrowser) {
let tab = tabbrowser.getTabForBrowser(this);
if (tab) {
tabbrowser.swapBrowsers(tab, aOtherBrowser);
tabbrowser.swapBrowsers(tab, aOtherBrowser, aFlags);
return;
}
}