0

Is it possible to use Text Input Processor on a specific Tab of a Firefox window?

Do all the tabs share the same nsIDOMWindow object? If so, then is there any other solution?

Rephrasing my problem: I want to type text to a specific tab, and if there is more than one, then it might not be the current.

Below is an example code to write text on any Firefox window, but only for current tab:

function myTestFunc() {
  // var windows = Services.wm.getEnumerator("navigation:browser");
  var windows = require("sdk/windows");
  for (let browserWindow of windows.browserWindows)  {
    //console.log(window.title);
    var chromeWindow = viewFor(browserWindow);
    console.log(chromeWindow.document.location.href);
    var idomWindow = chromeWindow.QueryInterface(Ci.nsIDOMWindow);

    var TIP = Cc["@mozilla.org/text-input-processor;1"].
              createInstance(Ci.nsITextInputProcessor);
    if(!TIP.beginInputTransaction(idomWindow, onNotifyImpl))  {
      console.log("Error TIP can't start");
      continue;
    }
    TIP.setPendingCompositionString("foo-bar-buzz");
    if (!TIP.flushPendingComposition()) {
      console.log("Failed to flush");
      continue; // Composition is not started
    }
  }

}
alandarev
  • 8,349
  • 2
  • 34
  • 43

1 Answers1

1

nsIDOMWindow (+ various related interfaces like the docshell) is the XPCOM representation of regular window objects in the w3c specs. And since window objects can be nested (e.g. via iframes) so can be nsIDOMWindows. When you're accessing browser windows you're generally accessing the outer windows representing the browser chrome, not the content.

In principle you can access a tab's content window directly from its <browser> XUL element, but to be forward-compatible with e10s you should use framescripts instead.

the8472
  • 40,999
  • 5
  • 70
  • 122
  • Could you elaborate on how do I acess it from `` XUL element? Unfortunately for my use case, framescripts is not an option. – alandarev May 30 '16 at 13:41
  • I do not intend to support the creation of addons that will break e10s-compatibility. Instead you should explain why you believe that you can't use framescripts. – the8472 May 30 '16 at 13:50
  • It all began from here: http://stackoverflow.com/questions/11456705/are-events-generated-by-firefox-extension-trusted/11461469#comment58574373_11461469 I need to generate a keyboard event that has `isTrusted=true` property. – alandarev May 30 '16 at 14:33
  • frame scripts run with chrome privileges, so that shouldn't be a problem. – the8472 May 30 '16 at 14:44
  • Thanks, these are all new concepts for me. Can you explain or direct me into how I can send trusted keyboard event using framescripts? – alandarev May 30 '16 at 15:30
  • Just use the nsITextInputProcessor on the [content](https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Frame_script_environment) window in the frame script – the8472 May 30 '16 at 16:04