Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Open 'Add-ons Manager' by extension code

45 views
Skip to first unread message

gNeandr

unread,
Jan 15, 2013, 10:50:51 AM1/15/13
to
Anyone having a tip how to open the 'Add-ons Manager' with an extension
JS call?
Is it the same call for Thunderbird and Firefox? How about Seamonkey?

Josh Matthews

unread,
Jan 15, 2013, 10:59:59 AM1/15/13
to
It looks like there's a global BrowserOpenAddonsMenu method on chrome
browser windows:
http://mxr.mozilla.org/mozilla-central/source/browser/base/content/browser.js#6272

Cheers,
Josh

gNeandr

unread,
Jan 16, 2013, 7:36:57 AM1/16/13
to
Thanks for that reference,
feel it costs too much to import the whole browser.js to get that
function available in an extention.
Any good idea to reduce that overhead?

Günter

Josh Matthews

unread,
Jan 16, 2013, 8:07:24 AM1/16/13
to
There should not be any importing required. If you have access to a
chrome window, you should just be able to use it.

Arivald

unread,
Jan 16, 2013, 8:20:41 AM1/16/13
to
W dniu 2013-01-16 14:07, Josh Matthews pisze:
Yes, but in FF only.

In TB it is openAddonsMgr(), with almost same code.
http://mxr.mozilla.org/comm-central/source/mail/base/content/mailCore.js#390

Anyway there seems to be no wide-compatible way.
For Seamonkey You need to investigate Yourself.

BTW DOM Inspector + MXR helps in such investigations ;-)

--
Arivald

gNeandr

unread,
Jan 16, 2013, 9:23:15 AM1/16/13
to
OK in TB:
I have to add
<script type="application/javascript"
src="chrome://messenger/content/mailCore.js"/>
<script type="application/javascript"
src="chrome://communicator/content/utilityOverlay.js"/>
to the XUL window to get executing the call:
openAddonsMgr("addons://list/extension");

Isn't the <script .. line a loading of that js file to the XUL?
That's what I thought it's the cost of it?
Am I wrong with that?
Günter


Arivald

unread,
Jan 16, 2013, 9:37:53 AM1/16/13
to
W dniu 2013-01-16 15:23, gNeandr pisze:
imho better to find messenger window, and call its copy of openAddonsMgr().

working example:

function openTBAddons() {
let winEnum =
Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator).getXULWindowEnumerator(null);
while (winEnum.hasMoreElements()) {
let wndE =
winEnum.getNext().QueryInterface(Components.interfaces.nsIXULWindow).docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow);
if (wndE.location == 'chrome://messenger/content/messenger.xul')
wndE.openAddonsMgr();

}
}

--
Arivald


gNeandr

unread,
Jan 16, 2013, 9:48:46 AM1/16/13
to
On 16.01.2013 15:37, Arivald wrote:
..
> imho better to find messenger window, and call its copy of openAddonsMgr().
>
> working example:
>
> function openTBAddons() {
> let winEnum =
> Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator).getXULWindowEnumerator(null);
>
> while (winEnum.hasMoreElements()) {
> let wndE =
> winEnum.getNext().QueryInterface(Components.interfaces.nsIXULWindow).docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow);
>
> if (wndE.location == 'chrome://messenger/content/messenger.xul')
> wndE.openAddonsMgr();
>
> }
> }
>
GREAT! That works for TB, also opening the 'tab' Extensions directly with:
calling openTBAddons("addons://list/extension")

and function openTBAddons(tab)
and wndE.openAddonsMgr(tab);

So it should be straight forward to do the same for Fx and eventually
for SM.
Thanks ;)

Jonathan Protzenko

unread,
Jan 16, 2013, 9:51:34 AM1/16/13
to dev-ext...@lists.mozilla.org
Hi,

Please use fixIterator when you post such snippets, people don't have to
deal with enumerators "by hand" in Thunderbird-land. This has caused a
lot of problems (especially with nsISimpleEnumerator going away) so I
think it's time to advertise that little-known yet very useful module :).

Thanks,

jonathan

Arivald

unread,
Jan 16, 2013, 10:17:31 AM1/16/13
to
W dniu 2013-01-16 15:51, Jonathan Protzenko pisze:
> Hi,
>
> Please use fixIterator when you post such snippets, people don't have to
> deal with enumerators "by hand" in Thunderbird-land. This has caused a
> lot of problems (especially with nsISimpleEnumerator going away) so I
> think it's time to advertise that little-known yet very useful module :).
>
> Thanks,

It was modified code example from my extension, written before
"fixIterator"...

And indeed code become simpler...

var cu = Components.utils;
var ci = Components.interfaces;
var cc = Components.classes;

cu.import('resource:///modules/iteratorUtils.jsm');

function openTBAddons() {
let mediator =
cc['@mozilla.org/appshell/window-mediator;1'].getService(ci.nsIWindowMediator);
for each (let domWnd in fixIterator(mediator.getEnumerator(null),
ci.nsIDOMWindow)) {
if (domWnd.location == 'chrome://messenger/content/messenger.xul')
domWnd.openAddonsMgr();
}
}


