+
+
+// components defined in this file
+const DIVXPROT_HANDLER_CONTRACTID = "@mozilla.org/network/protocol;1?name=divx";
+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";\r
+
+// interfaces used in this file
+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)
+{
+ this.scheme = scheme;
+}
+
+// attribute defaults
+Ten70ProtocolHandler.prototype.defaultPort = -1;
+Ten70ProtocolHandler.prototype.protocolFlags = nsIProtocolHandler.URI_NORELATIVE;
+
+Ten70ProtocolHandler.prototype.allowPort = function(aPort, aScheme)
+{
+ return false;
+}
+
+Ten70ProtocolHandler.prototype.newURI = function(aSpec, aCharset, aBaseURI)
+{ \r
+ var uri = Components.classes[URI_CONTRACTID].createInstance(nsIURI);\r
+ uri.spec = aSpec;\r
+ return uri;
+}
+
+Ten70ProtocolHandler.prototype.newChannel = function(aURI)
+{\r
+ var chemin = aURI.spec;\r
+ \r
+ var root = "F:/Films/";\r
+ chemin = chemin.replace("divx://", root)\r
+ \r
+ dump(chemin);\r
+ \r
+ // create an nsILocalFile for the executable\r
+ var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);\r
+ file.initWithPath("C:\\Program Files\\VideoLAN\\VLC\\vlc.exe");\r
+\r
+ // create an nsIProcess\r
+ var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);\r
+ process.init(file);\r
+\r
+ // Run the process.\r
+ // If first param is true, calling thread will be blocked until\r
+ // called process terminates.\r
+ // Second and third params are used to pass command-line arguments\r
+ // to the process.\r
+ var args = [chemin, "-f"];\r
+ process.run(false, args, args.length);\r
+ \r
+ \r
+ var ios = Components.classes[kIOSERVICE_CONTRACTID].getService(nsIIOService);\r
+\r
+ return ios.newChannel("javascript:document.location='" + finalURL + "'", null, null);
+}
+
+
+/***** DIVXProtocolHandlerFactory *****/
+
+function Ten70ProtocolHandlerFactory(scheme)
+{
+ this.scheme = scheme;
+}
+
+Ten70ProtocolHandlerFactory.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 *****/
+
+var DIVXModule = new Object();
+
+DIVXModule.registerSelf = function(compMgr, fileSpec, location, type)
+{
+ compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+
+ // register protocol handlers
+ compMgr.registerFactoryLocation(DIVXPROT_HANDLER_CID,
+ "DivX",
+ DIVXPROT_HANDLER_CONTRACTID,
+ fileSpec, location, type);
+}
+
+DIVXModule.unregisterSelf = function(compMgr, fileSpec, location)
+{
+ compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+
+ // unregister our components
+ compMgr.unregisterFactoryLocation(DIVXPROT_HANDLER_CID, fileSpec);
+}
+
+DIVXModule.getClassObject = function(compMgr, cid, iid)
+{
+ if(!iid.equals(Components.interfaces.nsIFactory))
+ throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+
+ if(cid.equals(DIVXPROT_HANDLER_CID)) return factory_divx;
+
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+}
+
+DIVXModule.canUnload = function(compMgr)
+{
+ return true;
+}
+
+/***** Entrypoint *****/
+
+function NSGetModule(compMgr, fileSpec)
+{
+ return DIVXModule;
+}