From 4917f98d6954fcb2e68178d4a2e635c887ac7960 Mon Sep 17 00:00:00 2001 From: pifou Date: Tue, 19 Jun 2007 15:34:54 +0000 Subject: [PATCH] MOD Nettoyage du fichier js de l'extension firefox. git-svn-id: svn://euphorik.ch/pompage@27 02bbb61a-6d21-0410-aba0-cb053bdfd66a --- xpi/components/handleProtocol.js | 148 +++++++++++++++++-------------- 1 file changed, 81 insertions(+), 67 deletions(-) diff --git a/xpi/components/handleProtocol.js b/xpi/components/handleProtocol.js index 30db1f1..96562cc 100644 --- a/xpi/components/handleProtocol.js +++ b/xpi/components/handleProtocol.js @@ -1,141 +1,155 @@ - - -// components defined in this file +// Le composant définit pour cette extension const DIVXPROT_HANDLER_CONTRACTID = "@mozilla.org/network/protocol;1?name=divx"; -const DIVXPROT_HANDLER_CID = Components.ID("{65aa548e-1dda-11dc-8314-0800200c9a66}"); +const DIVXPROT_HANDLER_CID = Components.ID("{65aa548e-1dda-11dc-8314-0800200c9a66}"); -// components used in this file -const NS_IOSERVICE_CID = "{9ac9e770-18bc-11d3-9337-00104ba0fd40}"; -const NS_PREFSERVICE_CONTRACTID = "@mozilla.org/preferences-service;1"; -const URI_CONTRACTID = "@mozilla.org/network/simple-uri;1"; -const NS_WINDOWWATCHER_CONTRACTID = "@mozilla.org/embedcomp/window-watcher;1"; -const STREAMIOCHANNEL_CONTRACTID = "@mozilla.org/network/stream-io-channel;1"; -const kIOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1"; +// Les composants utilisés +const URI_CONTRACTID = "@mozilla.org/network/simple-uri;1"; +const kIOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1"; -// interfaces used in this file +// Les interfaces utilisées const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler; const nsIURI = Components.interfaces.nsIURI; const nsISupports = Components.interfaces.nsISupports; const nsIIOService = Components.interfaces.nsIIOService; -const nsIPrefService = Components.interfaces.nsIPrefService; -const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher; -const nsIChannel = Components.interfaces.nsIChannel; - -/***** ProtocolHandler *****/ -function Ten70ProtocolHandler(scheme) +/** + * Classe ProtocolHandler. + */ +function ProtocolHandler(scheme) { this.scheme = scheme; } -// attribute defaults -Ten70ProtocolHandler.prototype.defaultPort = -1; -Ten70ProtocolHandler.prototype.protocolFlags = nsIProtocolHandler.URI_NORELATIVE; - -Ten70ProtocolHandler.prototype.allowPort = function(aPort, aScheme) +// attributs par défaut +DivxProtocolHandler.prototype.defaultPort = -1; +DivxProtocolHandler.prototype.protocolFlags = nsIProtocolHandler.URI_NORELATIVE; + +/** + * est-ce qu'un port est autorisé. + */ +DivxProtocolHandler.prototype.allowPort = function(aPort, aScheme) { return false; } - -Ten70ProtocolHandler.prototype.newURI = function(aSpec, aCharset, aBaseURI) + +/** + * Renvoie le nouvel URI. + */ +DivxProtocolHandler.prototype.newURI = function(aSpec, aCharset, aBaseURI) { var uri = Components.classes[URI_CONTRACTID].createInstance(nsIURI); uri.spec = aSpec; return uri; -} - -Ten70ProtocolHandler.prototype.newChannel = function(aURI) +} + +/** + * Renvoie le nouveau channel. + */ +DivxProtocolHandler.prototype.newChannel = function(aURI) { var chemin = aURI.spec; var root = "F:/Films/"; chemin = chemin.replace("divx://", root) - dump(chemin); - - // create an nsILocalFile for the executable + //dump(chemin); + + // crée un nouveau fichier var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath("C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"); - // create an nsIProcess + // crée un nouveau processus var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess); process.init(file); - // Run the process. - // If first param is true, calling thread will be blocked until - // called process terminates. - // Second and third params are used to pass command-line arguments - // to the process. + // lance le processus. false pour ne pas être blockant var args = [chemin, "-f"]; process.run(false, args, args.length); - - + + // trouver une méthode plus simple pour qu'il ne fasse rien.. var ios = Components.classes[kIOSERVICE_CONTRACTID].getService(nsIIOService); - return ios.newChannel("javascript:document.location='" + finalURL + "'", null, null); } - - -/***** DIVXProtocolHandlerFactory *****/ - -function Ten70ProtocolHandlerFactory(scheme) + +/** + * Classe DivxProtocolHandlerFactory. + */ +function DivxProtocolHandlerFactory(scheme) { this.scheme = scheme; -} - -Ten70ProtocolHandlerFactory.prototype.createInstance = function(outer, iid) +} + +/** + * Méthode permettant la création d'objet de type 'DivxProtocolHandler'. + */ +DivxProtocolHandlerFactory.prototype.createInstance = function(outer, iid) { if(outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION; if(!iid.equals(nsIProtocolHandler) && !iid.equals(nsISupports)) throw Components.results.NS_ERROR_INVALID_ARG; - return new Ten70ProtocolHandler(this.scheme); -} - -var factory_divx = new Ten70ProtocolHandlerFactory("divx"); - -/***** DIVXModule *****/ + return new DivxProtocolHandler(this.scheme); +} + +// la factory +var factory_divx = new DivxProtocolHandlerFactory("divx"); +/** + * Notre module. + */ var DIVXModule = new Object(); - + +/** + * Appelé lors de l'enregistrement du module. + */ DIVXModule.registerSelf = function(compMgr, fileSpec, location, type) { compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - // register protocol handlers + // on enregistre le protocole handler compMgr.registerFactoryLocation(DIVXPROT_HANDLER_CID, - "DivX", + "divx", DIVXPROT_HANDLER_CONTRACTID, fileSpec, location, type); } - + +/** + * Appelé lors du déchargement du module. + */ DIVXModule.unregisterSelf = function(compMgr, fileSpec, location) { compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - // unregister our components + // on dés-enregistre notre protocole handler compMgr.unregisterFactoryLocation(DIVXPROT_HANDLER_CID, fileSpec); } - + +/** + * Demande la factory pour construire le protocole handler. + */ DIVXModule.getClassObject = function(compMgr, cid, iid) { - if(!iid.equals(Components.interfaces.nsIFactory)) - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; + if(!iid.equals(Components.interfaces.nsIFactory)) + throw Components.results.NS_ERROR_NOT_IMPLEMENTED; - if(cid.equals(DIVXPROT_HANDLER_CID)) return factory_divx; + if(cid.equals(DIVXPROT_HANDLER_CID)) return factory_divx; - throw Components.results.NS_ERROR_NO_INTERFACE; + throw Components.results.NS_ERROR_NO_INTERFACE; } - + +/** + * Est-ce que le module peut être déchargé ? + */ DIVXModule.canUnload = function(compMgr) { return true; } -/***** Entrypoint *****/ - +/** + * Le point d'entré, retourne le module. + */ function NSGetModule(compMgr, fileSpec) { return DIVXModule; -- 2.45.2