--
Arivald

Jonathan Protzenko

unread,
Jan 16, 2013, 10:24:39 AM1/16/13
to dev-ext...@lists.mozilla.org
You can do better with services.jsm:
> var cu = Components.utils;
> var ci = Components.interfaces;
> var cc = Components.classes;
>
> cu.import('resource:///modules/iteratorUtils.jsm');
cu.import("resource://gre/modules/Services.jsm");
>
> function openTBAddons() {
for each (let domWnd in fixIterator(Services.wm.getEnumerator(null),
> ci.nsIDOMWindow)) {
> if (domWnd.location == 'chrome://messenger/content/messenger.xul')
> domWnd.openAddonsMgr();
> }
> }
>
>
Thanks for the updated snippet!

jonathan

gNeandr

unread,
Jan 16, 2013, 10:36:09 AM1/16/13
to
On 16.01.2013 15:51, Jonathan Protzenko wrote:
> Hi,
>
> Please use fixIterator when you post such snippets, people don't have to
> deal with enumerators "by hand" in Thunderbird-land. This has caused a
> lot of problems (especially with nsISimpleEnumerator going away) so I
> think it's time to advertise that little-known yet very useful module :).
>
> Thanks,
>
> jonathan
>

Thanks Jonathan for your feedback.

I found that 'fixIterator' only by chance .. it would be great to have a
more public presentation of all (your) "little-known yet very useful
module" .. should say "modules"!

I have used 'fixIterator' already for a function to get the identity for
a given mail address (see below). But isn't that also loading code with
the .import?

Günter



> ext.msgnr.getIdentity = function (address) {
> // =========================================================================
> const Cu = Components.utils;
> const Ci = Components.interfaces;
> Cu.import("resource:///modules/iteratorUtils.jsm");
> Cu.import("resource:///modules/mailServices.js"); // needed for MailServices.compose etc.
> Cu.import("resource://gre/modules/Services.jsm"); // needed for Services.io etc.
>
> var identity = null;
> for each (var account in fixIterator(MailServices.accounts.accounts, Ci.nsIMsgAccount)) {
> for each (var id in fixIterator(account.identities, Ci.nsIMsgIdentity)) {
> // We're only interested in identities that have a real email.
> if (id.email == ext.mail.address(address).email) {
> identity = id;
> break;
> }
> }
> }
> if (identity == null) ext.msgnr.getAccountMngr().defaultAccount.defaultIdentity;
> return identity;
> };


Arivald

unread,
Jan 16, 2013, 10:45:07 AM1/16/13
to
W dniu 2013-01-16 16:24, Jonathan Protzenko pisze:
Yeah, services module, I forgot ;-) So many nice features added since i
start writing my extension...

So updates code, even simpler: enumerate window by "windowtype"
attribute, so no need to check location.

function openTBAddons() {
for each (let domWnd in
fixIterator(Services.wm.getEnumerator('mail:3pane'), ci.nsIDOMWindow))
domWnd.openAddonsMgr();
}

--
Arivald

gNeandr

unread,
Jan 16, 2013, 10:50:43 AM1/16/13
to
Great .. simplify your life!
Unfortunately I need to do it also with Firefox and AFAIU "fixIterator"
is Thunderbird specific?!

Arivald

unread,
Jan 16, 2013, 10:51:51 AM1/16/13
to
W dniu 2013-01-16 16:36, gNeandr pisze:
> On 16.01.2013 15:51, Jonathan Protzenko wrote:
>> Hi,
>>
>> Please use fixIterator when you post such snippets, people don't have to
>> deal with enumerators "by hand" in Thunderbird-land. This has caused a
>> lot of problems (especially with nsISimpleEnumerator going away) so I
>> think it's time to advertise that little-known yet very useful module :).
>>
>> Thanks,
>>
>> jonathan
>>
>
> Thanks Jonathan for your feedback.
>
> I found that 'fixIterator' only by chance .. it would be great to have a
> more public presentation of all (your) "little-known yet very useful
> module" .. should say "modules"!
>

For start look here ;-)
https://developer.mozilla.org/en-US/docs/Thunderbird_5_for_developers


> I have used 'fixIterator' already for a function to get the identity for
> a given mail address (see below). But isn't that also loading code with
> the .import?

Yes, but only once for application. Any subsequent "import" just use
existing instance. And module is loaded to its own space, only few
exported symbols are imported to Your space.

I switch for modules in my extension (i was using XPCOM component
earlier). Modules really simplify work, at least since we can load them
from chrome: url.

--
Arivald

Arivald

unread,
Jan 16, 2013, 10:58:56 AM1/16/13
to
W dniu 2013-01-16 16:50, gNeandr pisze:
Don't know, but probably no.

Install this in FF:
https://addons.mozilla.org/pl/firefox/addon/extension-developer/
... then use "Realtime XUL editor" to do test.

In FF there will be different window type. Use DOM Inspector to check
"windowtype" attribute of main window.

--
Arivald


