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}");
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";
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
;
25 /***** ProtocolHandler *****/
27 function Ten70ProtocolHandler(scheme
)
33 Ten70ProtocolHandler
.prototype.defaultPort
= -1;
34 Ten70ProtocolHandler
.prototype.protocolFlags
= nsIProtocolHandler
.URI_NORELATIVE
;
36 Ten70ProtocolHandler
.prototype.allowPort = function(aPort
, aScheme
)
41 Ten70ProtocolHandler
.prototype.newURI = function(aSpec
, aCharset
, aBaseURI
)
43 var uri
= Components
.classes
[URI_CONTRACTID
].createInstance(nsIURI
);
48 Ten70ProtocolHandler
.prototype.newChannel = function(aURI
)
50 var chemin
= aURI
.spec
;
52 var root
= "F:/Films/";
53 chemin
= chemin
.replace("divx://", root
)
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");
61 // create an nsIProcess
62 var process
= Components
.classes
["@mozilla.org/process/util;1"].createInstance(Components
.interfaces
.nsIProcess
);
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
70 var args
= [chemin
, "-f"];
71 process
.run(false, args
, args
.length
);
74 var ios
= Components
.classes
[kIOSERVICE_CONTRACTID
].getService(nsIIOService
);
76 return ios
.newChannel("javascript:document.location='" + finalURL
+ "'", null, null);
80 /***** DIVXProtocolHandlerFactory *****/
82 function Ten70ProtocolHandlerFactory(scheme
)
87 Ten70ProtocolHandlerFactory
.prototype.createInstance = function(outer
, iid
)
89 if(outer
!= null) throw Components
.results
.NS_ERROR_NO_AGGREGATION
;
91 if(!iid
.equals(nsIProtocolHandler
) && !iid
.equals(nsISupports
))
92 throw Components
.results
.NS_ERROR_INVALID_ARG
;
94 return new Ten70ProtocolHandler(this.scheme
);
97 var factory_divx
= new Ten70ProtocolHandlerFactory("divx");
99 /***** DIVXModule *****/
101 var DIVXModule
= new Object();
103 DIVXModule
.registerSelf = function(compMgr
, fileSpec
, location
, type
)
105 compMgr
= compMgr
.QueryInterface(Components
.interfaces
.nsIComponentRegistrar
);
107 // register protocol handlers
108 compMgr
.registerFactoryLocation(DIVXPROT_HANDLER_CID
,
110 DIVXPROT_HANDLER_CONTRACTID
,
111 fileSpec
, location
, type
);
114 DIVXModule
.unregisterSelf = function(compMgr
, fileSpec
, location
)
116 compMgr
= compMgr
.QueryInterface(Components
.interfaces
.nsIComponentRegistrar
);
118 // unregister our components
119 compMgr
.unregisterFactoryLocation(DIVXPROT_HANDLER_CID
, fileSpec
);
122 DIVXModule
.getClassObject = function(compMgr
, cid
, iid
)
124 if(!iid
.equals(Components
.interfaces
.nsIFactory
))
125 throw Components
.results
.NS_ERROR_NOT_IMPLEMENTED
;
127 if(cid
.equals(DIVXPROT_HANDLER_CID
)) return factory_divx
;
129 throw Components
.results
.NS_ERROR_NO_INTERFACE
;
132 DIVXModule
.canUnload = function(compMgr
)
137 /***** Entrypoint *****/
139 function NSGetModule(compMgr
, fileSpec
)