Bug 690778 Update nsFeedSniffer.cpp (Port part of Bug 589292 Add contentDisposition{Filename} properties to nsIChannel). r=Neil.
authorPhilip Chee <philip.chee@gmail.com>
Thu, 06 Oct 2011 23:51:28 +0800
changeset 8605 3f0cb19942bc5e536465d2a0a91ef647c81d0f02
parent 8604 b7be236800c64f9b40f758b7cc3ce7cd968e310a
child 8606 c6a8260db0aa54e116597f98fc11e2df9d0537d5
push id6616
push userphilip.chee@gmail.com
push dateThu, 06 Oct 2011 15:52:40 +0000
treeherdercomm-central@3f0cb19942bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs690778, 589292
Bug 690778 Update nsFeedSniffer.cpp (Port part of Bug 589292 Add contentDisposition{Filename} properties to nsIChannel). r=Neil.
suite/feeds/src/nsFeedSniffer.cpp
--- a/suite/feeds/src/nsFeedSniffer.cpp
+++ b/suite/feeds/src/nsFeedSniffer.cpp
@@ -122,60 +122,27 @@ nsFeedSniffer::ConvertEncodedData(nsIReq
 template<int N>
 static bool
 StringBeginsWithLowercaseLiteral(nsAString& aString,
                                  const char (&aSubstring)[N])
 {
   return StringHead(aString, N).LowerCaseEqualsLiteral(aSubstring);
 }
 
-// XXXsayrer put this in here to get on the branch with minimal delay.
-// Trunk really needs to factor this out. This is the third usage.
 bool
 HasAttachmentDisposition(nsIHttpChannel* httpChannel)
 {
   if (!httpChannel)
     return PR_FALSE;
 
-  nsCAutoString contentDisposition;
-  nsresult rv =
-    httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("content-disposition"),
-                                   contentDisposition);
+  PRUint32 disp;
+  nsresult rv = httpChannel->GetContentDisposition(&disp);
 
-  if (NS_SUCCEEDED(rv) && !contentDisposition.IsEmpty()) {
-    nsCOMPtr<nsIURI> uri;
-    httpChannel->GetURI(getter_AddRefs(uri));
-    nsCOMPtr<nsIMIMEHeaderParam> mimehdrpar =
-      do_GetService(NS_MIMEHEADERPARAM_CONTRACTID, &rv);
-    if (NS_SUCCEEDED(rv))
-    {
-      nsCAutoString fallbackCharset;
-      if (uri)
-        uri->GetOriginCharset(fallbackCharset);
-      nsAutoString dispToken;
-      // Get the disposition type
-      rv = mimehdrpar->GetParameter(contentDisposition, "", fallbackCharset,
-                                    PR_TRUE, nsnull, dispToken);
-      // RFC 2183, section 2.8 says that an unknown disposition
-      // value should be treated as "attachment"
-      // XXXbz this code is duplicated in GetFilenameAndExtensionFromChannel in
-      // nsExternalHelperAppService.  Factor it out!
-      if (NS_FAILED(rv) ||
-          (!dispToken.IsEmpty() &&
-           !StringBeginsWithLowercaseLiteral(dispToken, "inline") &&
-           // Broken sites just send
-           // Content-Disposition: filename="file"
-           // without a disposition token... screen those out.
-           !StringBeginsWithLowercaseLiteral(dispToken, "filename") &&
-           // Also in use is Content-Disposition: name="file"
-           !StringBeginsWithLowercaseLiteral(dispToken, "name")))
-        // We have a content-disposition of "attachment" or unknown
-        return PR_TRUE;
-    }
-  }
+  if (NS_SUCCEEDED(rv) && disp == nsIChannel::DISPOSITION_ATTACHMENT)
+    return PR_TRUE;
 
   return PR_FALSE;
 }
 
 /**
  * @return the first occurrence of a character within a string buffer,
  *         or nsnull if not found
  */