diff --git a/content/treestyletab/hacks.js b/content/treestyletab/hacks.js index 86f543ae..4b686b6c 100644 --- a/content/treestyletab/hacks.js +++ b/content/treestyletab/hacks.js @@ -1176,4 +1176,51 @@ TreeStyleTabService.overrideExtensionsDelayed = function TSTService_overrideExte ); } + // Firefox Sync (Weave) + // http://www.mozilla.com/en-US/firefox/sync/ + if ('gFxWeaveGlue' in window) { + let ns = {}; + Components.utils.import('resource://weave/service.js', ns); + let engine = ns.Weave.Engines.get('tabs'); + let listener = { + handleEvent : function(aEvent) + { + switch (aEvent.type) + { + case 'TabOpen': + let tab = aEvent.originalTarget + let b = TreeStyleTabService.getTabBrowserFromChild(tab); + if (b.selectedTab.linkedBrowser.currentURI.spec != 'about:sync-tabs') + return; + + let uri = tab.getAttribute('label'); + if (engine.locallyOpenTabMatchesURL(uri)) + return; + + for (let [guid, client] in Iterator(engine.getAllClients())) + { + if (client.tabs.some(function({ urlHistory }) { + return urlHistory[0] == uri; + })) { + let parent = b.selectedTab; + window.setTimeout(function() { + if (tab.parentNode && !b.treeStyleTab.getParentTab(tab)) + b.treeStyleTab.attachTabTo(tab, parent); + }, 0); + return; + } + } + return; + + case 'unload': + window.removeEventListener('TabOpen', this, true); + window.removeEventListener('unload', this, false); + return; + } + } + }; + window.addEventListener('TabOpen', listener, true); + window.addEventListener('unload', listener, false); + } + }; diff --git a/modules/namespace.jsm b/modules/namespace.jsm index 8fda95d5..2a2990c9 100644 --- a/modules/namespace.jsm +++ b/modules/namespace.jsm @@ -4,8 +4,10 @@ Usage: Components.utils.import('resource://my-modules/namespace.jsm'); var namespace = getNamespaceFor('mylibrary'); - namespace.func1 = function() { ... }; - namespace.func2 = function() { ... }; + if (!namespace.func1) { + namespace.func1 = function() { ... }; + namespace.func2 = function() { ... }; + } var EXPORTED_SYMBOLS = ['func1', 'func2']; var func1 = namespace.func1; var func2 = namespace.func2;