Output debug log to the browser console also

This commit is contained in:
YUKI Hiroshi 2016-02-10 19:10:46 +09:00
parent 120dc6b522
commit e531d8cd93
11 changed files with 197 additions and 178 deletions

View File

@ -8,9 +8,11 @@ XPCOMUtils.defineLazyModuleGetter(this,
let { ReferenceCounter } = Components.utils.import('resource://treestyletab-modules/ReferenceCounter.js', {}); let { ReferenceCounter } = Components.utils.import('resource://treestyletab-modules/ReferenceCounter.js', {});
let { inherit } = Components.utils.import('resource://treestyletab-modules/lib/inherit.jsm', {}); let { inherit } = Components.utils.import('resource://treestyletab-modules/lib/inherit.jsm', {});
function mydump(aString) { function log(...aArgs) {
if (TreeStyleTabUtils.isDebugging('bookmark')) TreeStyleTabUtils.log.apply(utils, ['bookmark'].concat(aArgs));
dump(aString); }
function logWithStackTrace(...aArgs) {
TreeStyleTabUtils.logWithStackTrace.apply(utils, ['bookmark'].concat(aArgs));
} }
var TreeStyleTabBookmarksServiceEditable = inherit(TreeStyleTabBookmarksUIService, { var TreeStyleTabBookmarksServiceEditable = inherit(TreeStyleTabBookmarksUIService, {
@ -84,7 +86,7 @@ var TreeStyleTabBookmarksServiceEditable = inherit(TreeStyleTabBookmarksUIServic
TreeStyleTabBookmarksServiceEditable.saveParentFor(gEditItemOverlay.itemId, true); TreeStyleTabBookmarksServiceEditable.saveParentFor(gEditItemOverlay.itemId, true);
} }
catch(e) { catch(e) {
mydump(e+'\n'); log(e);
} }
return this.__treestyletab__onDialogAccept.apply(this, aArgs); return this.__treestyletab__onDialogAccept.apply(this, aArgs);
}; };
@ -92,7 +94,7 @@ var TreeStyleTabBookmarksServiceEditable = inherit(TreeStyleTabBookmarksUIServic
BookmarkPropertiesPanel.__treestyletab__endBatch = BookmarkPropertiesPanel._endBatch; BookmarkPropertiesPanel.__treestyletab__endBatch = BookmarkPropertiesPanel._endBatch;
BookmarkPropertiesPanel._endBatch = function(...aArgs) { BookmarkPropertiesPanel._endBatch = function(...aArgs) {
var id = this.__treestyletab__itemId || gEditItemOverlay.itemId; var id = this.__treestyletab__itemId || gEditItemOverlay.itemId;
mydump('BookmarkPropertiesPanel._endBatch for '+id+'\n'); log('BookmarkPropertiesPanel._endBatch for '+id);
var batching = this._batching; var batching = this._batching;
var result = this.__treestyletab__endBatch.apply(this, aArgs); var result = this.__treestyletab__endBatch.apply(this, aArgs);
if (id >= 0 && !batching && !this._batching) { if (id >= 0 && !batching && !this._batching) {
@ -101,7 +103,7 @@ var TreeStyleTabBookmarksServiceEditable = inherit(TreeStyleTabBookmarksUIServic
TreeStyleTabBookmarksServiceEditable.saveParentFor(id, true); TreeStyleTabBookmarksServiceEditable.saveParentFor(id, true);
} }
catch(e) { catch(e) {
mydump(e+'\n'); log(e);
} }
finally { finally {
this._batching = false; this._batching = false;

View File

@ -57,6 +57,12 @@ XPCOMUtils.defineLazyGetter(this, 'prefs', function() {
return window['piro.sakura.ne.jp'].prefs; return window['piro.sakura.ne.jp'].prefs;
}); });
function log(...aArgs) {
utils.log.apply(utils, ['autoHide'].concat(aArgs));
}
function logWithStackTrace(...aArgs) {
utils.logWithStackTrace.apply(utils, ['autoHide'].concat(aArgs));
}
var AutoHideConstants = Object.freeze(inherit(TreeStyleTabConstants, { var AutoHideConstants = Object.freeze(inherit(TreeStyleTabConstants, {
kMODE : 'treestyletab-tabbar-autohide-mode', kMODE : 'treestyletab-tabbar-autohide-mode',
@ -570,11 +576,10 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
extraInfo.push('expanded-by-unknown'); extraInfo.push('expanded-by-unknown');
if (this.lastMouseDownTarget) if (this.lastMouseDownTarget)
extraInfo.push('mousedown'); extraInfo.push('mousedown');
dump('showHideOnMouseMove: ' + log('showHideOnMouseMove: ' +
'('+aCoordinates.screenX + ', ' + aCoordinates.screenY + ') => ' + '('+aCoordinates.screenX + ', ' + aCoordinates.screenY + ') => ' +
humanReadablePosition.join(', ') + humanReadablePosition.join(', ') +
(extraInfo.length ? ('[' + extraInfo.join(', ') + ']') : '') + (extraInfo.length ? ('[' + extraInfo.join(', ') + ']') : ''));
'\n');
} }
if (sv.isPopupShown() || if (sv.isPopupShown() ||
@ -905,10 +910,9 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
let givenReason = this._getHumanReadableReason(aReason); let givenReason = this._getHumanReadableReason(aReason);
let unifiedReason = this._getHumanReadableReason(this.showHideReason); let unifiedReason = this._getHumanReadableReason(this.showHideReason);
if (this.expanded) if (this.expanded)
dump('autoHide: show by ' + aReason + '(' + givenReason + ' / ' + unifiedReason + ')\n'); logWithStackTrace('autoHide: show by ' + aReason + '(' + givenReason + ' / ' + unifiedReason + ')');
else else
dump('autoHide: hide by ' + aReason + '(' + givenReason + ' / ' + unifiedReason + ')\n'); logWithStackTrace('autoHide: hide by ' + aReason + '(' + givenReason + ' / ' + unifiedReason + ')');
dump((new Error()).stack.replace(/^/gm, ' ').replace(/\s+$/, '') + '\n');
} }
this.fireStateChangingEvent(); this.fireStateChangingEvent();

View File

@ -81,6 +81,13 @@ if (Services.appinfo.OS === 'WINNT') {
else { else {
this.AeroPeek = null; this.AeroPeek = null;
} }
function log(...aArgs) {
utils.log.apply(utils, ['base'].concat(aArgs));
}
function logWithStackTrace(...aArgs) {
utils.logWithStackTrace.apply(utils, ['base'].concat(aArgs));
}
var TreeStyleTabBase = inherit(TreeStyleTabConstants, { var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
@ -148,8 +155,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
this.overrideExtensions(); this.overrideExtensions();
} }
catch(e) { catch(e) {
if (utils.isDebugging('base')) log(e);
dump(e+'\n');
} }
}, },
_initialized : false, _initialized : false,
@ -505,8 +511,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
var message = 'ERROR: accessed after destruction!'; var message = 'ERROR: accessed after destruction!';
var error = new Error(message); var error = new Error(message);
if (utils.isDebugging('base')) logWithStackTrace(message);
dump(message+'\n'+error.stack.replace(/^/gm, ' ')+'\n');
throw error; throw error;
}, },
@ -877,10 +882,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
{ {
var strip = this.tabStrip; var strip = this.tabStrip;
if (!strip) { if (!strip) {
if (utils.isDebugging('base')) { logWithStackTrace('FAILED TO SET TABSTRIP ATTRIBUTE ' + aAttr + '=' + aValue);
dump('FAILED TO SET TABSTRIP ATTRIBUTE ' + aAttr + '=' + aValue + '\n');
dump((new Error()).stack.replace(/^/gm, ' ') + '\n');
}
return; return;
} }
var isFeatureAttribute = aAttr.indexOf('treestyletab-') == 0; var isFeatureAttribute = aAttr.indexOf('treestyletab-') == 0;
@ -1419,9 +1421,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
refId = aInsertBefore.getAttribute(this.kID); refId = aInsertBefore.getAttribute(this.kID);
} }
if (utils.isDebugging('base')) logWithStackTrace('new child tab is requested.');
dump('Tree Style Tab: new child tab is requested.\n'+
new Error().stack.replace(/^/gm, ' ')+'\n');
ownerBrowser.treeStyleTab.readiedToAttachNewTab = true; ownerBrowser.treeStyleTab.readiedToAttachNewTab = true;
ownerBrowser.treeStyleTab.readiedToAttachMultiple = aMultiple || false ; ownerBrowser.treeStyleTab.readiedToAttachMultiple = aMultiple || false ;
@ -1460,9 +1460,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
var ownerBrowser = this.getTabBrowserFromChild(browser); var ownerBrowser = this.getTabBrowserFromChild(browser);
if (utils.isDebugging('base')) logWithStackTrace('new orphan tab is requested.');
dump('Tree Style Tab: new orphan tab is requested.\n'+
new Error().stack.replace(/^/gm, ' ')+'\n');
ownerBrowser.treeStyleTab.readiedToAttachNewTab = false; ownerBrowser.treeStyleTab.readiedToAttachNewTab = false;
@ -1595,9 +1593,8 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
var ownerBrowser = this.getTabBrowserFromChild(browser); var ownerBrowser = this.getTabBrowserFromChild(browser);
if (ownerBrowser.treeStyleTab.readiedToAttachNewTab && utils.isDebugging('base')) if (ownerBrowser.treeStyleTab.readiedToAttachNewTab)
dump('Tree Style Tab: new child tab is canceled.\n'+ logWithStackTrace('new child tab is canceled.');
new Error().stack.replace(/^/gm, ' ')+'\n');
delete ownerBrowser.treeStyleTab.readiedToAttachNewTab; delete ownerBrowser.treeStyleTab.readiedToAttachNewTab;
delete ownerBrowser.treeStyleTab.readiedToAttachNewTabGroup; delete ownerBrowser.treeStyleTab.readiedToAttachNewTabGroup;
@ -1790,8 +1787,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
aTab.label+'\n '+ aTab.label+'\n '+
aTab.getAttribute(this.kID); aTab.getAttribute(this.kID);
}, this).join('\n'); }, this).join('\n');
if (utils.isDebugging('base')) log(message);
dump(message+'\n');
break; break;
} }
@ -1803,8 +1799,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
aTab.label+'\n '+ aTab.label+'\n '+
aTab.getAttribute(this.kID); aTab.getAttribute(this.kID);
}, this).join('\n'); }, this).join('\n');
if (utils.isDebugging('base')) log(message);
dump(message+'\n');
} }
tabs.push(parentTab); tabs.push(parentTab);
@ -1951,8 +1946,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
aTab.label+'\n '+ aTab.label+'\n '+
aTab.getAttribute(this.kID); aTab.getAttribute(this.kID);
}, this).join('\n'); }, this).join('\n');
if (utils.isDebugging('base')) log(message);
dump(message+'\n');
continue; continue;
} }
tabs.push(tab); tabs.push(tab);

