Questions and answers from the newsgroups

Return to mozilla-dev-extensions


Friday, September 22 - 29, 2006

(↑ top)

How do you write an XPCOM component in C++ that can communicate to a COM component?
Write an XPCOM component in C++ - it will talk to the COM component and will be accessible to JS code via XPConnect. There is a book, Creating XPCOM Components, available online, as well as quite a few articles on the topic, including Creating a C++ XPCOM componentand Creating Custom Firefox Extensions with the Mozilla Build System
How to customizes toolbar button to coexist in a toolbar palette and status bar?
Option #3
Install Status Buttons 1.0
<https://addons.mozilla.org/firefox/1272/>
"Lets you put toolbar buttons at either end of the status-bar. Just drag them there from the toolbar customisation window, like you would when adding buttons to the toolbars."
Option #4
Install Toolbar Control
<http://webdesigns.ms11.net/chromeditp.html>
How to creating an extension that can replace HTML code on a specific page that does not use Greasemonkey?
var newNode = document.createElement(" ... html content here ... ");
var replaceMe = document.getElementById("replaceMe");
replaceMe.parentNode.replaceChild(newNode, replaceMe);
Is it possible to place an image in the window that can be moved to anywhere in the window, and always remain on top of everything else?(similar to using position:absolute and-index:100000 in HTML)
you can almost do this with a stack:
<window ...>
    <stack flex="1">
       <image top="40" left="80"/>
       <vbox>
          other content here
       </vbox>
    </stack>
</window>
The only restriction is that your image can't overlap the right or bottom of the window. There are workarounds to this restriction by messing around with overflow or negative margins but I forgot offhand how to do that.
Request for a Thunderbird extension that can automatically detect the default domain when composing e-mails via auto detect.
<https://bugzilla.mozilla.org/show_bug.cgi?id=312818>
"Thunderbird requires domain in addresses and doesn't always add default"
There is an extension that allows what you want attached to one of the comments in this bug.

Friday, September 29 - October 6, 2006

(↑ top)

Is there anyway, via plug in or extension, for Firefox to mimic the functionality of IE in this respect?
The IETab (Opens IE in a Firefox tab) should be able do this if you set it to always open "file://*" URLs in an IE tab. The appearance with a FireFox tab isn't quite the same as having a completely separate Explorer window. However, it's functional and does allow for the Explorer to be handling the display of the folder contents, and all of the right-click context menu support is present so it should meet my needs.
What is the valid location and things needed to to release a Mozilla extension on Mozallia site?
You must remove update URL from the install.rdf and use a known to AMO minVersion/maxVersion.
No confirmation that the answer given worked yet.
Is it possible to open the URL in a new tab?
var tab = getBrowser().addTab( url );
// And if you want it to load in foreground:
getBrowser().selectedTab = tab;
Is it possible to read the html-code of the current URL/site?
Yes, this is possible. Use the DOM API (http://www.w3schools.com/dom/default.asp has a good tutorial).
Not the best answer but a good starting point for the question asker to do some research towards the answer.
Why does his extension not able to read the contents of a folder and then produce a segmentation fault after his extension reads preferences in Thunderbird?
The person was missing a method call to getService.

Friday, October 06 - 13, 2006

(↑ top)

Any suggestions to remove tool tip appears on the menu it when it should not?
What you described was a bug (https://bugzilla.mozilla.org/show_bug.cgi?id=147670). It looks like it has been fixed for Firefox version 2.
How to test a tab has been closed or not?
You can capture the even of tab closing. You can get the tab that is being closed. This should be enough for you.
Is it possible to fix the size exactly at 16x16 pixels avoiding any resize?
Simply position the image and it will no longer be stretched to the size of the stack. <image left="0" top="0"> would seem to suffice.
Could there be more than two images to reflect more than two states?
Does the rules in the CSS file have to be in any particular order (if two rules match, which is chosen)?
I have two states switching images in the tool bar and would have no problem implementing a third, so yes it's possible.

//setting the state document.getElementById("toolbar-button").setAttribute("toolbar-button", "on");
//or
document.getElementById("toolbar-button").setAttribute("toolbar-button","off");

//CSS

#myExten-toolbar-button[myExten-toolbar-button="on"] {
   list-style-image: url("chrome://myExten/skin/toolbar-button.png");
   -moz-image-region: rect(0px 24px 24px 0px);
}
 #myExten-toolbar-button[myExten-toolbar-button="off"] {
   list-style-image: url("chrome://myExten/skin/toolbar-button-off.png");
   -moz-image-region: rect(0px 24px 24px 0px);
}
To implement a third I would simply change add an attribute and the corresponding CSS
See http://www.w3.org/TR/REC-CSS2/cascade.html#cascade

Friday, October 13 - 20, 2006

(↑ top)

