Commit 95ab5a71 authored by Dan Ballard's avatar Dan Ballard Committed by Richard Pospesel
Browse files

fixup! Bug 10760: Integrate TorButton to TorBrowser core

Bug 40701: Remove old download popup
parent 627eab30
Loading
Loading
Loading
Loading
+0 −160
Changes for toolkit/torbutton/components/external-app-blocker.js: 0 added lines, 160 removed lines.
Original line number Diff line number Diff line
// Bug 1506 Android P1/TBB P5: This code provides users with notification
// in the event of external app launch. We want it to exist in the desktop
// port, but it is probably useless for Android.

/*************************************************************************
 * External App Handler.
 * Handles displaying confirmation dialogs for external apps and protocols
 * due to Firefox Bug https://bugzilla.mozilla.org/show_bug.cgi?id=440892
 *
 * An instance of this module is created each time the browser starts to
 * download a file and when an external application may be invoked to
 * handle an URL (e.g., when the user clicks on a mailto: URL).
 *************************************************************************/

const { XPCOMUtils } = ChromeUtils.import(
  "resource://gre/modules/XPCOMUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { PromptUtils } = ChromeUtils.import(
  "resource://gre/modules/SharedPromptUtils.jsm"
);

XPCOMUtils.defineLazyModuleGetters(this, {
  ComponentUtils: "resource://gre/modules/ComponentUtils.jsm",
});

let { torbutton_get_property_string } = ChromeUtils.import(
  "resource://torbutton/modules/utils.js"
);

// Module specific constants
const kMODULE_NAME = "Torbutton External App Handler";
const kCONTRACT_ID = "@torproject.org/torbutton-extAppBlocker;1";
const kMODULE_CID = Components.ID("3da0269f-fc29-4e9e-a678-c3b1cafcf13f");

const kInterfaces = [Ci.nsIObserver, Ci.nsIClassInfo];

function ExternalAppBlocker() {
  this.logger = Cc["@torproject.org/torbutton-logger;1"].getService(
    Ci.nsISupports
  ).wrappedJSObject;
  this.logger.log(3, "Component Load 0: New ExternalAppBlocker.");
}

ExternalAppBlocker.prototype = {
  _helperAppLauncher: undefined,

  QueryInterface: ChromeUtils.generateQI([
    Ci.nsIObserver,
    Ci.nsIHelperAppWarningDialog,
  ]),

  // make this an nsIClassInfo object
  flags: Ci.nsIClassInfo.DOM_OBJECT,
  classDescription: kMODULE_NAME,
  contractID: kCONTRACT_ID,
  classID: kMODULE_CID,

  // method of nsIClassInfo
  getInterfaces(count) {
    count.value = kInterfaces.length;
    return kInterfaces;
  },

  // method of nsIClassInfo
  getHelperForLanguage(count) {
    return null;
  },

  // method of nsIHelperAppWarningDialog
  maybeShow(aLauncher, aWindowContext) {
    // Hold a reference to the object that called this component. This is
    // important not just because we need to later invoke the
    // continueRequest() or cancelRequest() callback on aLauncher, but also
    // so that the launcher object (which is a reference counted object) is
    // not released too soon.
    this._helperAppLauncher = aLauncher;

    if (!Services.prefs.getBoolPref("extensions.torbutton.launch_warning")) {
      this._helperAppLauncher.continueRequest();
      return;
    }

    this._showPrompt(aWindowContext);
  },

  /*
   * The _showPrompt() implementation uses some XUL and JS that is part of the
   * browser's confirmEx() implementation. Specifically, _showPrompt() depends
   * on chrome://global/content/commonDialog.xhtml as well as some of the code
   * in resource://gre/modules/SharedPromptUtils.jsm.
   */
  _showPrompt(aWindowContext) {
    let parentWin;
    try {
      parentWin = aWindowContext.getInterface(Ci.nsIDOMWindow);
    } catch (e) {
      parentWin = Services.wm.getMostRecentWindow("navigator:browser");
    }

    let title = torbutton_get_property_string("torbutton.popup.external.title");
    let app = torbutton_get_property_string("torbutton.popup.external.app");
    let note = torbutton_get_property_string("torbutton.popup.external.note");
    let suggest = torbutton_get_property_string(
      "torbutton.popup.external.suggest"
    );
    let launch = torbutton_get_property_string("torbutton.popup.launch");
    let cancel = torbutton_get_property_string("torbutton.popup.cancel");
    let dontask = torbutton_get_property_string("torbutton.popup.dontask");

    let args = {
      promptType: "confirmEx",
      title,
      text: app + note + suggest + " ",
      checkLabel: dontask,
      checked: false,
      ok: false,
      button0Label: launch,
      button1Label: cancel,
      defaultButtonNum: 1, // Cancel
      buttonNumClicked: 1, // Cancel
      enableDelay: true,
    };

    let propBag = PromptUtils.objectToPropBag(args);
    let uri = "chrome://global/content/commonDialog.xhtml";
    let promptWin = Services.ww.openWindow(
      parentWin,
      uri,
      "_blank",
      "centerscreen,chrome,titlebar",
      propBag
    );
    promptWin.addEventListener("load", aEvent => {
      promptWin.addEventListener("unload", aEvent => {
        PromptUtils.propBagToObject(propBag, args);

        if (0 == args.buttonNumClicked) {
          // Save the checkbox value and tell the browser's external helper app
          // module about the user's choice.
          if (args.checked) {
            Services.prefs.setBoolPref(
              "extensions.torbutton.launch_warning",
              false
            );
          }

          this._helperAppLauncher.continueRequest();
        } else {
          this._helperAppLauncher.cancelRequest(Cr.NS_BINDING_ABORTED);
        }
      });
    });
  },
};

// Assign factory to global object.
const NSGetFactory = XPCOMUtils.generateNSGetFactory
  ? XPCOMUtils.generateNSGetFactory([ExternalAppBlocker])
  : ComponentUtils.generateNSGetFactory([ExternalAppBlocker]);
+0 −3
Changes for toolkit/torbutton/jar.mn: 0 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -34,9 +34,6 @@ torbutton.jar:
% component {f605ec27-d867-44b5-ad97-2a29276642c3} %components/dragDropFilter.js
% contract @torproject.org/torbutton-dragDropFilter;1 {f605ec27-d867-44b5-ad97-2a29276642c3}

% component {3da0269f-fc29-4e9e-a678-c3b1cafcf13f} %components/external-app-blocker.js
% contract @torproject.org/torbutton-extAppBlocker;1 {3da0269f-fc29-4e9e-a678-c3b1cafcf13f}

% component {06322def-6fde-4c06-aef6-47ae8e799629} %components/startup-observer.js
% contract @torproject.org/startup-observer;1 {06322def-6fde-4c06-aef6-47ae8e799629}