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

How to get directory in wich plugin is installed (or current profile)

2 views
Skip to first unread message

Oleksandr Shneyder

unread,
Nov 13, 2009, 8:16:23 AM11/13/09
to dev-tech...@lists.mozilla.org
Hello list,
I develope a plugin for firefox (in c++). Plugin is installed via XPI in
~/.mozilla/firefox/xxx.default/extensions/plugin@company/

Now how can I find in plugin in which directory is plugin installed?
Maybe there is a API function to get a current profile name of running
instance? In that case I can find a plugin directory too.

Thank you for your help.
--
Oleksandr Shneyder
Dipl. Informatik
X2go Core Developer Team

email: oleksandr...@obviously-nice.de
web: www.obviously-nice.de

--> X2go - everywhere@home

signature.asc

Georg Fritzsche

unread,
Nov 15, 2009, 4:03:07 AM11/15/09
to
The GNU extension dladdr() is commonly used for that.

Regards,
Georg

Oleksandr Shneyder

unread,
Nov 16, 2009, 2:23:45 AM11/16/09
to Georg Fritzsche, dev-tech...@lists.mozilla.org
Georg Fritzsche schrieb:

> The GNU extension dladdr() is commonly used for that.
>
> Regards,
> Georg
> _______________________________________________
> dev-tech-plugins mailing list
> dev-tech...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-plugins
Thank you very much, Georg. That is exactly what I need.

Have a nice day.

signature.asc

Benjamin Smedberg

unread,
Nov 16, 2009, 8:34:36 AM11/16/09
to
On 11/13/09 8:16 AM, Oleksandr Shneyder wrote:
> Hello list,
> I develope a plugin for firefox (in c++). Plugin is installed via XPI in
> ~/.mozilla/firefox/xxx.default/extensions/plugin@company/
>
> Now how can I find in plugin in which directory is plugin installed?
> Maybe there is a API function to get a current profile name of running
> instance? In that case I can find a plugin directory too.

Is this a plugin binary, or an extension? Binary plugins typically don't
know or care where they are installed. For extensions using __LOCATION__
from a JS file is the recommended solution:
https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO#Getting_your_extension%27s_folder

--BDS

Luca Cerutti

unread,
Dec 1, 2009, 8:48:46 AM12/1/09
to
On 13 Nov, 14:16, Oleksandr Shneyder <oleksandr.shney...@obviously-

nice.de> wrote:
> Hello list,
> I develope a plugin for firefox (in c++). Plugin is installed via XPI in
> ~/.mozilla/firefox/xxx.default/extensions/plugin@company/
>
> Now how can I find in plugin in which directory is plugin installed?
> Maybe there is a API function to get a current profile name of running
> instance? In that case I can find a plugin directory too.
>
> Thank you for your help.
> --
> Oleksandr Shneyder
> Dipl. Informatik
> X2go Core Developer Team
>
> email:  oleksandr.shney...@obviously-nice.de

> web:www.obviously-nice.de
>
> --> X2go - everywhere@home
>
>  signature.asc
> < 1KVisualizzaScarica

I've exactly the same question but I'm developing under MS Windows.
I need to know how to read a sort of configuration file for the plugin
because I need to let the plugin read/edit the following information:
- custom cache folder path
- custom cache dimension
- others

Since it seems that a plugin CANNOT access registry values, I've
thought of this config file.
If there are others acceptable solutions, please let me know.

Regards

cap2006debate

unread,
Jan 11, 2010, 8:25:56 AM1/11/10
to
On Dec 1 2009, 2:48 pm, Luca Cerutti <luca.cerutti...@gmail.com>
wrote:

> I've exactly the same question but I'm developing under MS Windows.

I Windows you can use the DLL API functions [1] in the plugin source
code to return the full path to its DLL:

#include <windows.h>

...

char pluginpath[1024];
HMODULE module;

GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
(char *)NP_Initialize,
&module);
GetModuleFileNameA(module, pluginpath, 1024);
FreeLibrary(module);

In Linux would be in this way:

/* Compile with -ldl */
#include <dlfcn.h>

/* See man dladdr(3) */
typedef struct {
const char *dli_fname; /* Pathname of shared object that
contains address */
void *dli_fbase; /* Address at which shared object
is loaded */
const char *dli_sname; /* Name of nearest symbol with address
lower than addr */
void *dli_saddr; /* Exact address of symbol named
in dli_sname */
} Dl_info;

...

Dl_info dlinfo;
if (dladdr(NP_Initialize, &dlinfo)) {
snprintf(pluginpath, 1024, "%s", dlinfo.dli_fname);
}

[1] http://msdn.microsoft.com/en-us/library/ms682599(VS.85).aspx

0 new messages