[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [Git][tpo/applications/tor-browser][base-browser-128.2.0esr-14.0-1] Bug 42220: Allow for more file types to be forced-inline.



Title: GitLab

Pier Angelo Vendrame pushed to branch base-browser-128.2.0esr-14.0-1 at The Tor Project / Applications / Tor Browser

Commits:

  • d72c2984
    by Pier Angelo Vendrame at 2024-09-18T15:36:07+02:00
    Bug 42220: Allow for more file types to be forced-inline.
    
    Firefox allows to open some files in the browser without any
    confirmation, but this will result in a disk leak, because the file will
    be downloaded to the temporary directory first (and not deleted, in some
    cases).
    A preference allows PDFs to be opened without being downloaded to disk.
    So, we introduce a similar one to do the same for all the files that are
    set to be opened automatically in the browser.
    

2 changed files:

Changes:

  • modules/libpref/init/StaticPrefList.yaml
    ... ... @@ -1446,6 +1446,12 @@
    1446 1446
       value: false
    
    1447 1447
       mirror: always
    
    1448 1448
     
    
    1449
    +# tor-browser#42220
    
    1450
    +- name: browser.download.ignore_content_disposition
    
    1451
    +  type: bool
    
    1452
    +  value: true
    
    1453
    +  mirror: always
    
    1454
    +
    
    1449 1455
     # See bug 1811830
    
    1450 1456
     - name: browser.download.force_save_internally_handled_attachments
    
    1451 1457
       type: bool
    

  • uriloader/base/nsURILoader.cpp
    ... ... @@ -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;
    

  • _______________________________________________
    tor-commits mailing list
    tor-commits@xxxxxxxxxxxxxxxxxxxx
    https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits