Richard Pospesel pushed to branch tor-browser-102.10.0esr-12.5-1 at The Tor Project / Applications / Tor Browser

Commits:

12 changed files:

Changes:

  • browser/app/profile/000-tor-browser.js
    ... ... @@ -64,11 +64,15 @@ pref("extensions.torbutton.startup", false);
    64 64
     
    
    65 65
     // Security prefs:
    
    66 66
     pref("extensions.torbutton.resize_new_windows", false);
    
    67
    -pref("extensions.torbutton.launch_warning", true);
    
    68 67
     
    
    69 68
     // Browser home page:
    
    70 69
     pref("browser.startup.homepage", "about:tor");
    
    71 70
     
    
    71
    +// tor-browser#40701: Add new download warning and flipping prefs to match Firefox
    
    72
    +pref("browser.download.useDownloadDir", true);
    
    73
    +pref("browser.download.always_ask_before_handling_new_types", false);
    
    74
    +pref("browser.download.showTorWarning", true);
    
    75
    +
    
    72 76
     // This pref specifies an ad-hoc "version" for various pref update hacks we need to do
    
    73 77
     pref("extensions.torbutton.pref_fixup_version", 0);
    
    74 78
     
    

  • browser/components/downloads/content/downloads.css
    ... ... @@ -95,6 +95,32 @@
    95 95
       padding: 0.62em;
    
    96 96
     }
    
    97 97
     
    
    98
    +#downloadsPanel-mainView {
    
    99
    +  /* Fix the layout to ensure the #downloadsWarningDescription is given enough
    
    100
    +   * vertical space. For tor-browser#40701.
    
    101
    +   * TODO: May no longer be necessary after esr 115 due to bugzilla bug 1816455.
    
    102
    +   */
    
    103
    +  display: flex;
    
    104
    +  flex-direction: column;
    
    105
    +}
    
    106
    +
    
    107
    +#downloadsWarning p {
    
    108
    +  padding-inline: 8px;
    
    109
    +  margin-block-start: 8px;
    
    110
    +  margin-block-end: 0;
    
    111
    +  line-height: 1.4;
    
    112
    +}
    
    113
    +
    
    114
    +#downloadsWarningHeaderTitle {
    
    115
    +  font-weight: bold;
    
    116
    +}
    
    117
    +
    
    118
    +#downloadsWarningDescription {
    
    119
    +  /* Make sure we wrap the text rather than request the default max-content
    
    120
    +   * width from the parent XUL -moz-box. */
    
    121
    +  width: 0;
    
    122
    +}
    
    123
    +
    
    98 124
     #downloadsHistory,
    
    99 125
     #downloadsFooterButtons {
    
    100 126
       margin: 0;
    

  • browser/components/downloads/content/downloads.js
    ... ... @@ -31,6 +31,10 @@
    31 31
     
    
    32 32
     "use strict";
    
    33 33
     
    
    34
    +const PREF_SHOW_DOWNLOAD_WARNING = "browser.download.showTorWarning";
    
    35
    +
    
    36
    +const TAILS_URI = "https://tails.boum.org/";
    
    37
    +
    
    34 38
     var { XPCOMUtils } = ChromeUtils.import(
    
    35 39
       "resource://gre/modules/XPCOMUtils.jsm"
    
    36 40
     );
    
    ... ... @@ -93,6 +97,13 @@ var DownloadsPanel = {
    93 97
        */
    
    94 98
       _state: 0,
    
    95 99
     
    
    100
    +  /**
    
    101
    +   * State of tor's download warning. It should only be initialized once (text assigned,
    
    102
    +   * button commands assigned). This tracks if that has been performed and prevents
    
    103
    +   * repeats.
    
    104
    +   */
    
    105
    +  _torWarningInitialized: false,
    
    106
    +
    
    96 107
       /** The panel is not linked to downloads data yet. */
    
    97 108
       get kStateUninitialized() {
    
    98 109
         return 0;
    
    ... ... @@ -132,6 +143,15 @@ var DownloadsPanel = {
    132 143
           );
    
    133 144
         }
    
    134 145
     
    
    146
    +    let showDownloadWarning = Services.prefs.getBoolPref(
    
    147
    +      PREF_SHOW_DOWNLOAD_WARNING
    
    148
    +    );
    
    149
    +    if (!showDownloadWarning) {
    
    150
    +      document.getElementById("downloadsWarning").hidden = true;
    
    151
    +    } else {
    
    152
    +      document.getElementById("downloadsWarning").hidden = false;
    
    153
    +    }
    
    154
    +
    
    135 155
         if (this._state != this.kStateUninitialized) {
    
    136 156
           DownloadsCommon.log("DownloadsPanel is already initialized.");
    
    137 157
           return;
    
    ... ... @@ -155,6 +175,44 @@ var DownloadsPanel = {
    155 175
           DownloadsSummary
    
    156 176
         );
    
    157 177
     
    
    178
    +    if (this._torWarningInitialized == 0) {
    
    179
    +      document.getElementById(
    
    180
    +        "downloadsWarningHeaderTitle"
    
    181
    +      ).textContent = this._getString("torbutton.download.warning.title");
    
    182
    +      let tailsBrandName = this._getString(
    
    183
    +        "torbutton.download.warning.tails_brand_name"
    
    184
    +      );
    
    185
    +
    
    186
    +      let warningDescriptionText = this._getString(
    
    187
    +        "torbutton.download.warning.description"
    
    188
    +      );
    
    189
    +      let [head, rest] = warningDescriptionText.split("%S");
    
    190
    +      const tailsLink = document.createElement("a");
    
    191
    +      tailsLink.setAttribute("href", TAILS_URI);
    
    192
    +      tailsLink.textContent = tailsBrandName.trim();
    
    193
    +      tailsLink.addEventListener("click", event => {
    
    194
    +        event.preventDefault();
    
    195
    +        this.hidePanel();
    
    196
    +        openWebLinkIn(TAILS_URI, "tab");
    
    197
    +      });
    
    198
    +
    
    199
    +      let downloadsWarningDescription = document.getElementById(
    
    200
    +        "downloadsWarningDescription"
    
    201
    +      );
    
    202
    +      downloadsWarningDescription.append(head, tailsLink, rest);
    
    203
    +
    
    204
    +      let dismissBtn = document.getElementById(
    
    205
    +        "downloadWarningDismiss"
    
    206
    +      );
    
    207
    +      dismissBtn.textContent = this._getString("torbutton.download.warning.dismiss");
    
    208
    +      dismissBtn.addEventListener("click", event => {
    
    209
    +        Services.prefs.setBoolPref(PREF_SHOW_DOWNLOAD_WARNING, false);
    
    210
    +        document.getElementById("downloadsWarning").hidden = true;
    
    211
    +        this._focusPanel(true);
    
    212
    +      });
    
    213
    +      this._torWarningInitialized = 1;
    
    214
    +    }
    
    215
    +
    
    158 216
         DownloadsCommon.log(
    
    159 217
           "DownloadsView attached - the panel for this window",
    
    160 218
           "should now see download items come in."
    
    ... ... @@ -530,16 +588,21 @@ var DownloadsPanel = {
    530 588
       /**
    
    531 589
        * Move focus to the main element in the downloads panel, unless another
    
    532 590
        * element in the panel is already focused.
    
    591
    +   *
    
    592
    +   * @param {bool} [forceFocus=false] - Whether to force move the focus.
    
    533 593
        */
    
    534
    -  _focusPanel() {
    
    535
    -    // We may be invoked while the panel is still waiting to be shown.
    
    536
    -    if (this._state != this.kStateShown) {
    
    537
    -      return;
    
    538
    -    }
    
    594
    +  _focusPanel(forceFocus=false) {
    
    595
    +    if (!forceFocus) {
    
    596
    +      // We may be invoked while the panel is still waiting to be shown.
    
    597
    +      if (this._state != this.kStateShown) {
    
    598
    +        return;
    
    599
    +      }
    
    539 600
     
    
    540
    -    if (document.activeElement && this.panel.contains(document.activeElement)) {
    
    541
    -      return;
    
    601
    +      if (document.activeElement && this.panel.contains(document.activeElement)) {
    
    602
    +        return;
    
    603
    +      }
    
    542 604
         }
    
    605
    +
    
    543 606
         let focusOptions = { preventFocusRing: !!this._preventFocusRing };
    
    544 607
         if (DownloadsView.richListBox.itemCount > 0) {
    
    545 608
           DownloadsView.richListBox.selectedIndex = 0;
    
    ... ... @@ -658,6 +721,30 @@ var DownloadsPanel = {
    658 721
           }
    
    659 722
         }, 0);
    
    660 723
       },
    
    724
    +
    
    725
    +  /**
    
    726
    +   * Get a string from the properties bundle.
    
    727
    +   *
    
    728
    +   * @param {string} name - The string name.
    
    729
    +   *
    
    730
    +   * @return {string} The string.
    
    731
    +   */
    
    732
    +  _getString(name) {
    
    733
    +    if (!this._stringBundle) {
    
    734
    +      this._stringBundle = Services.strings.createBundle(
    
    735
    +        "chrome://torbutton/locale/torbutton.properties"
    
    736
    +      );
    
    737
    +    }
    
    738
    +    try {
    
    739
    +      return this._stringBundle.GetStringFromName(name);
    
    740
    +    } catch {}
    
    741
    +    if (!this._fallbackStringBundle) {
    
    742
    +      this._fallbackStringBundle = Services.strings.createBundle(
    
    743
    +        "resource://torbutton/locale/en-US/torbutton.properties"
    
    744
    +      );
    
    745
    +    }
    
    746
    +    return this._fallbackStringBundle.GetStringFromName(name);
    
    747
    +  },
    
    661 748
     };
    
    662 749
     
    
    663 750
     XPCOMUtils.defineConstant(this, "DownloadsPanel", DownloadsPanel);
    

  • browser/components/downloads/content/downloadsPanel.inc.xhtml
    ... ... @@ -124,6 +124,21 @@
    124 124
                       disablekeynav="true">
    
    125 125
     
    
    126 126
         <panelview id="downloadsPanel-mainView">
    
    127
    +      <vbox id="downloadsWarning">
    
    128
    +        <vbox role="alert"
    
    129
    +              aria-labelledby="downloadsWarningHeaderTitle"
    
    130
    +              aria-describedby="downloadsWarningDescription">
    
    131
    +          <html:p id="downloadsWarningHeaderTitle"></html:p>
    
    132
    +          <html:p id="downloadsWarningDescription">
    
    133
    +          </html:p>
    
    134
    +
    
    135
    +          <html:div class="panel-footer">
    
    136
    +            <html:button id="downloadWarningDismiss">
    
    137
    +            </html:button>
    
    138
    +          </html:div>
    
    139
    +        </vbox>
    
    140
    +        <toolbarseparator />
    
    141
    +      </vbox>
    
    127 142
           <vbox class="panel-view-body-unscrollable">
    
    128 143
             <richlistbox id="downloadsListBox"
    
    129 144
                          data-l10n-id="downloads-panel-items"
    

  • browser/themes/shared/customizableui/panelUI-shared.css
    ... ... @@ -1324,6 +1324,7 @@ panelview .toolbarbutton-1 {
    1324 1324
     #downloadsFooterButtons > toolbarseparator,
    
    1325 1325
     .cui-widget-panelview menuseparator,
    
    1326 1326
     .cui-widget-panel toolbarseparator,
    
    1327
    +#downloadsWarning toolbarseparator,
    
    1327 1328
     #securityLevel-panel toolbarseparator {
    
    1328 1329
       appearance: none;
    
    1329 1330
       min-height: 0;
    

  • browser/themes/shared/downloads/downloads.inc.css
    ... ... @@ -258,6 +258,7 @@
    258 258
     }
    
    259 259
     
    
    260 260
     /*** Toolbarseparator ***/
    
    261
    +#downloadsWarning toolbarseparator,
    
    261 262
     #downloadsFooterButtons > toolbarseparator {
    
    262 263
       margin-inline: 0;
    
    263 264
     }

  • toolkit/torbutton/chrome/locale/en-US/torbutton.properties
    ... ... @@ -32,7 +32,7 @@ torbutton.circuit_display.click_to_copy = Click to Copy
    32 32
     torbutton.circuit_display.copied = Copied!
    
    33 33
     # end
    
    34 34
     
    
    35
    -# External app blocker
    
    35
    +# External app blocker strings used up to 12.0 - TODO: remove when 12.5 becomes stable:
    
    36 36
     torbutton.popup.external.title = Download an external file type?
    
    37 37
     torbutton.popup.external.app = Tor Browser cannot display this file. You will need to open it with another application.\n\n
    
    38 38
     torbutton.popup.external.note = Some types of files can cause applications to connect to the Internet without using Tor.\n\n
    
    ... ... @@ -41,6 +41,14 @@ torbutton.popup.launch = Download file
    41 41
     torbutton.popup.cancel = Cancel
    
    42 42
     torbutton.popup.dontask = Automatically download files from now on
    
    43 43
     
    
    44
    +# Download pane warning
    
    45
    +torbutton.download.warning.title = Be careful opening downloads
    
    46
    +# %S will be a link to the Tails operating system website. With the content given by torbutton.download.warning.tails_brand_name
    
    47
    +torbutton.download.warning.description = Some files may connect to the internet when opened without using Tor. To be safe, open the files while offline or use a portable operating system like %S.
    
    48
    +# Locale name for Tails operating system.
    
    49
    +torbutton.download.warning.tails_brand_name = Tails
    
    50
    +torbutton.download.warning.dismiss = Got it
    
    51
    +
    
    44 52
     # .Onion Page Info prompt.
    
    45 53
     pageInfo_OnionEncryptionWithBitsAndProtocol=Connection Encrypted (Onion Service, %1$S, %2$S bit keys, %3$S)
    
    46 54
     pageInfo_OnionEncryption=Connection Encrypted (Onion Service)
    

  • toolkit/torbutton/components/external-app-blocker.js deleted
    1
    -// Bug 1506 Android P1/TBB P5: This code provides users with notification
    
    2
    -// in the event of external app launch. We want it to exist in the desktop
    
    3
    -// port, but it is probably useless for Android.
    
    4
    -
    
    5
    -/*************************************************************************
    
    6
    - * External App Handler.
    
    7
    - * Handles displaying confirmation dialogs for external apps and protocols
    
    8
    - * due to Firefox Bug https://bugzilla.mozilla.org/show_bug.cgi?id=440892
    
    9
    - *
    
    10
    - * An instance of this module is created each time the browser starts to
    
    11
    - * download a file and when an external application may be invoked to
    
    12
    - * handle an URL (e.g., when the user clicks on a mailto: URL).
    
    13
    - *************************************************************************/
    
    14
    -
    
    15
    -const { XPCOMUtils } = ChromeUtils.import(
    
    16
    -  "resource://gre/modules/XPCOMUtils.jsm"
    
    17
    -);
    
    18
    -const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
    
    19
    -const { PromptUtils } = ChromeUtils.import(
    
    20
    -  "resource://gre/modules/SharedPromptUtils.jsm"
    
    21
    -);
    
    22
    -
    
    23
    -XPCOMUtils.defineLazyModuleGetters(this, {
    
    24
    -  ComponentUtils: "resource://gre/modules/ComponentUtils.jsm",
    
    25
    -});
    
    26
    -
    
    27
    -let { torbutton_get_property_string } = ChromeUtils.import(
    
    28
    -  "resource://torbutton/modules/utils.js"
    
    29
    -);
    
    30
    -
    
    31
    -// Module specific constants
    
    32
    -const kMODULE_NAME = "Torbutton External App Handler";
    
    33
    -const kCONTRACT_ID = "@torproject.org/torbutton-extAppBlocker;1";
    
    34
    -const kMODULE_CID = Components.ID("3da0269f-fc29-4e9e-a678-c3b1cafcf13f");
    
    35
    -
    
    36
    -const kInterfaces = [Ci.nsIObserver, Ci.nsIClassInfo];
    
    37
    -
    
    38
    -function ExternalAppBlocker() {
    
    39
    -  this.logger = Cc["@torproject.org/torbutton-logger;1"].getService(
    
    40
    -    Ci.nsISupports
    
    41
    -  ).wrappedJSObject;
    
    42
    -  this.logger.log(3, "Component Load 0: New ExternalAppBlocker.");
    
    43
    -}
    
    44
    -
    
    45
    -ExternalAppBlocker.prototype = {
    
    46
    -  _helperAppLauncher: undefined,
    
    47
    -
    
    48
    -  QueryInterface: ChromeUtils.generateQI([
    
    49
    -    Ci.nsIObserver,
    
    50
    -    Ci.nsIHelperAppWarningDialog,
    
    51
    -  ]),
    
    52
    -
    
    53
    -  // make this an nsIClassInfo object
    
    54
    -  flags: Ci.nsIClassInfo.DOM_OBJECT,
    
    55
    -  classDescription: kMODULE_NAME,
    
    56
    -  contractID: kCONTRACT_ID,
    
    57
    -  classID: kMODULE_CID,
    
    58
    -
    
    59
    -  // method of nsIClassInfo
    
    60
    -  getInterfaces(count) {
    
    61
    -    count.value = kInterfaces.length;
    
    62
    -    return kInterfaces;
    
    63
    -  },
    
    64
    -
    
    65
    -  // method of nsIClassInfo
    
    66
    -  getHelperForLanguage(count) {
    
    67
    -    return null;
    
    68
    -  },
    
    69
    -
    
    70
    -  // method of nsIHelperAppWarningDialog
    
    71
    -  maybeShow(aLauncher, aWindowContext) {
    
    72
    -    // Hold a reference to the object that called this component. This is
    
    73
    -    // important not just because we need to later invoke the
    
    74
    -    // continueRequest() or cancelRequest() callback on aLauncher, but also
    
    75
    -    // so that the launcher object (which is a reference counted object) is
    
    76
    -    // not released too soon.
    
    77
    -    this._helperAppLauncher = aLauncher;
    
    78
    -
    
    79
    -    if (!Services.prefs.getBoolPref("extensions.torbutton.launch_warning")) {
    
    80
    -      this._helperAppLauncher.continueRequest();
    
    81
    -      return;
    
    82
    -    }
    
    83
    -
    
    84
    -    this._showPrompt(aWindowContext);
    
    85
    -  },
    
    86
    -
    
    87
    -  /*
    
    88
    -   * The _showPrompt() implementation uses some XUL and JS that is part of the
    
    89
    -   * browser's confirmEx() implementation. Specifically, _showPrompt() depends
    
    90
    -   * on chrome://global/content/commonDialog.xhtml as well as some of the code
    
    91
    -   * in resource://gre/modules/SharedPromptUtils.jsm.
    
    92
    -   */
    
    93
    -  _showPrompt(aWindowContext) {
    
    94
    -    let parentWin;
    
    95
    -    try {
    
    96
    -      parentWin = aWindowContext.getInterface(Ci.nsIDOMWindow);
    
    97
    -    } catch (e) {
    
    98
    -      parentWin = Services.wm.getMostRecentWindow("navigator:browser");
    
    99
    -    }
    
    100
    -
    
    101
    -    let title = torbutton_get_property_string("torbutton.popup.external.title");
    
    102
    -    let app = torbutton_get_property_string("torbutton.popup.external.app");
    
    103
    -    let note = torbutton_get_property_string("torbutton.popup.external.note");
    
    104
    -    let suggest = torbutton_get_property_string(
    
    105
    -      "torbutton.popup.external.suggest"
    
    106
    -    );
    
    107
    -    let launch = torbutton_get_property_string("torbutton.popup.launch");
    
    108
    -    let cancel = torbutton_get_property_string("torbutton.popup.cancel");
    
    109
    -    let dontask = torbutton_get_property_string("torbutton.popup.dontask");
    
    110
    -
    
    111
    -    let args = {
    
    112
    -      promptType: "confirmEx",
    
    113
    -      title,
    
    114
    -      text: app + note + suggest + " ",
    
    115
    -      checkLabel: dontask,
    
    116
    -      checked: false,
    
    117
    -      ok: false,
    
    118
    -      button0Label: launch,
    
    119
    -      button1Label: cancel,
    
    120
    -      defaultButtonNum: 1, // Cancel
    
    121
    -      buttonNumClicked: 1, // Cancel
    
    122
    -      enableDelay: true,
    
    123
    -    };
    
    124
    -
    
    125
    -    let propBag = PromptUtils.objectToPropBag(args);
    
    126
    -    let uri = "chrome://global/content/commonDialog.xhtml";
    
    127
    -    let promptWin = Services.ww.openWindow(
    
    128
    -      parentWin,
    
    129
    -      uri,
    
    130
    -      "_blank",
    
    131
    -      "centerscreen,chrome,titlebar",
    
    132
    -      propBag
    
    133
    -    );
    
    134
    -    promptWin.addEventListener("load", aEvent => {
    
    135
    -      promptWin.addEventListener("unload", aEvent => {
    
    136
    -        PromptUtils.propBagToObject(propBag, args);
    
    137
    -
    
    138
    -        if (0 == args.buttonNumClicked) {
    
    139
    -          // Save the checkbox value and tell the browser's external helper app
    
    140
    -          // module about the user's choice.
    
    141
    -          if (args.checked) {
    
    142
    -            Services.prefs.setBoolPref(
    
    143
    -              "extensions.torbutton.launch_warning",
    
    144
    -              false
    
    145
    -            );
    
    146
    -          }
    
    147
    -
    
    148
    -          this._helperAppLauncher.continueRequest();
    
    149
    -        } else {
    
    150
    -          this._helperAppLauncher.cancelRequest(Cr.NS_BINDING_ABORTED);
    
    151
    -        }
    
    152
    -      });
    
    153
    -    });
    
    154
    -  },
    
    155
    -};
    
    156
    -
    
    157
    -// Assign factory to global object.
    
    158
    -const NSGetFactory = XPCOMUtils.generateNSGetFactory
    
    159
    -  ? XPCOMUtils.generateNSGetFactory([ExternalAppBlocker])
    
    160
    -  : ComponentUtils.generateNSGetFactory([ExternalAppBlocker]);

  • toolkit/torbutton/jar.mn
    ... ... @@ -34,9 +34,6 @@ torbutton.jar:
    34 34
     % component {f605ec27-d867-44b5-ad97-2a29276642c3} %components/dragDropFilter.js
    
    35 35
     % contract @torproject.org/torbutton-dragDropFilter;1 {f605ec27-d867-44b5-ad97-2a29276642c3}
    
    36 36
     
    
    37
    -% component {3da0269f-fc29-4e9e-a678-c3b1cafcf13f} %components/external-app-blocker.js
    
    38
    -% contract @torproject.org/torbutton-extAppBlocker;1 {3da0269f-fc29-4e9e-a678-c3b1cafcf13f}
    
    39
    -
    
    40 37
     % component {06322def-6fde-4c06-aef6-47ae8e799629} %components/startup-observer.js
    
    41 38
     % contract @torproject.org/startup-observer;1 {06322def-6fde-4c06-aef6-47ae8e799629}
    
    42 39
     
    

  • uriloader/exthandler/nsExternalHelperAppService.cpp
    ... ... @@ -144,9 +144,6 @@ static const char NEVER_ASK_FOR_SAVE_TO_DISK_PREF[] =
    144 144
     static const char NEVER_ASK_FOR_OPEN_FILE_PREF[] =
    
    145 145
         "browser.helperApps.neverAsk.openFile";
    
    146 146
     
    
    147
    -static const char WARNING_DIALOG_CONTRACT_ID[] =
    
    148
    -    "@torproject.org/torbutton-extAppBlocker;1";
    
    149
    -
    
    150 147
     StaticRefPtr<nsIFile> sFallbackDownloadDir;
    
    151 148
     
    
    152 149
     // Helper functions for Content-Disposition headers
    
    ... ... @@ -398,22 +395,6 @@ nsresult GenerateRandomName(nsACString& result) {
    398 395
       return NS_OK;
    
    399 396
     }
    
    400 397
     
    
    401
    -static already_AddRefed<nsIInterfaceRequestor> GetDialogParentAux(
    
    402
    -    BrowsingContext* aBrowsingContext, nsIInterfaceRequestor* aWindowContext) {
    
    403
    -  nsCOMPtr<nsIInterfaceRequestor> dialogParent = aWindowContext;
    
    404
    -
    
    405
    -  if (!dialogParent && aBrowsingContext) {
    
    406
    -    dialogParent = do_QueryInterface(aBrowsingContext->GetDOMWindow());
    
    407
    -  }
    
    408
    -  if (!dialogParent && aBrowsingContext && XRE_IsParentProcess()) {
    
    409
    -    RefPtr<Element> element = aBrowsingContext->Top()->GetEmbedderElement();
    
    410
    -    if (element) {
    
    411
    -      dialogParent = do_QueryInterface(element->OwnerDoc()->GetWindow());
    
    412
    -    }
    
    413
    -  }
    
    414
    -  return dialogParent.forget();
    
    415
    -}
    
    416
    -
    
    417 398
     /**
    
    418 399
      * Structure for storing extension->type mappings.
    
    419 400
      * @see defaultMimeEntries
    
    ... ... @@ -611,96 +592,6 @@ static const char* descriptionOverwriteExtensions[] = {
    611 592
         "avif", "jxl", "pdf", "svg", "webp", "xml",
    
    612 593
     };
    
    613 594
     
    
    614
    -//////////////////////////////////////////////////////////////////////////////////////////////////////
    
    615
    -// begin nsExternalLoadURIHandler class definition and implementation
    
    616
    -//////////////////////////////////////////////////////////////////////////////////////////////////////
    
    617
    -class nsExternalLoadURIHandler final : public nsIHelperAppWarningLauncher {
    
    618
    - public:
    
    619
    -  NS_DECL_THREADSAFE_ISUPPORTS
    
    620
    -  NS_DECL_NSIHELPERAPPWARNINGLAUNCHER
    
    621
    -
    
    622
    -  nsExternalLoadURIHandler(nsIHandlerInfo* aHandlerInfo, nsIURI* aURI,
    
    623
    -                           nsIPrincipal* aTriggeringPrincipal,
    
    624
    -                           BrowsingContext* aBrowsingContext,
    
    625
    -                           bool aTriggeredExternally);
    
    626
    -
    
    627
    - protected:
    
    628
    -  ~nsExternalLoadURIHandler();
    
    629
    -
    
    630
    -  nsCOMPtr<nsIHandlerInfo> mHandlerInfo;
    
    631
    -  nsCOMPtr<nsIURI> mURI;
    
    632
    -  nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
    
    633
    -  RefPtr<BrowsingContext> mBrowsingContext;
    
    634
    -  bool mTriggeredExternally;
    
    635
    -  nsCOMPtr<nsIHelperAppWarningDialog> mWarningDialog;
    
    636
    -};
    
    637
    -
    
    638
    -NS_IMPL_ADDREF(nsExternalLoadURIHandler)
    
    639
    -NS_IMPL_RELEASE(nsExternalLoadURIHandler)
    
    640
    -
    
    641
    -NS_INTERFACE_MAP_BEGIN(nsExternalLoadURIHandler)
    
    642
    -  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIHelperAppWarningLauncher)
    
    643
    -  NS_INTERFACE_MAP_ENTRY(nsIHelperAppWarningLauncher)
    
    644
    -NS_INTERFACE_MAP_END
    
    645
    -
    
    646
    -nsExternalLoadURIHandler::nsExternalLoadURIHandler(
    
    647
    -    nsIHandlerInfo* aHandlerInfo, nsIURI* aURI,
    
    648
    -    nsIPrincipal* aTriggeringPrincipal, BrowsingContext* aBrowsingContext,
    
    649
    -    bool aTriggeredExternally)
    
    650
    -    : mHandlerInfo(aHandlerInfo),
    
    651
    -      mURI(aURI),
    
    652
    -      mTriggeringPrincipal(aTriggeringPrincipal),
    
    653
    -      mBrowsingContext(aBrowsingContext),
    
    654
    -      mTriggeredExternally(aTriggeredExternally)
    
    655
    -
    
    656
    -{
    
    657
    -  nsresult rv = NS_OK;
    
    658
    -  mWarningDialog = do_CreateInstance(WARNING_DIALOG_CONTRACT_ID, &rv);
    
    659
    -  if (NS_SUCCEEDED(rv) && mWarningDialog) {
    
    660
    -    // This will create a reference cycle (the dialog holds a reference to us
    
    661
    -    // as nsIHelperAppWarningLauncher), which will be broken in ContinueRequest
    
    662
    -    // or CancelRequest.
    
    663
    -    nsCOMPtr<nsIInterfaceRequestor> dialogParent =
    
    664
    -        GetDialogParentAux(aBrowsingContext, nullptr);
    
    665
    -    rv = mWarningDialog->MaybeShow(this, dialogParent);
    
    666
    -  }
    
    667
    -
    
    668
    -  if (NS_FAILED(rv)) {
    
    669
    -    // If for some reason we could not open the download warning prompt,
    
    670
    -    // continue with the request.
    
    671
    -    ContinueRequest();
    
    672
    -  }
    
    673
    -}
    
    674
    -
    
    675
    -nsExternalLoadURIHandler::~nsExternalLoadURIHandler() {}
    
    676
    -
    
    677
    -NS_IMETHODIMP nsExternalLoadURIHandler::ContinueRequest() {
    
    678
    -  MOZ_ASSERT(mURI);
    
    679
    -  MOZ_ASSERT(mHandlerInfo);
    
    680
    -
    
    681
    -  // Break our reference cycle with the download warning dialog (set up in
    
    682
    -  // LoadURI).
    
    683
    -  mWarningDialog = nullptr;
    
    684
    -
    
    685
    -  nsresult rv = NS_OK;
    
    686
    -  nsCOMPtr<nsIContentDispatchChooser> chooser =
    
    687
    -      do_CreateInstance("@mozilla.org/content-dispatch-chooser;1", &rv);
    
    688
    -  NS_ENSURE_SUCCESS(rv, rv);
    
    689
    -
    
    690
    -  return chooser->HandleURI(mHandlerInfo, mURI, mTriggeringPrincipal,
    
    691
    -                            mBrowsingContext, mTriggeredExternally);
    
    692
    -}
    
    693
    -
    
    694
    -NS_IMETHODIMP nsExternalLoadURIHandler::CancelRequest(nsresult aReason) {
    
    695
    -  NS_ENSURE_ARG(NS_FAILED(aReason));
    
    696
    -
    
    697
    -  // Break our reference cycle with the download warning dialog (set up in
    
    698
    -  // LoadURI).
    
    699
    -  mWarningDialog = nullptr;
    
    700
    -
    
    701
    -  return NS_OK;
    
    702
    -}
    
    703
    -
    
    704 595
     static StaticRefPtr<nsExternalHelperAppService> sExtHelperAppSvcSingleton;
    
    705 596
     
    
    706 597
     /**
    
    ... ... @@ -723,9 +614,6 @@ nsExternalHelperAppService::GetSingleton() {
    723 614
       return do_AddRef(sExtHelperAppSvcSingleton);
    
    724 615
     }
    
    725 616
     
    
    726
    -//////////////////////////////////////////////////////////////////////////////////////////////////////
    
    727
    -// nsExternalHelperAppService definition and implementation
    
    728
    -//////////////////////////////////////////////////////////////////////////////////////////////////////
    
    729 617
     NS_IMPL_ISUPPORTS(nsExternalHelperAppService, nsIExternalHelperAppService,
    
    730 618
                       nsPIExternalAppLauncher, nsIExternalProtocolService,
    
    731 619
                       nsIMIMEService, nsIObserver, nsISupportsWeakReference)
    
    ... ... @@ -1238,15 +1126,14 @@ nsExternalHelperAppService::LoadURI(nsIURI* aURI,
    1238 1126
       rv = GetProtocolHandlerInfo(scheme, getter_AddRefs(handler));
    
    1239 1127
       NS_ENSURE_SUCCESS(rv, rv);
    
    1240 1128
     
    
    1241
    -  RefPtr<nsExternalLoadURIHandler> h = new nsExternalLoadURIHandler(
    
    1129
    +  nsCOMPtr<nsIContentDispatchChooser> chooser =
    
    1130
    +      do_CreateInstance("@mozilla.org/content-dispatch-chooser;1", &rv);
    
    1131
    +  NS_ENSURE_SUCCESS(rv, rv);
    
    1132
    +
    
    1133
    +  return chooser->HandleURI(
    
    1242 1134
           handler, escapedURI,
    
    1243 1135
           aRedirectPrincipal ? aRedirectPrincipal : aTriggeringPrincipal,
    
    1244 1136
           aBrowsingContext, aTriggeredExternally);
    
    1245
    -  if (!h) {
    
    1246
    -    return NS_ERROR_OUT_OF_MEMORY;
    
    1247
    -  }
    
    1248
    -
    
    1249
    -  return NS_OK;
    
    1250 1137
     }
    
    1251 1138
     
    
    1252 1139
     //////////////////////////////////////////////////////////////////////////////////////////////////////
    
    ... ... @@ -1391,7 +1278,6 @@ NS_INTERFACE_MAP_BEGIN(nsExternalAppHandler)
    1391 1278
       NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
    
    1392 1279
       NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
    
    1393 1280
       NS_INTERFACE_MAP_ENTRY(nsIHelperAppLauncher)
    
    1394
    -  NS_INTERFACE_MAP_ENTRY(nsIHelperAppWarningLauncher)
    
    1395 1281
       NS_INTERFACE_MAP_ENTRY(nsICancelable)
    
    1396 1282
       NS_INTERFACE_MAP_ENTRY(nsIBackgroundFileSaverObserver)
    
    1397 1283
       NS_INTERFACE_MAP_ENTRY(nsINamed)
    
    ... ... @@ -1647,7 +1533,18 @@ void nsExternalAppHandler::MaybeApplyDecodingForExtension(
    1647 1533
     
    
    1648 1534
     already_AddRefed<nsIInterfaceRequestor>
    
    1649 1535
     nsExternalAppHandler::GetDialogParent() {
    
    1650
    -  return GetDialogParentAux(mBrowsingContext, mWindowContext);
    
    1536
    +  nsCOMPtr<nsIInterfaceRequestor> dialogParent = mWindowContext;
    
    1537
    +
    
    1538
    +  if (!dialogParent && mBrowsingContext) {
    
    1539
    +    dialogParent = do_QueryInterface(mBrowsingContext->GetDOMWindow());
    
    1540
    +  }
    
    1541
    +  if (!dialogParent && mBrowsingContext && XRE_IsParentProcess()) {
    
    1542
    +    RefPtr<Element> element = mBrowsingContext->Top()->GetEmbedderElement();
    
    1543
    +    if (element) {
    
    1544
    +      dialogParent = do_QueryInterface(element->OwnerDoc()->GetWindow());
    
    1545
    +    }
    
    1546
    +  }
    
    1547
    +  return dialogParent.forget();
    
    1651 1548
     }
    
    1652 1549
     
    
    1653 1550
     NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest* request) {
    
    ... ... @@ -1795,34 +1692,6 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest* request) {
    1795 1692
         loadInfo->SetForceAllowDataURI(true);
    
    1796 1693
       }
    
    1797 1694
     
    
    1798
    -  mWarningDialog = do_CreateInstance(WARNING_DIALOG_CONTRACT_ID, &rv);
    
    1799
    -  if (NS_SUCCEEDED(rv) && mWarningDialog) {
    
    1800
    -    // This will create a reference cycle (the dialog holds a reference to us
    
    1801
    -    // as nsIHelperAppWarningLauncher), which will be broken in ContinueRequest
    
    1802
    -    // or CancelRequest.
    
    1803
    -    nsCOMPtr<nsIInterfaceRequestor> dialogParent = GetDialogParent();
    
    1804
    -    rv = mWarningDialog->MaybeShow(this, dialogParent);
    
    1805
    -  }
    
    1806
    -
    
    1807
    -  if (NS_FAILED(rv)) {
    
    1808
    -    // If for some reason we could not open the download warning prompt,
    
    1809
    -    // continue with the request.
    
    1810
    -    ContinueRequest();
    
    1811
    -  }
    
    1812
    -
    
    1813
    -  return NS_OK;
    
    1814
    -}
    
    1815
    -
    
    1816
    -NS_IMETHODIMP nsExternalAppHandler::ContinueRequest() {
    
    1817
    -  nsAutoCString MIMEType;
    
    1818
    -  if (mMimeInfo) {
    
    1819
    -    mMimeInfo->GetMIMEType(MIMEType);
    
    1820
    -  }
    
    1821
    -
    
    1822
    -  // Break our reference cycle with the download warning dialog (set up in
    
    1823
    -  // OnStartRequest).
    
    1824
    -  mWarningDialog = nullptr;
    
    1825
    -
    
    1826 1695
       // now that the temp file is set up, find out if we need to invoke a dialog
    
    1827 1696
       // asking the user what they want us to do with this content...
    
    1828 1697
     
    
    ... ... @@ -1968,7 +1837,7 @@ NS_IMETHODIMP nsExternalAppHandler::ContinueRequest() {
    1968 1837
           GetTargetFile(getter_AddRefs(fileToTest));
    
    1969 1838
           if (fileToTest) {
    
    1970 1839
             bool isExecutable;
    
    1971
    -        nsresult rv = fileToTest->IsExecutable(&isExecutable);
    
    1840
    +        rv = fileToTest->IsExecutable(&isExecutable);
    
    1972 1841
             if (NS_FAILED(rv) || mTempFileIsExecutable ||
    
    1973 1842
                 isExecutable) {  // checking NS_FAILED, because paranoia is good
    
    1974 1843
               alwaysAsk = true;
    
    ... ... @@ -1984,7 +1853,20 @@ NS_IMETHODIMP nsExternalAppHandler::ContinueRequest() {
    1984 1853
       }
    
    1985 1854
     #endif
    
    1986 1855
     
    
    1987
    -  nsresult rv = NS_OK;
    
    1856
    +  nsAutoCString actionTelem;
    
    1857
    +  if (alwaysAsk) {
    
    1858
    +    actionTelem.AssignLiteral("ask");
    
    1859
    +  } else if (shouldAutomaticallyHandleInternally) {
    
    1860
    +    actionTelem.AssignLiteral("internal");
    
    1861
    +  } else if (action == nsIMIMEInfo::useHelperApp ||
    
    1862
    +             action == nsIMIMEInfo::useSystemDefault) {
    
    1863
    +    actionTelem.AssignLiteral("external");
    
    1864
    +  } else {
    
    1865
    +    actionTelem.AssignLiteral("save");
    
    1866
    +  }
    
    1867
    +
    
    1868
    +  RecordDownloadTelemetry(aChannel, actionTelem.get());
    
    1869
    +
    
    1988 1870
       if (alwaysAsk) {
    
    1989 1871
         // Display the dialog
    
    1990 1872
         mDialog = do_CreateInstance(NS_HELPERAPPLAUNCHERDLG_CONTRACTID, &rv);
    
    ... ... @@ -2017,14 +1899,6 @@ NS_IMETHODIMP nsExternalAppHandler::ContinueRequest() {
    2017 1899
       return NS_OK;
    
    2018 1900
     }
    
    2019 1901
     
    
    2020
    -NS_IMETHODIMP nsExternalAppHandler::CancelRequest(nsresult aReason) {
    
    2021
    -  // Break our reference cycle with the download warning dialog (set up in
    
    2022
    -  // OnStartRequest).
    
    2023
    -  mWarningDialog = nullptr;
    
    2024
    -
    
    2025
    -  return Cancel(aReason);
    
    2026
    -}
    
    2027
    -
    
    2028 1902
     void nsExternalAppHandler::RecordDownloadTelemetry(nsIChannel* aChannel,
    
    2029 1903
                                                        const char* aAction) {
    
    2030 1904
       // Telemetry for helper app dialog
    
    ... ... @@ -2888,7 +2762,7 @@ NS_IMETHODIMP nsExternalAppHandler::Cancel(nsresult aReason) {
    2888 2762
       }
    
    2889 2763
     
    
    2890 2764
       // Break our reference cycle with the helper app dialog (set up in
    
    2891
    -  // ContinueRequest)
    
    2765
    +  // OnStartRequest)
    
    2892 2766
       mDialog = nullptr;
    
    2893 2767
       mDialogShowing = false;
    
    2894 2768
     
    

  • uriloader/exthandler/nsExternalHelperAppService.h
    ... ... @@ -261,7 +261,6 @@ class nsExternalHelperAppService : public nsIExternalHelperAppService,
    261 261
      */
    
    262 262
     class nsExternalAppHandler final : public nsIStreamListener,
    
    263 263
                                        public nsIHelperAppLauncher,
    
    264
    -                                   public nsIHelperAppWarningLauncher,
    
    265 264
                                        public nsIBackgroundFileSaverObserver,
    
    266 265
                                        public nsINamed {
    
    267 266
      public:
    
    ... ... @@ -269,7 +268,6 @@ class nsExternalAppHandler final : public nsIStreamListener,
    269 268
       NS_DECL_NSISTREAMLISTENER
    
    270 269
       NS_DECL_NSIREQUESTOBSERVER
    
    271 270
       NS_DECL_NSIHELPERAPPLAUNCHER
    
    272
    -  NS_DECL_NSIHELPERAPPWARNINGLAUNCHER
    
    273 271
       NS_DECL_NSICANCELABLE
    
    274 272
       NS_DECL_NSIBACKGROUNDFILESAVEROBSERVER
    
    275 273
       NS_DECL_NSINAMED
    
    ... ... @@ -546,7 +544,6 @@ class nsExternalAppHandler final : public nsIStreamListener,
    546 544
       nsCOMPtr<nsITransfer> mTransfer;
    
    547 545
     
    
    548 546
       nsCOMPtr<nsIHelperAppLauncherDialog> mDialog;
    
    549
    -  nsCOMPtr<nsIHelperAppWarningDialog> mWarningDialog;
    
    550 547
     
    
    551 548
       /**
    
    552 549
     
    

  • uriloader/exthandler/nsIExternalHelperAppService.idl
    ... ... @@ -189,50 +189,3 @@ interface nsIHelperAppLauncher : nsICancelable
    189 189
        */
    
    190 190
       readonly attribute uint64_t browsingContextId;
    
    191 191
     };
    192
    -
    
    193
    -/**
    
    194
    -  * nsIHelperAppWarningLauncher is implemented by two classes:
    
    195
    -  *   nsExternalLoadURIHandler
    
    196
    -  *   nsExternalAppHandler
    
    197
    -  */
    
    198
    -[scriptable, uuid(cffd508b-4aaf-43ad-99c6-671d35cbc558)]
    
    199
    -interface nsIHelperAppWarningLauncher : nsISupports
    
    200
    -{
    
    201
    -  /**
    
    202
    -   * Callback invoked by the external app warning dialog to continue the
    
    203
    -   * request.
    
    204
    -   * NOTE: This will release the reference to the nsIHelperAppWarningDialog.
    
    205
    -   */
    
    206
    -  void continueRequest();
    
    207
    -
    
    208
    -  /**
    
    209
    -   * Callback invoked by the external app warning dialog to cancel the request.
    
    210
    -   * NOTE: This will release the reference to the nsIHelperAppWarningDialog.
    
    211
    -   *
    
    212
    -   * @param aReason
    
    213
    -   *        Pass a failure code to indicate the reason why this operation is
    
    214
    -   *        being canceled. It is an error to pass a success code.
    
    215
    -   */
    
    216
    -  void cancelRequest(in nsresult aReason);
    
    217
    -};
    
    218
    -
    
    219
    -/**
    
    220
    - * nsIHelperAppWarningDialog is implemented by Torbutton's external app
    
    221
    - * blocker (src/components/external-app-blocker.js).
    
    222
    - */
    
    223
    -[scriptable, uuid(f4899a3f-0df3-42cc-9db8-bdf599e5a208)]
    
    224
    -interface nsIHelperAppWarningDialog : nsISupports
    
    225
    -{
    
    226
    -  /**
    
    227
    -   * Possibly show a launch warning dialog (it will not be shown if the user
    
    228
    -   * has chosen to not see the warning again).
    
    229
    -   *
    
    230
    -   * @param aLauncher
    
    231
    -   *        A nsIHelperAppWarningLauncher to be invoked after the user confirms
    
    232
    -   *        or cancels the download.
    
    233
    -   * @param aWindowContext
    
    234
    -   *        The window associated with the download.
    
    235
    -   */
    
    236
    -  void maybeShow(in nsIHelperAppWarningLauncher aLauncher,
    
    237
    -                 in nsISupports aWindowContext);
    
    238
    -};