Bug 413915 - isValidFeed modifies its first paramter, r=sayrer
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Sat, 06 Sep 2008 19:28:36 -0700
changeset 18915 c989ea4a711965e63552a19bb66a5cef28c6e0bf
parent 18914 41790e7f7ae2fe9c1611c0c6cc2b9664e7368c0c
child 18916 551b4e4c78135bb25e9304453bb61475a6724eb6
push id1821
push userphilringnalda@gmail.com
push dateSun, 07 Sep 2008 02:29:33 +0000
treeherderautoland@c989ea4a7119 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssayrer
bugs413915
milestone1.9.1b1pre
Bug 413915 - isValidFeed modifies its first paramter, r=sayrer
browser/base/content/browser.js
browser/base/content/pageinfo/feeds.js
browser/base/content/utilityOverlay.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2820,19 +2820,18 @@ const DOMLinkHandler = {
     for (let relVal in rels) {
       switch (relVal) {
         case "feed":
         case "alternate":
           if (!feedAdded) {
             if (!rels.feed && rels.alternate && rels.stylesheet)
               break;
 
-            var feed = { title: link.title, href: link.href, type: link.type };
-            if (isValidFeed(feed, link.ownerDocument.nodePrincipal, rels.feed)) {
-              FeedHandler.addFeed(feed, link.ownerDocument);
+            if (isValidFeed(link, link.ownerDocument.nodePrincipal, rels.feed)) {
+              FeedHandler.addFeed(link, link.ownerDocument);
               feedAdded = true;
             }
           }
           break;
         case "icon":
           if (!iconAdded) {
             if (!gPrefService.getBoolPref("browser.chrome.site_icons"))
               break;
--- a/browser/base/content/pageinfo/feeds.js
+++ b/browser/base/content/pageinfo/feeds.js
@@ -57,19 +57,19 @@ function initFeedTab()
     var rel = link.rel && link.rel.toLowerCase();
     var rels = {};
     if (rel) {
       for each (let relVal in rel.split(/\s+/))
         rels[relVal] = true;
     }
 
     if (rels.feed || (link.type && rels.alternate && !rels.stylesheet)) {
-      var feed = { title: link.title, href: link.href, type: link.type || "" };
-      if (isValidFeed(feed, gDocument.nodePrincipal, rels.feed)) {
-        var type = feedTypes[feed.type] || feedTypes["application/rss+xml"];
+      var type = isValidFeed(link, gDocument.nodePrincipal, rels.feed);
+      if (type) {
+        type = feedTypes[type] || feedTypes["application/rss+xml"];
         addRow(feed.title, type, feed.href);
       }
     }
   }
 
   var feedListbox = document.getElementById("feedListbox");
   document.getElementById("feedTab").hidden = feedListbox.getRowCount() == 0;
 }
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -626,51 +626,46 @@ function openNewWindowWith(aURL, aDocume
   return window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no",
                            aURL, charsetArg, referrerURI, aPostData,
                            aAllowThirdPartyFixup);
 }
 
 /**
  * isValidFeed: checks whether the given data represents a valid feed.
  *
- * @param  aData
+ * @param  aLink
  *         An object representing a feed with title, href and type.
  * @param  aPrincipal
  *         The principal of the document, used for security check.
  * @param  aIsFeed
  *         Whether this is already a known feed or not, if true only a security
  *         check will be performed.
  */ 
-function isValidFeed(aData, aPrincipal, aIsFeed)
+function isValidFeed(aLink, aPrincipal, aIsFeed)
 {
-  if (!aData || !aPrincipal)
+  if (!aLink || !aPrincipal)
     return false;
 
+  var type = aLink.type.toLowerCase().replace(/^\s+|\s*(?:;.*)?$/g, "");
   if (!aIsFeed) {
-    var type = aData.type && aData.type.toLowerCase();
-    type = type.replace(/^\s+|\s*(?:;.*)?$/g, "");
-
     aIsFeed = (type == "application/rss+xml" ||
                type == "application/atom+xml");
   }
 
   if (aIsFeed) {
     try {
-      urlSecurityCheck(aData.href, aPrincipal,
+      urlSecurityCheck(aLink.href, aPrincipal,
                        Components.interfaces.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
+      return type || "application/rss+xml";
     }
     catch(ex) {
-      aIsFeed = false;
     }
   }
 
-  if (type)
-    aData.type = type;
-
-  return aIsFeed;
+  return null;
 }
 
 // aCalledFromModal is optional
 function openHelpLink(aHelpTopic, aCalledFromModal) {
   var url = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"]
                       .getService(Components.interfaces.nsIURLFormatter)
                       .formatURLPref("app.support.baseURL");
   url += aHelpTopic;