Skip to content

Commit 6df0b76

Browse files
committed
Exclude protected tabs when warning about closing tabs
1 parent e397266 commit 6df0b76

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

chrome/content/tabutils.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,14 @@ tabutils._protectAndLockTab = function() {
11781178
}
11791179
};
11801180

1181+
gBrowser.isProtected = function isProtected(aTab) {
1182+
return aTab.hasAttribute("protected") || aTab.pinned && this._autoProtectPinned;
1183+
};
1184+
1185+
gBrowser.isLocked = function isLocked(aTab) {
1186+
return aTab.hasAttribute("locked") || aTab.pinned && this._autoLockPinned;
1187+
};
1188+
11811189
TU_hookCode("gBrowser.onTabRestoring", "}", function() {
11821190
this.protectTab(aTab, ss.getTabValue(aTab, "protected") == "true", true);
11831191
this.lockTab(aTab, ss.getTabValue(aTab, "locked") == "true", true);
@@ -1199,30 +1207,23 @@ tabutils._protectAndLockTab = function() {
11991207
TU_hookCode("gBrowser.onLocationChange", "}", "this.autoProtectTab(aTab, uri, tags);this.autoLockTab(aTab, uri, tags);");
12001208

12011209
TU_hookCode("gBrowser.removeTab", "{", function() {
1202-
if (aTab.hasAttribute("protected") ||
1203-
aTab.pinned && TU_getPref("extensions.tabutils.pinTab.autoProtect", false))
1210+
if (this.isProtected(aTab))
12041211
return;
12051212
});
12061213
TU_hookCode("gBrowser.createTooltip", /(tab|tn).mOverCloseButton/, "$& && !$1.hasAttribute('protected')");
12071214

12081215
TU_hookCode("gBrowser.loadURI", "{", function() {
1209-
let locked = this.mCurrentTab.hasAttribute("locked")
1210-
|| this.mCurrentTab.pinned && TU_getPref("extensions.tabutils.pinTab.autoLock", false);
1211-
if (locked && !aURI.startsWith("javascript:"))
1216+
if (this.isLocked(this.mCurrentTab) && !aURI.startsWith("javascript:"))
12121217
return this.loadOneTab(aURI, aReferrerURI, aCharset, null, null, false);
12131218
});
12141219

12151220
TU_hookCode("gBrowser.loadURIWithFlags", "{", function() {
1216-
let locked = this.mCurrentTab.hasAttribute("locked")
1217-
|| this.mCurrentTab.pinned && TU_getPref("extensions.tabutils.pinTab.autoLock", false);
1218-
if (locked && !aURI.startsWith("javascript:"))
1221+
if (this.isLocked(this.mCurrentTab) && !aURI.startsWith("javascript:"))
12191222
return this.loadOneTab(aURI, aReferrerURI, aCharset, aPostData, null, aFlags & Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP);
12201223
});
12211224

12221225
TU_hookCode("contentAreaClick", /if[^{}]*event.button == 0[^{}]*{([^{}]|{[^{}]*}|{([^{}]|{[^{}]*})*})*(?=})/, "$&" + (function() {
1223-
let locked = gBrowser.mCurrentTab.hasAttribute("locked")
1224-
|| gBrowser.mCurrentTab.pinned && TU_getPref("extensions.tabutils.pinTab.autoLock", false);
1225-
if (locked && !href.startsWith("javascript:")) {
1226+
if (gBrowser.isLocked(gBrowser.mCurrentTab) && !href.startsWith("javascript:")) {
12261227
openNewTabWith(href, linkNode.ownerDocument, null, event, false);
12271228
event.preventDefault();
12281229
return;
@@ -1345,8 +1346,7 @@ tabutils._restartTab = function() {
13451346
if (aTab.hasAttribute("pending")) // Bug 817947 [Fx20]
13461347
return;
13471348

1348-
if (aTab.hasAttribute("locked") ||
1349-
aTab.pinned && TU_getPref("extensions.tabutils.pinTab.autoLock", false))
1349+
if (this.isLocked(aTab))
13501350
return;
13511351

13521352
var tabState = tabutils._ss.getTabState(aTab);
@@ -1720,6 +1720,8 @@ tabutils._multiTabHandler = function() {
17201720
aTabs = aTabs ? "length" in aTabs ? aTabs : [aTabs] : [];
17211721
bTabs = bTabs ? "length" in bTabs ? bTabs : [bTabs] : [];
17221722

1723+
aTabs = Array.filter(aTabs, function(aTab) !this.isProtected(aTab), this);
1724+
17231725
if (bTabs.length > 0)
17241726
aTabs = Array.filter(aTabs, function(aTab) Array.indexOf(bTabs, aTab) == -1);
17251727

@@ -2464,13 +2466,13 @@ tabutils._tabContextMenu = function() {
24642466
}
24652467

24662468
[
2467-
["context_protectTab", "protected", "autoProtect"],
2468-
["context_lockTab", "locked", "autoLock"],
2469-
["context_faviconizeTab", "faviconized", "autoFaviconize"]
2470-
].forEach(function([aId, aAttr, aPref]) {
2469+
["context_protectTab", "protected", "_autoProtectPinned"],
2470+
["context_lockTab", "locked", "_autoLockPinned"],
2471+
["context_faviconizeTab", "faviconized", "_autoFaviconizePinned"]
2472+
].forEach(function([aId, aAttr, aProp]) {
24712473
let item = $(aId);
24722474
if (item && !item.hidden && !item.collapsed) {
2473-
let disabled = TU_getPref("extensions.tabutils.pinTab." + aPref, false) &&
2475+
let disabled = gBrowser[aProp] &&
24742476
tabs.every(function(aTab) aTab.pinned && !aTab.hasAttribute(aAttr));
24752477
item.setAttribute("disabled", disabled);
24762478
item.setAttribute("checked", disabled || tabs.every(function(aTab) aTab.hasAttribute(aAttr)));
@@ -3200,8 +3202,17 @@ tabutils._tabPrefObserver = {
32003202
tabsToolbar._dragBindingAlive = TU_getPref("extensions.tabutils.dragBindingAlive", true);
32013203
},
32023204

3205+
pinTab_autoProtect: function() {
3206+
gBrowser._autoProtectPinned = TU_getPref("extensions.tabutils.pinTab.autoProtect");
3207+
},
3208+
3209+
pinTab_autoLock: function() {
3210+
gBrowser._autoLockPinned = TU_getPref("extensions.tabutils.pinTab.autoLock");
3211+
},
3212+
32033213
pinTab_autoFaviconize: function() {
3204-
gBrowser.mTabContainer.setAttribute("autoFaviconizePinned", TU_getPref("extensions.tabutils.pinTab.autoFaviconize"));
3214+
gBrowser._autoFaviconizePinned = TU_getPref("extensions.tabutils.pinTab.autoFaviconize");
3215+
gBrowser.mTabContainer.setAttribute("autoFaviconizePinned", gBrowser._autoFaviconizePinned);
32053216
gBrowser.mTabContainer.positionPinnedTabs();
32063217
gBrowser.mTabContainer.adjustTabstrip();
32073218
},

0 commit comments

Comments
 (0)