mozilla-bmo1822730.patch
branchfirefox117
changeset 1193 16de98d33e97
child 1200 2a0735b1eb92
equal deleted inserted replaced
1192:7612b8d8c46f 1193:16de98d33e97
       
     1 # HG changeset patch
       
     2 # User Rob Krum <biggestsonicfan@gmail.com>
       
     3 # Date 1695432215 25200
       
     4 #      Fri Sep 22 18:23:35 2023 -0700
       
     5 # Node ID e6a8a9f0956d124e8de34eb4bcf09d8e17077d9d
       
     6 # Parent  677cbf2e64cdcd3a93e644f781be2bdc2529ba1a
       
     7 Bug 1822730 - Add basic blob protocol handling for blob URIs that contain parsable http/s protocols
       
     8 
       
     9 diff --git a/toolkit/mozapps/downloads/DownloadLastDir.sys.mjs b/toolkit/mozapps/downloads/DownloadLastDir.sys.mjs
       
    10 --- a/toolkit/mozapps/downloads/DownloadLastDir.sys.mjs
       
    11 +++ b/toolkit/mozapps/downloads/DownloadLastDir.sys.mjs
       
    12 @@ -221,11 +221,13 @@ export class DownloadLastDir {
       
    13  
       
    14    /**
       
    15     * Pre-processor to extract a domain name to be used with the content-prefs
       
    16 -   * service. This specially handles data and file URIs so that the download
       
    17 -   * dirs are recalled in a more consistent way:
       
    18 +   * service. This specially handles data, file and blob URIs so that the
       
    19 +   * download dirs are recalled in a more consistent way:
       
    20     *  - all file:/// URIs share the same folder
       
    21     *  - data: URIs share a folder per mime-type. If a mime-type is not
       
    22     *    specified text/plain is assumed.
       
    23 +   *  - blob: blob URIs are tested for http/https and the blob protocol
       
    24 +   *    is stripped.
       
    25     * In any other case the original URL is returned as a string and ContentPrefs
       
    26     * will do its usual parsing.
       
    27     *
       
    28 @@ -234,6 +236,9 @@ export class DownloadLastDir {
       
    29     */
       
    30    #cpsGroupFromURL(url) {
       
    31      if (typeof url == "string") {
       
    32 +      if (url.startsWith("blob:http://") || url.startsWith("blob:https://")) {
       
    33 +        url = url.replace("blob:", "");
       
    34 +      }
       
    35        url = new URL(url);
       
    36      } else if (url instanceof Ci.nsIURI) {
       
    37        url = URL.fromURI(url);
       
    38 @@ -241,6 +246,14 @@ export class DownloadLastDir {
       
    39      if (!URL.isInstance(url)) {
       
    40        return url;
       
    41      }
       
    42 +    if (url.protocol == "blob:") {
       
    43 +      if (
       
    44 +        url.href.startsWith("blob:http://") ||
       
    45 +        url.href.startsWith("blob:https://")
       
    46 +      ) {
       
    47 +        return url.href.replace("blob:", "");
       
    48 +      }
       
    49 +    }
       
    50      if (url.protocol == "data:") {
       
    51        return url.href.match(/^data:[^;,]*/i)[0].replace(/:$/, ":text/plain");
       
    52      }