home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / AIMP2 / aimp_2.61.583.exe / $TEMP / YandexPackSetup.msi / fil430F182886DFD9DBB49CDE67B94F10B9 < prev    next >
Text File  |  2010-07-12  |  4KB  |  105 lines

  1. const EXTENSION_PATH = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newFileURI(__LOCATION__.parent.parent).spec;
  2. Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
  3.                    .getService(Components.interfaces.mozIJSSubScriptLoader)
  4.                    .loadSubScript(EXTENSION_PATH + "modules/xb/config.js");
  5.  
  6. function CustomBarProtocol() {
  7.     this._providers = [];
  8.     this._observerService.addObserver(this, CommonConsts.APP_ACTION_QUIT_TOPIC, false);
  9. };
  10.  
  11. CustomBarProtocol.prototype = {
  12.     addDataProvider: function CBPH_addDataProvider(aProvider) {
  13.         if (this._providers.some(function(handler) { return aProvider === handler; }))
  14.             return;
  15.         
  16.         this._providers.push(aProvider);
  17.     },
  18.     
  19.     removeDataProvider: function CBPH_removeDataProvider(aProvider) {
  20.         this._providers = this._providers.filter(function(handler) { return aProvider !== handler; });
  21.     },
  22.     
  23.     get wrappedJSObject() {
  24.         return this;
  25.     },
  26.     
  27.     observe: function CBPH_observe(aSubject, aTopic, aData) {
  28.         switch (aTopic) {
  29.             case CommonConsts.APP_ACTION_QUIT_TOPIC:
  30.                 this._destroy();
  31.                 break;
  32.         }
  33.     },
  34.     
  35.     get scheme() {
  36.         return this._scheme;
  37.     },
  38.     
  39.     get protocolFlags() {
  40.         return Ci.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD;
  41.     },
  42.     
  43.     get defaultPort() {
  44.         return -1;
  45.     },
  46.     
  47.     allowPort: function CBPH_allowPort(port, scheme) {
  48.         return false;
  49.     },
  50.     
  51.     newURI: function CBPH_newURI(aSpec, aOriginalCharset, baseURI) {
  52.         let uri = this._handleNewURI(aSpec, aOriginalCharset, baseURI);
  53.         
  54.         if (!uri)
  55.             throw Cr.NS_ERROR_MALFORMED_URI;
  56.         
  57.         return uri;
  58.     },
  59.     
  60.     newChannel: function CBPH_newChannel(aURI) {
  61.         var channel = this._ioService.newChannel("data:,", null, null);
  62.         channel.originalURI = aURI;
  63.         return channel;
  64.     },
  65.     
  66.     _scheme: PROTOCOL_APP_SCHEME,
  67.     _ioService: Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService),
  68.     _observerService: Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService),
  69.     
  70.     _handleNewURI: function CBPH__handleNewURI(aSpec, aOriginalCharset, aBaseURI) {
  71.         let uri = null;
  72.         let spec = aSpec.replace(this.scheme + ":", "");
  73.         
  74.         this._providers.some(function(aProvider) {
  75.             return (null !== (uri = aProvider.newURI(spec, aOriginalCharset, aBaseURI)));
  76.         });
  77.         
  78.         if (uri && typeof uri == "string")
  79.             uri = this._ioService.newURI(uri, aOriginalCharset, aBaseURI);
  80.         
  81.         return uri;
  82.     },
  83.     
  84.     _destroy: function CBPH__destroy() {
  85.         this._observerService.removeObserver(this, CommonConsts.APP_ACTION_QUIT_TOPIC, false);
  86.         this._providers.forEach(function(aProvider) aProvider.clear());
  87.         this._providers = null;
  88.     },
  89.     
  90.     classDescription: "Custom Yandex bar protocol handler JS component for " + APP_NAME,
  91.     classID: PROTOCOL_APP_CLASS_ID,
  92.     contractID: PROTOCOL_APP_CONTRACT_ID,
  93.     QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
  94.     
  95.     _xpcom_categories: [{
  96.         category: "app-startup",
  97.         service: true
  98.     }]
  99. };
  100.  
  101. var components = [CustomBarProtocol];
  102.  
  103. function NSGetModule(compMgr, fileSpec) {
  104.     return XPCOMUtils.generateModule(components);
  105. }