From dd75958b3cf9f78e1574234bd7bc35fbba9b5950 Mon Sep 17 00:00:00 2001 From: piro Date: Tue, 22 Jun 2010 16:50:55 +0000 Subject: [PATCH] =?UTF-8?q?Firefox=20Sync=20(Weave)=E3=81=A7Tabs=20from=20?= =?UTF-8?q?Other=20Computers=E3=81=8B=E3=82=89=E9=96=8B=E3=81=84=E3=81=9F?= =?UTF-8?q?=E3=82=BF=E3=83=96=E3=82=92=E3=83=84=E3=83=AA=E3=83=BC=E3=81=AB?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@6685 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/hacks.js | 47 +++++++++++++++++++++++++++++++++++ modules/namespace.jsm | 6 +++-- 2 files changed, 51 insertions(+), 2 deletions(-) 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;