I spent several days trying to share one of my Firefox for Android extension objects with web pages, which I also open from my extension (declared as resources). The fact is that I read a lot about the latest changes about unsafewindow, so I tried a very small example with new features, but didn’t do the job. I copied the examples, and I also tried my own, but there is no way to copy existing objects with functionality. Look, I have a VERY large object for cloning in the content window, but I decided to test with a small one:
var dog = {
name: 'Spike',
woof: function(){alert('woof woof!')}
};
And after that I tried to copy this object to the active window:
var contentWindow = window.BrowserApp.selectedBrowser.contentWindow;
contentWindow.dog = Components.utils.cloneInto(
dog,
contentWindow,
{cloneFunctions: true}
);
, :
alert(contentWindow.dog);
alert(contentWindow.dog.name);
alert(contentWindow.dog.woof);
, , , "cloneFunctions: true".
, ( ) :
function greetme(user) {
return "cheers " + user;
}
var foo = Components.utils.createObjectIn(contentWindow,{defineAs: "foo"});
Components.utils.exportFunction(greetme, foo, {defineAs: "greetme"});
... , , , .
(A LOT) !
https://blog.mozilla.org/addons/2014/04/10/changes-to-unsafewindow-for-the-add-on-sdk/