0

I've exactly the same issue : How do I use the canvas drawWindow function in an addon created using the addon sdk?

But the solution doesn't work.

If drawWindow can't be use with the firefox add-on sdk, there is an other solution to put a clicked pixel to a canvas ?

Community
  • 1
  • 1
user3433920
  • 131
  • 1
  • 6

1 Answers1

2

Get a privileged canvas

var chromewin = require('sdk/windows/utils').getHiddenWindow();
var canvas = chromewin.document.createElementNS('http://www.w3.org/1999/xhtml',
                                                'canvas');

and work with it from main.js, not a content script.

paa
  • 5,048
  • 1
  • 18
  • 22
  • It works ! thanks. There is really no solution to call this function from the content script ? – user3433920 May 28 '14 at 08:49
  • A content script runs with the permissions of the page it is attached to. So the answer is a stern no. But the content script can always ask `main.js` to do that, through the `port` mechanism. – paa May 28 '14 at 16:09
  • 2
    Using directly the `hiddenWindow` is not suggested, 'cause it's global to the browser: other add-ons could mess with that. AMO reviewer will probably takes care of such code and suggest to change it to the author. Anyway, it's better replacing: `var chromewin = require('sdk/windows/utils').getHiddenWindow()` with `let { window } = require('sdk/addon/window')` then proceed to create the canvas as above. The module `addon/window` provides a hidden window for each add-on – you can still mess with that, 'cause in the current implementation they're hosted in the `hiddenWindow`, but it's less likely – ZER0 Jun 04 '14 at 04:38
  • @ZER0 good point, I wasn't aware of bug 565388. Still, I wonder how well this will work for Fennec on low-end devices. – paa Jun 04 '14 at 07:46
  • @paa the bottle neck on Fennec and low-end device is related to the operations on canvas – I mean, compare to Firefox Desktop –; not how do you get a reference to a window. Especially in this case, where there is no much difference to get the hidden window and the addon window (that as I said is hosted in the `hiddenWindow`). – ZER0 Jun 06 '14 at 07:07