MozillaZine

Last browser window standing

Talk about add-ons and extension development.
arno.
 
Posts: 50
Joined: August 29th, 2004, 12:12 pm

Post Posted November 9th, 2005, 2:55 am

Thanx for the component code, it works perfectly.
What I would like to do is to call some function of it from the extension, something like :
Code: Select all
var f = Components.classes["@mozilla.doslash.org/test/component;1"].getService(Components.intefaces.nsIsupports);
f.init();


I saw in noscript that it is possible to call all the functions from the component by defining a wrapper in the component :
Code: Select all
get wrappedJSObject () {
       return this;
}

and by calling the component that way :
Code: Select all
var f = Components.classes["@mozilla.doslash.org/test/component;1"].getService(Components.intefaces.nsIsupports).wrappedJSObject;
f.init();


I'm not sure, but I think it is possible to do that in some other way, for example to define which functions are accessible from outside the component, and which are not. I tried to find informations about the meaning of get but couldn't find. Has anyone some clue or pointer to a documentation that could help me (I tried to read the book about component creation, but, as I don't known C++ at all, that didn't help me much)

thanx

richwklein
 
Posts: 331
Joined: November 24th, 2002, 8:20 pm
Location: Iowa

Post Posted November 9th, 2005, 7:38 am

You can access the underlying js object through the magic property wrappedJSObject.
My Extensions:
<a href="http://forecastfox.mozdev.org">Forecastfox</a>
<a href="http://tipbar.mozdev.org">Tip of the Day</a>
<a href="http://urlnav.mozdev.org">Location Navigator</a>
<a href="http://finder.mozdev.org">Finder</a>
<a href="http://rsszilla.mozdev.org">RSSzilla</a>

arno.
 
Posts: 50
Joined: August 29th, 2004, 12:12 pm

Post Posted November 9th, 2005, 8:02 am

thanx

asqueella
 
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post Posted November 9th, 2005, 8:04 am

arno: generally the preferred way is to write a 'real' XPCOM component implementing interfaces defined in IDL. Then you can QI your component to that interface and call a function defined on that interface.

For components implemented in JS you can access the wrappedJSObject property on the component's instance (thanks to some XPConnect magic), but only if the code on the component implementation side defines such property on the object.

The get() syntax that confused you simply defines a getter for the property (see the explanation in JavaScript Guide). It's a SpiderMonkey extension, iirc.

ericjung
 
Posts: 846
Joined: August 4th, 2003, 9:32 am

Post Posted January 9th, 2006, 3:55 pm

Anyone know how to register this component when using it with the Mozilla Suite?

Philip Chee

User avatar
 
Posts: 6475
Joined: March 1st, 2005, 3:03 pm

Post Posted January 10th, 2006, 5:19 am

You need to copy the component (and .xpt file) into the <applicationdir>/components/ directory,
the same way you copy the preferences into <applicationdir>/defaults/pref/

Phil

ericjung
 
Posts: 846
Joined: August 4th, 2003, 9:32 am

Post Posted January 10th, 2006, 7:22 am

And that's it? Don't have to muck with autoreg or anything? Does the browser have to be restarted?

Philip Chee

User avatar
 
Posts: 6475
Joined: March 1st, 2005, 3:03 pm

Post Posted January 10th, 2006, 8:57 am

Ooops. Yes you have to touch .autoreg and restart the Suite.

Phil

ericjung
 
Posts: 846
Joined: August 4th, 2003, 9:32 am

Post Posted January 10th, 2006, 12:18 pm

Thanks, but I need to do all of this from within my extension. Shouldn't I be able to do it with nsIComponentLoader (if that's implemented in Mozilla Suite) or XPInstall? Any ideas?

Philip Chee

User avatar
 
Posts: 6475
Joined: March 1st, 2005, 3:03 pm

Post Posted January 10th, 2006, 7:37 pm

Look at how the install.js for the Tidy extension does it.
Basically there is an empty .autoreg file inside the tidy.xpi/components/
folder and the install.js copies that file to the programme folder.