How to get a reference to the sidebar window
Assuming you have chrome privileges, this should work:
var Ci = Components.interfaces;
var topLevelWindow = 
window.QueryInterface(Ci.nsIInterfaceRequestor)
       .getInterface(Ci.nsIWebNavigation)
       .QueryInterface(Ci.nsIDocShellTreeItem)
       .rootTreeItem
       .QueryInterface(Ci.nsIInterfaceRequestor)
       .getInterface(Ci.nsIDOMWindow)
       .QueryInterface(Ci.nsIDOMChromeWindow);
var sidebar = topLevelWindow.document.getElementById("sidebar");
alert(sidebar.contentDocument); 
Is there anyone successfully using Dojo in a Firefox extension and where to fine sample codes?
The problem with most JS frameworks is that they bootstrap by dynamically appending script elements, which doesn't work in XUL, last I checked. Take a look at the bottom of http://svn.dojotoolkit.org/dojo/trunk/dojo.js

see what it's trying to load and write out the script element by hand.

Could someone write an extension that would collapse the current sidebar in Firefox?
These are called "Grippies"
<https://addons.mozilla.org/firefox/2242/>

This extension brings grippies back to Firefox (and Thunderbird!)

Would anyone be able to suggest the best way to do source level debugging in a Firefox extension?
In the Debug menu, uncheck Exclude Browser Files.
Use the debugger by typing in a command like this: /break chrome://myextension/content/myfile.js 123
Then I suggest using flat chrome. If you turn off the XUL cache you don't even need to restart to see changes, simply open a new window.
How can I backup some of the files before upgrade an extension and put them back afterward? Do I need to write an installation script to achieve this?
You shouldn't store data there, so there's nothing to backup.
Do not store files within the extension directory.
The Profile directory is meant to do so.
Storing files within the extension directory is a no-no because it might break the multi-user support of those Mozilla products, as it is possible to install extensions directly within the application directory.
Inspector, Talkback and the default theme are nowadays installed like this.
Does Firefox clean up the preferences set by extension? If not, how to proceed?
When user chooses to uninstall an extension, a nsIObserverService notification is sent out. The problem is, while your extension is still active, user can cancel uninstallation, and when it is physically uninstalled, your code can't run.
Right. And if you uninstall Firefox, the profile data is left behind.
It would be nice to give the option of clearing extension's data, but it should be implemented at application level, not by each extension individually.
It might be an option to stick with it and perform stuff when it comes to application shutdown.
The Sanitize stuff does this (clean stuff on exit).
http://lxr.mozilla.org/mozilla1.8/so...ents/nsBrowser...
Firefox will clean all those preferences which are still "default", that is not changed by the user or the application/extension.
To provide those default preferences to your extension see: http://kb.mozillazine.org/Dev_:_Usin...lt_preferences
BTW: Resetting prefences to default will clear them in case no default prefence is (still) available.
Those will be completely removed upon next application launch.
Is it possible to create a sidebar on the top of the page?
Not unless you make it a separate window. There's a bug in bugzilla about stacking other widgets on top of browser/iframe, which hopefully will be fixed for Gecko 1.9.
Could someone write an extension that zaps the Google Analytics cookie, the Urchin cookie, switches Gmail and Google Calender to HTTPS?
CustomizeGoogle extension already has support for switching Gmail to HTTPS (and calendar possibly, too).
Does anyone know how write a bounce email extension?
Are you aware of the "mailredirect" extension? It allows bouncing to arbitrary addresses. It seems what you want is a one button access to that extension with a prefilled bounce address, right?
Is each window is essentially a separate JavaScript sandbox?
It's best to define singletons as custom XPCOM services. You'll avoid problems like these.
could someone make an extension for Thunderbird that preview upcoming events and number of new messages?
In our company I write this extension that connects to our GroupWare server (HTTP). What server should search extension work against? Did you mean Exchange?
How to attach information using the StringProperties of an IMAP message with out changing the properties?
String properties are implemented as IMAP user flags. However not all servers support user flags, in which case you get reduced functionality as follows: all flags are stored in your local cache and are lost if your cache gets invalidated, and only "known" properties are copied when messages are copied. The list of "known" properties is: junkscore junkscoreorigin label priority keywords.
Keywords - In the GUI they are called Tags. They replace the old Labels.
Preserved properties source code - nsImapMailFolder::CopyMessages
Why xbl thinks method is not a function?
It's a common oversight when working with JavaScript callbacks. Both setTimeout( fn, ... ) and addEventListener(receiver, fn, .. ) have this problem. In the case of setTimeout fn is called with this equal to the window. In the case of addEventListener fn is called with this equal to the receiver that you added the event listener to. In your case that is also the window.
It is possible to get events and timer notifications in an object-oriented manner. For events it is as simple as passing an object instead of a function. This object's handleEvent method will get called with this equal to the object itself. However you would need to add logic to distinguish multiple events, or create a separate object for each event, which would require you to track event objects to avoid leaking.
If you want an object-oriented timer callback then currently the only way to do this is from an extension where you can use the timer service to register a callback object. This object's notify method will get called with this equal to the object itself. In this case it is even more vital that you track your objects to avoid leaking.

