From 3f5ae8bc7c6e21f03a66a0bc49360f68d3084eee Mon Sep 17 00:00:00 2001 From: Infocatcher Date: Fri, 16 May 2014 17:05:04 +0400 Subject: [PATCH] Add window.privateTab.tabLabelIsEmpty() API (#143) --- bootstrap.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/bootstrap.js b/bootstrap.js index d2b81be..3d00a79 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -2947,8 +2947,11 @@ var privateTab = { isEmptyTab: function(tab, gBrowser) { // See "addTab" method in chrome://browser/content/tabbrowser.xml var tabLabel = tab.getAttribute("label") || ""; - if(tabLabel in this.emptyTabLabels) + if(tabLabel in this.emptyTabLabels) { + if(_dbg && this.emptyTabLabels[tabLabel] == "API") + _log("isEmptyTab() + API: detect \"" + tabLabel + "\" as empty"); return true; + } if(/^\w+:\S*$/.test(tabLabel)) return false; // We should check tab label for SeaMonkey and old Firefox @@ -3844,6 +3847,26 @@ API.prototype = { stopToOpenTabs: function privateTab_stopToOpenTabs() { this._openNewTabsPrivate = undefined; this.window.removeEventListener("TabOpen", this, true); + }, + tabLabelIsEmpty: function(tabLabel, isEmpty) { + var emptyLabels = privateTabInternal.emptyTabLabels; + if(isEmpty === undefined) + return tabLabel in emptyLabels; + if(tabLabel in emptyLabels && emptyLabels[tabLabel] != "API") { + var stack = Components.stack.caller; + Components.utils.reportError(new Error( + LOG_PREFIX + "tabLabelIsEmpty(): \"" + tabLabel + "\" => you can't modify built-in entries!", + stack.filename, + stack.lineNumber + )); + return true; + } + if(isEmpty) + emptyLabels[tabLabel] = "API"; + else + delete emptyLabels[tabLabel]; + _log("tabLabelIsEmpty(): \"" + tabLabel + "\" => " + isEmpty); + return isEmpty; } };