javascript - Overriding nsIWindowWatcher Component -


i'm writing firefox addon instead of opening content in new windows open content in new tab or sidebar.

there several ways open windows:

  • window.open()
  • window.opendialog() or...
  • using openwindow() function form component @mozilla.org/embedcomp/window-watcher;1 nsiwindowwatcher interface

i override window.open , window.opendialog , seems work have problem overriding openwindow() function in window-watcher component.

i override whole component because don't know how override specify functions. implement functions of component , redirect them internal original component this._windowwatcher=cc["@mozilla.org/embedcomp/window-watcher;1"].getservice(ci.nsiwindowwatcher) in way function:

getwindowbyname : function(/* in wstring */ atargetname, /* in nsidomwindow */ acurrentwindow)  // --> nsidomwindow; {     var all_args = array.prototype.slice.call(arguments); // convert array     return this._windowwatcher.getwindowbyname.apply(this._windowwatcher, all_args);     }, 

then register component using xpcomutils.jsm , nsicomponentregistrar :

var nsgetfactory = xpcomutils.generatensgetfactory([windowwatcher]); var windowwatcherfactory = nsgetfactory(windowwatcher.prototype.classid); var nsicomponentregistrar = components.manager                             .queryinterface(ci.nsicomponentregistrar); var oldcid = nsicomponentregistrar              .contractidtocid("@mozilla.org/embedcomp/window-watcher;1"); nsicomponentregistrar.registerfactory(        windowwatcher.prototype.classid,         null,         "@mozilla.org/embedcomp/window-watcher;1",         windowwatcherfactory ); 

then seems work when use directly window watcher in javascript:

 ww = cc["@mozilla.org/embedcomp/window-watcher;1"]       .getservice(ci.nsiwindowwatcher)  var win = ww.openwindow(null, "about:home",                      "_blank", "chrome,centerscreen", null);  

but when firefox internally use overriden component (e.g. clicking link on error item in console; firefox using nsglobalwindow::opendialog), causes error :

  ns_error_unexpected: component returned failure code: 0x8000ffff    (ns_error_unexpected) [nsidomjswindow.opendialog] 

my extension here (overriding component module in modules\window-watcher.jsm)

for tests use firebug console on chrome context or javascript shell in developer assistant addon , import component module components.utils.import("resource://moreicuiplus/window-watcher.jsm");

thanks every possible hints.

just 1 not need skim comments:

re-implementing (wrapping) @mozilla.org/embedcomp/window-watcher;1 component in javascript component not possible, because 1 need implement non-scriptable nspiwindowwatcher interface.

re-implementing (wrapping) in c++ component possible, in context of add-ons isn't feasible, because 1 need compile supported os/platforms, , 1 need recompile each version of gecko, binary-components version-tagged , won't load if gecko versions don't match.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -