1 // Le composant définit pour cette extension
2 const DIVXPROT_HANDLER_CONTRACTID
= "@mozilla.org/network/protocol;1?name=divx";
3 const DIVXPROT_HANDLER_CID
= Components
.ID("{65aa548e-1dda-11dc-8314-0800200c9a66}");
5 // Les composants utilisés
6 const URI_CONTRACTID
= "@mozilla.org/network/simple-uri;1";
7 const kIOSERVICE_CONTRACTID
= "@mozilla.org/network/io-service;1";
9 // Les interfaces utilisées
10 const nsIProtocolHandler
= Components
.interfaces
.nsIProtocolHandler
;
11 const nsIURI
= Components
.interfaces
.nsIURI
;
12 const nsISupports
= Components
.interfaces
.nsISupports
;
13 const nsIIOService
= Components
.interfaces
.nsIIOService
;
17 * Classe ProtocolHandler.
19 function ProtocolHandler(scheme
)
24 // attributs par défaut
25 DivxProtocolHandler
.prototype.defaultPort
= -1;
26 DivxProtocolHandler
.prototype.protocolFlags
= nsIProtocolHandler
.URI_NORELATIVE
;
29 * est-ce qu'un port est autorisé.
31 DivxProtocolHandler
.prototype.allowPort = function(aPort
, aScheme
)
37 * Renvoie le nouvel URI.
39 DivxProtocolHandler
.prototype.newURI = function(aSpec
, aCharset
, aBaseURI
)
41 var uri
= Components
.classes
[URI_CONTRACTID
].createInstance(nsIURI
);
47 * Renvoie le nouveau channel.
49 DivxProtocolHandler
.prototype.newChannel = function(aURI
)
51 var chemin
= aURI
.spec
;
53 var root
= "F:/Films/";
54 chemin
= chemin
.replace("divx://", root
)
58 // crée un nouveau fichier
59 var file
= Components
.classes
["@mozilla.org/file/local;1"].createInstance(Components
.interfaces
.nsILocalFile
);
60 file
.initWithPath("C:\\Program Files\\VideoLAN\\VLC\\vlc.exe");
62 // crée un nouveau processus
63 var process
= Components
.classes
["@mozilla.org/process/util;1"].createInstance(Components
.interfaces
.nsIProcess
);
66 // lance le processus. false pour ne pas être blockant
67 var args
= [chemin
, "-f"];
68 process
.run(false, args
, args
.length
);
70 // trouver une méthode plus simple pour qu'il ne fasse rien..
71 var ios
= Components
.classes
[kIOSERVICE_CONTRACTID
].getService(nsIIOService
);
72 return ios
.newChannel("javascript:document.location='" + finalURL
+ "'", null, null);
76 * Classe DivxProtocolHandlerFactory.
78 function DivxProtocolHandlerFactory(scheme
)
84 * Méthode permettant la création d'objet de type 'DivxProtocolHandler'.
86 DivxProtocolHandlerFactory
.prototype.createInstance = function(outer
, iid
)
88 if(outer
!= null) throw Components
.results
.NS_ERROR_NO_AGGREGATION
;
90 if(!iid
.equals(nsIProtocolHandler
) && !iid
.equals(nsISupports
))
91 throw Components
.results
.NS_ERROR_INVALID_ARG
;
93 return new DivxProtocolHandler(this.scheme
);
97 var factory_divx
= new DivxProtocolHandlerFactory("divx");
102 var DIVXModule
= new Object();
105 * Appelé lors de l'enregistrement du module.
107 DIVXModule
.registerSelf = function(compMgr
, fileSpec
, location
, type
)
109 compMgr
= compMgr
.QueryInterface(Components
.interfaces
.nsIComponentRegistrar
);
111 // on enregistre le protocole handler
112 compMgr
.registerFactoryLocation(DIVXPROT_HANDLER_CID
,
114 DIVXPROT_HANDLER_CONTRACTID
,
115 fileSpec
, location
, type
);
119 * Appelé lors du déchargement du module.
121 DIVXModule
.unregisterSelf = function(compMgr
, fileSpec
, location
)
123 compMgr
= compMgr
.QueryInterface(Components
.interfaces
.nsIComponentRegistrar
);
125 // on dés-enregistre notre protocole handler
126 compMgr
.unregisterFactoryLocation(DIVXPROT_HANDLER_CID
, fileSpec
);
130 * Demande la factory pour construire le protocole handler.
132 DIVXModule
.getClassObject = function(compMgr
, cid
, iid
)
134 if(!iid
.equals(Components
.interfaces
.nsIFactory
))
135 throw Components
.results
.NS_ERROR_NOT_IMPLEMENTED
;
137 if(cid
.equals(DIVXPROT_HANDLER_CID
)) return factory_divx
;
139 throw Components
.results
.NS_ERROR_NO_INTERFACE
;
143 * Est-ce que le module peut être déchargé ?
145 DIVXModule
.canUnload = function(compMgr
)
151 * Le point d'entré, retourne le module.
153 function NSGetModule(compMgr
, fileSpec
)