Rewrite hack for Greasemonkey (based on GM 3.5)

This commit is contained in:
YUKI Hiroshi 2015-10-26 17:47:05 +09:00
parent 75f761d291
commit 4509c76e90

View File

@ -318,33 +318,22 @@ TreeStyleTabWindowHelper.overrideExtensionsPreInit = function TSTWH_overrideExte
// https://addons.mozilla.org/firefox/addon/748 // https://addons.mozilla.org/firefox/addon/748
if (TreeStyleTabUtils.getTreePref('compatibility.Greasemonkey')) { if (TreeStyleTabUtils.getTreePref('compatibility.Greasemonkey')) {
try { try {
let hitchModule = Components.utils.import('chrome://greasemonkey-modules/content/util/hitch.js', {}); if ('GM_BrowserUI' in window &&
let hitch = hitchModule.hitch; typeof GM_BrowserUI.openInTab == 'function') {
if (hitch.toSource().indexOf('TreeStyleTabService') < 0) { window.messageManager.removeMessageListener('greasemonkey:open-in-tab', GM_BrowserUI.openInTab);
let ns = {}; let originalOpenInTab = GM_BrowserUI.openInTab;
Components.utils.import('chrome://greasemonkey-modules/content/third-party/getChromeWinForContentWin.js', ns); GM_BrowserUI.openInTab = function(aMessage, ...aArgs) {
let getChromeWinForContentWin = ns.getChromeWinForContentWin; var owner = aMessage.target;
hitchModule.hitch = function(aObject, aMethod) { TreeStyleTabService.readyToOpenChildTab(owner, true);
if (typeof aMethod == 'function' && var retVal = originalOpenInTab.apply(this, [aMessage].concat(aArgs));
aMethod.toSource().indexOf('function openInTab') > -1) { window.setTimeout(function() {
let originalOpenInTab = aMethod; window.setTimeout(function() {
/** TreeStyleTabService.stopToOpenChildTab(owner);
* This function must be replaced on scripts in "chrome:" URL, like this. }, 0);
* Otherwise the original openInTab() will raise violation error. }, 0);
* Don't move this hack into JS code modules with "resource:" URL. return retVal;
*/
aMethod = function openInTab(aSafeContentWindow, aURL, aLoadInBackgtound) {
let chrome = getChromeWinForContentWin(aSafeContentWindow);
if (chrome && chrome.TreeStyleTabService)
chrome.TreeStyleTabService.readyToOpenChildTabNow(aSafeContentWindow);
return originalOpenInTab.apply(this, arguments);
};
}
return hitch.apply(this, arguments);
}; };
Components.utils.import('chrome://greasemonkey-modules/content/util.js', ns); window.messageManager.addMessageListener('greasemonkey:open-in-tab', GM_BrowserUI.openInTab);
if (ns.GM_util)
ns.GM_util.hitch = hitchModule.hitch;
} }
} }
catch(e) { catch(e) {