Bootstraped addon: How to access (sandboxed) addon methods from an injected onclick event (executed in global scope)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Bootstraped addon: How to access (sandboxed) addon methods from an injected onclick event (executed in global scope)

Mozilla - Thunderbird mailing list
I have converted my addon to bootstrap. Inside the bootstrap.js I do three things:


1. load my jsm, which exposes a tbsync object, which contains all my code:
Components.utils.import("chrome://tbsync/content/tbsync.jsm");


2. Add an observer, which will call a method of my tbsync object:
Services.obs.addObserver(tbSync.openManagerObserver, "tbsync.openManager", false);


3. inject an UI element into the status bar of the mail:3pane window.

--------------------------------------------------------
let window = Services.wm.getMostRecentWindow("mail:3pane");

let statuspanel = window.document.createElement('statusbarpanel');
statuspanel.setAttribute("label","TbSync");
statuspanel.setAttribute("id","TbSyncStatus");
statuspanel.onclick = function (event) {if (event.button == 0)Services.obs.notifyObservers(null, 'tbsync.openManager', null);};

window.document.getElementById("status-bar").appendChild(statuspanel);

--------------------------------------------------------


As you can see, I assigned a notifyObservers to the onlick event, which will notify my own observer, which I added as shown in 2). As a result, a method of my tbsync object is called, when my UI element in the statusbar is clicked.

I was not able to assign my method - tbsync.openManager() - directly to the onclick event, because my tbsync object is not available in the scope of the main window (mail:3pane).

Is using observers the only way to execute addon code from injected UI elements (whose onclick events are always executed in the global scope, and not in the sandboxed scope of my addon)?

Thanks for your time
John

_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird