Hello,
I am trying to use the autoconfig feature of Mozilla to register new MIME handlers at browser *startup*.
To avoid duplicating code, I am using the logic from "chrome://communicator/content/pref/overrideHandler.js", the one used by the preferences panel dealing with helper applications.
However, as there's no 'include' or 'import' feature in JavaScript, I have to fetch the file and then eval() the code.
I also took the glue code from "http://lxr.mozilla.org/seamonkey/source/xpfe/components/prefwindow/resources/content/pref-applications-new.js#106" onwards.
I can successfully create a HandlerOverride object, but any call on the setter/getter of this class fails (silently unfortunately). Where could this come from ?
What is strange is that this process works in a <script> included in an HTML page (though it needs XPConnect privileges).
I know this is a (bad) trick, but as "http://bugzilla.mozilla.org/show_bug.cgi?id=190413" isn't implemented, I have no choice.
Follows my code :
//////
function readFile(path)
{
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var channel = ioService.newChannel(path, null, null);
var inputStream = channel.open();
var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"]
.createInstance(Components.interfaces.nsIScriptableInputStream); sInputStream.init(inputStream); return sInputStream.read(sInputStream.available()); }
var gDS = null; function addMIMEHandler(mime, extension, description, application) { var gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"] .getService(Components.interfaces.nsIRDFService);
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var file = fileLocator.get("UMimTyp", Components.interfaces.nsIFile);var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
gDS = gRDF.GetDataSource(fileHandler.getURLSpecFromFile(file));
var js_data = readFile("chrome://communicator/content/pref/overrideHandler.js");
eval(js_data);
// works, a 'for ( i in handler )' sees its methods var handler = new HandlerOverride(MIME_URI(mime));
// it works, because mUpdateMode isn't accessed through a setter (?) handler.mUpdateMode = true;
handler.mimeType = mime; // !!! stops/fails here !!! handler.description = description; handler.addExtension(extension); handler.appPath = application;
handler.isEditable = true; handler.saveToDisk = false; handler.handleInternal = false; handler.alwaysAsk = false; handler.appDisplayName = application.split(/[\/\\]/).pop();
handler.buildLinks();
gDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush(); }
Cheers,
-- Damiano
_______________________________________________ Mozilla-xpcom mailing list [EMAIL PROTECTED] http://mail.mozilla.org/listinfo/mozilla-xpcom