Friday, October 20 - 27, 2006

(↑ top)

How to "migrate" an existing FF extension to Thunderbird?
Step 1: Add Thunderbird compatibility info to install.rdf.
Step 2: Overlay messenger.xul { instead of / as well as } browser.xul.
Step 3: Add code to fix errors that crop up now that your extension is running in Thunderbird.
Hint: Look at how the autohidestatusbar extension (which works in Firefox, Thunderbird and seaMonkey) does it.
Does any one know why radio button icon does not show in sidebars?
Many widgets work in boilerplate code from simpler sidebars, but to use radio buttons one must include the browser stylesheet.
<?xml-stylesheet href="chrome://browser/skin/browser.css" type="text/css" ?>
needed for e.g.radio button icons
<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?> this is the more general solution.
How to control window watcher?
Not sure that it's possible to resize and move a window immediately after it's been created, you might try waiting for it to load first.
After changed the openWindow call to
ww.openWindow(null, url, 'Title of Window', features, null);
was able to add events handlers and control the window. So it must of been an issue with using the browser XUL.
How to parse the DOM?
content.document?
Is there a way to trigger screengrab by command line args?
This is a standard XPCOM component. You install/use it by putting in your extension's/application's 'components' folder: http://developer.mozilla.org/en/docs/Bundles
Whether you'll be able to "call the necessary javascript" depends on what exactly you're going to call. Do you have the actual screen grabbing code? I'd start with that rather than the cmd line handler.
compreg.dat / xpti.dat contain information about registered components and interfaces. These files are written out by Firefox after the XPCOM registration process.
During the registration process, Firefox looks in a few predefined places (like app's and each extension's components folder) for files that may contain components or interfaces.
For each file that might provide components (e.g. js or binary so or dll), it tries to run its registration function, which calls back into component manager to register the components it provides (and adds them to XPCOM "categories" if needed). Each typelib (xpt) file is scanned for interfaces.
So all you need to do is to put a specially-crafted component file in one of folders Firefox searches for components and trigger the registration process (a common way to do it when developing is to delete compreg.dat). Or just create an XPI with your component in its components/ folder and install it; autoregistration happens after installing XPIs too.
There's a separate "scope" (different global object) for each "window" (which is not just windows in the window manager sense - see http://developer.mozilla.org/en/docs...ontent_windows) and for each XPCOM component.
That extension's code most likely lives in a browser.xul overlay, meaning it's is in a different scope than your cmd line handler's code. On the other hand, the handler's code is invoked early when you can't make screen shots of the page yet. So you'll probably have to find a way to defer the handling until the browser window opens.
How to get return value from modal dialog?
Here's one way to do it.
The code to open the a dialog named mydialog.xul and pass it arguments:
 var params = {inn:{name:"foo", description:"bar", enabled:true}, out:null};        
  window.openDialog("chrome://myext/chrome/mydialog.xul", "",
    "chrome, dialog, modal, resizable=yes", params).focus();
  if (params.out) {
   // user clicked ok--process changed arguments (write them to disk or whatever)
 }
mydialog.xul:
 <dialog 
 xmlns="http://www.mozilla.org/keymaster/gat...re.is.only.xul" 
 id="theId"   title="some title"
 ondialogaccept="return onOK();"
 onload="onLoad();"
 persist="screenX screenY width height"
 windowtype="mywintype">
 <script type="application/x-javascript" src="chrome://myext/content/mydialog.js"/>
 // xul here
</dialog>
mydialog.js:
function onLoad() {
 sizeToContent();
 // use the arguments passed to us
 document.getElementById("name").value = window.arguments[0].inn.name;
 document.getElementById("description").value = window.arguments[0].inn.description;
 document.getElementById("enabled").checked = window.arguments[0].inn.enabled;
}
function onOK() {
  // return the changed arguments.
  // notice if user clicks cancel, window.arguments[0].out remains null
  window.arguments[0].out = {name:document.getElementById("name").value,
       description:document.getElementById("description").value,    
       enabled:document.getElementById("enabled").checked};
  return true; 
} 
How to update internet search RDF?
nsIRDFRemoteDataSource
<http://www.xulplanet.com/references/...ataSource.html>
This interface appears to have several methods you can use including: void Flush ( )
Request that a data source write it's contents out to permanent storage,if applicable.
void Refresh ( PRBool blocking )
Refresh the remote datasource, re-loading its contents from the URI.
Arguments:
   blocking: If true, the call will block until the data source has completely reloaded. 

UAQ

Friday, September 22 - 29, 2006

(↑ top)

Friday, September 29 - October 6, 2006

(↑ top)

Friday, October 6 - 13, 2006

(↑ top)

Friday, October 13 - 20, 2006

(↑ top)

Friday, October 20 - 27, 2006

(↑ top)

Document Tags and Contributors

Contributors to this page: RichardChu, Mckwan, Nickolay, Ted_Mielczarek
Last updated by: RichardChu,