home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 233 / Computer Shopper 233 / ComputerShopperDVD233.iso / Toolkit / Internet / Firefox / Firefox Setup 2.0.0.3.exe / nonlocalized / components / FeedWriter.js < prev    next >
Encoding:
Text File  |  2007-03-10  |  40.4 KB  |  1,168 lines

  1. //@line 40 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  2.  
  3. const Cc = Components.classes;
  4. const Ci = Components.interfaces;
  5. const Cr = Components.results;
  6.  
  7. function LOG(str) {
  8.   var prefB = 
  9.     Cc["@mozilla.org/preferences-service;1"].
  10.     getService(Ci.nsIPrefBranch);
  11.  
  12.   var shouldLog = false;
  13.   try {
  14.     shouldLog = prefB.getBoolPref("feeds.log");
  15.   } 
  16.   catch (ex) {
  17.   }
  18.  
  19.   if (shouldLog)
  20.     dump("*** Feeds: " + str + "\n");
  21. }
  22.  
  23. /**
  24.  * Wrapper function for nsIIOService::newURI.
  25.  * @param aURLSpec
  26.  *        The URL string from which to create an nsIURI.
  27.  * @returns an nsIURI object, or null if the creation of the URI failed.
  28.  */
  29. function makeURI(aURLSpec, aCharset) {
  30.   var ios = Cc["@mozilla.org/network/io-service;1"].
  31.             getService(Ci.nsIIOService);
  32.   try {
  33.     return ios.newURI(aURLSpec, aCharset, null);
  34.   } catch (ex) { }
  35.  
  36.   return null;
  37. }
  38.  
  39. const XML_NS = "http://www.w3.org/XML/1998/namespace"
  40. const HTML_NS = "http://www.w3.org/1999/xhtml";
  41. const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  42. const AAA_NS = "http://www.w3.org/2005/07/aaa";
  43. const TYPE_MAYBE_FEED = "application/vnd.mozilla.maybe.feed";
  44. const URI_BUNDLE = "chrome://browser/locale/feeds/subscribe.properties";
  45.  
  46. const PREF_SELECTED_APP = "browser.feeds.handlers.application";
  47. const PREF_SELECTED_WEB = "browser.feeds.handlers.webservice";
  48. const PREF_SELECTED_ACTION = "browser.feeds.handler";
  49. const PREF_SELECTED_READER = "browser.feeds.handler.default";
  50. const PREF_SHOW_FIRST_RUN_UI = "browser.feeds.showFirstRunUI";
  51.  
  52. const FW_CLASSID = Components.ID("{49bb6593-3aff-4eb3-a068-2712c28bd58e}");
  53. const FW_CLASSNAME = "Feed Writer";
  54. const FW_CONTRACTID = "@mozilla.org/browser/feeds/result-writer;1";
  55.  
  56. const TITLE_ID = "feedTitleText";
  57. const SUBTITLE_ID = "feedSubtitleText";
  58.  
  59. const ICON_DATAURL_PREFIX = "data:image/x-icon;base64,";
  60.  
  61. function FeedWriter() {
  62. }
  63. FeedWriter.prototype = {
  64.   _getPropertyAsBag: function FW__getPropertyAsBag(container, property) {
  65.     return container.fields.getProperty(property).
  66.                      QueryInterface(Ci.nsIPropertyBag2);
  67.   },
  68.   
  69.   _getPropertyAsString: function FW__getPropertyAsString(container, property) {
  70.     try {
  71.       return container.fields.getPropertyAsAString(property);
  72.     }
  73.     catch (e) {
  74.     }
  75.     return "";
  76.   },
  77.   
  78.   _setContentText: function FW__setContentText(id, text) {
  79.     var element = this._document.getElementById(id);
  80.     while (element.hasChildNodes())
  81.       element.removeChild(element.firstChild);
  82.     element.appendChild(this._document.createTextNode(text));
  83.   },
  84.   
  85.   /**
  86.    * Safely sets the href attribute on an anchor tag, providing the URI 
  87.    * specified can be loaded according to rules. 
  88.    * @param   element
  89.    *          The element to set a URI attribute on
  90.    * @param   attribute
  91.    *          The attribute of the element to set the URI to, e.g. href or src
  92.    * @param   uri
  93.    *          The URI spec to set as the href
  94.    */
  95.   _safeSetURIAttribute: 
  96.   function FW__safeSetURIAttribute(element, attribute, uri) {
  97.     var secman = 
  98.         Cc["@mozilla.org/scriptsecuritymanager;1"].
  99.         getService(Ci.nsIScriptSecurityManager);    
  100.     const flags = Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT_OR_DATA;
  101.     try {
  102.       secman.checkLoadURIStr(this._window.location.href, uri, flags);
  103.       // checkLoadURIStr will throw if the link URI should not be loaded per 
  104.       // the rules specified in |flags|, so we'll never "linkify" the link...
  105.       element.setAttribute(attribute, uri);
  106.     }
  107.     catch (e) {
  108.       // Not allowed to load this link because secman.checkLoadURIStr threw
  109.     }
  110.   },
  111.   
  112.   get _bundle() {
  113.     var sbs = 
  114.         Cc["@mozilla.org/intl/stringbundle;1"].
  115.         getService(Ci.nsIStringBundleService);
  116.     return sbs.createBundle(URI_BUNDLE);
  117.   },
  118.   
  119.   _getFormattedString: function FW__getFormattedString(key, params) {
  120.     return this._bundle.formatStringFromName(key, params, params.length);
  121.   },
  122.   
  123.   _getString: function FW__getString(key) {
  124.     return this._bundle.GetStringFromName(key);
  125.   },
  126.  
  127.   /* Magic helper methods to be used instead of xbl properties */
  128.   _getSelectedItemFromMenulist: function FW__getSelectedItemFromList(aList) {
  129.     var node = aList.firstChild.firstChild;
  130.     while (node) {
  131.       if (node.localName == "menuitem" && node.getAttribute("selected") == "true")
  132.         return node;
  133.  
  134.       node = node.nextSibling;
  135.     }
  136.  
  137.     return null;
  138.   },
  139.  
  140.   _setCheckboxCheckedState: function FW__setCheckboxCheckedState(aCheckbox, aValue) {
  141.     // see checkbox.xml
  142.     var change = (aValue != (aCheckbox.getAttributeNS('', 'checked') == 'true'));
  143.     if (aValue)
  144.       aCheckbox.setAttributeNS('', 'checked', 'true');
  145.     else
  146.       aCheckbox.removeAttributeNS('', 'checked');
  147.  
  148.     if (change) {
  149.       var event = this._document.createEvent('Events');
  150.       event.initEvent('CheckboxStateChange', true, true);
  151.       aCheckbox.dispatchEvent(event);
  152.     }
  153.   },
  154.  
  155.   // For setting and getting the file expando property, we need to keep a
  156.   // reference to an explict XPCNativeWrapper around the associated menuitems
  157.   _selectedApplicationItemWrapped: null,
  158.   get selectedApplicationItemWrapped() {
  159.     if (!this._selectedApplicationItemWrapped) {
  160.       this._selectedApplicationItemWrapped =
  161.         XPCNativeWrapper(this._document.getElementById("selectedAppMenuItem"));
  162.     }
  163.  
  164.     return this._selectedApplicationItemWrapped;
  165.   },
  166.  
  167. //@line 206 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  168.   _defaultSystemReaderItemWrapped: null,
  169.   get defaultSystemReaderItemWrapped() {
  170.     if (!this._defaultSystemReaderItemWrapped) {
  171.       // Unlike the selected application item, this might not exist at all,
  172.       // see _initSubscriptionUI
  173.       var menuItem = this._document.getElementById("defaultHandlerMenuItem");
  174.       if (menuItem)
  175.         this._defaultSystemReaderItemWrapped = XPCNativeWrapper(menuItem);
  176.     }
  177.  
  178.     return this._defaultSystemReaderItemWrapped;
  179.   },
  180. //@line 219 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  181.  
  182.   /**
  183.    * Writes the feed title into the preview document.
  184.    * @param   container
  185.    *          The feed container
  186.    */
  187.   _setTitleText: function FW__setTitleText(container) {
  188.     if (container.title) {
  189.       this._setContentText(TITLE_ID, container.title.plainText());
  190.       this._document.title = container.title.plainText();
  191.     }
  192.     
  193.     var feed = container.QueryInterface(Ci.nsIFeed);
  194.     if (feed && feed.subtitle)
  195.       this._setContentText(SUBTITLE_ID, container.subtitle.plainText());
  196.   },
  197.   
  198.   /**
  199.    * Writes the title image into the preview document if one is present.
  200.    * @param   container
  201.    *          The feed container
  202.    */
  203.   _setTitleImage: function FW__setTitleImage(container) {
  204.     try {
  205.       var parts = this._getPropertyAsBag(container, "image");
  206.       
  207.       // Set up the title image (supplied by the feed)
  208.       var feedTitleImage = this._document.getElementById("feedTitleImage");
  209.       this._safeSetURIAttribute(feedTitleImage, "src", 
  210.                                 parts.getPropertyAsAString("url"));
  211.       
  212.       // Set up the title image link
  213.       var feedTitleLink = this._document.getElementById("feedTitleLink");
  214.       
  215.       var titleText = 
  216.         this._getFormattedString("linkTitleTextFormat", 
  217.                                  [parts.getPropertyAsAString("title")]);
  218.       feedTitleLink.setAttribute("title", titleText);
  219.       this._safeSetURIAttribute(feedTitleLink, "href", 
  220.                                 parts.getPropertyAsAString("link"));
  221.  
  222.       // Fix the margin on the main title, so that the image doesn't run over
  223.       // the underline
  224.       var feedTitleText = this._document.getElementById("feedTitleText");
  225.       var titleImageWidth = parseInt(parts.getPropertyAsAString("width")) + 15;
  226.       feedTitleText.style.marginRight = titleImageWidth + "px";
  227.     }
  228.     catch (e) {
  229.       LOG("Failed to set Title Image (this is benign): " + e);
  230.     }
  231.   },
  232.   
  233.   /**
  234.    * Writes all entries contained in the feed.
  235.    * @param   container
  236.    *          The container of entries in the feed
  237.    */
  238.   _writeFeedContent: function FW__writeFeedContent(container) {
  239.     // Build the actual feed content
  240.     var feedContent = this._document.getElementById("feedContent");
  241.     var feed = container.QueryInterface(Ci.nsIFeed);
  242.     
  243.     for (var i = 0; i < feed.items.length; ++i) {
  244.       var entry = feed.items.queryElementAt(i, Ci.nsIFeedEntry);
  245.       entry.QueryInterface(Ci.nsIFeedContainer);
  246.       
  247.       var entryContainer = this._document.createElementNS(HTML_NS, "div");
  248.       entryContainer.className = "entry";
  249.  
  250.       // If the entry has a title, make it a like
  251.       if (entry.title) {
  252.         var a = this._document.createElementNS(HTML_NS, "a");
  253.         a.appendChild(this._document.createTextNode(entry.title.plainText()));
  254.       
  255.         // Entries are not required to have links, so entry.link can be null.
  256.         if (entry.link)
  257.           this._safeSetURIAttribute(a, "href", entry.link.spec);
  258.  
  259.         var title = this._document.createElementNS(HTML_NS, "h3");
  260.         title.appendChild(a);
  261.         entryContainer.appendChild(title);
  262.       }
  263.  
  264.       var body = this._document.createElementNS(HTML_NS, "p");
  265.       var summary = entry.summary || entry.content;
  266.       var docFragment = null;
  267.       if (summary) {
  268.  
  269.         if (summary.base)
  270.           body.setAttributeNS(XML_NS, "base", summary.base.spec);
  271.         else
  272.           LOG("no base?");
  273.         docFragment = summary.createDocumentFragment(body);
  274.         body.appendChild(docFragment);
  275.  
  276.         // If the entry doesn't have a title, append a # permalink
  277.         // See http://scripting.com/rss.xml for an example
  278.         if (!entry.title && entry.link) {
  279.           var a = this._document.createElementNS(HTML_NS, "a");
  280.           a.appendChild(this._document.createTextNode("#"));
  281.           this._safeSetURIAttribute(a, "href", entry.link.spec);
  282.           body.appendChild(this._document.createTextNode(" "));
  283.           body.appendChild(a);
  284.         }
  285.  
  286.       }
  287.       body.className = "feedEntryContent";
  288.       entryContainer.appendChild(body);
  289.       feedContent.appendChild(entryContainer);
  290.     }
  291.   },
  292.   
  293.   /**
  294.    * Gets a valid nsIFeedContainer object from the parsed nsIFeedResult.
  295.    * Displays error information if there was one.
  296.    * @param   result
  297.    *          The parsed feed result
  298.    * @returns A valid nsIFeedContainer object containing the contents of
  299.    *          the feed.
  300.    */
  301.   _getContainer: function FW__getContainer(result) {
  302.     var feedService = 
  303.         Cc["@mozilla.org/browser/feeds/result-service;1"].
  304.         getService(Ci.nsIFeedResultService);
  305.  
  306.     try {
  307.       var result = 
  308.         feedService.getFeedResult(this._getOriginalURI(this._window));
  309.     }
  310.     catch (e) {
  311.       LOG("Subscribe Preview: feed not available?!");
  312.     }
  313.     
  314.     if (result.bozo) {
  315.       LOG("Subscribe Preview: feed result is bozo?!");
  316.     }
  317.  
  318.     try {
  319.       var container = result.doc;
  320.       container.title;
  321.     }
  322.     catch (e) {
  323.       LOG("Subscribe Preview: An error occurred in parsing! Fortunately, you can still subscribe...");
  324.       var feedError = this._document.getElementById("feedError");
  325.       feedError.removeAttribute("style");
  326.       var feedBody = this._document.getElementById("feedBody");
  327.       feedBody.setAttribute("style", "display:none;");
  328.       this._setContentText("errorCode", e);
  329.       return null;
  330.     }
  331.     return container;
  332.   },
  333.   
  334.   /**
  335.    * Get the human-readable display name of a file. This could be the 
  336.    * application name.
  337.    * @param   file
  338.    *          A nsIFile to look up the name of
  339.    * @returns The display name of the application represented by the file.
  340.    */
  341.   _getFileDisplayName: function FW__getFileDisplayName(file) {
  342. //@line 381 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  343.     if (file instanceof Ci.nsILocalFileWin) {
  344.       try {
  345.         return file.getVersionInfoField("FileDescription");
  346.       }
  347.       catch (e) {
  348.       }
  349.     }
  350. //@line 398 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  351.     var ios = 
  352.         Cc["@mozilla.org/network/io-service;1"].
  353.         getService(Ci.nsIIOService);
  354.     var url = ios.newFileURI(file).QueryInterface(Ci.nsIURL);
  355.     return url.fileName;
  356.   },
  357.  
  358.   /**
  359.    * Get moz-icon url for a file
  360.    * @param   file
  361.    *          A nsIFile to look up the name of
  362.    * @returns moz-icon url of the given file as a string
  363.    */
  364.   _getFileIconURL: function FW__getFileIconURL(file) {
  365.     var ios = Cc["@mozilla.org/network/io-service;1"].
  366.               getService(Components.interfaces.nsIIOService);
  367.     var fph = ios.getProtocolHandler("file")
  368.                  .QueryInterface(Ci.nsIFileProtocolHandler);
  369.     var urlSpec = fph.getURLSpecFromFile(file);
  370.     return "moz-icon://" + urlSpec + "?size=16";
  371.   },
  372.  
  373.   /**
  374.    * Helper method to set the selected application and system default
  375.    * reader menuitems details from a file object
  376.    *   @param aMenuItem
  377.    *          The menuitem on which the attributes should be set
  378.    *   @param aFile
  379.    *          the menuitem associated file object
  380.    */
  381.   _initMenuItemWithFile: function(aMenuItem, aFile) {
  382.     var label = this._getFileDisplayName(aFile);
  383.     aMenuItem.setAttribute("label", label);
  384.     aMenuItem.setAttribute("src",
  385.                           this._getFileIconURL(aFile));
  386.     aMenuItem.setAttribute("handlerType", "client");
  387.     aMenuItem.file = aFile;
  388.  
  389.     // a11y
  390.     aMenuItem.setAttribute("title", label);
  391.   },
  392.  
  393.   /**
  394.    * Displays a prompt from which the user may choose a (client) feed reader.
  395.    * @return - true if a feed reader was selected, false otherwise.
  396.    */
  397.   _chooseClientApp: function FW__chooseClientApp() {
  398.     try {
  399.       var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
  400.       fp.init(this._window,
  401.               this._getString("chooseApplicationDialogTitle"),
  402.               Ci.nsIFilePicker.modeOpen);
  403.       fp.appendFilters(Ci.nsIFilePicker.filterApps);
  404.  
  405.       if (fp.show() == Ci.nsIFilePicker.returnOK) {
  406.         var selectedApp = fp.file;
  407.         if (selectedApp) {
  408.           // XXXben - we need to compare this with the running instance executable
  409.           //          just don't know how to do that via script...
  410.           // XXXmano TBD: can probably add this to nsIShellService
  411. //@line 459 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  412.           if (fp.file.leafName != "firefox.exe") {
  413. //@line 467 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  414.             var selectedAppMenuItem = this.selectedApplicationItemWrapped;
  415.             this._initMenuItemWithFile(selectedAppMenuItem, selectedApp);
  416.  
  417.             // Show and select the selected application menuitem
  418.             selectedAppMenuItem.hidden = false;
  419.             selectedAppMenuItem.doCommand();
  420.             return true;
  421.           }
  422.         }
  423.       }
  424.     }
  425.     catch(ex) { }
  426.  
  427.     return false;
  428.   },
  429.  
  430.   _setAlwaysUseCheckedState: function FW__setAlwaysUseCheckedState() {
  431.     var checkbox = this._document.getElementById("alwaysUse");
  432.     if (checkbox) {
  433.       var alwaysUse = false;
  434.       try {
  435.         var prefs = Cc["@mozilla.org/preferences-service;1"].
  436.                     getService(Ci.nsIPrefBranch);
  437.         if (prefs.getCharPref(PREF_SELECTED_ACTION) != "ask")
  438.           alwaysUse = true;
  439.       }
  440.       catch(ex) { }
  441.       this._setCheckboxCheckedState(checkbox, alwaysUse);
  442.     }
  443.   },
  444.  
  445.   _setAlwaysUseLabel: function FW__setAlwaysUseLabel() {
  446.     var checkbox = this._document.getElementById("alwaysUse");
  447.     if (checkbox) {
  448.       var handlersMenuList = this._document.getElementById("handlersMenuList");
  449.       if (handlersMenuList) {
  450.         var handlerName = this._getSelectedItemFromMenulist(handlersMenuList)
  451.                               .getAttribute("label");
  452.         var label = this._getFormattedString("alwaysUse", [handlerName]);
  453.         checkbox.setAttribute("label", label);
  454.  
  455.         // Needed for a11y
  456.         checkbox.setAttribute("title", label);
  457.       }
  458.     }
  459.   },
  460.  
  461.   /**
  462.    * See nsIDOMEventListener
  463.    */
  464.   handleEvent: function(event) {
  465.     // see comments in the write method
  466.     event = new XPCNativeWrapper(event);
  467.     if (event.target.ownerDocument != this._document) {
  468.       LOG("FeedWriter.handleEvent: Someone passed the feed writer as a listener to the events of another document!");
  469.       return;
  470.     }
  471.  
  472.     switch (event.type) {
  473.       case "command" : {
  474.         switch (event.target.id) {
  475.           case "subscribeButton":
  476.             this.subscribe();
  477.             break;
  478.           case "chooseApplicationMenuItem":
  479.             // For keyboard-only users, we only show the file picker once the 
  480.             // subscribe button is pressed. See click event handling for the
  481.             // mouse-case.
  482.             break;
  483.           default:
  484.             event.target.parentNode.parentNode.setAttributeNS
  485.               (AAA_NS, "valuenow", event.target.getAttribute("label"));
  486.  
  487.             this._setAlwaysUseLabel();
  488.         }
  489.         break;
  490.       }
  491.       case "click": {
  492.         if (event.target.id == "chooseApplicationMenuItem") {
  493.           if (!this._chooseClientApp()) {
  494.             // Select the (per-prefs) selected handler if no application was selected
  495.             this._setSelectedHandler();
  496.           }
  497.         }
  498.       }
  499.       case "CheckboxStateChange": {
  500.         // Needed for a11y
  501.         var checkbox = this._document.getElementById("alwaysUse");
  502.         if (checkbox.getAttributeNS("", "checked") == "true")
  503.           checkbox.setAttributeNS(AAA_NS, "checked", "true");
  504.         else
  505.           checkbox.setAttributeNS(AAA_NS, "checked", "false");
  506.        }
  507.     }
  508.   },
  509.  
  510.   _setSelectedHandler: function FW__setSelectedHandler() {
  511.     var prefs =   
  512.         Cc["@mozilla.org/preferences-service;1"].
  513.         getService(Ci.nsIPrefBranch);
  514.  
  515.     var handler = "bookmarks";
  516.     try {
  517.       handler = prefs.getCharPref(PREF_SELECTED_READER);
  518.     }
  519.     catch (ex) { }
  520.     
  521.     switch (handler) {
  522.       case "web": {
  523.         var handlersMenuList = this._document.getElementById("handlersMenuList");
  524.         if (handlersMenuList) {
  525.           var url = prefs.getCharPref(PREF_SELECTED_WEB);
  526.           var handlers =
  527.             handlersMenuList.getElementsByAttribute("webhandlerurl", url);
  528.           if (handlers.length == 0) {
  529.             LOG("FeedWriter._setSelectedHandler: selected web handler isn't in the menulist")
  530.             return;
  531.           }
  532.  
  533.           handlers[0].doCommand();
  534.         }
  535.         break;
  536.       }
  537.       case "client": {
  538.         var selectedAppMenuItem = this.selectedApplicationItemWrapped;
  539.         if (selectedAppMenuItem) {
  540.           try {
  541.             var selectedApp = prefs.getComplexValue(PREF_SELECTED_APP,
  542.                                                     Ci.nsILocalFile);
  543.           } catch(ex) { }
  544.  
  545.           if (selectedApp) {
  546.             this._initMenuItemWithFile(selectedAppMenuItem, selectedApp);
  547.             selectedAppMenuItem.hidden = false;
  548.             selectedAppMenuItem.doCommand();
  549.  
  550. //@line 604 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  551.             // Only show the default reader menuitem if the default reader
  552.             // isn't the selected application
  553.             var defaultHandlerMenuItem = this.defaultSystemReaderItemWrapped;
  554.             if (defaultHandlerMenuItem) {
  555.               defaultHandlerMenuItem.hidden =
  556.                 defaultHandlerMenuItem.file.path == selectedApp.path;
  557.             }
  558. //@line 612 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  559.             break;
  560.           }
  561.         }
  562.       }
  563.       case "bookmarks":
  564.       default: {
  565.         var liveBookmarksMenuItem =
  566.           this._document.getElementById("liveBookmarksMenuItem");
  567.         if (liveBookmarksMenuItem)
  568.           liveBookmarksMenuItem.doCommand();
  569.       } 
  570.     }
  571.   },
  572.  
  573.   _initSubscriptionUI: function FW__initSubscriptionUI() {
  574.     var handlersMenuPopup =
  575.       this._document.getElementById("handlersMenuPopup");
  576.     if (!handlersMenuPopup)
  577.       return;
  578.  
  579.     // Last-selected application
  580.     var selectedApp;
  581.     menuItem = this._document.createElementNS(XUL_NS, "menuitem");
  582.     menuItem.id = "selectedAppMenuItem";
  583.     menuItem.className = "menuitem-iconic";
  584.     handlersMenuPopup.appendChild(menuItem);
  585.  
  586.     var selectedApplicationItem = this.selectedApplicationItemWrapped;
  587.     // a11y
  588.     selectedApplicationItem.setAttributeNS("http://www.w3.org/TR/xhtml2",
  589.                                            "role", "wairole:listitem");
  590.     selectedApplicationItem.setAttributeNS(AAA_NS, "selected", "false");
  591.     try {
  592.       var prefs = Cc["@mozilla.org/preferences-service;1"].
  593.                   getService(Ci.nsIPrefBranch);
  594.       selectedApp = prefs.getComplexValue(PREF_SELECTED_APP,
  595.                                           Ci.nsILocalFile);
  596.       if (selectedApp.exists())
  597.         this._initMenuItemWithFile(selectedApplicationItem, selectedApp);
  598.       else {
  599.         // Hide the menuitem if the last selected application doesn't exist
  600.         selectedApplicationItem.hidden = true;
  601.       }
  602.     }
  603.     catch(ex) {
  604.       // Hide the menuitem until an application is selected
  605.       selectedApplicationItem.hidden = true;
  606.     }
  607.  
  608. //@line 662 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  609.     // On Windows, also list the default feed reader
  610.     var defaultReader;
  611.     try {
  612.       const WRK = Ci.nsIWindowsRegKey;
  613.       var regKey =
  614.           Cc["@mozilla.org/windows-registry-key;1"].createInstance(WRK);
  615.       regKey.open(WRK.ROOT_KEY_CLASSES_ROOT, 
  616.                   "feed\\shell\\open\\command", WRK.ACCESS_READ);
  617.       var path = regKey.readStringValue("");
  618.       if (path.charAt(0) == "\"") {
  619.         // Everything inside the quotes
  620.         path = path.substr(1);
  621.         path = path.substr(0, path.indexOf("\""));
  622.       }
  623.       else {
  624.         // Everything up to the first space
  625.         path = path.substr(0, path.indexOf(" "));
  626.       }
  627.  
  628.       defaultReader = Cc["@mozilla.org/file/local;1"].
  629.                       createInstance(Ci.nsILocalFile);
  630.       defaultReader.initWithPath(path);
  631.  
  632.       if (defaultReader.exists()) {
  633.         menuItem = this._document.createElementNS(XUL_NS, "menuitem");
  634.         menuItem.id = "defaultHandlerMenuItem";
  635.         menuItem.className = "menuitem-iconic";
  636.         // a11y
  637.         menuItem.setAttributeNS("http://www.w3.org/TR/xhtml2",
  638.                                 "role", "wairole:listitem");
  639.         handlersMenuPopup.appendChild(menuItem);
  640.  
  641.         var defaultSystemReaderItem = this.defaultSystemReaderItemWrapped;
  642.         this._initMenuItemWithFile(defaultSystemReaderItem, defaultReader);
  643.  
  644.         // Hide the default reader item if it points to the same application
  645.         // as the last-selected application
  646.         if (selectedApp && selectedApp.path == defaultReader.path)
  647.           defaultSystemReaderItem.hidden = true;
  648.       }
  649.     }
  650.     catch (e) {
  651.       LOG("No feed handler registered on system");
  652.     }
  653. //@line 707 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  654.  
  655.     // "Choose Application..." menuitem
  656.     menuItem = this._document.createElementNS(XUL_NS, "menuitem");
  657.     menuItem.id = "chooseApplicationMenuItem";
  658.  
  659.     var chooseAppItemLabel = this._getString("chooseApplicationMenuItem");
  660.     menuItem.setAttribute("label", chooseAppItemLabel);
  661.     // a11y
  662.     menuItem.setAttributeNS("http://www.w3.org/TR/xhtml2",
  663.                             "role", "wairole:listitem");
  664.     menuItem.setAttribute("title", chooseAppItemLabel);
  665.     menuItem.addEventListener("click", this, false);
  666.  
  667.     handlersMenuPopup.appendChild(menuItem);
  668.  
  669.     // separator
  670.     handlersMenuPopup.appendChild(this._document.createElementNS(XUL_NS,
  671.                                   "menuseparator"));
  672.  
  673.     // List of web handlers
  674.     var wccr = 
  675.       Cc["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"].
  676.       getService(Ci.nsIWebContentConverterService);
  677.     var handlers = wccr.getContentHandlers(TYPE_MAYBE_FEED, {});
  678.     if (handlers.length != 0) {
  679.       for (var i = 0; i < handlers.length; ++i) {
  680.         menuItem = this._document.createElementNS(XUL_NS, "menuitem");
  681.         menuItem.className = "menuitem-iconic";
  682.         menuItem.setAttribute("label", handlers[i].name);
  683.         menuItem.setAttribute("handlerType", "web");
  684.         menuItem.setAttribute("webhandlerurl", handlers[i].uri);
  685.  
  686.         // a11y
  687.         menuItem.setAttribute("title", handlers[i].name);
  688.         menuItem.setAttributeNS("http://www.w3.org/TR/xhtml2",
  689.                                 "role", "wairole:listitem");
  690.         handlersMenuPopup.appendChild(menuItem);
  691.  
  692.         // For privacy reasons we cannot set the image attribute directly
  693.         // to the icon url, see Bug 358878
  694.         var uri = makeURI(handlers[i].uri);
  695.         if (uri && /^https?/.test(uri.scheme))
  696.           new iconDataURIGenerator(uri.prePath + "/favicon.ico", menuItem)
  697.       }
  698.     }
  699.  
  700.     // We update the "Always use.." checkbox label whenever the selected item
  701.     // in the list is changed
  702.     handlersMenuPopup.addEventListener("command", this, false);
  703.     this._setSelectedHandler();
  704.  
  705.     // "Always use..." checkbox initial state
  706.     this._setAlwaysUseLabel();
  707.     this._setAlwaysUseCheckedState();
  708.  
  709.     // Syncs xul:checked with aaa:checked, needed for a11y
  710.     var checkbox = this._document.getElementById("alwaysUse");
  711.     checkbox.addEventListener("CheckboxStateChange", this, false);
  712.  
  713.     // Set up the "Subscribe Now" button
  714.     this._document
  715.         .getElementById("subscribeButton")
  716.         .addEventListener("command", this, false);
  717.     
  718.     // first-run ui
  719.     var showFirstRunUI = true;
  720.     try {
  721.       showFirstRunUI = prefs.getBoolPref(PREF_SHOW_FIRST_RUN_UI);
  722.     }
  723.     catch (ex) { }
  724.     if (showFirstRunUI) {
  725.       var feedHeader = this._document.getElementById("feedHeader");
  726.       if (feedHeader)
  727.         feedHeader.setAttribute("firstrun", "true");
  728.  
  729.       prefs.setBoolPref(PREF_SHOW_FIRST_RUN_UI, false);
  730.     }
  731.   },
  732.  
  733.   /**
  734.    * Returns the original URI object of the feed and ensures that this
  735.    * component is only ever invoked from the preview document.  
  736.    * @param window 
  737.    *        The window of the document invoking the BrowserFeedWriter
  738.    */
  739.   _getOriginalURI: function FW__getOriginalURI(window) {  
  740.     var chan = 
  741.         window.QueryInterface(Ci.nsIInterfaceRequestor).
  742.         getInterface(Ci.nsIWebNavigation).
  743.         QueryInterface(Ci.nsIDocShell_MOZILLA_1_8_BRANCH).
  744.         currentDocumentChannel;
  745.     const kPrefix = "jar:file:";
  746.     if (chan.URI.spec.substring(0, kPrefix.length) == kPrefix)
  747.       return chan.originalURI;
  748.     else
  749.       return null;
  750.   },
  751.  
  752.   _window: null,
  753.   _document: null,
  754.   _feedURI: null,
  755.  
  756.   /**
  757.    * See nsIFeedWriter
  758.    */
  759.   write: function FW_write(window) {
  760.     // Explicitly wrap |window| in an XPCNativeWrapper to make sure
  761.     // it's a real native object! This will throw an exception if we
  762.     // get a non-native object.
  763.     window = new XPCNativeWrapper(window);
  764.  
  765.     this._feedURI = this._getOriginalURI(window);
  766.      if (!this._feedURI)
  767.       return;
  768.     try {
  769.       this._window = window;
  770.       this._document = window.document;
  771.         
  772.       LOG("Subscribe Preview: feed uri = " + this._window.location.href);
  773.        
  774.       // Set up the displayed handler
  775.       this._initSubscriptionUI();
  776.       var prefs =   
  777.       Cc["@mozilla.org/preferences-service;1"].
  778.       getService(Ci.nsIPrefBranch2);
  779.       prefs.addObserver(PREF_SELECTED_ACTION, this, false);
  780.       prefs.addObserver(PREF_SELECTED_READER, this, false);
  781.       prefs.addObserver(PREF_SELECTED_APP, this, false);
  782.       
  783.        // Set up the feed content
  784.       var container = this._getContainer();
  785.       if (!container)
  786.         return;
  787.       
  788.       this._setTitleText(container);
  789.       
  790.       this._setTitleImage(container);
  791.       
  792.       this._writeFeedContent(container);
  793.     }
  794.     finally {
  795.       this._removeFeedFromCache();
  796.     }
  797.   },
  798.   
  799.   /**
  800.    * See nsIFeedWriter
  801.    */
  802.   close: function FW_close() {
  803.     this._document = null;
  804.     this._window = null;
  805.     var prefs =   
  806.         Cc["@mozilla.org/preferences-service;1"].
  807.         getService(Ci.nsIPrefBranch2);
  808.     prefs.removeObserver(PREF_SELECTED_ACTION, this);
  809.     prefs.removeObserver(PREF_SELECTED_READER, this);
  810.     prefs.removeObserver(PREF_SELECTED_WEB, this);
  811.     prefs.removeObserver(PREF_SELECTED_APP, this);
  812.     this._removeFeedFromCache();
  813.   },
  814.       
  815.   _removeFeedFromCache: function FW__removeFeedFromCache() {
  816.     if (this._feedURI) {
  817.       var feedService = 
  818.           Cc["@mozilla.org/browser/feeds/result-service;1"].
  819.           getService(Ci.nsIFeedResultService);
  820.       feedService.removeFeedResult(this._feedURI);
  821.       this._feedURI = null;
  822.     }
  823.   },  
  824.   
  825.   subscribe: function FW_subscribe() {
  826.     // Subscribe to the feed using the selected handler and save prefs
  827.     var prefs =   
  828.         Cc["@mozilla.org/preferences-service;1"].
  829.         getService(Ci.nsIPrefBranch);
  830.     var defaultHandler = "reader";
  831.     var useAsDefault = this._document.getElementById("alwaysUse")
  832.                                      .getAttribute("checked");
  833.  
  834.     var selectedItem =
  835.       this._getSelectedItemFromMenulist(this._document.getElementById("handlersMenuList"));
  836.  
  837.     // Show the file picker before subscribing if the
  838.     // choose application menuitem was choosen using the keyboard
  839.     if (selectedItem.id == "chooseApplicationMenuItem") {
  840.       if (!this._chooseClientApp())
  841.         return;
  842.       
  843.       selectedItem = this._getSelectedItemFromMenulist(this._document.getElementById("handlersMenuList"));
  844.     }
  845.  
  846.     if (selectedItem.hasAttribute("webhandlerurl")) {
  847.       var webURI = selectedItem.getAttribute("webhandlerurl");
  848.       prefs.setCharPref(PREF_SELECTED_READER, "web");
  849.       prefs.setCharPref(PREF_SELECTED_WEB, webURI);
  850.  
  851.       var wccr = 
  852.         Cc["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"].
  853.         getService(Ci.nsIWebContentConverterService);
  854.       var handler = wccr.getWebContentHandlerByURI(TYPE_MAYBE_FEED, webURI);
  855.       if (handler) {
  856.         if (useAsDefault)
  857.           wccr.setAutoHandler(TYPE_MAYBE_FEED, handler);
  858.  
  859.         this._window.location.href =
  860.           handler.getHandlerURI(this._window.location.href);
  861.       }
  862.     }
  863.     else {
  864.       switch (selectedItem.id) {
  865.         case "selectedAppMenuItem":
  866.           prefs.setCharPref(PREF_SELECTED_READER, "client");
  867.           prefs.setComplexValue(PREF_SELECTED_APP, Ci.nsILocalFile, 
  868.                                 this.selectedApplicationItemWrapped.file);
  869.           break;
  870. //@line 924 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  871.         case "defaultHandlerMenuItem":
  872.           prefs.setCharPref(PREF_SELECTED_READER, "client");
  873.           prefs.setComplexValue(PREF_SELECTED_APP, Ci.nsILocalFile, 
  874.                                 this.defaultSystemReaderItemWrapped.file);
  875.           break;
  876. //@line 930 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/FeedWriter.js"
  877.         case "liveBookmarksMenuItem":
  878.           defaultHandler = "bookmarks";
  879.           prefs.setCharPref(PREF_SELECTED_READER, "bookmarks");
  880.           break;
  881.       }
  882.       var feedService = Cc["@mozilla.org/browser/feeds/result-service;1"].
  883.                         getService(Ci.nsIFeedResultService);
  884.  
  885.       // Pull the title and subtitle out of the document
  886.       var feedTitle = this._document.getElementById(TITLE_ID).textContent;
  887.       var feedSubtitle =
  888.         this._document.getElementById(SUBTITLE_ID).textContent;
  889.       feedService.addToClientReader(this._window.location.href,
  890.                                     feedTitle, feedSubtitle);
  891.     }
  892.  
  893.     // If "Always use..." is checked, we should set PREF_SELECTED_ACTION
  894.     // to either "reader" (If a web reader or if an application is selected),
  895.     // or to "bookmarks" (if the live bookmarks option is selected).
  896.     // Otherwise, we should set it to "ask"
  897.     if (useAsDefault)
  898.       prefs.setCharPref(PREF_SELECTED_ACTION, defaultHandler);
  899.     else
  900.       prefs.setCharPref(PREF_SELECTED_ACTION, "ask");
  901.   },
  902.   
  903.   /**
  904.    * See nsIObserver
  905.    */
  906.   observe: function FW_observe(subject, topic, data) {
  907.     if (!this._window) {
  908.       // this._window is null unless this.write was called with a trusted
  909.       // window object.
  910.       return;
  911.     }
  912.  
  913.     if (topic == "nsPref:changed") {
  914.       switch (data) {
  915.         case PREF_SELECTED_READER:
  916.         case PREF_SELECTED_WEB:
  917.         case PREF_SELECTED_APP:
  918.           this._setSelectedHandler();
  919.           break;
  920.         case PREF_SELECTED_ACTION:
  921.           this._setAlwaysUseCheckedState();
  922.       }
  923.     } 
  924.   },  
  925.   
  926.   /**
  927.    * See nsIClassInfo
  928.    */
  929.   getInterfaces: function WCCR_getInterfaces(countRef) {
  930.     var interfaces = 
  931.         [Ci.nsIFeedWriter, Ci.nsIClassInfo, Ci.nsISupports];
  932.     countRef.value = interfaces.length;
  933.     return interfaces;
  934.   },
  935.   getHelperForLanguage: function WCCR_getHelperForLanguage(language) {
  936.     return null;
  937.   },
  938.   contractID: FW_CONTRACTID,
  939.   classDescription: FW_CLASSNAME,
  940.   classID: FW_CLASSID,
  941.   implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT,
  942.   flags: Ci.nsIClassInfo.DOM_OBJECT,
  943.  
  944.   QueryInterface: function FW_QueryInterface(iid) {
  945.     if (iid.equals(Ci.nsIFeedWriter) ||
  946.         iid.equals(Ci.nsIClassInfo) ||
  947.         iid.equals(Ci.nsIDOMEventListener) ||
  948.         iid.equals(Ci.nsIObserver) ||
  949.         iid.equals(Ci.nsISupports))
  950.       return this;
  951.     throw Cr.NS_ERROR_NO_INTERFACE;
  952.   }
  953. };
  954.  
  955. function iconDataURIGenerator(aURISpec, aElement) {
  956.   var ios = Cc["@mozilla.org/network/io-service;1"].
  957.             getService(Ci.nsIIOService);
  958.   var chan = ios.newChannelFromURI(makeURI(aURISpec));
  959.   chan.notificationCallbacks = this;
  960.   chan.asyncOpen(this, null);
  961.  
  962.   this._channel = chan;
  963.   this._bytes = [];
  964.   this._element = aElement;
  965. }
  966. iconDataURIGenerator.prototype = {
  967.   _channel: null,
  968.   _countRead: 0,
  969.   _stream: null,
  970.  
  971.   QueryInterface: function FW_IDUG_loadQI(aIID) {
  972.     if (aIID.equals(Ci.nsISupports)           ||
  973.         aIID.equals(Ci.nsIRequestObserver)    ||
  974.         aIID.equals(Ci.nsIStreamListener)     ||
  975.         aIID.equals(Ci.nsIChannelEventSink)   ||
  976.         aIID.equals(Ci.nsIInterfaceRequestor) ||
  977.         aIID.equals(Ci.nsIBadCertListener)    ||
  978.         // See bug 358878 comment 11
  979.         aIID.equals(Ci.nsIPrompt)             ||
  980.         // See FIXME comment below
  981.         aIID.equals(Ci.nsIHttpEventSink)      ||
  982.         aIID.equals(Ci.nsIProgressEventSink)  ||
  983.         false)
  984.       return this;
  985.  
  986.     throw Cr.NS_ERROR_NO_INTERFACE;
  987.   },
  988.  
  989.   // nsIRequestObserver
  990.   onStartRequest: function FW_IDUG_loadStartR(aRequest, aContext) {
  991.     this._stream = Cc["@mozilla.org/binaryinputstream;1"].
  992.                    createInstance(Ci.nsIBinaryInputStream);
  993.   },
  994.  
  995.   onStopRequest: function FW_IDUG_loadStopR(aRequest, aContext, aStatusCode) {
  996.     var requestFailed = !Components.isSuccessCode(aStatusCode);
  997.     if (!requestFailed && (aRequest instanceof Ci.nsIHttpChannel))
  998.       requestFailed = !aRequest.requestSucceeded;
  999.  
  1000.     if (!requestFailed && this._countRead != 0) {
  1001.       var str = String.fromCharCode.apply(null, this._bytes);
  1002.       try {
  1003.         var dataURI = ICON_DATAURL_PREFIX +
  1004.                       this._element.ownerDocument.defaultView.btoa(str);
  1005.         this._element.setAttribute("src", dataURI);
  1006.         if (this._element.getAttribute("selected") == "true")
  1007.           this._element.parentNode.parentNode.setAttribute("src", dataURI);
  1008.       }
  1009.       catch(ex) {}
  1010.     }
  1011.     this._channel = null;
  1012.     this._element  = null;
  1013.   },
  1014.  
  1015.   // nsIStreamListener
  1016.   onDataAvailable: function FW_IDUG_loadDAvailable(aRequest, aContext,
  1017.                                                    aInputStream, aOffset,
  1018.                                                    aCount) {
  1019.     this._stream.setInputStream(aInputStream);
  1020.  
  1021.     // Get a byte array of the data
  1022.     this._bytes = this._bytes.concat(this._stream.readByteArray(aCount));
  1023.     this._countRead += aCount;
  1024.   },
  1025.  
  1026.   // nsIChannelEventSink
  1027.   onChannelRedirect: function FW_IDUG_loadCRedirect(aOldChannel, aNewChannel,
  1028.                                                     aFlags) {
  1029.     this._channel = aNewChannel;
  1030.   },
  1031.  
  1032.   // nsIInterfaceRequestor
  1033.   getInterface: function FW_IDUG_load_GI(aIID) {
  1034.     return this.QueryInterface(aIID);
  1035.   },
  1036.  
  1037.   // nsIBadCertListener
  1038.   confirmUnknownIssuer: function FW_IDUG_load_CUI(aSocketInfo, aCert,
  1039.                                                   aCertAddType) {
  1040.     return false;
  1041.   },
  1042.  
  1043.   confirmMismatchDomain: function FW_IDUG_load_CMD(aSocketInfo, aTargetURL,
  1044.                                                    aCert) {
  1045.     return false;
  1046.   },
  1047.  
  1048.   confirmCertExpired: function FW_IDUG_load_CCE(aSocketInfo, aCert) {
  1049.     return false;
  1050.   },
  1051.  
  1052.   notifyCrlNextupdate: function FW_IDUG_load_NCN(aSocketInfo, aTargetURL, aCert) {
  1053.   },
  1054.  
  1055.   // FIXME: bug 253127
  1056.   // nsIHttpEventSink
  1057.   onRedirect: function (aChannel, aNewChannel) { },
  1058.   // nsIProgressEventSink
  1059.   onProgress: function (aRequest, aContext, aProgress, aProgressMax) { },
  1060.   onStatus: function (aRequest, aContext, aStatus, aStatusArg) { }
  1061. };
  1062.  
  1063. var Module = {
  1064.   QueryInterface: function M_QueryInterface(iid) {
  1065.     if (iid.equals(Ci.nsIModule) ||
  1066.         iid.equals(Ci.nsISupports))
  1067.       return this;
  1068.     throw Cr.NS_ERROR_NO_INTERFACE;
  1069.   },
  1070.   
  1071.   getClassObject: function M_getClassObject(cm, cid, iid) {
  1072.     if (!iid.equals(Ci.nsIFactory))
  1073.       throw Cr.NS_ERROR_NOT_IMPLEMENTED;
  1074.     
  1075.     if (cid.equals(FW_CLASSID))
  1076.       return new GenericComponentFactory(FeedWriter);
  1077.       
  1078.     throw Cr.NS_ERROR_NO_INTERFACE;
  1079.   },
  1080.   
  1081.   registerSelf: function M_registerSelf(cm, file, location, type) {
  1082.     var cr = cm.QueryInterface(Ci.nsIComponentRegistrar);
  1083.     
  1084.     cr.registerFactoryLocation(FW_CLASSID, FW_CLASSNAME, FW_CONTRACTID,
  1085.                                file, location, type);
  1086.     
  1087.     var catman = 
  1088.         Cc["@mozilla.org/categorymanager;1"].
  1089.         getService(Ci.nsICategoryManager);
  1090.     catman.addCategoryEntry("JavaScript global constructor",
  1091.                             "BrowserFeedWriter", FW_CONTRACTID, true, true);
  1092.   },
  1093.   
  1094.   unregisterSelf: function M_unregisterSelf(cm, location, type) {
  1095.     var cr = cm.QueryInterface(Ci.nsIComponentRegistrar);
  1096.     cr.unregisterFactoryLocation(FW_CLASSID, location);
  1097.   },
  1098.   
  1099.   canUnload: function M_canUnload(cm) {
  1100.     return true;
  1101.   }
  1102. };
  1103.  
  1104. function NSGetModule(cm, file) {
  1105.   return Module;
  1106. }
  1107.  
  1108. //@line 44 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/../../../../toolkit/content/debug.js"
  1109.  
  1110. var gTraceOnAssert = true;
  1111.  
  1112. /**
  1113.  * This function provides a simple assertion function for JavaScript.
  1114.  * If the condition is true, this function will do nothing.  If the
  1115.  * condition is false, then the message will be printed to the console
  1116.  * and an alert will appear showing a stack trace, so that the (alpha
  1117.  * or nightly) user can file a bug containing it.  For future enhancements, 
  1118.  * see bugs 330077 and 330078.
  1119.  *
  1120.  * To suppress the dialogs, you can run with the environment variable
  1121.  * XUL_ASSERT_PROMPT set to 0 (if unset, this defaults to 1).
  1122.  *
  1123.  * @param condition represents the condition that we're asserting to be
  1124.  *                  true when we call this function--should be
  1125.  *                  something that can be evaluated as a boolean.
  1126.  * @param message   a string to be displayed upon failure of the assertion
  1127.  */
  1128.  
  1129. function NS_ASSERT(condition, message) {
  1130.   if (condition)
  1131.     return;
  1132.  
  1133.   var assertionText = "ASSERT: " + message + "\n";
  1134.  
  1135. //@line 72 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/../../../../toolkit/content/debug.js"
  1136.   Components.util.reportError(assertionText);
  1137.   return;
  1138. //@line 108 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/../../../../toolkit/content/debug.js"
  1139. }
  1140. //@line 37 "/cygdrive/c/builds/tinderbox/Fx-Mozilla1.8-release/WINNT_5.2_Depend/mozilla/browser/components/feeds/src/GenericFactory.js"
  1141.  
  1142. /**
  1143.  * An object implementing nsIFactory that can construct other objects upon
  1144.  * createInstance, passing a set of parameters to that object's constructor.
  1145.  */
  1146. function GenericComponentFactory(ctor, params) {
  1147.   this._ctor = ctor;
  1148.   this._params = params;
  1149. }
  1150. GenericComponentFactory.prototype = {
  1151.   _ctor: null,
  1152.   _params: null,
  1153.   
  1154.   createInstance: function GCF_createInstance(outer, iid) {
  1155.     if (outer != null)
  1156.       throw Cr.NS_ERROR_NO_AGGREGATION;
  1157.     return (new this._ctor(this._params)).QueryInterface(iid);
  1158.   },
  1159.   
  1160.   QueryInterface: function GCF_QueryInterface(iid) {
  1161.     if (iid.equals(Ci.nsIFactory) ||
  1162.         iid.equals(Ci.nsISupports)) 
  1163.       return this;
  1164.     throw Cr.NS_ERROR_NO_INTERFACE;
  1165.   }
  1166. };
  1167.  
  1168.