| ... | 
... | 
@@ -292,34 +292,42 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest* request) { | 
| 
292
 | 
292
 | 
   LOG(("  forceExternalHandling: %s", forceExternalHandling ? "yes" : "no"));
 | 
| 
293
 | 
293
 | 
 
  | 
| 
294
 | 
294
 | 
   if (forceExternalHandling &&
  | 
| 
295
 | 
 
 | 
-      mozilla::StaticPrefs::browser_download_open_pdf_attachments_inline()) {
 | 
| 
 
 | 
295
 | 
+      (mozilla::StaticPrefs::browser_download_open_pdf_attachments_inline() ||
  | 
| 
 
 | 
296
 | 
+       mozilla::StaticPrefs::browser_download_ignore_content_disposition())) {
 | 
| 
296
 | 
297
 | 
     // Check if this is a PDF which should be opened internally. We also handle
  | 
| 
297
 | 
298
 | 
     // octet-streams that look like they might be PDFs based on their extension.
  | 
| 
298
 | 
299
 | 
     bool isPDF = mContentType.LowerCaseEqualsASCII(APPLICATION_PDF);
  | 
| 
299
 | 
 
 | 
-    if (!isPDF &&
  | 
| 
300
 | 
 
 | 
-        (mContentType.LowerCaseEqualsASCII(APPLICATION_OCTET_STREAM) ||
  | 
| 
301
 | 
 
 | 
-         mContentType.IsEmpty())) {
 | 
| 
 
 | 
300
 | 
+    nsAutoCString ext;
  | 
| 
 
 | 
301
 | 
+    if (mContentType.LowerCaseEqualsASCII(APPLICATION_OCTET_STREAM) ||
  | 
| 
 
 | 
302
 | 
+        mContentType.IsEmpty()) {
 | 
| 
302
 | 
303
 | 
       nsAutoString flname;
  | 
| 
303
 | 
304
 | 
       aChannel->GetContentDispositionFilename(flname);
  | 
| 
304
 | 
 
 | 
-      isPDF = StringEndsWith(flname, u".pdf"_ns);
  | 
| 
305
 | 
 
 | 
-      if (!isPDF) {
 | 
| 
 
 | 
305
 | 
+      if (!flname.IsEmpty()) {
 | 
| 
 
 | 
306
 | 
+        int32_t extStart = flname.RFindChar(u'.');
  | 
| 
 
 | 
307
 | 
+        if (extStart != kNotFound) {
 | 
| 
 
 | 
308
 | 
+          CopyUTF16toUTF8(Substring(flname, extStart + 1), ext);
  | 
| 
 
 | 
309
 | 
+        }
  | 
| 
 
 | 
310
 | 
+      }
  | 
| 
 
 | 
311
 | 
+      if (ext.IsEmpty() || (!mozilla::StaticPrefs::
  | 
| 
 
 | 
312
 | 
+                                browser_download_ignore_content_disposition() &&
  | 
| 
 
 | 
313
 | 
+                            !ext.EqualsLiteral("pdf"))) {
 | 
| 
306
 | 
314
 | 
         nsCOMPtr<nsIURI> uri;
  | 
| 
307
 | 
315
 | 
         aChannel->GetURI(getter_AddRefs(uri));
  | 
| 
308
 | 
316
 | 
         nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
  | 
| 
309
 | 
317
 | 
         if (url) {
 | 
| 
310
 | 
 
 | 
-          nsAutoCString ext;
  | 
| 
311
 | 
318
 | 
           url->GetFileExtension(ext);
  | 
| 
312
 | 
 
 | 
-          isPDF = ext.EqualsLiteral("pdf");
 | 
| 
313
 | 
319
 | 
         }
  | 
| 
314
 | 
320
 | 
       }
  | 
| 
 
 | 
321
 | 
+      isPDF = ext.EqualsLiteral("pdf");
 | 
| 
315
 | 
322
 | 
     }
  | 
| 
316
 | 
323
 | 
 
  | 
| 
317
 | 
 
 | 
-    // For a PDF, check if the preference is set that forces attachments to be
  | 
| 
318
 | 
 
 | 
-    // opened inline. If so, treat it as a non-attachment by clearing
  | 
| 
319
 | 
 
 | 
-    // 'forceExternalHandling' again. This allows it open a PDF directly
  | 
| 
320
 | 
 
 | 
-    // instead of downloading it first. It may still end up being handled by
  | 
| 
321
 | 
 
 | 
-    // a helper app depending anyway on the later checks.
  | 
| 
322
 | 
 
 | 
-    if (isPDF) {
 | 
| 
 
 | 
324
 | 
+    // One of the preferences to forces attachments to be opened inline is set.
  | 
| 
 
 | 
325
 | 
+    // If so, treat it as a non-attachment by clearing 'forceExternalHandling'
  | 
| 
 
 | 
326
 | 
+    // again. This allows it open a file directly instead of downloading it
  | 
| 
 
 | 
327
 | 
+    // first. It may still end up being handled by a helper app depending anyway
  | 
| 
 
 | 
328
 | 
+    // on the later checks.
  | 
| 
 
 | 
329
 | 
+    if (mozilla::StaticPrefs::browser_download_ignore_content_disposition() ||
  | 
| 
 
 | 
330
 | 
+        isPDF) {
 | 
| 
323
 | 
331
 | 
       nsCOMPtr<nsILoadInfo> loadInfo;
  | 
| 
324
 | 
332
 | 
       aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
  | 
| 
325
 | 
333
 | 
 
  | 
| ... | 
... | 
@@ -328,8 +336,13 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest* request) { | 
| 
328
 | 
336
 | 
       nsCOMPtr<nsIMIMEService> mimeSvc(
  | 
| 
329
 | 
337
 | 
           do_GetService(NS_MIMESERVICE_CONTRACTID));
  | 
| 
330
 | 
338
 | 
       NS_ENSURE_TRUE(mimeSvc, NS_ERROR_FAILURE);
  | 
| 
331
 | 
 
 | 
-      mimeSvc->GetFromTypeAndExtension(nsLiteralCString(APPLICATION_PDF), ""_ns,
  | 
| 
332
 | 
 
 | 
-                                       getter_AddRefs(mimeInfo));
  | 
| 
 
 | 
339
 | 
+      if (isPDF) {
 | 
| 
 
 | 
340
 | 
+        mimeSvc->GetFromTypeAndExtension(nsLiteralCString(APPLICATION_PDF),
  | 
| 
 
 | 
341
 | 
+                                         ""_ns, getter_AddRefs(mimeInfo));
  | 
| 
 
 | 
342
 | 
+      } else {
 | 
| 
 
 | 
343
 | 
+        mimeSvc->GetFromTypeAndExtension(mContentType, ext,
  | 
| 
 
 | 
344
 | 
+                                         getter_AddRefs(mimeInfo));
  | 
| 
 
 | 
345
 | 
+      }
  | 
| 
333
 | 
346
 | 
 
  | 
| 
334
 | 
347
 | 
       if (mimeInfo) {
 | 
| 
335
 | 
348
 | 
         int32_t action = nsIMIMEInfo::saveToDisk;
  |