View File

@ -49,9 +49,11 @@ Cu.import('resource://treestyletab-modules/constants.js');
XPCOMUtils.defineLazyModuleGetter(this, 'utils', 'resource://treestyletab-modules/utils.js', 'TreeStyleTabUtils'); XPCOMUtils.defineLazyModuleGetter(this, 'utils', 'resource://treestyletab-modules/utils.js', 'TreeStyleTabUtils');
function mydump(aString) { function log(...aArgs) {
if (utils.isDebugging('bookmark')) utils.log.apply(utils, ['bookmark'].concat(aArgs));
dump(aString); }
function logWithStackTrace(...aArgs) {
utils.logWithStackTrace.apply(utils, ['bookmark'].concat(aArgs));
} }
var TreeStyleTabBookmarksService = inherit(TreeStyleTabConstants, { var TreeStyleTabBookmarksService = inherit(TreeStyleTabConstants, {
@ -296,18 +298,18 @@ var TreeStyleTabBookmarksService = inherit(TreeStyleTabConstants, {
result.behavior = TST.openGroupBookmarkBehavior(); result.behavior = TST.openGroupBookmarkBehavior();
if (result.behavior & this.kGROUP_BOOKMARK_SUBTREE) { if (result.behavior & this.kGROUP_BOOKMARK_SUBTREE) {
mydump('TSTBMService_handleTabsOpenProcess: open as a group\n'); log('handleTabsOpenProcess: open as a group');
let treeStructure = result.behavior & this.kGROUP_BOOKMARK_DONT_RESTORE_TREE_STRUCTURE ? let treeStructure = result.behavior & this.kGROUP_BOOKMARK_DONT_RESTORE_TREE_STRUCTURE ?
null : null :
this.getTreeStructureFromItems(aIDs) ; this.getTreeStructureFromItems(aIDs) ;
mydump(' treeStructure => '+JSON.stringify(treeStructure)+'\n'); log(' treeStructure => '+JSON.stringify(treeStructure));
if (treeStructure) { if (treeStructure) {
let parentTabs = treeStructure.filter(function(aParent) { let parentTabs = treeStructure.filter(function(aParent) {
return aParent < 0; return aParent < 0;
}); });
let haveMultipleTrees = parentTabs.length != treeStructure.length; let haveMultipleTrees = parentTabs.length != treeStructure.length;
if (result.behavior & this.kGROUP_BOOKMARK_USE_DUMMY) { if (result.behavior & this.kGROUP_BOOKMARK_USE_DUMMY) {
mydump(' trying to use dummy group tab\n'); log(' trying to use dummy group tab');
let parentCount = 0; let parentCount = 0;
let childCount = 0; let childCount = 0;
for (let i in treeStructure) { for (let i in treeStructure) {
@ -316,8 +318,8 @@ var TreeStyleTabBookmarksService = inherit(TreeStyleTabConstants, {
else else
childCount++; childCount++;
} }
mydump(' parentCount: '+parentCount+'\n'); log(' parentCount: '+parentCount);
mydump(' childCount: '+childCount+'\n'); log(' childCount: '+childCount);
if ( if (
parentCount > 1 && parentCount > 1 &&
( (
@ -338,7 +340,7 @@ var TreeStyleTabBookmarksService = inherit(TreeStyleTabConstants, {
title: aFolderTitle, title: aFolderTitle,
uri: uri uri: uri
}) })
mydump(' updated treeStructure => '+JSON.stringify(treeStructure)+'\n'); log(' updated treeStructure => '+JSON.stringify(treeStructure));
} }
} }
else if (!haveMultipleTrees) { else if (!haveMultipleTrees) {
@ -388,7 +390,7 @@ var TreeStyleTabBookmarksService = inherit(TreeStyleTabConstants, {
PlacesUIUtils.__treestyletab__openTabset = PlacesUIUtils._openTabset; PlacesUIUtils.__treestyletab__openTabset = PlacesUIUtils._openTabset;
PlacesUIUtils._openTabset = function(aItemsToOpen, aEvent, aWindow, ...aArgs) { PlacesUIUtils._openTabset = function(aItemsToOpen, aEvent, aWindow, ...aArgs) {
mydump('TSTBookmarks_openTabset\n'); log('TSTBookmarks_openTabset');
var uris = []; var uris = [];
var ids = []; var ids = [];
@ -400,12 +402,12 @@ PlacesUIUtils._openTabset = function(aItemsToOpen, aEvent, aWindow, ...aArgs) {
if (!id && aIndex in nodes) if (!id && aIndex in nodes)
id = nodes[aIndex].itemId; id = nodes[aIndex].itemId;
ids.push(id); ids.push(id);
mydump(' '+aIndex+': '+id+' / '+aItem.uri+'\n'); log(' '+aIndex+': '+id+' / '+aItem.uri);
return true; return true;
} }
return false; return false;
}); });
mydump(' items => '+aItemsToOpen.length+'\n'); log(' items => '+aItemsToOpen.length);
var allArgs = [aItemsToOpen, aEvent, aWindow].concat(aArgs); var allArgs = [aItemsToOpen, aEvent, aWindow].concat(aArgs);
if (aItemsToOpen.length <= 0) if (aItemsToOpen.length <= 0)
@ -418,17 +420,17 @@ PlacesUIUtils._openTabset = function(aItemsToOpen, aEvent, aWindow, ...aArgs) {
var BS = TreeStyleTabBookmarksService; var BS = TreeStyleTabBookmarksService;
var where = w && w.whereToOpenLink(aEvent, false, true) || 'window'; var where = w && w.whereToOpenLink(aEvent, false, true) || 'window';
mydump(' where: '+where+'\n'); log(' where: '+where);
if (where === 'window') if (where === 'window')
return this.__treestyletab__openTabset.apply(this, allArgs); return this.__treestyletab__openTabset.apply(this, allArgs);
var result = BS.handleTabsOpenProcess(where, aEvent, w, ids, uris, aItemsToOpen, this.__treestyletab__folderName); var result = BS.handleTabsOpenProcess(where, aEvent, w, ids, uris, aItemsToOpen, this.__treestyletab__folderName);
mydump(' result: '+JSON.stringify(result)+'\n'); log(' result: '+JSON.stringify(result));
var tabs = TST.doAndGetNewTabs((function() { var tabs = TST.doAndGetNewTabs((function() {
this.__treestyletab__openTabset.apply(this, allArgs); this.__treestyletab__openTabset.apply(this, allArgs);
}).bind(this), w.gBrowser); }).bind(this), w.gBrowser);
mydump(' tabs: '+tabs.length+'\n'); log(' tabs: '+tabs.length);
if (!result.treeStructure) if (!result.treeStructure)
tabs = []; tabs = [];

View File

@ -75,9 +75,11 @@ function wait(aMilliSeconds) {
}); });
} }
function mydump(aString) { function log(...aArgs) {
if (utils.isDebugging('browser')) utils.log.apply(utils, ['browser'].concat(aArgs));
dump(aString); }
function logWithStackTrace(...aArgs) {
utils.logWithStackTrace.apply(utils, ['browser'].concat(aArgs));
} }
Cu.import('resource://treestyletab-modules/window.js'); Cu.import('resource://treestyletab-modules/window.js');
@ -1974,7 +1976,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
(aReason & this.kTABBAR_UPDATE_BY_AUTOHIDE ? 'autohide ' : '' ) + (aReason & this.kTABBAR_UPDATE_BY_AUTOHIDE ? 'autohide ' : '' ) +
(aReason & this.kTABBAR_UPDATE_BY_INITIALIZE ? 'initialize ' : '' ) + (aReason & this.kTABBAR_UPDATE_BY_INITIALIZE ? 'initialize ' : '' ) +
(aReason & this.kTABBAR_UPDATE_BY_TOGGLE_SIDEBAR ? 'toggle-sidebar ' : '' ); (aReason & this.kTABBAR_UPDATE_BY_TOGGLE_SIDEBAR ? 'toggle-sidebar ' : '' );
mydump('TSTBrowser_updateFloatingTabbarInternal: ' + humanReadableReason + '\n'); log('updateFloatingTabbarInternal: ' + humanReadableReason);
} }
var d = this.document; var d = this.document;
@ -3168,20 +3170,20 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
var pareintIndexInTree = hasStructure ? this.treeStructure.shift() : 0 ; var pareintIndexInTree = hasStructure ? this.treeStructure.shift() : 0 ;
var lastRelatedTab = b._lastRelatedTab; var lastRelatedTab = b._lastRelatedTab;
mydump('TSTBrowser_onTabOpen\n ' + [ log('onTabOpen\n ' + [
'readiedToAttachNewTab: '+this.readiedToAttachNewTab, 'readiedToAttachNewTab: '+this.readiedToAttachNewTab,
'parentTab: '+this.parentTab + ' (' + this.getTabById(this.parentTab) + ')', 'parentTab: '+this.parentTab + ' (' + this.getTabById(this.parentTab) + ')',
'insertBefore: '+this.insertBefore, 'insertBefore: '+this.insertBefore,
'treeStructure: '+this.treeStructure 'treeStructure: '+this.treeStructure
].join('\n ') + '\n'); ].join('\n '));
if (typeof this.readiedToAttachNewTab !== 'boolean') { if (typeof this.readiedToAttachNewTab !== 'boolean') {
this.window.setTimeout((function() { this.window.setTimeout((function() {
if (!tab.owner) if (!tab.owner)
return; return;
mydump('TSTBrowser_onTabOpen: new child tab opened by browser.tabs.insertRelatedAfterCurrent=true\n'); log('onTabOpen: new child tab opened by browser.tabs.insertRelatedAfterCurrent=true');
var nextTab = this.findNextTabForNewChild(tab, tab.owner); var nextTab = this.findNextTabForNewChild(tab, tab.owner);
mydump(' next tab: '+(nextTab && nextTab._tPos)+'\n'); log(' next tab: '+(nextTab && nextTab._tPos));
this.attachTabTo(tab, tab.owner, { this.attachTabTo(tab, tab.owner, {
insertBefore: nextTab insertBefore: nextTab
}); });
@ -3403,7 +3405,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
var closeParentBehavior = this.getCloseParentBehaviorForTab(tab); var closeParentBehavior = this.getCloseParentBehaviorForTab(tab);
var backupAttributes = this._collectBackupAttributes(tab); var backupAttributes = this._collectBackupAttributes(tab);
mydump('onTabClose: backupAttributes = '+JSON.stringify(backupAttributes)+'\n'); log('onTabClose: backupAttributes = '+JSON.stringify(backupAttributes));
if (closeParentBehavior == this.kCLOSE_PARENT_BEHAVIOR_CLOSE_ALL_CHILDREN || if (closeParentBehavior == this.kCLOSE_PARENT_BEHAVIOR_CLOSE_ALL_CHILDREN ||
this.isSubtreeCollapsed(tab)) this.isSubtreeCollapsed(tab))
@ -3631,7 +3633,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
var prevPosition = aEvent.detail; var prevPosition = aEvent.detail;
if (tab.__treestyletab__isOpening && !this.isTabInternallyMoving(tab)) { if (tab.__treestyletab__isOpening && !this.isTabInternallyMoving(tab)) {
mydump('onTabMove for new child tab: move back '+tab._tPos+' => '+prevPosition+'\n'); log('onTabMove for new child tab: move back '+tab._tPos+' => '+prevPosition);
tab.__treestyletab__internallyTabMovingCount++; tab.__treestyletab__internallyTabMovingCount++;
b.moveTabTo(tab, prevPosition); b.moveTabTo(tab, prevPosition);
tab.__treestyletab__internallyTabMovingCount--; tab.__treestyletab__internallyTabMovingCount--;
@ -3639,8 +3641,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
} }
tab.__treestyletab__previousPosition = prevPosition; tab.__treestyletab__previousPosition = prevPosition;
mydump('onTabMove '+prevPosition+' => '+tab._tPos+' (internal moving count='+tab.__treestyletab__internallyTabMovingCount+', owner='+String(tab.owner)+')\n'); logWithStackTrace('onTabMove '+prevPosition+' => '+tab._tPos+' (internal moving count='+tab.__treestyletab__internallyTabMovingCount+', owner='+String(tab.owner)+')');
mydump((new Error()).stack.replace(/^/gm, ' ')+'\n');
// When the tab was moved before TabOpen event is fired, we have to update manually. // When the tab was moved before TabOpen event is fired, we have to update manually.
var newlyOpened = !this.isTabInitialized(tab) && this.onTabOpen(null, tab); var newlyOpened = !this.isTabInitialized(tab) && this.onTabOpen(null, tab);
@ -3663,11 +3664,11 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
if (storedId && tab.getAttribute(this.kID) != storedId) if (storedId && tab.getAttribute(this.kID) != storedId)
restored = this.onTabRestoring(aEvent); restored = this.onTabRestoring(aEvent);
} }
mydump(' newlyOpened: '+newlyOpened+'\n'); log(' newlyOpened: '+newlyOpened);
mydump(' restored: '+restored+'\n'); log(' restored: '+restored);
if (this.hasChildTabs(tab) && !this.subTreeMovingCount) { if (this.hasChildTabs(tab) && !this.subTreeMovingCount) {
mydump(' => move sub tree\n'); log(' => move sub tree');
this.moveTabSubtreeTo(tab, tab._tPos); this.moveTabSubtreeTo(tab, tab._tPos);
} }
@ -3703,7 +3704,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
if (!this.subTreeChildrenMovingCount) if (!this.subTreeChildrenMovingCount)
this.updateChildrenArray(parentTab); this.updateChildrenArray(parentTab);
} }
mydump(' tabsToBeUpdated: '+tabsToBeUpdated.map(function(aTab) { return aTab._tPos; })+'\n'); log(' tabsToBeUpdated: '+tabsToBeUpdated.map(function(aTab) { return aTab._tPos; }));
var updatedTabs = new WeakMap(); var updatedTabs = new WeakMap();
tabsToBeUpdated.forEach(function(aTab) { tabsToBeUpdated.forEach(function(aTab) {
@ -3736,7 +3737,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
attachTabFromPosition : function TSTBrowser_attachTabFromPosition(aTab, aOldPosition) attachTabFromPosition : function TSTBrowser_attachTabFromPosition(aTab, aOldPosition)
{ {
mydump('attachTabFromPosition '+aOldPosition+' => '+aTab._tPos+'\n'); log('attachTabFromPosition '+aOldPosition+' => '+aTab._tPos);
var parent = this.getParentTab(aTab); var parent = this.getParentTab(aTab);
if (aOldPosition === void(0)) if (aOldPosition === void(0))
@ -3747,7 +3748,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
var oldPos = this.getChildIndex(oldPositionTab, parent); var oldPos = this.getChildIndex(oldPositionTab, parent);
var delta; var delta;
if (oldPositionTab == aTab && pos == oldPos) { // no move? if (oldPositionTab == aTab && pos == oldPos) { // no move?
mydump(' => no move\n'); log(' => no move');
return; return;
} }
else if (pos < 0 || oldPos < 0) { else if (pos < 0 || oldPos < 0) {
@ -3757,7 +3758,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
delta = Math.abs(pos - oldPos); delta = Math.abs(pos - oldPos);
} }
mydump((new Error()).stack.replace(/^/gm, ' ')+'\n'); logWithStackTrace(' moving');
var prevTab = this.getPreviousVisibleTab(aTab); var prevTab = this.getPreviousVisibleTab(aTab);
var nextTab = this.getNextVisibleTab(aTab); var nextTab = this.getNextVisibleTab(aTab);
@ -3766,45 +3767,45 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
if (tabs.length) { if (tabs.length) {
nextTab = this.getNextTab(tabs[tabs.length-1]); nextTab = this.getNextTab(tabs[tabs.length-1]);
} }
mydump(' prevTab: '+(prevTab&&(prevTab._tPos+'('+prevTab.linkedBrowser.currentURI.spec+')'))+'\n'); log(' prevTab: '+(prevTab&&(prevTab._tPos+'('+prevTab.linkedBrowser.currentURI.spec+')')));
mydump(' nextTab: '+(nextTab&&(nextTab._tPos+'('+nextTab.linkedBrowser.currentURI.spec+')'))+'\n'); log(' nextTab: '+(nextTab&&(nextTab._tPos+'('+nextTab.linkedBrowser.currentURI.spec+')')));
var prevParent = this.getParentTab(prevTab); var prevParent = this.getParentTab(prevTab);
var nextParent = this.getParentTab(nextTab); var nextParent = this.getParentTab(nextTab);
var prevLevel = prevTab ? Number(prevTab.getAttribute(this.kNEST)) : -1 ; var prevLevel = prevTab ? Number(prevTab.getAttribute(this.kNEST)) : -1 ;
var nextLevel = nextTab ? Number(nextTab.getAttribute(this.kNEST)) : -1 ; var nextLevel = nextTab ? Number(nextTab.getAttribute(this.kNEST)) : -1 ;
mydump(' prevLevel: '+prevLevel+'\n'); log(' prevLevel: '+prevLevel);
mydump(' nextLevel: '+nextLevel+'\n'); log(' nextLevel: '+nextLevel);
var newParent; var newParent;
if (!prevTab) { if (!prevTab) {
mydump(' => moved to topmost position\n'); log(' => moved to topmost position');
newParent = null; newParent = null;
} }
else if (!nextTab) { else if (!nextTab) {
mydump(' => movedmoved to last position\n'); log(' => movedmoved to last position');
newParent = (delta > 1) ? prevParent : parent ; newParent = (delta > 1) ? prevParent : parent ;
} }
else if (prevParent == nextParent) { else if (prevParent == nextParent) {
mydump(' => moved into existing tree\n'); log(' => moved into existing tree');
newParent = prevParent; newParent = prevParent;
} }
else if (prevLevel > nextLevel) { else if (prevLevel > nextLevel) {
mydump(' => moved to end of existing tree\n'); log(' => moved to end of existing tree');
if (this.mTabBrowser.selectedTab != aTab) { if (this.mTabBrowser.selectedTab != aTab) {
mydump(' => maybe newly opened tab\n'); log(' => maybe newly opened tab');
newParent = prevParent; newParent = prevParent;
} }
else { else {
mydump(' => maybe drag and drop\n'); log(' => maybe drag and drop');
var realDelta = Math.abs(aTab._tPos - aOldPosition); var realDelta = Math.abs(aTab._tPos - aOldPosition);
newParent = realDelta < 2 ? prevParent : (parent || nextParent) ; newParent = realDelta < 2 ? prevParent : (parent || nextParent) ;
} }
} }
else if (prevLevel < nextLevel) { else if (prevLevel < nextLevel) {
mydump(' => moved to first child position of existing tree\n'); log(' => moved to first child position of existing tree');
newParent = prevTab || parent || nextParent; newParent = prevTab || parent || nextParent;
} }
@ -4119,7 +4120,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
handleRestoredTab : function TSTBrowser_handleRestoredTab(aTab) handleRestoredTab : function TSTBrowser_handleRestoredTab(aTab)
{ {
if (aTab.__treestyletab__restoreState === undefined) { if (aTab.__treestyletab__restoreState === undefined) {
mydump('handleRestoredTab: ' + aTab._tPos + ' is already restored!\n'); log('handleRestoredTab: ' + aTab._tPos + ' is already restored!');
return false; return false;
} }
@ -4347,7 +4348,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
var restoringMultipleTabs = this.windowService.restoringTree; var restoringMultipleTabs = this.windowService.restoringTree;
var position = this._prepareInsertionPosition(aTab, aMayBeDuplicated); var position = this._prepareInsertionPosition(aTab, aMayBeDuplicated);
var parent = position.parent; var parent = position.parent;
mydump('handleRestoredTab: found parent = ' + parent+'\n'); log('handleRestoredTab: found parent = ' + parent);
if (parent) { if (parent) {
aTab.removeAttribute(this.kPARENT); aTab.removeAttribute(this.kPARENT);
parent = this.getTabById(parent); parent = this.getTabById(parent);
@ -4393,7 +4394,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
} }
var ancestors = (this.getTabValue(aTab, this.kANCESTORS) || this.getTabValue(aTab, this.kPARENT)).split('|'); var ancestors = (this.getTabValue(aTab, this.kANCESTORS) || this.getTabValue(aTab, this.kPARENT)).split('|');
mydump('handleRestoredTab: ancestors = ' + ancestors+'\n'); log('handleRestoredTab: ancestors = ' + ancestors);
var parent = null; var parent = null;
for (let i in ancestors) for (let i in ancestors)
{ {
@ -4415,7 +4416,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
*/ */
if (!parent) { if (!parent) {
parent = aTab.getAttribute(this.kPARENT); parent = aTab.getAttribute(this.kPARENT);
mydump('handleRestoredTab: parent = ' + parent+'\n'); log('handleRestoredTab: parent = ' + parent);
if (parent && !next) if (parent && !next)
next = this.getNextSiblingTab(aTab); next = this.getNextSiblingTab(aTab);
} }
@ -5171,9 +5172,9 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
} }
if (isContentResize || isChromeResize) { if (isContentResize || isChromeResize) {
mydump('TSTBrowser_onResize\n'); log('TSTBrowser_onResize');
mydump(' isContentResize = '+isContentResize+'\n'); log(' isContentResize = '+isContentResize);
mydump(' isChromeResize = '+isChromeResize+'\n'); log(' isChromeResize = '+isChromeResize);
this.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_WINDOW_RESIZE); this.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_WINDOW_RESIZE);
this.updateInvertedTabContentsOrder(true); this.updateInvertedTabContentsOrder(true);
this.mTabBrowser.mTabContainer.adjustTabstrip(); this.mTabBrowser.mTabContainer.adjustTabstrip();
@ -5335,10 +5336,10 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
onBeforeFullScreenToggle : function TSTBrowser_onBeforeFullScreenToggle(aEnterFS) onBeforeFullScreenToggle : function TSTBrowser_onBeforeFullScreenToggle(aEnterFS)
{ {
mydump('onBeforeFullScreenToggle / ' + this.position + '\n'); log('onBeforeFullScreenToggle / ' + this.position);
if (this.position != 'top') { if (this.position != 'top') {
mydump(' this.document.mozFullScreen => ' + this.document.mozFullScreen + '\n'); log(' this.document.mozFullScreen => ' + this.document.mozFullScreen);
mydump(' aEnterFS => ' + aEnterFS + '\n'); log(' aEnterFS => ' + aEnterFS);
// ignore entering to the DOM-fullscreen (ex. YouTube Player) // ignore entering to the DOM-fullscreen (ex. YouTube Player)
if (!this.document.mozFullScreen) { if (!this.document.mozFullScreen) {
if (aEnterFS) if (aEnterFS)
@ -7116,9 +7117,9 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
Components.utils.reportError(new Error('There is no property named "_browserEpochs"!!')); Components.utils.reportError(new Error('There is no property named "_browserEpochs"!!'));
} }
mydump('TSTBrowser::restoreTree\n'); log('TSTBrowser::restoreTree');
mydump(' level = '+level+'\n'); log(' level = '+level);
mydump(' tabsToRestore = '+tabsToRestore+'\n'); log(' tabsToRestore = '+tabsToRestore);
if ( if (
level <= this.kRESTORE_TREE_LEVEL_NONE || level <= this.kRESTORE_TREE_LEVEL_NONE ||
@ -7141,7 +7142,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
); );
}); });
mydump(' restoring member tabs = '+tabs.length+' ('+tabs.map(function(aTab) { return aTab._tPos; })+')\n'); log(' restoring member tabs = '+tabs.length+' ('+tabs.map(function(aTab) { return aTab._tPos; })+')');
if (tabs.length <= 1) if (tabs.length <= 1)
return; return;

View File

@ -42,6 +42,13 @@ Components.utils.import('resource://treestyletab-modules/constants.js');
XPCOMUtils.defineLazyModuleGetter(this, 'utils', 'resource://treestyletab-modules/utils.js', 'TreeStyleTabUtils'); XPCOMUtils.defineLazyModuleGetter(this, 'utils', 'resource://treestyletab-modules/utils.js', 'TreeStyleTabUtils');
function log(...aArgs) {
utils.log.apply(utils, ['browserUIShowHideObserver'].concat(aArgs));
}
function logWithStackTrace(...aArgs) {
utils.logWithStackTrace.apply(utils, ['browserUIShowHideObserver'].concat(aArgs));
}
function BrowserUIShowHideObserver(aOwner, aBox, aOptions) { function BrowserUIShowHideObserver(aOwner, aBox, aOptions) {
this.owner = aOwner; this.owner = aOwner;
this.box = aBox; this.box = aBox;
@ -91,7 +98,7 @@ BrowserUIShowHideObserver.prototype = {
{ {
case 'childList': case 'childList':
if (aMutation.target == this.box) { if (aMutation.target == this.box) {
this.dumpMutation(aMutation, 'BrowserUIShowHideObserver_onMutation/childList'); this.logMutation(aMutation, 'BrowserUIShowHideObserver_onMutation/childList');
this.owner.browser.treeStyleTab.updateFloatingTabbar(TreeStyleTabConstants.kTABBAR_UPDATE_BY_WINDOW_RESIZE); this.owner.browser.treeStyleTab.updateFloatingTabbar(TreeStyleTabConstants.kTABBAR_UPDATE_BY_WINDOW_RESIZE);
} }
return; return;
@ -102,7 +109,7 @@ BrowserUIShowHideObserver.prototype = {
} }
} }
catch(error) { catch(error) {
this.dumpMutation(aMutation, 'BrowserUIShowHideObserver_onMutation(error)'); this.logMutation(aMutation, 'BrowserUIShowHideObserver_onMutation(error)');
Components.utils.reportError(error); Components.utils.reportError(error);
} }
}, this); }, this);
@ -118,7 +125,7 @@ BrowserUIShowHideObserver.prototype = {
delete this.owner; delete this.owner;
}, },
dumpMutation : function BrowserUIShowHideObserver_dumpMutation(aMutation, aDescription) logMutation : function BrowserUIShowHideObserver_logMutation(aMutation, aDescription)
{ {
if (!utils.isDebugging('browserUIShowHideObserver')) if (!utils.isDebugging('browserUIShowHideObserver'))
return; return;
@ -132,10 +139,10 @@ BrowserUIShowHideObserver.prototype = {
aMutation.attributeName + ', ' + aMutation.attributeName + ', ' +
aMutation.oldValue + ' => ' + aMutation.oldValue + ' => ' +
target.getAttribute(aMutation.attributeName); target.getAttribute(aMutation.attributeName);
dump(aDescription + ' ' + log(aDescription + ' ' +
ownerInformation + ' / ' + ownerInformation + ' / ' +
targetInformation + targetInformation +
attributeInformation + '\n'); attributeInformation);
}, },
onAttributeModified : function BrowserUIShowHideObserver_onAttributeModified(aMutation, aObserver) onAttributeModified : function BrowserUIShowHideObserver_onAttributeModified(aMutation, aObserver)
@ -220,7 +227,7 @@ BrowserUIShowHideObserver.prototype = {
) )
return; return;
this.dumpMutation(aMutation, 'BrowserUIShowHideObserver_onAttributeModified'); this.logMutation(aMutation, 'BrowserUIShowHideObserver_onAttributeModified');
this.handlingAttrChange = true; this.handlingAttrChange = true;

View File

@ -46,6 +46,13 @@ Cu.import('resource://gre/modules/Promise.jsm');
XPCOMUtils.defineLazyModuleGetter(this, 'utils', 'resource://treestyletab-modules/utils.js', 'TreeStyleTabUtils'); XPCOMUtils.defineLazyModuleGetter(this, 'utils', 'resource://treestyletab-modules/utils.js', 'TreeStyleTabUtils');
function log(...aArgs) {
utils.log.apply(utils, ['contentBridge'].concat(aArgs));
}
function logWithStackTrace(...aArgs) {
utils.logWithStackTrace.apply(utils, ['contentBridge'].concat(aArgs));
}
function ContentBridge(aTab, aTabBrowser) function ContentBridge(aTab, aTabBrowser)
{ {
this.init(aTab, aTabBrowser); this.init(aTab, aTabBrowser);
@ -107,11 +114,9 @@ ContentBridge.prototype = inherit(TreeStyleTabConstants, {
}, },
handleMessage : function CB_handleMessage(aMessage) handleMessage : function CB_handleMessage(aMessage)
{ {
if (utils.isDebugging('contentBridge')) { log('*********************handleMessage*******************');
dump('*********************handleMessage*******************\n'); log('TARGET IS: '+aMessage.target.localName);
dump('TARGET IS: '+aMessage.target.localName+'\n'); log(JSON.stringify(aMessage.json));
dump(JSON.stringify(aMessage.json)+'\n');
}
if (aMessage.target != this.mTab.linkedBrowser) if (aMessage.target != this.mTab.linkedBrowser)
return; return;

View File

@ -39,9 +39,11 @@ Components.utils.import('resource://treestyletab-modules/constants.js');
Components.utils.import('resource://treestyletab-modules/utils.js'); Components.utils.import('resource://treestyletab-modules/utils.js');
function mydump(aString) { function log(...aArgs) {
if (TreeStyleTabUtils.isDebugging('fullscreenObserver')) TreeStyleTabUtils.log.apply(utils, ['fullscreenObserver'].concat(aArgs));
dump(aString); }
function logWithStackTrace(...aArgs) {
TreeStyleTabUtils.logWithStackTrace.apply(utils, ['fullscreenObserver'].concat(aArgs));
} }
function FullscreenObserver(aWindow) { function FullscreenObserver(aWindow) {
@ -95,7 +97,7 @@ FullscreenObserver.prototype = {
onSizeModeChange : function FullscreenObserver_onSizeModeChange() onSizeModeChange : function FullscreenObserver_onSizeModeChange()
{ {
mydump('onSizeModeChange: '+this.window.document.documentElement.getAttribute('sizemode')+'\n'); log('onSizeModeChange: '+this.window.document.documentElement.getAttribute('sizemode'));
this.updateToolboxPosition(); this.updateToolboxPosition();
if (!this.window.gBrowser.treeStyleTab.notifyingRenderedEvent) if (!this.window.gBrowser.treeStyleTab.notifyingRenderedEvent)
this.window.gBrowser.treeStyleTab.updateFloatingTabbar(TreeStyleTabConstants.kTABBAR_UPDATE_BY_WINDOW_RESIZE); this.window.gBrowser.treeStyleTab.updateFloatingTabbar(TreeStyleTabConstants.kTABBAR_UPDATE_BY_WINDOW_RESIZE);

View File

@ -63,6 +63,13 @@ const SSS = Cc['@mozilla.org/content/style-sheet-service;1']
const SecMan = Cc['@mozilla.org/scriptsecuritymanager;1'] const SecMan = Cc['@mozilla.org/scriptsecuritymanager;1']
.getService(Ci.nsIScriptSecurityManager); .getService(Ci.nsIScriptSecurityManager);
function log(...aArgs) {
utils.log.apply(utils, ['tabbarDNDObserver'].concat(aArgs));
}
function logWithStackTrace(...aArgs) {
utils.logWithStackTrace.apply(utils, ['tabbarDNDObserver'].concat(aArgs));
}
function TabbarDNDObserver(aTabBrowser) function TabbarDNDObserver(aTabBrowser)
{ {
this.init(aTabBrowser); this.init(aTabBrowser);
@ -187,8 +194,7 @@ try{
return info.canDrop; return info.canDrop;
} }
catch(e) { catch(e) {
if (utils.isDebugging('tabbarDNDObserver')) log('canDrop', e);
dump('TabbarDND::canDrop\n'+e+'\n');
return false; return false;
} }
}, },
@ -262,8 +268,7 @@ catch(e) {
getDropActionInternal : function TabbarDND_getDropActionInternal(aEvent, aSourceTab) getDropActionInternal : function TabbarDND_getDropActionInternal(aEvent, aSourceTab)
{ {
if (utils.isDebugging('tabbarDNDObserver')) log('getDropActionInternal: start');
dump('getDropActionInternal: start\n');
var sv = this.treeStyleTab; var sv = this.treeStyleTab;
var b = this.browser; var b = this.browser;
var d = this.document; var d = this.document;
@ -304,21 +309,18 @@ catch(e) {
var isNewTabAction = !aSourceTab || aSourceTab.ownerDocument != d; var isNewTabAction = !aSourceTab || aSourceTab.ownerDocument != d;
if (!tab || tab.localName != 'tab') { if (!tab || tab.localName != 'tab') {
if (utils.isDebugging('tabbarDNDObserver')) log(' not on a tab');
dump(' not on a tab\n');
let action = isTabMoveFromOtherWindow ? sv.kACTION_STAY : (sv.kACTION_MOVE | sv.kACTION_PART) ; let action = isTabMoveFromOtherWindow ? sv.kACTION_STAY : (sv.kACTION_MOVE | sv.kACTION_PART) ;
if (isNewTabAction) action |= sv.kACTION_NEWTAB; if (isNewTabAction) action |= sv.kACTION_NEWTAB;
if (aEvent[sv.screenPositionProp] < sv.getTabActualScreenPosition(firstTab)) { if (aEvent[sv.screenPositionProp] < sv.getTabActualScreenPosition(firstTab)) {
if (utils.isDebugging('tabbarDNDObserver')) log(' above the first tab');
dump(' above the first tab\n');
info.target = info.parent = info.insertBefore = firstTab; info.target = info.parent = info.insertBefore = firstTab;
info.position = isInverted ? sv.kDROP_AFTER : sv.kDROP_BEFORE ; info.position = isInverted ? sv.kDROP_AFTER : sv.kDROP_BEFORE ;
info.action = action; info.action = action;
return info; return info;
} }
else if (aEvent[sv.screenPositionProp] > sv.getTabActualScreenPosition(tabs[lastTabIndex]) + tabs[lastTabIndex].boxObject[sv.sizeProp]) { else if (aEvent[sv.screenPositionProp] > sv.getTabActualScreenPosition(tabs[lastTabIndex]) + tabs[lastTabIndex].boxObject[sv.sizeProp]) {
if (utils.isDebugging('tabbarDNDObserver')) log(' below the last tab');
dump(' below the last tab\n');
info.target = info.parent = tabs[lastTabIndex]; info.target = info.parent = tabs[lastTabIndex];
info.position = isInverted ? sv.kDROP_BEFORE : sv.kDROP_AFTER ; info.position = isInverted ? sv.kDROP_BEFORE : sv.kDROP_AFTER ;
info.action = action; info.action = action;
@ -328,30 +330,25 @@ catch(e) {
let index = b.getNewIndex ? let index = b.getNewIndex ?
b.getNewIndex(aEvent) : b.getNewIndex(aEvent) :
b.tabContainer._getDropIndex(aEvent) ; b.tabContainer._getDropIndex(aEvent) ;
if (utils.isDebugging('tabbarDNDObserver')) log(' on the tab '+index);
dump(' on the tab '+index+'\n');
index = Math.min(index, lastTabIndex); index = Math.min(index, lastTabIndex);
info.target = tab = tabs[index]; info.target = tab = tabs[index];
if (index == tabs[lastTabIndex]._tPos) { if (index == tabs[lastTabIndex]._tPos) {
if (index > 0) if (index > 0)
info.target = tab = tabs[index - 1]; info.target = tab = tabs[index - 1];
info.position = sv.kDROP_AFTER; info.position = sv.kDROP_AFTER;
if (utils.isDebugging('tabbarDNDObserver')) log(' => after the last tab');
dump(' => after the last tab\n');
} else if (index == firstTab._tPos) { } else if (index == firstTab._tPos) {
if (index < lastTabIndex - 1) if (index < lastTabIndex - 1)
info.target = tab = tabs[index + 1]; info.target = tab = tabs[index + 1];
info.position = sv.kDROP_BEFORE; info.position = sv.kDROP_BEFORE;
if (utils.isDebugging('tabbarDNDObserver')) log(' => before the first tab');
dump(' => before the first tab\n');
} }
if (utils.isDebugging('tabbarDNDObserver')) log(' info.target = ' + info.target._tPos);
dump(' info.target = ' + info.target._tPos + '\n');
} }
} }
else { else {
if (utils.isDebugging('tabbarDNDObserver')) log(' on the tab '+tab._tPos);
dump(' on the tab '+tab._tPos+'\n');
sv.ensureTabInitialized(tab); sv.ensureTabInitialized(tab);
info.target = tab; info.target = tab;
} }
@ -387,21 +384,19 @@ catch(e) {
switch (info.position) switch (info.position)
{ {
case sv.kDROP_ON: case sv.kDROP_ON:
if (utils.isDebugging('tabbarDNDObserver')) log(' position = on the tab');
dump(' position = on the tab\n');
var visible = sv.getNextVisibleTab(tab); var visible = sv.getNextVisibleTab(tab);
info.action = sv.kACTION_STAY | sv.kACTION_ATTACH; info.action = sv.kACTION_STAY | sv.kACTION_ATTACH;
info.parent = tab; info.parent = tab;
info.insertBefore = utils.getTreePref('insertNewChildAt') == sv.kINSERT_FISRT ? info.insertBefore = utils.getTreePref('insertNewChildAt') == sv.kINSERT_FISRT ?
(sv.getFirstChildTab(tab) || visible) : (sv.getFirstChildTab(tab) || visible) :
(sv.getNextSiblingTab(tab) || sv.getNextTab(sv.getLastDescendantTab(tab) || tab)); (sv.getNextSiblingTab(tab) || sv.getNextTab(sv.getLastDescendantTab(tab) || tab));
if (utils.isDebugging('tabbarDNDObserver') && info.insertBefore) if (info.insertBefore)
dump(' insertBefore = '+info.insertBefore._tPos+'\n'); log(' insertBefore = '+info.insertBefore._tPos);
break; break;
case sv.kDROP_BEFORE: case sv.kDROP_BEFORE:
if (utils.isDebugging('tabbarDNDObserver')) log(' position = before the tab');
dump(' position = before the tab\n');
/* /*
<= detach from parent, and move <= detach from parent, and move
[TARGET ] [TARGET ]
@ -437,13 +432,12 @@ catch(e) {
info.action = sv.kACTION_MOVE | (info.parent ? sv.kACTION_ATTACH : sv.kACTION_PART ); info.action = sv.kACTION_MOVE | (info.parent ? sv.kACTION_ATTACH : sv.kACTION_PART );
info.insertBefore = tab; info.insertBefore = tab;
} }
if (utils.isDebugging('tabbarDNDObserver') && info.insertBefore) if (info.insertBefore)
dump(' insertBefore = '+info.insertBefore._tPos+'\n'); log(' insertBefore = '+info.insertBefore._tPos);
break; break;
case sv.kDROP_AFTER: case sv.kDROP_AFTER:
if (utils.isDebugging('tabbarDNDObserver')) log(' position = after the tab');
dump(' position = after the tab\n');
/* /*
[TARGET ] [TARGET ]
<= if the target has a parent, attach to it and and move <= if the target has a parent, attach to it and and move
@ -487,8 +481,8 @@ catch(e) {
} }
} }
} }
if (utils.isDebugging('tabbarDNDObserver') && info.insertBefore) if (info.insertBefore)
dump(' insertBefore = '+info.insertBefore._tPos+'\n'); log(' insertBefore = '+info.insertBefore._tPos);
break; break;
} }
@ -499,16 +493,14 @@ catch(e) {
performDrop : function TabbarDND_performDrop(aInfo, aDraggedTab) performDrop : function TabbarDND_performDrop(aInfo, aDraggedTab)
{ {
if (utils.isDebugging('tabbarDNDObserver')) log('performDrop: start');
dump('performDrop: start\n');
var sv = this.treeStyleTab; var sv = this.treeStyleTab;
var b = this.browser; var b = this.browser;
var w = this.window; var w = this.window;
var tabsInfo = this.getDraggedTabsInfoFromOneTab(aDraggedTab, aInfo); var tabsInfo = this.getDraggedTabsInfoFromOneTab(aDraggedTab, aInfo);
if (!tabsInfo.draggedTab) { if (!tabsInfo.draggedTab) {
if (utils.isDebugging('tabbarDNDObserver')) log(' => no dragged tab');
dump(' => no dragged tab\n');
return false; return false;
} }
@ -565,8 +557,7 @@ catch(e) {
sourceBrowser == targetBrowser && sourceBrowser == targetBrowser &&
sourceService.getNextVisibleTab(draggedTabs[draggedTabs.length-1]) == aInfo.insertBefore sourceService.getNextVisibleTab(draggedTabs[draggedTabs.length-1]) == aInfo.insertBefore
) { ) {
if (utils.isDebugging('tabbarDNDObserver')) log(' => no change');
dump(' => no change\n');
// then, do nothing // then, do nothing
return true; return true;
} }
@ -1053,8 +1044,7 @@ try{
return (info.position == sv.kDROP_ON || sv.position != 'top') return (info.position == sv.kDROP_ON || sv.position != 'top')
} }
catch(e) { catch(e) {
if (utils.isDebugging('tabbarDNDObserver')) log('onDragOver', e);
dump('TabbarDND::onDragOver\n'+e+'\n');
} }
}, },
@ -1100,10 +1090,9 @@ catch(e) {
var draggedTab = dt.mozGetDataAt(TAB_DROP_TYPE, 0); var draggedTab = dt.mozGetDataAt(TAB_DROP_TYPE, 0);
if (utils.isDebugging('tabbarDNDObserver')) log('TabbarDND::onDrop',
dump('TabbarDND::onDrop\n' + ' dt.dropEffect: ' + dt.dropEffect,
' dt.dropEffect: ' + dt.dropEffect + '\n' + ' draggedTab: ' + draggedTab);
' draggedTab: ' + draggedTab + '\n');
if (dt.dropEffect != 'link' && if (dt.dropEffect != 'link' &&
dt.dropEffect != 'move' && dt.dropEffect != 'move' &&
@ -1173,9 +1162,8 @@ catch(e) {
if (aURI.indexOf(this.BOOKMARK_FOLDER) == 0) { if (aURI.indexOf(this.BOOKMARK_FOLDER) == 0) {
let newTabs = sv.getNewTabsWithOperation(function() { let newTabs = sv.getNewTabsWithOperation(function() {
var data = aURI.replace(self.BOOKMARK_FOLDER, ''); var data = aURI.replace(self.BOOKMARK_FOLDER, '');
if (utils.isDebugging('tabbarDNDObserver')) log('TabbarDND::handleLinksOrBookmarks' +
dump('TabbarDND::handleLinksOrBookmarks\n' + ' bookmark folder data: ' + data);
' bookmark folder data: ' + data + '\n');
data = JSON.parse(data); data = JSON.parse(data);
w.PlacesUIUtils._openTabset(data.children, { type : 'drop' }, w, data.title); w.PlacesUIUtils._openTabset(data.children, { type : 'drop' }, w, data.title);
}, b); }, b);

View File

@ -63,6 +63,8 @@ XPCOMUtils.defineLazyModuleGetter(this, 'Task',
'resource://gre/modules/Task.jsm'); 'resource://gre/modules/Task.jsm');
XPCOMUtils.defineLazyModuleGetter(this, 'Promise', XPCOMUtils.defineLazyModuleGetter(this, 'Promise',
'resource://gre/modules/Promise.jsm'); 'resource://gre/modules/Promise.jsm');
XPCOMUtils.defineLazyModuleGetter(this, 'Services',
'resource://gre/modules/Services.jsm');
XPCOMUtils.defineLazyModuleGetter(this, 'TreeStyleTabConstants', XPCOMUtils.defineLazyModuleGetter(this, 'TreeStyleTabConstants',
'resource://treestyletab-modules/constants.js', 'TreeStyleTabConstants'); 'resource://treestyletab-modules/constants.js', 'TreeStyleTabConstants');
@ -250,6 +252,21 @@ var TreeStyleTabUtils = {
return this.getTreePref('debug.' + aModule) || this.getTreePref('debug.all'); return this.getTreePref('debug.' + aModule) || this.getTreePref('debug.all');
}, },
log : function utils_log(aModule, ...aArgs)
{
if (!this.isDebugging(aModule))
return;
var logString = '[treestyletab:' + aModule+'] '+ aArgs.join(', ');
Serivces.console.logStringMessage(logString);
dump(logString+'\n');
},
logWithStackTrace : function utils_logWithStackTrace(aModule, ...aArgs)
{
var stack = (new Error()).stack.replace(/^/gm, ' '));
return this.log.apply(this, [aModule].concat(aArgs).concat([stack]));
},
/* string bundle */ /* string bundle */
get treeBundle () { get treeBundle () {
return stringBundle.get('chrome://treestyletab/locale/treestyletab.properties'); return stringBundle.get('chrome://treestyletab/locale/treestyletab.properties');

View File

@ -71,6 +71,13 @@ XPCOMUtils.defineLazyModuleGetter(this, 'ContentBridge', 'resource://treestyleta
XPCOMUtils.defineLazyServiceGetter(this, 'SessionStore', XPCOMUtils.defineLazyServiceGetter(this, 'SessionStore',
'@mozilla.org/browser/sessionstore;1', 'nsISessionStore'); '@mozilla.org/browser/sessionstore;1', 'nsISessionStore');
function log(...aArgs) {
utils.log.apply(utils, ['window'].concat(aArgs));
}
function logWithStackTrace(...aArgs) {
utils.logWithStackTrace.apply(utils, ['window'].concat(aArgs));
}
function TreeStyleTabWindow(aWindow) function TreeStyleTabWindow(aWindow)
{ {
this.window = aWindow; this.window = aWindow;
@ -1336,8 +1343,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
if (!aTab) if (!aTab)
return; return;
if (utils.isDebugging('window')) log('onBeforeOpenLinkWithTab '+[aTab, JSON.stringify(aParams), this.checkToOpenChildTab(aTab)]);
dump('TSTWindow_onBeforeOpenLinkWithTab '+[aTab, JSON.stringify(aParams), this.checkToOpenChildTab(aTab)]+'\n');
if (!this.checkToOpenChildTab(aTab)) { if (!this.checkToOpenChildTab(aTab)) {
if (!aParams.fromChrome) if (!aParams.fromChrome)
@ -1349,8 +1355,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
onBeforeOpenNewTabByThirdParty : function TSTWindow_onBeforeOpenNewTabByThirdParty(aOwner) onBeforeOpenNewTabByThirdParty : function TSTWindow_onBeforeOpenNewTabByThirdParty(aOwner)
{ {
if (utils.isDebugging('window')) log('onBeforeOpenNewTabByThirdParty '+[aOwner, this.checkToOpenChildTab(aTab)]);
dump('TSTWindow_onBeforeOpenNewTabByThirdParty '+[aOwner, this.checkToOpenChildTab(aTab)]+'\n');
if (!this.checkToOpenChildTab(aOwner)) { if (!this.checkToOpenChildTab(aOwner)) {
this.handleNewTabFromCurrent(aOwner); this.handleNewTabFromCurrent(aOwner);
@ -1363,17 +1368,14 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
var opener = null; var opener = null;
if (aOpener) { if (aOpener) {
if (aOpener instanceof Ci.nsIDOMWindow) { if (aOpener instanceof Ci.nsIDOMWindow) {
if (utils.isDebugging('window')) log('onBeforeBrowserAccessOpenURI: opener is DOMWindow');
dump('TSTWindow_onBeforeBrowserAccessOpenURI: opener is DOMWindow\n');
opener = aOpener; opener = aOpener;
hasOwnerTab = this.getTabFromFrame(opener.top); hasOwnerTab = this.getTabFromFrame(opener.top);
if (utils.isDebugging('window')) log(' opener =>'+[opener,hasOwnerTab]);
dump(' opener =>'+[opener,hasOwnerTab]+'\n');
} }
else if (Ci.nsIOpenURIInFrameParams && else if (Ci.nsIOpenURIInFrameParams &&
aOpener instanceof Ci.nsIOpenURIInFrameParams) { aOpener instanceof Ci.nsIOpenURIInFrameParams) {
if (utils.isDebugging('window')) log('TSTWindow_onBeforeBrowserAccessOpenURI: opener is nsIOpenURIInFrameParams');
dump('TSTWindow_onBeforeBrowserAccessOpenURI: opener is nsIOpenURIInFrameParams\n');
// from remote contents, we have to detect its opener from the URI. // from remote contents, we have to detect its opener from the URI.
let referrer = aOpener.referrer; let referrer = aOpener.referrer;
if (referrer) { if (referrer) {
@ -1388,8 +1390,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
break; break;
} }
} }
if (utils.isDebugging('window')) log(' opener =>'+[opener,hasOwnerTab]);
dump(' opener =>'+[opener,hasOwnerTab]+'\n');
} }
} }
if (aOpener && if (aOpener &&
@ -1404,8 +1405,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
{ {
var where = String(this.window.whereToOpenLink(aEvent, false, true)); var where = String(this.window.whereToOpenLink(aEvent, false, true));
if (utils.isDebugging('window')) log('onBeforeViewMedia '+[aEvent, aOwner, where]);
dump('TSTWindow_onBeforeViewMedia '+[aEvent, aOwner, where]+'\n');
if (where.indexOf('tab') == 0) if (where.indexOf('tab') == 0)
this.handleNewTabFromCurrent(aOwner); this.handleNewTabFromCurrent(aOwner);
@ -1415,8 +1415,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
onBeforeBrowserSearch : function TSTWindow_onBeforeBrowserSearch(aTerm, aForceNewTab) onBeforeBrowserSearch : function TSTWindow_onBeforeBrowserSearch(aTerm, aForceNewTab)
{ {
if (utils.isDebugging('window')) log('onBeforeBrowserSearch '+[aTerm, aForceNewTab, this.shouldOpenSearchResultAsChild(aTerm)]);
dump('TSTWindow_onBeforeBrowserSearch '+[aTerm, aForceNewTab, this.shouldOpenSearchResultAsChild(aTerm)]+'\n');
if ((arguments.length == 1 || aForceNewTab) && if ((arguments.length == 1 || aForceNewTab) &&
this.shouldOpenSearchResultAsChild(aTerm)) this.shouldOpenSearchResultAsChild(aTerm))
@ -1609,10 +1608,9 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
createSubtree : function TSTWindow_createSubtree(aTabs) createSubtree : function TSTWindow_createSubtree(aTabs)
{ {
if (utils.isDebugging('window')) log('TSTWindow_createSubtree\n'+aTabs.map(function(aTab) {
dump('TSTWindow_createSubtree\n'+aTabs.map(function(aTab) { return ' '+aTab._tPos+': '+aTab.linkedBrowser.currentURI.spec;
return ' '+aTab._tPos+': '+aTab.linkedBrowser.currentURI.spec; }).join('\n'));
}).join('\n')+'\n');
var rootTabs = this.getRootTabs(aTabs); var rootTabs = this.getRootTabs(aTabs);
@ -1633,8 +1631,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
var parentInTargets = aTabs.indexOf(this.getParentTab(aDescendantTab)) > -1; var parentInTargets = aTabs.indexOf(this.getParentTab(aDescendantTab)) > -1;
if (inTargets || (inTargets == parentInTargets)) if (inTargets || (inTargets == parentInTargets))
return; return;
if (utils.isDebugging('window')) log(' detaching unselected descendant: '+aDescendantTab._tPos+': '+aDescendantTab.linkedBrowser.currentURI.spec);
dump(' detaching unselected descendant: '+aDescendantTab._tPos+': '+aDescendantTab.linkedBrowser.currentURI.spec+'\n');
if (parentTab) if (parentTab)
b.treeStyleTab.attachTabTo(aDescendantTab, parentTab, { b.treeStyleTab.attachTabTo(aDescendantTab, parentTab, {
dontExpand : true, dontExpand : true,