Private_Tab icon indicating copy to clipboard operation
Private_Tab copied to clipboard

Issue with Tab Mix when closing last tab in a window

Open onemen opened this issue 11 years ago • 8 comments

Tab Mix have an option to open not the default (about:newtab) tab when closing last tab in a window http://tmp.garyr.net/support/viewpage.php?t=3&p=events-tab-closing

Starting with Tab Mix 0.4.1.5.1 (https://addons.mozilla.org/en-us/firefox/addon/tab-mix-plus/versions/) if the last tab was private the new tab is private unless the address is the same as about:newtab preference.

I'm not sure what is the right behavior here. let me know if you need more information.

onemen.

onemen avatar Sep 28 '14 07:09 onemen

Probably this is something expected... There is extensions.privateTab.makeNewEmptyTabsPrivate preference https://github.com/Infocatcher/Private_Tab/blob/0.1.7.3/defaults/preferences/prefs.js#L36-L40 And some tricks to detect new empty tabs: https://github.com/Infocatcher/Private_Tab/blob/0.1.7.3/bootstrap.js#L2998

So, if opened URI looks non-empty, tab inherits private state from selected tab.

Also there is privateTab.tabLabelIsEmpty() API: https://github.com/Infocatcher/Private_Tab#privatetabtablabelisempty But I probably should also add something for users... And anyway this is only to mark entire URI as empty, but user may want to open something like google.com in new tabs.

Infocatcher avatar Sep 28 '14 17:09 Infocatcher

non of the above helped

let say user set Tabmix to open www.foo.com when last tab is closed. if the last tab is private how can i make sure the new www.foo.com will be non-private?

maybe you can add privateTab.readyToOpenTab(true) then the next tab will be private and privateTab.readyToOpenTab(false) then the next tab will be not private

onemen avatar Sep 28 '14 20:09 onemen

Should work already:

window.addEventListener("TabClose", function onTabClose(e) {
    window.removeEventListener(e.type, onTabClose, false);
    // Let's imagine, that this is last tab in window
    privateTab.readyToOpenTab(false);
    gBrowser.addTab("about:");
}, false);
gBrowser.removeTab(gBrowser.selectedTab);

But for now used zero-based setTimeout() delay to stop watching for new tabs. Or alternative:

privateTab.readyToOpenTabs(false);
// ...
// Later:
privateTab.stopToOpenTabs();

Infocatcher avatar Sep 29 '14 09:09 Infocatcher

do you think it is simpler if i toggleTabPrivate after the new tab is open? if user set makeNewEmptyTabsPrivate to -1 or 1 i don't think i need to change the tab privacy

if (privateTab.isTabPrivate(tab) && Services.prefs.getIntPref("extensions.privateTab.makeNewEmptyTabsPrivate") == 0) privateTab.toggleTabPrivate(tab, false)

onemen avatar Sep 29 '14 09:09 onemen

if user set makeNewEmptyTabsPrivate to -1 or 1 i don't think i need to change the tab privacy

Yes, I agree.

if (privateTab.isTabPrivate(tab) && Services.prefs.getIntPref("extensions.privateTab.makeNewEmptyTabsPrivate") == 0) privateTab.toggleTabPrivate(tab, false)

You can toggle private mode only on "TabOpen" event, not later (and even not right after addTab() call). Also you should ignore private windows. And be careful: this should be called after

        // See https://github.com/Infocatcher/Private_Tab/issues/83
        // It's better to handle "TabOpen" before other extensions, but after our waitForTab()
        // with window.addEventListener("TabOpen", ..., true);
        document.addEventListener("TabOpen", this, true);

So, you can use something like

document.documentElement.addEventListener("TabOpen", ..., true);

(or just wait for bubbling phase)

So, probably, this isn't really simpler...

Or alternatively you can somehow mark tabs as new, something like

window.addEventListener("TabOpen", function(e) {
    var tab = e.originalTarget;
    tab.tabMixPlusIsNew = true;
}, true);

(or any other property/attribute, that I can check) And there is not documented _privateTabIgnore for similar purposes (readyToOpenTab() -> waitForTab() -> tab._privateTabIgnore = true -> toggleTabPrivate()).

Infocatcher avatar Sep 29 '14 11:09 Infocatcher

this work

   var loadInBackground = replaceLastTab ? false :
                          Tabmix.prefs.getBoolPref("loadNewInBackground");
   var loadBlank = isBlankPageURL(url);
   if (replaceLastTab && !loadBlank &&
        typeof privateTab == "object" && privateTab.isTabPrivate(selectedTab) &&
        TabmixSvc.prefs.get("extensions.privateTab.makeNewEmptyTabsPrivate", 0) == 0) {
     window.addEventListener("TabOpen", function _tabopen(e) {
        window.removeEventListener("TabOpen", _tabopen, true);
        let tab = e.originalTarget;
        tab._privateTabIgnore = true;
     }, true);
   }
   var newTab = gBrowser.addTab(url, {
            charset: loadBlank ? null : gBrowser.selectedBrowser.characterSet,
            ownerTab: loadInBackground ? null : selectedTab,
            skipAnimation: replaceLastTab,
            dontMove: true});

onemen avatar Sep 29 '14 13:09 onemen

Yes, this looks correct. But also may be non-private tabs in private window (and new tabs should becomes private by default). So, && privateTab.isTabPrivate(selectedTab) may be just removed.

Or something like

   if (replaceLastTab && !loadBlank &&
        typeof privateTab == "object" && "PrivateBrowsingUtils" in window
        TabmixSvc.prefs.get("extensions.privateTab.makeNewEmptyTabsPrivate", 0) == 0) {
     var isPrivate = PrivateBrowsingUtils.isWindowPrivate(window);
     privateTab.readyToOpenTab(isPrivate);
   }
   var newTab = gBrowser.addTab(url, {
            ...

P.S. Right now I don't have time to test this, sorry... Should work, but not tested.

Infocatcher avatar Sep 29 '14 17:09 Infocatcher

Thank you,

i will use privateTab.readyToOpenTab(false) to prevent the new tab from becoming private tab only in non-private window

onemen avatar Sep 29 '14 18:09 onemen