Last Updated: February 25, 2016
·
481
· noitidart

Firefox Addon Dev: nativeHandle

No need for the js-ctypes and hacks. For example on windows: The FindWindow trick to get the handle for chrome windows. Just use the nativeHandle of the nsIBaseWindow.

var baseWindow = aDOMWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShellTreeItem).treeOwner.QueryInterface(Ci.nsIInterfaceRequestor).nsIBaseWindow;
var nativeHandle = baseWindow.nativeHandle;
//var targetWindow_handle = ctypes.voidptr_t(ctypes.UInt64(nativeHandle)); //may need to do this for certain applications (like plugging into a js-ctypes function with argument ctypes.voidptr_t

No longer need this hack (Windows):

Cu.import('resource://gre/modules/ctypes.jsm');

var user32 = ctypes.open('user32.dll');

var FindWindow = user32.declare('FindWindowW', ctypes.winapi_abi, ctypes.int32_t, ctypes.jschar.ptr, ctypes.jschar.ptr);

var targetWindow_title = aDOMWindow.document.documentElement.getAttribute('title');
var targetWindow_titleOriginal = targetWindow_title;
targetWindow_title += ' - blah blah blah';
aDOMWindow.document.documentElement.setAttribute('title', targetWindow_title);
aDOMWindow.alert('need to wait after set attribute on title for os to understand it');
var targetWindow_handle = FindWindow(null, targetWindow_title);
aDOMWindow.document.documentElement.setAttribute('title', targetWindow_titleOriginal);