1 /* coded by Ketmar // Invisible Vector (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://www.wtfpl.net/txt/copying/ for more details.
10 ////////////////////////////////////////////////////////////////////////////////
11 exports
.openTab = function (win
, url
, inbg
) {
12 let afterCurrent
= null;
13 if (typeof(inbg
) === "object") {
14 afterCurrent
= ("afterCurrent" in inbg
? !!inbg
.afterCurrent
: null);
15 inbg
= ("background" in inbg
? !!inbg
.background
: null);
16 } else if (typeof(inbg
) != "boolean") {
19 let dwn
= win
.QueryInterface(Ci
.nsIInterfaceRequestor
).getInterface(Ci
.nsIDOMWindow
);
22 dwn
.QueryInterface(Ci
.nsIInterfaceRequestor
).
23 getInterface(Ci
.nsIWebNavigation
).
24 QueryInterface(Ci
.nsIDocShellTreeItem
).
26 QueryInterface(Ci
.nsIInterfaceRequestor
).
27 getInterface(Ci
.nsIDOMWindow
);
28 if (!chromeWindow
) return;
29 let bro
= chromeWindow
.gBrowser
;
31 let docbro
= bro
.getBrowserForDocument(dwn
.top
.document
);
33 //let tabIdx = bro.getBrowserIndexForDocument(dwn.top.document);
34 //let myTab = bro.tabs[tabIdx];
35 let myTab
= bro
._getTabForContentWindow(dwn
.top
);
36 let tabIdx
= myTab
._tPos
;
37 let myIsCurrent
= (myTab
== bro
.mCurrentTab
);
38 let nt
= bro
.addTab(url
, {ownerTab
: myTab
, relatedToCurrent
: myIsCurrent
});
39 let bg
= (inbg
!== null ? inbg
: Services
.prefs
.getBoolPref("browser.tabs.loadInBackground"));
40 let rel
= (afterCurrent
!== null ? afterCurrent
: Services
.prefs
.getBoolPref("browser.tabs.insertRelatedAfterCurrent"));
41 if (!bg
&& myIsCurrent
) bro
.selectedTab
= nt
;
42 if (myTab
&& rel
) bro
.moveTabTo(nt
, tabIdx
+1);