summaryrefslogtreecommitdiffstats
path: root/toolkit/components/apppicker/content
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /toolkit/components/apppicker/content
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/apppicker/content')
-rw-r--r--toolkit/components/apppicker/content/appPicker.js210
-rw-r--r--toolkit/components/apppicker/content/appPicker.xul40
2 files changed, 250 insertions, 0 deletions
diff --git a/toolkit/components/apppicker/content/appPicker.js b/toolkit/components/apppicker/content/appPicker.js
new file mode 100644
index 000000000..469a6ca23
--- /dev/null
+++ b/toolkit/components/apppicker/content/appPicker.js
@@ -0,0 +1,210 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+Components.utils.import("resource://gre/modules/AppConstants.jsm");
+
+function AppPicker() {}
+
+AppPicker.prototype =
+{
+ // Class members
+ _incomingParams:null,
+
+ /**
+ * Init the dialog and populate the application list
+ */
+ appPickerLoad: function appPickerLoad() {
+ const nsILocalHandlerApp = Components.interfaces.nsILocalHandlerApp;
+
+ this._incomingParams = window.arguments[0];
+ this._incomingParams.handlerApp = null;
+
+ document.title = this._incomingParams.title;
+
+ // Header creation - at the very least, we must have
+ // a mime type:
+ //
+ // (icon) Zip File
+ // (icon) filename
+ //
+ // (icon) Web Feed
+ // (icon) mime/type
+ //
+ // (icon) mime/type
+ // (icon)
+
+ var mimeInfo = this._incomingParams.mimeInfo;
+ var filename = this._incomingParams.filename;
+ if (!filename) {
+ filename = mimeInfo.MIMEType;
+ }
+ var description = this._incomingParams.description;
+ if (!description) {
+ description = filename;
+ filename = "";
+ }
+
+ // Setup the dialog header information
+ document.getElementById("content-description").setAttribute("value",
+ description);
+ document.getElementById("suggested-filename").setAttribute("value",
+ filename);
+ document.getElementById("content-icon").setAttribute("src",
+ "moz-icon://" + filename + "?size=32&contentType=" +
+ mimeInfo.MIMEType);
+
+ // Grab a list of nsILocalHandlerApp application helpers to list
+ var fileList = mimeInfo.possibleLocalHandlers;
+
+ var list = document.getElementById("app-picker-listbox");
+
+ var primaryCount = 0;
+
+ if (!fileList || fileList.length == 0) {
+ // display a message saying nothing is configured
+ document.getElementById("app-picker-notfound").removeAttribute("hidden");
+ return;
+ }
+
+ for (var idx = 0; idx < fileList.length; idx++) {
+ var file = fileList.queryElementAt(idx, nsILocalHandlerApp);
+ try {
+ if (!file.executable || !file.executable.isFile())
+ continue;
+ } catch (err) {
+ continue;
+ }
+
+ var item = document.createElement("listitem");
+ item.className = "listitem-iconic";
+ item.handlerApp = file;
+ item.setAttribute("label", this.getFileDisplayName(file.executable));
+ item.setAttribute("image", this.getFileIconURL(file.executable));
+ list.appendChild(item);
+
+ primaryCount++;
+ }
+
+ if ( primaryCount == 0 ) {
+ // display a message saying nothing is configured
+ document.getElementById("app-picker-notfound").removeAttribute("hidden");
+ }
+ },
+
+ /**
+ * Retrieve the moz-icon for the app
+ */
+ getFileIconURL: function getFileIconURL(file) {
+ var ios = Components.classes["@mozilla.org/network/io-service;1"].
+ getService(Components.interfaces.nsIIOService);
+
+ if (!ios) return "";
+ const nsIFileProtocolHandler =
+ Components.interfaces.nsIFileProtocolHandler;
+
+ var fph = ios.getProtocolHandler("file")
+ .QueryInterface(nsIFileProtocolHandler);
+ if (!fph) return "";
+
+ var urlSpec = fph.getURLSpecFromFile(file);
+ return "moz-icon://" + urlSpec + "?size=32";
+ },
+
+ /**
+ * Retrieve the pretty description from the file
+ */
+ getFileDisplayName: function getFileDisplayName(file) {
+ if (AppConstants.platform == "win") {
+ if (file instanceof Components.interfaces.nsILocalFileWin) {
+ try {
+ return file.getVersionInfoField("FileDescription");
+ } catch (e) {}
+ }
+ } else if (AppConstants.platform == "macosx") {
+ if (file instanceof Components.interfaces.nsILocalFileMac) {
+ try {
+ return file.bundleDisplayName;
+ } catch (e) {}
+ }
+ }
+ return file.leafName;
+ },
+
+ /**
+ * Double click accepts an app
+ */
+ appDoubleClick: function appDoubleClick() {
+ var list = document.getElementById("app-picker-listbox");
+ var selItem = list.selectedItem;
+
+ if (!selItem) {
+ this._incomingParams.handlerApp = null;
+ return true;
+ }
+
+ this._incomingParams.handlerApp = selItem.handlerApp;
+ window.close();
+
+ return true;
+ },
+
+ appPickerOK: function appPickerOK() {
+ if (this._incomingParams.handlerApp) return true;
+
+ var list = document.getElementById("app-picker-listbox");
+ var selItem = list.selectedItem;
+
+ if (!selItem) {
+ this._incomingParams.handlerApp = null;
+ return true;
+ }
+ this._incomingParams.handlerApp = selItem.handlerApp;
+
+ return true;
+ },
+
+ appPickerCancel: function appPickerCancel() {
+ this._incomingParams.handlerApp = null;
+ return true;
+ },
+
+ /**
+ * User browse for an app.
+ */
+ appPickerBrowse: function appPickerBrowse() {
+ var nsIFilePicker = Components.interfaces.nsIFilePicker;
+ var fp = Components.classes["@mozilla.org/filepicker;1"].
+ createInstance(nsIFilePicker);
+
+ fp.init(window, this._incomingParams.title, nsIFilePicker.modeOpen);
+ fp.appendFilters(nsIFilePicker.filterApps);
+
+ var fileLoc = Components.classes["@mozilla.org/file/directory_service;1"]
+ .getService(Components.interfaces.nsIProperties);
+ var startLocation;
+ if (AppConstants.platform == "win") {
+ startLocation = "ProgF"; // Program Files
+ } else if (AppConstants.platform == "macosx") {
+ startLocation = "LocApp"; // Local Applications
+ } else {
+ startLocation = "Home";
+ }
+ fp.displayDirectory =
+ fileLoc.get(startLocation, Components.interfaces.nsILocalFile);
+
+ if (fp.show() == nsIFilePicker.returnOK && fp.file) {
+ var localHandlerApp =
+ Components.classes["@mozilla.org/uriloader/local-handler-app;1"].
+ createInstance(Components.interfaces.nsILocalHandlerApp);
+ localHandlerApp.executable = fp.file;
+
+ this._incomingParams.handlerApp = localHandlerApp;
+ window.close();
+ }
+ return true;
+ }
+}
+
+// Global object
+var g_dialog = new AppPicker();
diff --git a/toolkit/components/apppicker/content/appPicker.xul b/toolkit/components/apppicker/content/appPicker.xul
new file mode 100644
index 000000000..3a50483c1
--- /dev/null
+++ b/toolkit/components/apppicker/content/appPicker.xul
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+ <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
+ <?xml-stylesheet href="chrome://global/skin/appPicker.css" type="text/css"?>
+
+ <!DOCTYPE dialog SYSTEM "chrome://global/locale/appPicker.dtd" >
+
+ <dialog id="app-picker"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="g_dialog.appPickerLoad();"
+ buttons="accept,cancel,extra2"
+ buttonlabelextra2="&BrowseButton.label;"
+ ondialogextra2="g_dialog.appPickerBrowse();"
+ defaultButton="cancel"
+ ondialogaccept="return g_dialog.appPickerOK();"
+ ondialogcancel="return g_dialog.appPickerCancel();"
+ aria-describedby="content-description suggested-filename"
+ persist="screenX screenY">
+
+ <script type="application/javascript" src="chrome://global/content/appPicker.js"/>
+
+ <hbox id="file-info" align="center">
+ <image id="content-icon" src=""/>
+ <vbox flex="1">
+ <label id="content-description" crop="center" value=""/>
+ <label id="suggested-filename" crop="center" value=""/>
+ </vbox>
+ </hbox>
+
+ <label id="sendto-message" value="&SendMsg.label;" control="app-picker-listbox"/>
+
+ <listbox id="app-picker-listbox" rows="5"
+ ondblclick="g_dialog.appDoubleClick();"/>
+
+ <label id="app-picker-notfound" value="&NoAppFound.label;" hidden="true"/>
+ </dialog>