update for new Greasemonkey

This commit is contained in:
Piro / SHIMODA Hiroshi 2011-10-28 04:13:25 +09:00
parent b31af73100
commit e4ae635760

View File

@ -668,25 +668,53 @@ TreeStyleTabWindowHelper.overrideExtensionsAfterBrowserInit = function TSTWH_ove
// Greasemonkey // Greasemonkey
// https://addons.mozilla.org/firefox/addon/748 // https://addons.mozilla.org/firefox/addon/748
if (sv.getTreePref('compatibility.Greasemonkey')) { if (sv.getTreePref('compatibility.Greasemonkey')) {
if ('GM_BrowserUI' in window && 'openInTab' in GM_BrowserUI) { try {
eval('GM_BrowserUI.openInTab = '+ let hitchModule = Components.utils.import('resource://greasemonkey/util/hitch.js', {});
GM_BrowserUI.openInTab.toSource().replace( let hitch = hitchModule.hitch;
/(if\s*\(this\.isMyWindow\([^\)]+\)\)\s*\{\s*)(this\.tabBrowser)/, if (hitch.toSource().indexOf('TreeStyleTabService') < 0) {
'$1 TreeStyleTabService.readyToOpenChildTab($2); $2' hitchModule.hitch = function(aObject, aMethod) {
) if (typeof aMethod == 'function' &&
); aMethod.toSource().indexOf('function openInTab') > -1) {
let originalOpenInTab = aMethod;
/**
* This function must be replaced on scripts in "chrome:" URL, like this.
* Otherwise the original openInTab() will raise violation error.
* Don't move this hack into JS code modules with "resource:" URL.
*/
aMethod = function openInTab(aSafeContentWindow, aChromeWindow, aURL, aLoadInBackgtound) {
if (aChromeWindow.TreeStyleTabService)
aChromeWindow.TreeStyleTabService.readyToOpenChildTabNow(aSafeContentWindow);
return originalOpenInTab.apply(this, arguments);
};
}
return hitch.apply(this, arguments);
};
}
} }
else if ('@greasemonkey.mozdev.org/greasemonkey-service;1' in Components.classes) { catch(e) {
let service = Components.classes['@greasemonkey.mozdev.org/greasemonkey-service;1'].getService().wrappedJSObject; dump(e+'\n');
if (service) {
let _openInTab = service.__proto__._openInTab; // hacks for old versions
if (_openInTab.toSource().indexOf('TreeStyleTabService') < 0) { if ('GM_BrowserUI' in window && 'openInTab' in GM_BrowserUI) {
service.__proto__._openInTab = function() { eval('GM_BrowserUI.openInTab = '+
let contentWindow = arguments[0]; GM_BrowserUI.openInTab.toSource().replace(
let chromeWindow = arguments[1]; /(if\s*\(this\.isMyWindow\([^\)]+\)\)\s*\{\s*)(this\.tabBrowser)/,
chromeWindow.TreeStyleTabService.readyToOpenChildTabNow(contentWindow); '$1 TreeStyleTabService.readyToOpenChildTab($2); $2'
return _openInTab.apply(this, arguments); )
}; );
}
else if ('@greasemonkey.mozdev.org/greasemonkey-service;1' in Components.classes) {
let service = Components.classes['@greasemonkey.mozdev.org/greasemonkey-service;1'].getService().wrappedJSObject;
if (service && service.__proto__._openInTab) {
let _openInTab = service.__proto__._openInTab;
if (_openInTab.toSource().indexOf('TreeStyleTabService') < 0) {
service.__proto__._openInTab = function() {
let contentWindow = arguments[0];
let chromeWindow = arguments[1];
chromeWindow.TreeStyleTabService.readyToOpenChildTabNow(contentWindow);
return _openInTab.apply(this, arguments);
};
}
} }
} }
} }