When in doubt, see how other extensions do it. See also the install.js
for doron's gmail notifier extension. The tagzilla extension doesn't do
this but the component there is a .js file and I think mozilla/firefox
does some magic autoreg for javascript components.

Phil

belaviyo
 
Posts: 51
Joined: November 20th, 2007, 8:10 am

Post Posted November 21st, 2007, 12:49 am

i want to add a global variable to this component to access it from my extension, any body can help

Ravjot
 
Posts: 10
Joined: November 14th, 2006, 2:44 pm

Post Posted January 17th, 2008, 1:28 pm

I'm listening for quit-application-granted to run an uninstall script for my extension. While combing through the Firefox 3.0 Beta 2 source, it looks like the notify for this was removed from globalOverlay.js. My observer won't catch any other notify when the user hits the X button on Windows XP or uses Alt-F4, but it will work if the user uses the restart button on the Add-ons window. Has anyone found a way around this?

Thanks,
Rav

asqueella
 
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post Posted January 17th, 2008, 1:39 pm

The notification should still be fired, the reason it's not in globalOverlay.js is https://bugzilla.mozilla.org/show_bug.cgi?id=386810

I'm not sure what's your problem, but if you don't get the notification when closing firefox via Alt+F4, did you check that it actually exits (i.e. there's no process in the task manager)? Are you 100% sure your code doesn't run?

Oh, and this question should really be in its own thread.

Ravjot
 
Posts: 10
Joined: November 14th, 2006, 2:44 pm

Post Posted January 17th, 2008, 2:15 pm

Yeah I'm sure its still there. If I install the extension in 1.5 and 2.0.x, when I hit 'X', my code does run (it deletes a directory and deletes prefs associated with my extension). However hitting 'X' in Firefox 3.0 Beta 3, my code does not run (100% sure :-D)

Here's roughly what I'm doing:
<blockquote>
UninstallObserver : {

_uninstall : false,

observe:function(subject,topic,data)
{
if (topic == "em-action-requested") {

subject = subject.QueryInterface(Components.interfaces.nsIUpdateItem);

if (subject.name == "Extension Name"){
if (data == "item-uninstalled") {
this._uninstall = true;
}
else if(data == "item-upgraded"){
//set upgrade prefs
}
else if (data == "item-cancel-action") {
this._uninstall = false;
}
}
}
else if (topic == "quit-application-granted") {
alert("QUIT!");
if (this._uninstall) {
/* uninstall stuff. */

}
}
},

register:function()
{
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "em-action-requested", false);
observerService.addObserver(this, "quit-application-granted", false);
},

deregister:function()
{
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(this,"em-action-requested");
observerService.removeObserver(this,"quit-application-granted");
}
}
</blockquote>
When my extension loads I call the register function. That alert fires and if uninstall is true, my code in that if statement runs in FF1.5 and FF2.0, but not in the latest FF3.0 beta. The problem is I need that code to run when I hit 'X', or risk leaving a bunch of useless files and prefs on the user's machine. I've tried the other shutdown events listed here http://developer-cluster.mozilla.org/en ... ifications and none of them work.

Thanks in advance for your help. (Sorry about the formatting... not sure what tag to use to post code)

ankit428
 
Posts: 95
Joined: November 10th, 2008, 2:14 pm

Post Posted May 25th, 2009, 1:51 pm

I am a newbie to xpcom components.. I read a tutorial on mdc and also the thread . But, still am not sure how do i go about. I have creating a basic "helloworld"ish skeleton but do not know how to go ahead ...if i cud get some help !!

Here's my problem statement -->

I have an extension where in i create sockets using the nsiServerSocket interface..
The thing works for normal scenario but when multiple windows are opened up .... multiple sockets are created on the same port no.. Strange but true. !!
So, after reading online...i came to the conclusion that i can create an xpcom comp... which would provide a single instance of the serversocket for eacch socket..
I want to create a component for the above... !!

If some1 cud please give out some pointers regarding the same...i wud appreciate it...

Thanks,

Return to Extension Development


Who is online

Users browsing this forum: Bing [Bot] and 4 guests