ADD Extension Firefox pour lancer les divx (pas fini)
[pompage.git] / xpi / components / handleProtocol.js
1
2
3 // components defined in this file
4 const DIVXPROT_HANDLER_CONTRACTID = "@mozilla.org/network/protocol;1?name=divx";
5 const DIVXPROT_HANDLER_CID = Components.ID("{65aa548e-1dda-11dc-8314-0800200c9a66}");
6
7 // components used in this file
8 const NS_IOSERVICE_CID = "{9ac9e770-18bc-11d3-9337-00104ba0fd40}";
9 const NS_PREFSERVICE_CONTRACTID = "@mozilla.org/preferences-service;1";
10 const URI_CONTRACTID = "@mozilla.org/network/simple-uri;1";
11 const NS_WINDOWWATCHER_CONTRACTID = "@mozilla.org/embedcomp/window-watcher;1";
12 const STREAMIOCHANNEL_CONTRACTID = "@mozilla.org/network/stream-io-channel;1";
13 const kIOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
14
15 // interfaces used in this file
16 const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler;
17 const nsIURI = Components.interfaces.nsIURI;
18 const nsISupports = Components.interfaces.nsISupports;
19 const nsIIOService = Components.interfaces.nsIIOService;
20 const nsIPrefService = Components.interfaces.nsIPrefService;
21 const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
22 const nsIChannel = Components.interfaces.nsIChannel;
23
24
25 /***** ProtocolHandler *****/
26
27 function Ten70ProtocolHandler(scheme)
28 {
29 this.scheme = scheme;
30 }
31
32 // attribute defaults
33 Ten70ProtocolHandler.prototype.defaultPort = -1;
34 Ten70ProtocolHandler.prototype.protocolFlags = nsIProtocolHandler.URI_NORELATIVE;
35
36 Ten70ProtocolHandler.prototype.allowPort = function(aPort, aScheme)
37 {
38 return false;
39 }
40
41 Ten70ProtocolHandler.prototype.newURI = function(aSpec, aCharset, aBaseURI)
42 {
43 var uri = Components.classes[URI_CONTRACTID].createInstance(nsIURI);
44 uri.spec = aSpec;
45 return uri;
46 }
47
48 Ten70ProtocolHandler.prototype.newChannel = function(aURI)
49 {
50 var chemin = aURI.spec;
51
52 var root = "F:/Films/";
53 chemin = chemin.replace("divx://", root)
54
55 dump(chemin);
56
57 // create an nsILocalFile for the executable
58 var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
59 file.initWithPath("C:\\Program Files\\VideoLAN\\VLC\\vlc.exe");
60
61 // create an nsIProcess
62 var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
63 process.init(file);
64
65 // Run the process.
66 // If first param is true, calling thread will be blocked until
67 // called process terminates.
68 // Second and third params are used to pass command-line arguments
69 // to the process.
70 var args = [chemin, "-f"];
71 process.run(false, args, args.length);
72
73
74 var ios = Components.classes[kIOSERVICE_CONTRACTID].getService(nsIIOService);
75
76 return ios.newChannel("javascript:document.location='" + finalURL + "'", null, null);
77 }
78
79
80 /***** DIVXProtocolHandlerFactory *****/
81
82 function Ten70ProtocolHandlerFactory(scheme)
83 {
84 this.scheme = scheme;
85 }
86
87 Ten70ProtocolHandlerFactory.prototype.createInstance = function(outer, iid)
88 {
89 if(outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION;
90
91 if(!iid.equals(nsIProtocolHandler) && !iid.equals(nsISupports))
92 throw Components.results.NS_ERROR_INVALID_ARG;
93
94 return new Ten70ProtocolHandler(this.scheme);
95 }
96
97 var factory_divx = new Ten70ProtocolHandlerFactory("divx");
98
99 /***** DIVXModule *****/
100
101 var DIVXModule = new Object();
102
103 DIVXModule.registerSelf = function(compMgr, fileSpec, location, type)
104 {
105 compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
106
107 // register protocol handlers
108 compMgr.registerFactoryLocation(DIVXPROT_HANDLER_CID,
109 "DivX",
110 DIVXPROT_HANDLER_CONTRACTID,
111 fileSpec, location, type);
112 }
113
114 DIVXModule.unregisterSelf = function(compMgr, fileSpec, location)
115 {
116 compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
117
118 // unregister our components
119 compMgr.unregisterFactoryLocation(DIVXPROT_HANDLER_CID, fileSpec);
120 }
121
122 DIVXModule.getClassObject = function(compMgr, cid, iid)
123 {
124 if(!iid.equals(Components.interfaces.nsIFactory))
125 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
126
127 if(cid.equals(DIVXPROT_HANDLER_CID)) return factory_divx;
128
129 throw Components.results.NS_ERROR_NO_INTERFACE;
130 }
131
132 DIVXModule.canUnload = function(compMgr)
133 {
134 return true;
135 }
136
137 /***** Entrypoint *****/
138
139 function NSGetModule(compMgr, fileSpec)
140 {
141 return DIVXModule;
142 }