home *** CD-ROM | disk | FTP | other *** search
- const EXTENSION_PATH = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newFileURI(__LOCATION__.parent.parent).spec;
- Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
- .getService(Components.interfaces.mozIJSSubScriptLoader)
- .loadSubScript(EXTENSION_PATH + "modules/xb/config.js");
-
- Cu.import(EXTENSION_PATH + "modules/xb/XPCOMUtilsEx.jsm");
-
- function XBProtocolHandler() {
- this._providers = {};
- this._observerService.addObserver(this, CommonConsts.APP_ACTION_QUIT_TOPIC, false);
- };
-
- XBProtocolHandler.prototype = {
- version: PLATFORM_VERSION,
- classDescription: "Custom Yandex.Bar protocol handler for XB-resources.",
- classID: PROTOCOL_XB_CLASS_ID,
- contractID: PROTOCOL_XB_CONTRACT_ID,
- QueryInterface: XPCOMUtilsEx.generateQI([Ci.nsIProtocolHandler, Ci.nsISupports, Ci.nsIObserver]),
-
- addDataProvider: function XBProtocolHandler_addDataProvider(aProvider) {
- this._providers[aProvider.providerId] = aProvider;
- },
-
- removeDataProvider: function XBProtocolHandler_removeDataProvider(aProvider) {
- delete this._providers[aProvider.providerId];
- },
-
- get wrappedJSObject() {
- return this;
- },
-
- observe: function XBProtocolHandler_observe(aSubject, aTopic, aData) {
- },
-
- get scheme() {
- return PROTOCOL_XB_SCHEME;
- },
-
- get protocolFlags() {
- return Ci.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD | Ci.nsIProtocolHandler.URI_NOAUTH;
- },
-
- get defaultPort() {
- return -1;
- },
-
- allowPort: function XBProtocolHandler_allowPort() {
- return false;
- },
-
- newURI: function XBProtocolHandler_newURI(aSpec, aOriginalCharset, aBaseURI) {
- var uri = new XBProtocolHandler.XBURI(aSpec, aOriginalCharset, aBaseURI);
- if (uri.host == "toolkit") {
- var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
- return ioService.newURI("chrome://" + APP_NAME + "/content/custombar/packages/toolkit" + uri.path, null, null);
- }
- return new XBProtocolHandler.XBURI(aSpec, aOriginalCharset, aBaseURI);
- },
-
- newChannel: function XBProtocolHandler_newChannel(aURI) {
- var uri = new XBProtocolHandler.XBURI(aURI.spec);
- var channel = null;
- var provider = this._providers[uri.provider];
- if (provider)
- channel = provider.newChannel(uri);
- if (!channel)
- throw Components.results.NS_ERROR_FAILURE;
- return channel;
- },
-
- _observerService: Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService),
-
- _destroy: function XBProtocolHandler__destroy() {
- this._observerService.removeObserver(this, CommonConsts.APP_ACTION_QUIT_TOPIC, false);
- this._providers = null;
- }
- };
-
- XBProtocolHandler.XBURI = function XBURI_constructor(aSpec, aOriginalCharset, aBaseURI) {
- if (aBaseURI)
- this.spec = aBaseURI.resolve(aSpec);
- else
- this.spec = aSpec;
-
- this._suppressRelativePathReference();
- this._construct();
- };
-
- XBProtocolHandler.XBURI.prototype = {
- get wrappedJSObject() {
- return this;
- },
-
- QueryInterface: XPCOMUtilsEx.generateQI([Ci.nsIURI, Ci.nsISupports]),
-
- get provider() {
- return this._provider;
- },
-
- get spec() {
- return this._spec;
- },
-
- set spec(aSpec) {
- this._spec = aSpec;
- this._parse();
- return this._spec;
- },
-
- prePath: "",
- scheme: PROTOCOL_XB_SCHEME,
- userPass: "",
- username: "",
- password: "",
- hostPort: "",
-
- get host() {
- return this._host;
- },
-
- set host(aHost) {
- this._host = aHost;
- this._construct();
- return this._host;
- },
-
- port: -1,
-
- get path() {
- return this._path;
- },
- set path(aPath) {
- this._path = aPath;
- this._suppressRelativePathReference();
- this._construct();
- return this._path;
- },
- get asciiSpec() {
- return this.spec;
- },
- get asciiHost() {
- return this.host;
- },
- get originCharset() {
- return "UTF-8";
- },
-
- clone: function() {
- return new XBProtocolHandler.XBURI(this.spec);
- },
-
- equals: function(aUri) {
- return aUri.spec == this.spec;
- },
-
- resolve: function(aRelativePath) {
- if (aRelativePath.indexOf(this.scheme + "://") == 0)
- return aRelativePath;
-
- if (aRelativePath.indexOf("//") == 0)
- return this.scheme + ":" + aRelativePath;
-
- if (aRelativePath[0] == "/")
- return this.scheme + '://' + this.host + aRelativePath;
-
- return this.scheme + '://' + this.host + this.path.replace(/[^\/]*$/, "") + aRelativePath;
- },
-
- schemeIs: function(aScheme) {
- aScheme = aScheme.toLowerCase();
- return aScheme == this.scheme || aScheme == "chrome";
- },
-
- _host: "",
- _path: "",
- _provider: "",
- _spec: "",
- _reSpec: /^(\w+)\:\/\/([^\/]*)(\/[^\?\;\#]*)(;(.*))?$/,
-
- _parse: function() {
- var components = this._spec.match(this._reSpec);
- if (!components || components[1] != this.scheme)
- throw Cr.NS_ERROR_MALFORMED_URI;
- this._host = components[2];
- this._path = components[3];
- this._suppressRelativePathReference();
- this._provider = components[2];
- },
-
- _construct: function() {
- this._spec = this.scheme + "://" + this.host + this.path;
- },
-
- _suppressRelativePathReference: function() {
- var path = this._path;
-
- var re = [
- /\/\//g,
- /\/\.\//g,
- /\/[^\/]+\/\.\.\//g,
- /\/\.\.\//g,
- ];
-
- for each (var expression in re)
- while (expression.test(path))
- path = path.replace(expression, "/");
-
- this._path = path;
- }
- };
-
- var components = [XBProtocolHandler];
-
- function NSGetModule(compMgr, fileSpec) {
- return XPCOMUtilsEx.generateModule(components);
- }
-