MozillaZine

Dev : Tips : Disable XUL cache

From MozillaZine Knowledge Base

(Difference between revisions)
Revision as of 20:18, 28 August 2005
Asqueella (Talk | contribs)
(Editing chrome.rdf)
<-- Previous diff
Revision as of 20:41, 28 August 2005
Asqueella (Talk | contribs)

Next diff -->
Line 1: Line 1:
{{extdev}} {{extdev}}
-'''nglayout.debug.disable_xul_cache''' is a preference useful for extension developers. Basically when it is set to '''false''' (which is default), Mozilla caches chrome XUL and JavaScript (and more) in a file named XUL.mfl or similarly. This means you have to restart Mozilla to test your changes to chrome files.+'''nglayout.debug.disable_xul_cache''' is a preference useful for extension developers. Basically when it is set to <code>false</code> (which is default), Mozilla caches chrome XUL and JavaScript (and more) in a file named XUL.mfl or similarly. This means you have to restart Mozilla to test your changes to chrome files.
-If you develop and extension you should disable the XUL cache by [[Editing configuration|setting]] this pref to '''true''', although it will make Mozilla slower at startup and when opening new windows.+If you develop and extension you should disable the XUL cache by [[Editing configuration|setting]] this pref to <code>true</code>, although it will make Mozilla slower at startup and when opening new windows.
==Getting rid of JARs== ==Getting rid of JARs==
-However even when '''nglayout.debug.disable_xul_cache''' is set to '''true''', Mozilla forbids rewriting *.jar files containing installed extensions. To overcome this and to avoid having to repackage after making any changes, you can do one of the following:+However even when <code>nglayout.debug.disable_xul_cache</code> is set to <code>true</code>, Mozilla forbids rewriting *.jar files containing installed extensions. To overcome this and to avoid having to repackage after making any changes, you can do one of the following:
* Use the [[Getting_started_with_extension_development#reg-em|new features of Firefox/Thunderbird 1.5's Extension Manager]] ('''recommended'''). * Use the [[Getting_started_with_extension_development#reg-em|new features of Firefox/Thunderbird 1.5's Extension Manager]] ('''recommended''').
* [[#Changing install.rdf|Package your extension to use plain directories]] instead of a single JAR before installing (you should use this if you have to develop using Firefox/Thunderbird 1.0 or older). * [[#Changing install.rdf|Package your extension to use plain directories]] instead of a single JAR before installing (you should use this if you have to develop using Firefox/Thunderbird 1.0 or older).
Line 44: Line 44:
==The overlay problem== ==The overlay problem==
 +<!-- This needs to be worded better and moved to a separate article -->
There is still another issue to be solved: a Javascript that's called from the overlay. There is still another issue to be solved: a Javascript that's called from the overlay.
The steps above help you test scripts that are not part of the overlay, like your settings dialog. But they can't help you test the overlay scripts because Firefox caches those. The steps above help you test scripts that are not part of the overlay, like your settings dialog. But they can't help you test the overlay scripts because Firefox caches those.

Revision as of 20:41, 28 August 2005

This page is part of the extension development documentation project.

Ask your questions in MozillaZine Forums. Also try browsing example code.

Note: development documentation is in process of being moved to Mozilla Development Center (MDC).

nglayout.debug.disable_xul_cache is a preference useful for extension developers. Basically when it is set to false (which is default), Mozilla caches chrome XUL and JavaScript (and more) in a file named XUL.mfl or similarly. This means you have to restart Mozilla to test your changes to chrome files.

If you develop and extension you should disable the XUL cache by setting this pref to true, although it will make Mozilla slower at startup and when opening new windows.

Contents

Getting rid of JARs

However even when nglayout.debug.disable_xul_cache is set to true, Mozilla forbids rewriting *.jar files containing installed extensions. To overcome this and to avoid having to repackage after making any changes, you can do one of the following:

The following sections provide detailed instructions

Changing install.rdf

Note: this tip is most useful for developing extensions in the Mozilla Suite or Firefox/Thunderbird 1.0 or older. If you develop for Firefox/Thunderbird 1.5 or if you are new to extension development, you really ought to consider using the new features of Extension Manager instead.

An easy way to make Firefox/Thunderbird read your extension's chrome files from a plain directory instead of a JAR file is to create and install an XPI that doesn't use a JAR file. There are a few differences from the regular packaging technique:

  • Put your chrome files in a directory instead of a JAR:
    Instead of putting your chrome files into myextension.xpi/chrome/myextension.jar you should put them into a directory called myextension.xpi/chrome/myextension/
  • Replace the following line in install.rdf:
    <Description about="urn:mozilla:extension:file:myextension.jar">
    with
    <Description about="urn:mozilla:extension:file:myextension">
  • Change the install.js:
    For Mozilla Suite there might be additional modifications in the install.js file necessary which reflect the install.rdf file changes which is replaced by the .js file.

An example of this technique is available. Also, myk is planning to update his tinderstatus extension to demonstrate this technique.

Please note, that it's recommended to package chrome files in a JAR when doing a public release - for better startup performance.

Editing chrome.rdf

Note: chrome.rdf is no longer used in Firefox/Thunderbird 1.5. Use the new features of Extension Manager instead.

We assume that the extension is installed in profile in this section.

Important: backup your profile before editing chrome.rdf!

First, unpack the JAR file you have, say [profile]\extensions\{YOUR-EXTENSION'S-GUID}\chrome\my-ext.jar to the same directory. You will get (at least) [profile]\extensions\{YOUR-EXTENSION'S-GUID}\chrome\content directory.

Second, modify the chrome.rdf: in [profile]\chrome\chrome.rdf look for my-ext.jar! and delete it. For example replace this line

c:baseURL="jar:file:///D:/Firefox/Profiles/default/extensions/{GUID}/chrome/my-ext.jar!/content/my-ext/"

with this:

c:baseURL="file:///D:/Firefox/Profiles/default/extensions/{GUID}/chrome/content/my-ext/"

Note, that you should also delete jar: at the beginning of the path.

The overlay problem

There is still another issue to be solved: a Javascript that's called from the overlay. The steps above help you test scripts that are not part of the overlay, like your settings dialog. But they can't help you test the overlay scripts because Firefox caches those.

The solution is to have the overlay script load its code from an external file, which is reloaded and re-evaluated constantly. Here's an example:

var TheExt = {

	//aFuncCall is a string to be evaluated as a function call
	inject : function (aFuncCall) {
                var codeFileName =  "injected.js";

		// Get profile directory
		var file = Components.classes["@mozilla.org/file/directory_service;1"].
		createInstance(Components.interfaces.nsIProperties).
		get("ProfD", Components.interfaces.nsIFile);

		// Get the file with the code
		file.append(codeFileName);
		if (!file.exists()) {
			dump ("Error: " + file.path + "does not exist.\n");
			return;
		}

		// Read the file into code
		var code = "";
		var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]
			.createInstance(Components.interfaces.nsIFileInputStream);
		var sstream = Components.classes["@mozilla.org/scriptableinputstream;1"]
			.createInstance(Components.interfaces.nsIScriptableInputStream);
		fstream.init(file, 1, 0, false);
		sstream.init(fstream);
		code += sstream.read(-1);
		sstream.close();
		fstream.close();
		
		// Run the code
		eval(code);	
		eval(aFuncCall);	
	},
	
	doAction : function() {
		this.inject("doAction()");
	}
}

dump ("Testing the extension.\n");
TheExt.doAction();

The file injected.js simply looks like this:

function doAction() {
	dump ("Action!\n")
}

You can add as many functions as you want. inject() evaluates all the functions in the file, but only executes the aFuncCall parameter.