window.addEventListener("click"..) doesn't work with shims?

Talk about add-ons and extension development.
Post Reply
Orangutan100
Posts: 54
Joined: July 9th, 2015, 11:56 am

window.addEventListener("click"..) doesn't work with shims?

Post by Orangutan100 »

I am using the Save Image in Folder addon on FF v50.0a2. I have e10s enabled. It works well with shims, except for one small feature - the addon allows you to double click images to save them in the last directory directly. This feature stops working when e10s is enabled. Here is the relevant part (I think) of the code:

Code: Select all

if (siif_pref.getBoolPref("doubleclick"))
            window.addEventListener("dblclick", siif_main.onDblClick, false);
Could somebody please tell me what it needs to be replaced with to work? I am not looking for full e10s compatibility or anything, just make it work with shims.

Thanks.
lithopsian
Posts: 3664
Joined: September 15th, 2010, 9:03 am

Re: window.addEventListener("click"..) doesn't work with shi

Post by lithopsian »

No shims there. Shims are only used when you access content from the chrome process. There is nothing in your code that access content. So far, so good, except that events do not bubble from the content process to the chrome process so any clicks on content will not fire your listener.

The quick and dirty way to fix this would be to add the listener to a content element. contentWindow would probably be the way to go, although you might be able to work with window.content since click events are only likely to happen in the visible page I guess. You might have to re-add to every new browser, or perhaps remove and re-add every time tabs are switched, or maybe just be lazy since adding an existing even listener again does nothing (but not tested with shims!). Then the way it is supposed to work is that the shim understands it is working on a content element, sets up the listener in the content process, AND relays the click back to the chrome process when it happens. Magic!!! If it works. I haven't tried this particular piece of magic, and in any case it is really about as awful as bad a thing as you could imagine doing with a shim.

Unfortunately, the doing it the proper way in this case is a bit messy. You inject a frame script, presumably into every browser, and set up your listener in there. Then when someone double-clicks you grab the image in your frame script but you can't save it because there is no file I/O allowed. You have to send it back to the chrome process to be saved, probably as a file blob but maybe the base64 image string or a data url depending how you plan to store the image.
Orangutan100
Posts: 54
Joined: July 9th, 2015, 11:56 am

Re: window.addEventListener("click"..) doesn't work with shi

Post by Orangutan100 »

Thanks for responding!

Sorry, but I think I should have mentioned in the OP that I know next to nothing about javascript or add-on development. I am just a user of the above add-on; trying to make it compatible.

I tried replacing window.addEventListener in (only) the line in the OP with contentWindow.addEventListener but it didn't work. I also tried window.content.addEventListener but couldn't get that to work either. I wouldn't know how to implement the other things you mentioned.

If this is too much work, I will probably just wait for the developer to fix it.

Thanks, again :)
lithopsian
Posts: 3664
Joined: September 15th, 2010, 9:03 am

Re: window.addEventListener("click"..) doesn't work with shi

Post by lithopsian »

Yes, you won't be able to do this with a one-liner.
Post Reply