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.
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
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 *************************************************************************/
15 const { XPCOMUtils
} = ChromeUtils
.import(
16 "resource://gre/modules/XPCOMUtils.jsm"
18 const { Services
} = ChromeUtils
.import("resource://gre/modules/Services.jsm");
19 const { PromptUtils
} = ChromeUtils
.import(
20 "resource://gre/modules/SharedPromptUtils.jsm"
23 XPCOMUtils
.defineLazyModuleGetters(this, {
24 ComponentUtils
: "resource://gre/modules/ComponentUtils.jsm",
27 let { torbutton_get_property_string
} = ChromeUtils
.import(
28 "resource://torbutton/modules/utils.js"
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");
36 const kInterfaces
= [Ci
.nsIObserver
, Ci
.nsIClassInfo
];
38 function ExternalAppBlocker() {
39 this.logger
= Cc
["@torproject.org/torbutton-logger;1"].getService(
42 this.logger
.log(3, "Component Load 0: New ExternalAppBlocker.");
45 ExternalAppBlocker
.prototype = {
46 _helperAppLauncher
: undefined,
48 QueryInterface
: ChromeUtils
.generateQI([
50 Ci
.nsIHelperAppWarningDialog
,
53 // make this an nsIClassInfo object
54 flags
: Ci
.nsIClassInfo
.DOM_OBJECT
,
55 classDescription
: kMODULE_NAME
,
56 contractID
: kCONTRACT_ID
,
59 // method of nsIClassInfo
60 getInterfaces(count
) {
61 count
.value
= kInterfaces
.length
;
65 // method of nsIClassInfo
66 getHelperForLanguage(count
) {
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
;
79 if (!Services
.prefs
.getBoolPref("extensions.torbutton.launch_warning")) {
80 this._helperAppLauncher
.continueRequest();
84 this._showPrompt(aWindowContext
);
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.
93 _showPrompt(aWindowContext
) {
96 parentWin
= aWindowContext
.getInterface(Ci
.nsIDOMWindow
);
98 parentWin
= Services
.wm
.getMostRecentWindow("navigator:browser");
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"
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");
112 promptType
: "confirmEx",
114 text
: app
+ note
+ suggest
+ " ",
118 button0Label
: launch
,
119 button1Label
: cancel
,
120 defaultButtonNum
: 1, // Cancel
121 buttonNumClicked
: 1, // Cancel
125 let propBag
= PromptUtils
.objectToPropBag(args
);
126 let uri
= "chrome://global/content/commonDialog.xhtml";
127 let promptWin
= Services
.ww
.openWindow(
131 "centerscreen,chrome,titlebar",
134 promptWin
.addEventListener("load", aEvent
=> {
135 promptWin
.addEventListener("unload", aEvent
=> {
136 PromptUtils
.propBagToObject(propBag
, args
);
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.
142 Services
.prefs
.setBoolPref(
143 "extensions.torbutton.launch_warning",
148 this._helperAppLauncher
.continueRequest();
150 this._helperAppLauncher
.cancelRequest(Cr
.NS_BINDING_ABORTED
);
157 // Assign factory to global object.
158 const NSGetFactory
= XPCOMUtils
.generateNSGetFactory
159 ? XPCOMUtils
.generateNSGetFactory([ExternalAppBlocker
])
160 : ComponentUtils
.generateNSGetFactory([ExternalAppBlocker
]);