1 // -*- coding: utf-8 -*-
2 // vi:si:et:sw=2:sts=2:ts=2
4 TribeProtocolHandler - Torrent video for <video>
6 Written by Jan Gerber, Riccardo Petrocco
7 see LICENSE.txt for license information
10 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
12 const Cc = Components.classes;
13 const Ci = Components.interfaces;
15 var tribeLoggingEnabled = false;
18 if (tribeLoggingEnabled)
20 aMsg = ("*** Tribe : " + aMsg);
21 Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(aMsg);
27 function TribeProtocol() {
28 this.prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).QueryInterface(Ci.nsIPrefService);
30 tribeLoggingEnabled = this.prefService.getBoolPref("tribe.logging.enabled");
35 TribeProtocol.prototype =
37 classDescription: "Tribe protocol",
38 classID: Components.ID("bcb8d306-66cf-4358-8473-807981ffe365"),
39 contractID: "@mozilla.org/network/protocol;1?name=tribe",
40 QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler,
42 _xpcom_factory : TribeProtocolFactory,
45 protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE |
46 Ci.nsIProtocolHandler.URI_NOAUTH |
47 Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,
49 allowPort: function(port, scheme)
54 newURI: function(spec, charset, baseURI)
56 var uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
61 newChannel: function(input_uri)
63 // aURI is a nsIUri, so get a string from it using .spec
64 var key = input_uri.spec;
66 // strip away the kSCHEME: part
67 var torrent_url = key.substring(key.indexOf("://") + 3, key.length);
68 // the URL will not be encoded since we will not be able to decode it afterwards
69 //torrent_url = encodeURI(torrent_url);
70 LOG('\nopening: '+torrent_url+'\n');
72 var channel = Cc["@p2pnext.org/tribe/channel;1"].createInstance(Ci.tribeIChannel);
73 channel.setTorrentUrl(torrent_url);
79 var TribeProtocolFactory =
81 createInstance: function (outer, iid)
84 throw Components.results.NS_ERROR_NO_AGGREGATION;
86 if (!iid.equals(Ci.nsIProtocolHandler) &&
87 !iid.equals(Ci.nsISupports) )
88 throw Components.results.NS_ERROR_NO_INTERFACE;
90 return (new TribeProtocol()).QueryInterface(iid);
94 function NSGetModule(compMgr, fileSpec) {
95 return XPCOMUtils.generateModule([TribeProtocol]);