gNeandr

unread,
Jan 16, 2013, 11:09:34 AM1/16/13
to
On 16.01.2013 16:58, Arivald wrote:
..
> In FF there will be different window type. Use DOM Inspector to check
> "windowtype" attribute of main window.
>
Thanks and Greetings to Polen ;)

(there is also an English version of that addon description
https://addons.mozilla.org/en/firefox/addon/extension-developer/
)

gNeandr

unread,
Jan 16, 2013, 1:17:15 PM1/16/13
to
On 16.01.2013 14:20, Arivald wrote:
.. ..
> In TB it is openAddonsMgr(), with almost same code.
> http://mxr.mozilla.org/comm-central/source/mail/base/content/mailCore.js#390
>
>
> Anyway there seems to be no wide-compatible way.
> For Seamonkey You need to investigate Yourself.
>
> BTW DOM Inspector + MXR helps in such investigations ;-)
>
For the records:
I was not able to find any result for SeaMonkey similar to FX && TB.
Non of the XUL I find with the query method gives access to
.openAddonsMgr() or .BrowserOpenAddonsMgr()

Philip Chee

unread,
Jan 16, 2013, 1:36:59 PM1/16/13
to
In SeaMonkey it's:

function toEM(aView)
{
switchToTabHavingURI("about:addons", true, function(browser) {
if (aView)
browser.contentWindow.wrappedJSObject.loadView(aView);
});
}

Phil

--
Philip Chee <phi...@aleytys.pc.my>, <phili...@gmail.com>
http://flashblock.mozdev.org/ http://xsidebar.mozdev.org
Guard us from the she-wolf and the wolf, and guard us from the thief,
oh Night, and so be good for us to pass.

Neil

unread,
Jan 16, 2013, 3:27:58 PM1/16/13
to
Arivald wrote:

> function openTBAddons() {
> for each (let domWnd in
> fixIterator(Services.wm.getEnumerator('mail:3pane'), ci.nsIDOMWindow))
> domWnd.openAddonsMgr();
> }

DOM windows have class info, so you don't actually need to
QueryInterface them to nsIDOMWindow to use them. Also this code is
broken in the case of more than one 3pane window being open.

--
Warning: May contain traces of nuts.

Neil

unread,
Jan 16, 2013, 3:30:32 PM1/16/13
to
Philip Chee wrote:

>On 17/01/2013 02:17, gNeandr wrote:
>
>
>>On 16.01.2013 14:20, Arivald wrote:
>>
>>
>>>In TB it is openAddonsMgr(), with almost same code.
>>>http://mxr.mozilla.org/comm-central/source/mail/base/content/mailCore.js#390
>>>
>>>Anyway there seems to be no wide-compatible way.
>>>For Seamonkey You need to investigate Yourself.
>>>
>>>BTW DOM Inspector + MXR helps in such investigations ;-)
>>>
>>For the records:
>>I was not able to find any result for SeaMonkey similar to FX && TB.
>>Non of the XUL I find with the query method gives access to
>>.openAddonsMgr() or .BrowserOpenAddonsMgr()
>>
>>
>In SeaMonkey it's:
>
>function toEM(aView)
>{
> switchToTabHavingURI("about:addons", true, function(browser) {
> if (aView)
> browser.contentWindow.wrappedJSObject.loadView(aView);
> });
>}
>
>
Note that this code gets loaded into most SeaMonkey windows so you can
use it even when there isn't a browser window open.

gNeandr

unread,
Jan 16, 2013, 4:38:39 PM1/16/13
to
Maybe, but if you only have the messenger window active, that doesn't
get the Add-on Manager, think because it always goes to the browser. But
if the browser isn't shown/opened before the call, the user will not see
it. And that's what I need to have .. it's about the UI!

Mook

unread,
Jan 16, 2013, 11:48:06 PM1/16/13
to
On 1/16/2013 6:37 AM, Arivald wrote:
<snippy snip>
> imho better to find messenger window, and call its copy of openAddonsMgr().
<snip>
> Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator).getXULWindowEnumerator(null);

Normally, there's no need to enumerate, you just need one addon manager
tab open:

Services.wm.getMostRecentWindow("mail:3pane").openAddonsMgr();

HTH,

--
Mook

Neil

unread,
Jan 17, 2013, 5:18:15 AM1/17/13
to
How did you think the messenger window's Add-on Manager menuitem works?

gNeandr

unread,
Jan 17, 2013, 5:52:17 AM1/17/13
to
Good point! But my current code (which follows the recommendations in
this thread, I hope ;)) doesn't open the browser/AM etc.
See pastebin http://pastebin.mozilla.org/2065807

Neil

unread,
Jan 17, 2013, 6:14:53 AM1/17/13
to
gNeandr wrote:

> my current code (which follows the recommendations in this thread, I
> hope ;)) doesn't open the browser/AM etc.

You should use something like this:
if ('toEM' in wndE) {
wndE.toEM(aView);
break;
}

Also why not use .getEnumerator(null), it returns DOM windows directly
from its getNext().
0 new messages