Bug 1502069 - isTabEmpty should be a property on the tab rather than a global function. r=dao

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2018-10-26 16:42:11 +00:00
Родитель 109fda93b5
Коммит e7f2c79ef9
11 изменённых файлов: 39 добавлений и 39 удалений

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

@ -7175,7 +7175,7 @@ function BrowserOpenAddonsMgr(aView) {
// This must be a new load, else the ping/pong would have
// found the window above.
let whereToOpen = (window.gBrowser && isTabEmpty(gBrowser.selectedTab)) ?
let whereToOpen = (window.gBrowser && gBrowser.selectedTab.isEmpty) ?
"current" :
"tab";
openTrustedLinkIn("about:addons", whereToOpen);
@ -7225,7 +7225,7 @@ function AddKeywordForSearchField() {
function undoCloseTab(aIndex) {
// wallpaper patch to prevent an unnecessary blank tab (bug 343895)
var blankTabToRemove = null;
if (gBrowser.tabs.length == 1 && isTabEmpty(gBrowser.selectedTab))
if (gBrowser.tabs.length == 1 && gBrowser.selectedTab.isEmpty)
blankTabToRemove = gBrowser.selectedTab;
var tab = null;
@ -7253,30 +7253,6 @@ function undoCloseWindow(aIndex) {
return window;
}
/*
* Determines if a tab is "empty", usually used in the context of determining
* if it's ok to close the tab.
*/
function isTabEmpty(aTab) {
if (aTab.hasAttribute("busy"))
return false;
if (aTab.hasAttribute("customizemode"))
return false;
let browser = aTab.linkedBrowser;
if (!isBlankPageURL(browser.currentURI.spec))
return false;
if (!checkEmptyPageOrigin(browser))
return false;
if (browser.canGoForward || browser.canGoBack)
return false;
return true;
}
/**
* Check whether a page can be considered as 'empty', that its URI
* reflects its origin, and that if it's loaded in a tab, that tab
@ -7655,7 +7631,7 @@ function switchToTabHavingURI(aURI, aOpenNew, aOpenParams = {}) {
// No opened tab has that url.
if (aOpenNew) {
if (isBrowserWindow && isTabEmpty(gBrowser.selectedTab))
if (isBrowserWindow && gBrowser.selectedTab.isEmpty)
openTrustedLinkIn(aURI.spec, "current", aOpenParams);
else
openTrustedLinkIn(aURI.spec, "tab", aOpenParams);

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

@ -1118,7 +1118,7 @@ window._gBrowser = {
return;
}
if (!window.fullScreen || isTabEmpty(newTab)) {
if (!window.fullScreen || newTab.isEmpty) {
focusAndSelectUrlBar();
return;
}
@ -5008,7 +5008,7 @@ class TabProgressListener {
if (aWebProgress.isTopLevel) {
let isSuccessful = Components.isSuccessCode(aStatus);
if (!isSuccessful && !isTabEmpty(this.mTab)) {
if (!isSuccessful && !this.mTab.isEmpty) {
// Restore the current document's location in case the
// request was stopped (possibly from a content script)
// before the location changed.

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

@ -2059,6 +2059,30 @@
</getter>
</property>
<property name="isEmpty" readonly="true">
<getter>
// Determines if a tab is "empty", usually used in the context of determining
// if it's ok to close the tab.
if (this.hasAttribute("busy"))
return false;
if (this.hasAttribute("customizemode"))
return false;
let browser = this.linkedBrowser;
if (!isBlankPageURL(browser.currentURI.spec))
return false;
if (!checkEmptyPageOrigin(browser))
return false;
if (browser.canGoForward || browser.canGoBack)
return false;
return true;
</getter>
</property>
<property name="lastAccessed">
<getter>
return this._lastAccessed == Infinity ? Date.now() : this._lastAccessed;

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

@ -50,7 +50,7 @@ add_task(async function checkPrefTurnsOffCanonize() {
let tabsToClose = [];
// Ensure we don't end up loading something in the current tab becuase it's empty:
if (isTabEmpty(gBrowser.selectedTab)) {
if (gBrowser.selectedTab.isEmpty) {
tabsToClose.push(await BrowserTestUtils.openNewForegroundTab({gBrowser, opening: "about:mozilla"}));
}
let initialTabURL = gBrowser.selectedBrowser.currentURI.spec;

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

@ -620,7 +620,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
}
reuseEmpty = true;
}
if (where == "tab" && reuseEmpty && isTabEmpty(gBrowser.selectedTab)) {
if (where == "tab" && reuseEmpty && gBrowser.selectedTab.isEmpty) {
where = "current";
}
return where;
@ -736,7 +736,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
};
if (switchToTabHavingURI(url, false, loadOpts) &&
isTabEmpty(prevTab)) {
prevTab.isEmpty) {
gBrowser.removeTab(prevTab);
}
return;

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

@ -677,7 +677,7 @@ var PlacesUIUtils = {
if (where == "current" && !aNode.uri.startsWith("javascript:")) {
where = "tab";
}
if (where == "tab" && browserWindow.isTabEmpty(browserWindow.gBrowser.selectedTab)) {
if (where == "tab" && browserWindow.gBrowser.selectedTab.isEmpty) {
where = "current";
}
}

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

@ -19,7 +19,7 @@ var Pocket = {
let win = event.view;
let where = win.whereToOpenLink(event);
// Never override the current tab unless it's blank:
if (where == "current" && !win.isTabEmpty(win.gBrowser.selectedTab)) {
if (where == "current" && !win.gBrowser.selectedTab.isEmpty) {
where = "tab";
}
win.openTrustedLinkIn(this.listURL, where);

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

@ -857,7 +857,7 @@ class MozSearchOneOffs extends MozXULElement {
} else {
var newTabPref = Services.prefs.getBoolPref("browser.search.openintab");
if ((aEvent instanceof KeyboardEvent && aEvent.altKey) ^ newTabPref &&
!isTabEmpty(gBrowser.selectedTab)) {
!gBrowser.selectedTab.isEmpty) {
where = "tab";
}
if (aEvent instanceof MouseEvent &&

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

@ -273,7 +273,7 @@ class MozSearchbar extends MozXULElement {
} else {
var newTabPref = Services.prefs.getBoolPref("browser.search.openintab");
if (((aEvent instanceof KeyboardEvent && aEvent.altKey) ^ newTabPref) &&
!isTabEmpty(gBrowser.selectedTab)) {
!gBrowser.selectedTab.isEmpty) {
where = "tab";
}
if ((aEvent instanceof MouseEvent) &&

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

@ -215,7 +215,7 @@ class UrlbarController {
};
if (this.window.switchToTabHavingURI(url, false, loadOpts) &&
this.window.isTabEmpty(prevTab)) {
prevTab.isEmpty) {
this.window.gBrowser.removeTab(prevTab);
}
return;
@ -381,7 +381,7 @@ class UrlbarController {
}
if (where == "tab" &&
reuseEmpty &&
this.window.isTabEmpty(this.window.gBrowser.selectedTab)) {
this.window.gBrowser.selectedTab.isEmpty) {
where = "current";
}
return where;

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

@ -52,7 +52,7 @@ add_task(function test_handleEnteredText_url() {
add_task(function test_resultSelected_switchtab() {
sandbox.stub(window, "switchToTabHavingURI").returns(true);
sandbox.stub(window, "isTabEmpty").returns(false);
sandbox.stub(window.gBrowser.selectedTab, "isEmpty").returns(false);
sandbox.stub(window.gBrowser, "removeTab");
const event = new MouseEvent("click", {button: 0});