Chris Shen wrote:
> 
> Thanks for your suggestions. I did use the do_GetService(getService) before
> using CreateInstance(createInstance).
> It was not working. Now, I use do_GetService(getService) and test again. I
> found that it wouldn't work until I reloaded
> the page again. That's a bit of weird. I don't see why it doesn't work on
> first load. 

I couldn't guess without seeing all the code.

> Upon reloading the page and then
> pressing the button associated with the javascript method again, it popped
> up a window to say "a script from "file://" has
> requested enhanced privilege..." message to ask me if allowing the
> privilege. The message is actually defined in
> the /caps/src/security.properties. It's a bit of annoying. I like to turn on
> the privilege option in some config file like pref.js
> so that the message window won't popup while it still grants the privilege.
> So, which setting in which config file grants the privilege?
> Or, some other setting like "UniversalXPConnect" could do so from
> javascript?

The mozilla security group is a good place to ask about specific
options. There's likely an FAQ or something people could point
you to.

If you were running this from chome: then you would not see a
dialog - it would just allow the call to continue silently.

If you are going to call through xpconnect from downloaded
content the user really needs to be able to decide if they trust
you to do that or not.

Anyway, the mozilla security newsgroup is the place to discuss
such things. There are people reading that group that know a lot
more than me about the practicalities of that stuff.

John.

> 
> Thanks
> 
> "Mike Shaver" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > Chris Shen wrote:
> >
> > > Components.classes["@mozilla.org/notifservice;1"].createInstance();
> >
> >
> > >     notifserv = do_CreateInstance(NS_NOTIFSERVICE_CONTRACTID, &rv);
> >
> >
> > > I expect:
> > > At the runtime, my browser application loads the notifservice first and
> > > add itself as a listener to the service. By the time, I assume the
> > > notifservice
> > > remaining in memory. Then my browser app loads the test html page which
> > > loads
> > > the notifservice as well. Because the notifservice already registered in
> > > memory,
> > > I assume the xpconnect only increases the reference count rather than
> > > creates
> > > a new instance again.
> >
> >
> > do_CreateInstance (C++) and createInstance (JS) will always create a new
> > instance.  To access (possibly instantiating, if none exists) a shared
> > service, use do_GetService (C++) and getService (JS) instead.
> >
> > > The breakpoint never reaches nsNotifService's notif method. It seems
> tell me
> > > that
> > > loading the notifservice in js isn't successfully.
> >
> >
> > What's the error it gives?  Did you put the typelib for the
> > nsINotifService in the components directory?
> >
> > (We have nsIObserver for this sort of mechanism already, which you might
> > find requires you to write less new code -- you'd just need an
> > implementation of nsIObserver in C++, really, and there are lots to
> follow.)
> >
> > Mike
> >

Reply via email to