home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / firefox / components / WebContentConverter.js < prev    next >
Encoding:
Text File  |  2006-08-18  |  22.8 KB  |  757 lines

  1. //@line 37 "/build/buildd/firefox-1.99+2.0b1+dfsg/browser/components/feeds/src/WebContentConverter.js"
  2.  
  3. const Cc = Components.classes;
  4. const Ci = Components.interfaces;
  5. const Cr = Components.results;
  6.  
  7. function LOG(str) {
  8.   dump("*** " + str + "\n");
  9. }
  10.  
  11. const WCCR_CONTRACTID = "@mozilla.org/embeddor.implemented/web-content-handler-registrar;1";
  12. const WCCR_CLASSID = Components.ID("{792a7e82-06a0-437c-af63-b2d12e808acc}");
  13. const WCCR_CLASSNAME = "Web Content Handler Registrar";
  14.  
  15. const WCC_CLASSID = Components.ID("{db7ebf28-cc40-415f-8a51-1b111851df1e}");
  16. const WCC_CLASSNAME = "Web Service Handler";
  17.  
  18. const TYPE_MAYBE_FEED = "application/vnd.mozilla.maybe.feed";
  19. const TYPE_ANY = "*/*";
  20.  
  21. const PREF_CONTENTHANDLERS_AUTO = "browser.contentHandlers.auto.";
  22. const PREF_CONTENTHANDLERS_BRANCH = "browser.contentHandlers.types.";
  23. const PREF_SELECTED_WEB = "browser.feeds.handlers.webservice";
  24. const PREF_SELECTED_HANDLER = "browser.feeds.handler";
  25.  
  26. function WebContentConverter() {
  27. }
  28. WebContentConverter.prototype = {
  29.   convert: function WCC_convert() { },
  30.   asyncConvertData: function WCC_asyncConvertData() { },
  31.   onDataAvailable: function WCC_onDataAvailable() { },
  32.   onStopRequest: function WCC_onStopRequest() { },
  33.   
  34.   onStartRequest: function WCC_onStartRequest(request, context) {
  35.     var wccr = 
  36.         Cc[WCCR_CONTRACTID].
  37.         getService(Ci.nsIWebContentConverterService);
  38.     wccr.loadPreferredHandler(request);
  39.   },
  40.   
  41.   QueryInterface: function WCC_QueryInterface(iid) {
  42.     if (iid.equals(Ci.nsIStreamConverter) ||
  43.         iid.equals(Ci.nsIStreamListener) ||
  44.         iid.equals(Ci.nsISupports))
  45.       return this;
  46.     throw Cr.NS_ERROR_NO_INTERFACE;
  47.   }
  48. };
  49.  
  50. var WebContentConverterFactory = {
  51.   createInstance: function WCCF_createInstance(outer, iid) {
  52.     if (outer != null)
  53.       throw Cr.NS_ERROR_NO_AGGREGATION;
  54.     return new WebContentConverter().QueryInterface(iid);
  55.   },
  56.     
  57.   QueryInterface: function WCC_QueryInterface(iid) {
  58.     if (iid.equals(Ci.nsIFactory) ||
  59.         iid.equals(Ci.nsISupports))
  60.       return this;
  61.     throw Cr.NS_ERROR_NO_INTERFACE;
  62.   }
  63. };
  64.  
  65. function ServiceInfo(contentType, uri, name) {
  66.   this._contentType = contentType;
  67.   this._uri = uri;
  68.   this._name = name;
  69. }
  70. ServiceInfo.prototype = {
  71.   /**
  72.    * See nsIWebContentHandlerInfo
  73.    */
  74.   get contentType() {
  75.     return this._contentType;
  76.   },
  77.  
  78.   /**
  79.    * See nsIWebContentHandlerInfo
  80.    */
  81.   get uri() {
  82.     return this._uri;
  83.   },
  84.  
  85.   /**
  86.    * See nsIWebContentHandlerInfo
  87.    */
  88.   get name() {
  89.     return this._name;
  90.   },
  91.   
  92.   /**
  93.    * See nsIWebContentHandlerInfo
  94.    */
  95.   getHandlerURI: function SI_getHandlerURI(uri) {
  96.     return this._uri.replace(/%s/gi, encodeURIComponent(uri));
  97.   },
  98.   
  99.   /**
  100.    * See nsIWebContentHandlerInfo
  101.    */
  102.   equals: function SI_equals(other) {
  103.     return this.contentType == other.contentType &&
  104.            this.uri == other.uri;
  105.   },
  106.   
  107.   QueryInterface: function SI_QueryInterface(iid) {
  108.     if (iid.equals(Ci.nsIWebContentHandlerInfo) ||
  109.         iid.equals(Ci.nsISupports))
  110.       return this;
  111.     throw Cr.NS_ERROR_NO_INTERFACE;
  112.   }
  113. };
  114.  
  115. var WebContentConverterRegistrar = {
  116.   _contentTypes: { },
  117.   _protocols: { },
  118.   
  119.   /**
  120.    * Track auto handlers for various content types using a content-type to 
  121.    * handler map.
  122.    */
  123.   _autoHandleContentTypes: { },
  124.  
  125.   /**
  126.    * See nsIWebContentConverterService
  127.    */
  128.   getAutoHandler: 
  129.   function WCCR_getAutoHandler(contentType) {
  130.     contentType = this._resolveContentType(contentType);
  131.     if (contentType in this._autoHandleContentTypes)
  132.       return this._autoHandleContentTypes[contentType];
  133.     return null;
  134.   },
  135.   
  136.   /**
  137.    * See nsIWebContentConverterService
  138.    */
  139.   setAutoHandler:
  140.   function WCCR_setAutoHandler(contentType, handler) {
  141.     if (handler && !this._typeIsRegistered(contentType, handler.uri))
  142.       throw Cr.NS_ERROR_NOT_AVAILABLE;
  143.       
  144.     contentType = this._resolveContentType(contentType);
  145.     this._setAutoHandler(contentType, handler);
  146.     
  147.     var ps = 
  148.         Cc["@mozilla.org/preferences-service;1"].
  149.         getService(Ci.nsIPrefService);
  150.     var autoBranch = ps.getBranch(PREF_CONTENTHANDLERS_AUTO);
  151.     if (handler)
  152.       autoBranch.setCharPref(contentType, handler.uri);
  153.     else if (autoBranch.prefHasUserValue(contentType))
  154.       autoBranch.clearUserPref(contentType);
  155.      
  156.     ps.savePrefFile(null);
  157.   },
  158.   
  159.   /**
  160.    * Update the internal data structure (not persistent)
  161.    */
  162.   _setAutoHandler:
  163.   function WCCR__setAutoHandler(contentType, handler) {
  164.     if (handler) 
  165.       this._autoHandleContentTypes[contentType] = handler;
  166.     else if (contentType in this._autoHandleContentTypes)
  167.       delete this._autoHandleContentTypes[contentType];
  168.   },
  169.   
  170.   /**
  171.    * See nsIWebContentConverterService
  172.    */
  173.   getWebContentHandlerByURI:
  174.   function WCCR_getWebContentHandlerByURI(contentType, uri) {
  175.     var handlers = this.getContentHandlers(contentType, { });
  176.     for (var i = 0; i < handlers.length; ++i) {
  177.       if (handlers[i].uri == uri) 
  178.         return handlers[i];
  179.     }
  180.     return null;
  181.   },
  182.   
  183.   /**
  184.    * See nsIWebContentConverterService
  185.    */
  186.   loadPreferredHandler: 
  187.   function WCCR_loadPreferredHandler(request) {
  188.     var channel = request.QueryInterface(Ci.nsIChannel);
  189.     var contentType = this._resolveContentType(channel.contentType);
  190.     var handler = this.getAutoHandler(contentType);
  191.     if (handler) {
  192.       request.cancel(Cr.NS_ERROR_FAILURE);
  193.       
  194.       var webNavigation = 
  195.           channel.notificationCallbacks.getInterface(Ci.nsIWebNavigation);
  196.       webNavigation.loadURI(handler.getHandlerURI(channel.URI.spec), 
  197.                             Ci.nsIWebNavigation.LOAD_FLAGS_NONE, 
  198.                             null, null, null);
  199.     }      
  200.   },
  201.   
  202.   /**
  203.    * See nsIWebContentConverterService
  204.    */
  205.   removeProtocolHandler: 
  206.   function WCCR_removeProtocolHandler(protocol, uri) {
  207.     function notURI(currentURI) {
  208.       return currentURI != uri;
  209.     }
  210.   
  211.     if (protocol in this._protocols) 
  212.       this._protocols[protocol] = this._protocols[protocol].filter(notURI);
  213.   },
  214.   
  215.   /**
  216.    * See nsIWebContentConverterService
  217.    */
  218.   removeContentHandler: 
  219.   function WCCR_removeContentHandler(contentType, uri) {
  220.     function notURI(serviceInfo) {
  221.       return serviceInfo.uri != uri;
  222.     }
  223.   
  224.     if (contentType in this._contentTypes) {
  225.       this._contentTypes[contentType] = 
  226.         this._contentTypes[contentType].filter(notURI);
  227.     }
  228.   },
  229.   
  230.   /**
  231.    *
  232.    */
  233.   _mappings: { 
  234.     "application/rss+xml": TYPE_MAYBE_FEED,
  235.     "application/atom+xml": TYPE_MAYBE_FEED,
  236.   },
  237.   
  238.   /**
  239.    * These are types for which there is a separate content converter aside 
  240.    * from our built in generic one. We should not automatically register
  241.    * a factory for creating a converter for these types.
  242.    */
  243.   _blockedTypes: {
  244.     "application/vnd.mozilla.maybe.feed": true,
  245.   },
  246.   
  247.   /**
  248.    * Determines the "internal" content type based on the _mappings.
  249.    * @param   contentType
  250.    * @returns The resolved contentType value. 
  251.    */
  252.   _resolveContentType: 
  253.   function WCCR__resolveContentType(contentType) {
  254.     if (contentType in this._mappings)
  255.       return this._mappings[contentType];
  256.     return contentType;
  257.   },
  258.   
  259.   _wrapString: function WCCR__wrapString(string) {
  260.     var supportsString = 
  261.         Cc["@mozilla.org/supports-string;1"].
  262.         createInstance(Ci.nsISupportsString);
  263.     supportsString.data = string;
  264.     return supportsString;
  265.   },
  266.   
  267.   _updateDefaultReader: function WCCR__updateDefaultReader(uri) {
  268.     var ps = 
  269.         Cc["@mozilla.org/preferences-service;1"].
  270.         getService(Ci.nsIPrefBranch);
  271.     var localizedString = 
  272.         Cc["@mozilla.org/pref-localizedstring;1"].
  273.         createInstance(Ci.nsIPrefLocalizedString);
  274.     localizedString.data = uri;
  275.     ps.setComplexValue(PREF_SELECTED_WEB, Ci.nsIPrefLocalizedString, 
  276.                        localizedString);
  277.     
  278.     var needToUpdateHandler = true;
  279.     try {
  280.       needToUpdateHandler = ps.getCharPref(PREF_SELECTED_HANDLER) != "web";
  281.     }
  282.     catch (e) {
  283.     }
  284.     if (needToUpdateHandler)
  285.       ps.setCharPref(PREF_SELECTED_HANDLER, "web");
  286.   },
  287.   
  288.   _confirmAddHandler: function WCCR__confirmAddHandler(contentType, title, uri) {
  289.     var args =
  290.         Cc["@mozilla.org/supports-array;1"].
  291.         createInstance(Ci.nsISupportsArray);
  292.     
  293.     var paramBlock = 
  294.         Cc["@mozilla.org/embedcomp/dialogparam;1"].
  295.         createInstance(Ci.nsIDialogParamBlock);
  296.     // Used to tell the WCCR that the user chose to add the handler (rather 
  297.     // than canceling) and whether or not they made it their default handler.
  298.     const PARAM_SHOULD_ADD_HANDLER = 0;
  299.     const PARAM_SHOULD_MAKE_DEFAULT = 1;
  300.     paramBlock.SetInt(PARAM_SHOULD_ADD_HANDLER, 0);
  301.     paramBlock.SetInt(PARAM_SHOULD_MAKE_DEFAULT, 0);
  302.     args.AppendElement(paramBlock);
  303.     args.AppendElement(this._wrapString(uri));
  304.     args.AppendElement(this._wrapString(title));
  305.     args.AppendElement(this._wrapString(contentType));
  306.     
  307.     var typeType = 
  308.         Cc["@mozilla.org/supports-PRInt32;1"].
  309.         createInstance(Ci.nsISupportsPRInt32);
  310.     typeType.data = 1;
  311.     args.AppendElement(typeType);
  312.     
  313.     var ww = 
  314.         Cc["@mozilla.org/embedcomp/window-watcher;1"].
  315.         getService(Ci.nsIWindowWatcher);
  316.     ww.openWindow(null, "chrome://browser/content/feeds/addFeedReader.xul", 
  317.                   "", "modal,titlebar,centerscreen,dialog=yes", args);
  318.     
  319.     var shouldAdd = paramBlock.GetInt(PARAM_SHOULD_ADD_HANDLER) == 1;
  320.     if (shouldAdd&& contentType == TYPE_MAYBE_FEED && 
  321.         paramBlock.GetInt(PARAM_SHOULD_MAKE_DEFAULT) == 1) {
  322.       // User chose to use the reader as their default, so update the 
  323.       // chosen reader preference, too.
  324.       this._updateDefaultReader(uri);
  325.     }
  326.     return shouldAdd;
  327.   },
  328.   
  329.   _checkForDuplicateContentType: 
  330.   function WCCR__checkForDuplicateContentType(contentType, uri, title) {
  331.     contentType = this._resolveContentType(contentType);
  332.     if (this._typeIsRegistered(contentType, uri)) {
  333.       // Show a special dialog for the feed case (XXXben - generalize at some 
  334.       // point to allow other types to register specialized prompts).
  335.       this._confirmAddHandler(contentType, title, uri);
  336.       return false;
  337.     }
  338.     return true;
  339.   },
  340.   
  341.   /**
  342.    * See nsIWebContentHandlerRegistrar
  343.    */
  344.   registerProtocolHandler: 
  345.   function WCCR_registerProtocolHandler(protocol, uri, title) {
  346.     // XXXben - for Firefox 2 we only support feed types
  347.     return;
  348.     
  349.     LOG("registerProtocolHandler(" + protocol + "," + uri + "," + title + ")");
  350.     if (this._confirmAddHandler(protocol, title, uri))
  351.       this._protocols[protocol] = uri;
  352.   },
  353.  
  354.   /**
  355.    * See nsIWebContentHandlerRegistrar
  356.    * This is the web front end into the registration system, so a prompt to 
  357.    * confirm the registration is provided, and the result is saved to 
  358.    * preferences.
  359.    */
  360.   registerContentHandler: 
  361.   function WCCR_registerContentHandler(contentType, uri, title) {
  362.     LOG("registerContentHandler(" + contentType + "," + uri + "," + title + ")");
  363.     
  364.     // XXXben - for Firefox 2 we only support feed types
  365.     contentType = this._resolveContentType(contentType);
  366.     if (contentType != TYPE_MAYBE_FEED)
  367.       return;    
  368.  
  369.     if (!this._checkForDuplicateContentType(contentType, uri, title) ||
  370.         !this._confirmAddHandler(contentType, title, uri))
  371.       return;
  372.     
  373.     // Reset the auto handler so that the user is asked again the next time
  374.     // they load content of this type.
  375.     if (this.getAutoHandler(contentType)) 
  376.       this.setAutoHandler(contentType, null);
  377.  
  378.     this._registerContentHandler(contentType, uri, title);
  379.     this._saveContentHandlerToPrefs(contentType, uri, title);    
  380.   },
  381.   
  382.   /**
  383.    * Save Web Content Handler metadata to persistent preferences. 
  384.    * @param   contentType
  385.    *          The content Type being handled
  386.    * @param   uri
  387.    *          The uri of the web service
  388.    * @param   title
  389.    *          The human readable name of the web service
  390.    *
  391.    * This data is stored under:
  392.    * 
  393.    *    browser.contentHandlers.type0 = content/type
  394.    *    browser.contentHandlers.uri0 = http://www.foo.com/q=%s
  395.    *    browser.contentHandlers.title0 = Foo 2.0alphr
  396.    */
  397.   _saveContentHandlerToPrefs: 
  398.   function WCCR__saveContentHandlerToPrefs(contentType, uri, title) {
  399.     var ps = 
  400.         Cc["@mozilla.org/preferences-service;1"].
  401.         getService(Ci.nsIPrefService);
  402.     var i = 0;
  403.     var typeBranch = null;
  404.     while (true) {
  405.       typeBranch = 
  406.         ps.getBranch(PREF_CONTENTHANDLERS_BRANCH + i + ".");
  407.       try {
  408.         typeBranch.getCharPref("type");
  409.         ++i;
  410.       }
  411.       catch (e) {
  412.         // No more handlers
  413.         break;
  414.       }
  415.     }
  416.     if (typeBranch) {
  417.       typeBranch.setCharPref("type", contentType);
  418.       typeBranch.setCharPref("uri", uri);
  419.       typeBranch.setCharPref("title", title);
  420.     
  421.       ps.savePrefFile(null);
  422.     }
  423.   },
  424.   
  425.   /**
  426.    * Determines if there is a type with a particular uri registered for the 
  427.    * specified content type already.
  428.    * @param   contentType
  429.    *          The content type that the uri handles
  430.    * @param   uri
  431.    *          The uri of the 
  432.    */
  433.   _typeIsRegistered: function WCCR__typeIsRegistered(contentType, uri) {
  434.     if (!(contentType in this._contentTypes))
  435.       return false;
  436.       
  437.     var services = this._contentTypes[contentType];
  438.     for (var i = 0; i < services.length; ++i) {
  439.       // This uri has already been registered
  440.       if (services[i].uri == uri)
  441.         return true;
  442.     }
  443.     return false;
  444.   },
  445.   
  446.   /**
  447.    * Gets a stream converter contract id for the specified content type.
  448.    * @param   contentType
  449.    *          The source content type for the conversion.
  450.    * @returns A contract id to construct a converter to convert between the 
  451.    *          contentType and *\/*.
  452.    */
  453.   _getConverterContractID: function WCCR__getConverterContractID(contentType) {
  454.     const template = "@mozilla.org/streamconv;1?from=%s&to=*/*";
  455.     return template.replace(/%s/, contentType);
  456.   },
  457.   
  458.   /**
  459.    * Update the content type -> handler map. This mapping is not persisted, use
  460.    * registerContentHandler or _saveContentHandlerToPrefs for that purpose.
  461.    * @param   contentType
  462.    *          The content Type being handled
  463.    * @param   uri
  464.    *          The uri of the web service
  465.    * @param   title
  466.    *          The human readable name of the web service
  467.    */
  468.   _registerContentHandler: 
  469.   function WCCR__registerContentHandler(contentType, uri, title) {
  470.     if (!(contentType in this._contentTypes))
  471.       this._contentTypes[contentType] = [];
  472.  
  473.     // Avoid adding duplicates
  474.     if (this._typeIsRegistered(contentType, uri)) 
  475.       return;
  476.     
  477.     this._contentTypes[contentType].push(new ServiceInfo(contentType, uri, title));
  478.     
  479.     if (!(contentType in this._blockedTypes)) {
  480.       var converterContractID = this._getConverterContractID(contentType);
  481.       var cr = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
  482.       cr.registerFactory(WCC_CLASSID, WCC_CLASSNAME, converterContractID, 
  483.                          WebContentConverterFactory);
  484.     }
  485.   },
  486.   
  487.   /**
  488.    * See nsIWebContentConverterService
  489.    */
  490.   getContentHandlers: 
  491.   function WCCR_getContentHandlers(contentType, countRef) {
  492.     countRef.value = 0;
  493.     if (!(contentType in this._contentTypes))
  494.       return [];
  495.     
  496.     var handlers = this._contentTypes[contentType];
  497.     countRef.value = handlers.length;
  498.     return handlers;
  499.   },
  500.   
  501.   /**
  502.    * See nsIWebContentConverterService
  503.    */
  504.   resetHandlersForType: 
  505.   function WCCR_resetHandlersForType(contentType) {
  506.     contentType = this._resolveContentType(contentType);
  507.     var ps = 
  508.         Cc["@mozilla.org/preferences-service;1"].
  509.         getService(Ci.nsIPrefService);
  510.     try {
  511.       var i = 0;
  512.       while (true) {
  513.         var handlerBranch = 
  514.           ps.getBranch(PREF_CONTENTHANDLERS_BRANCH + i + ".");
  515.         try {
  516.           if (handlerBranch.getCharPref("type") == contentType)
  517.             handlerBranch.resetBranch("");
  518.           var defaultBranch = 
  519.               ps.getDefaultBranch(PREF_CONTENTHANDLERS_BRANCH + i + ".");
  520.           if (!this._registerContentHandlerWithBranch(defaultBranch))
  521.             break;
  522.           ++i;
  523.         }
  524.         catch (e) {
  525.         }
  526.       }
  527.     }
  528.     catch (e) {
  529.     }
  530.     ps.savePrefFile(null);
  531.   },
  532.   
  533.   /**
  534.    * Registers a handler from the settings on a branch
  535.    */
  536.   _registerContentHandlerWithBranch: function(branch) {
  537.     try {
  538.       var type = branch.getCharPref("type");
  539.       var uri = branch.getCharPref("uri");
  540.       var title = branch.getCharPref("title");
  541.       this._registerContentHandler(type, uri, title);
  542.     }
  543.     catch (e) {
  544.       return false;
  545.     }
  546.     return true;
  547.   },
  548.   
  549.   /**
  550.    * Load the auto handler, content handler and protocol tables from 
  551.    * preferences.
  552.    */
  553.   _init: function WCCR__init() {
  554.     var ps = 
  555.         Cc["@mozilla.org/preferences-service;1"].
  556.         getService(Ci.nsIPrefService);
  557.     try {
  558.       var i = 0;
  559.       while (true) {
  560.         var handlerBranch = 
  561.           ps.getBranch(PREF_CONTENTHANDLERS_BRANCH + (i++) + ".");
  562.         if (!this._registerContentHandlerWithBranch(handlerBranch))
  563.           break;
  564.       }
  565.     }
  566.     catch (e) {
  567.       // No content handlers yet, that's fine
  568.       //LOG("WCCR.init: There are no content handlers registered in preferences (benign).");
  569.     }
  570.  
  571.     // We need to do this _after_ registering all of the available handlers, 
  572.     // so that getWebContentHandlerByURI can return successfully.
  573.     try {
  574.       var autoBranch = ps.getBranch(PREF_CONTENTHANDLERS_AUTO);
  575.       var childPrefs = autoBranch.getChildList("", { });
  576.       for (var i = 0; i < childPrefs.length; ++i) {
  577.         var type = childPrefs[i];
  578.         var uri = autoBranch.getCharPref(type);
  579.         if (uri) {
  580.           var handler = this.getWebContentHandlerByURI(type, uri);
  581.           this._setAutoHandler(type, handler);
  582.         }
  583.       }
  584.     }
  585.     catch (e) {
  586.       // No auto branch yet, that's fine
  587.       //LOG("WCCR.init: There is no auto branch, benign");
  588.     }
  589.   },
  590.   
  591.   /**
  592.    * See nsIObserver
  593.    */
  594.   observe: function WCCR_observe(subject, topic, data) {
  595.     var os = 
  596.         Cc["@mozilla.org/observer-service;1"].
  597.         getService(Ci.nsIObserverService);
  598.     switch (topic) {
  599.     case "app-startup":
  600.       os.addObserver(this, "profile-after-change", false);
  601.       break;
  602.     case "profile-after-change":
  603.       os.removeObserver(this, "profile-after-change");
  604.       this._init();
  605.       break;      
  606.     }
  607.   },
  608.   
  609.   /**
  610.    * See nsIFactory
  611.    */
  612.   createInstance: function WCCR_createInstance(outer, iid) {
  613.     if (outer != null)
  614.       throw Cr.NS_ERROR_NO_AGGREGATION;
  615.     return this.QueryInterface(iid);
  616.   },
  617.  
  618.   /**
  619.    * See nsIClassInfo
  620.    */
  621.   getInterfaces: function WCCR_getInterfaces(countRef) {
  622.     var interfaces = 
  623.         [Ci.nsIWebContentConverterService, Ci.nsIWebContentHandlerRegistrar,
  624.          Ci.nsIObserver, Ci.nsIClassInfo, Ci.nsIFactory, Ci.nsISupports];
  625.     countRef.value = interfaces.length;
  626.     return interfaces;
  627.   },
  628.   getHelperForLanguage: function WCCR_getHelperForLanguage(language) {
  629.     return null;
  630.   },
  631.   contractID: WCCR_CONTRACTID,
  632.   classDescription: WCCR_CLASSNAME,
  633.   classID: WCCR_CLASSID,
  634.   implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT,
  635.   flags: Ci.nsIClassInfo.DOM_OBJECT,
  636.   
  637.   /**
  638.    * See nsISupports
  639.    */
  640.   QueryInterface: function WCCR_QueryInterface(iid) {
  641.     if (iid.equals(Ci.nsIWebContentConverterService) || 
  642.         iid.equals(Ci.nsIWebContentHandlerRegistrar) ||
  643.         iid.equals(Ci.nsIObserver) ||
  644.         iid.equals(Ci.nsIClassInfo) ||
  645.         iid.equals(Ci.nsIFactory) ||
  646.         iid.equals(Ci.nsISupports))
  647.       return this;
  648.     throw Cr.NS_ERROR_NO_INTERFACE;
  649.   },
  650. };
  651.  
  652. var Module = {
  653.   QueryInterface: function M_QueryInterface(iid) {
  654.     if (iid.equals(Ci.nsIModule) ||
  655.         iid.equals(Ci.nsISupports))
  656.       return this;
  657.     throw Cr.NS_ERROR_NO_INTERFACE;
  658.   },
  659.   
  660.   getClassObject: function M_getClassObject(cm, cid, iid) {
  661.     if (!iid.equals(Ci.nsIFactory))
  662.       throw Cr.NS_ERROR_NOT_IMPLEMENTED;
  663.     
  664.     if (cid.equals(WCCR_CLASSID))
  665.       return WebContentConverterRegistrar;
  666.       
  667.     throw Cr.NS_ERROR_NO_INTERFACE;
  668.   },
  669.   
  670.   registerSelf: function M_registerSelf(cm, file, location, type) {
  671.     var cr = cm.QueryInterface(Ci.nsIComponentRegistrar);
  672.     cr.registerFactoryLocation(WCCR_CLASSID, WCCR_CLASSNAME, WCCR_CONTRACTID,
  673.                                file, location, type);
  674.  
  675.     var catman = 
  676.         Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
  677.     catman.addCategoryEntry("app-startup", WCCR_CLASSNAME, 
  678.                             "service," + WCCR_CONTRACTID, true, true, null);
  679.   },
  680.   
  681.   unregisterSelf: function M_unregisterSelf(cm, location, type) {
  682.     var cr = cm.QueryInterface(Ci.nsIComponentRegistrar);
  683.     cr.unregisterFactoryLocation(WCCR_CLASSID, location);
  684.   },
  685.   
  686.   canUnload: function M_canUnload(cm) {
  687.     return true;
  688.   }
  689. };
  690.  
  691. function NSGetModule(cm, file) {
  692.   return Module;
  693. }
  694.  
  695. //@line 44 "/build/buildd/firefox-1.99+2.0b1+dfsg/browser/components/feeds/src/../../../../toolkit/content/debug.js"
  696.  
  697. const NS_ASSERT_ENVIRONMENT_VARIABLE_NAME = "XUL_ASSERT_PROMPT";
  698. var gTraceOnAssert = true;
  699.  
  700. /**
  701.  * This function provides a simple assertion function for JavaScript.
  702.  * If the condition is true, this function will do nothing.  If the
  703.  * condition is false, then the message will be printed to the console
  704.  * and an alert will appear showing a stack trace, so that the (alpha
  705.  * or nightly) user can file a bug containing it.  For future enhancements, 
  706.  * see bugs 330077 and 330078.
  707.  *
  708.  * To suppress the dialogs, you can run with the environment variable
  709.  * XUL_ASSERT_PROMPT set to 0 (if unset, this defaults to 1).
  710.  *
  711.  * @param condition represents the condition that we're asserting to be
  712.  *                  true when we call this function--should be
  713.  *                  something that can be evaluated as a boolean.
  714.  * @param message   a string to be displayed upon failure of the assertion
  715.  */
  716.  
  717. function NS_ASSERT(condition, message) {
  718.   if (condition)
  719.     return;
  720.  
  721.   var caller = arguments.callee.caller;
  722.   var assertionText = "ASSERT: " + message + "\n";
  723.   dump(assertionText);
  724.  
  725.   var stackText = "";
  726.   if (gTraceOnAssert) {
  727.     stackText = "Stack Trace: \n";
  728.     var count = 0;
  729.     while (caller) {
  730.       stackText += count++ + ":" + caller.name + "(";
  731.       for (var i = 0; i < caller.arguments.length; ++i) {
  732.         var arg = caller.arguments[i];
  733.         stackText += arg;
  734.         if (i < caller.arguments.length - 1)
  735.           stackText += ",";
  736.       }
  737.       stackText += ")\n";
  738.       caller = caller.arguments.callee.caller;
  739.     }
  740.   }
  741.  
  742.   var environment = Components.classes["@mozilla.org/process/environment;1"].
  743.                     getService(Components.interfaces.nsIEnvironment);
  744.   if (environment.exists(NS_ASSERT_ENVIRONMENT_VARIABLE_NAME) &&
  745.       !parseInt(environment.get(NS_ASSERT_ENVIRONMENT_VARIABLE_NAME)))
  746.     return;
  747.  
  748.   var source = null;
  749.   if (this.window)
  750.     source = window;
  751.   var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
  752.            getService(Components.interfaces.nsIPromptService);
  753.   ps.alert(source, "Assertion Failed", assertionText + stackText);
  754. }
  755. //@line 731 "/build/buildd/firefox-1.99+2.0b1+dfsg/browser/components/feeds/src/WebContentConverter.js"
  756.  
  757.