Bug 1559255 - Port Bug 1297686 [List GIO handlers in the protocol handler list, in the handlers dialog, and in preferences] to SeaMonkey. r=IanN
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Mon, 22 Apr 2019 16:34:21 +0200
changeset 35871 2da4df6a339f3f26108d322f3e2917327991ab0f
parent 35870 12611e8ca4489c44a3bb6e8c3c685117e6afbd87
child 35872 5ad70183bb37ecf2c33e7b7e06628bc7a1d128db
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersIanN
bugs1559255, 1297686
Bug 1559255 - Port Bug 1297686 [List GIO handlers in the protocol handler list, in the handlers dialog, and in preferences] to SeaMonkey. r=IanN
suite/components/pref/content/pref-applications.js
--- a/suite/components/pref/content/pref-applications.js
+++ b/suite/components/pref/content/pref-applications.js
@@ -1225,16 +1225,19 @@ var gApplicationsPane = {
     if (aHandlerApp instanceof Ci.nsILocalHandlerApp)
       return this._isValidHandlerExecutable(aHandlerApp.executable);
 
     if (aHandlerApp instanceof Ci.nsIWebHandlerApp)
       return aHandlerApp.uriTemplate;
 
     if (aHandlerApp instanceof Ci.nsIWebContentHandlerInfo)
       return aHandlerApp.uri;
+ 
+    if (aHandlerApp instanceof Ci.nsIGIOMimeApp)
+      return aHandlerApp.command;
 
     return false;
   },
 
   _isValidHandlerExecutable: function(aExecutable) {
     var file = Services.dirsvc.get("XREExeF",
                                    Ci.nsIFile);
     return aExecutable &&
@@ -1359,16 +1362,57 @@ var gApplicationsPane = {
       // Attach the handler app object to the menu item so we can use it
       // to make changes to the datastore when the user selects the item.
       menuItem.handlerApp = possibleApp;
 
       menuPopup.appendChild(menuItem);
       possibleAppMenuItems.push(menuItem);
     }
 
+// Add gio handlers
+    if (Cc["@mozilla.org/gio-service;1"]) {
+      let gIOSvc = Cc["@mozilla.org/gio-service;1"]
+                     .getService(Ci.nsIGIOService);
+      var gioApps = gIOSvc.getAppsForURIScheme(typeItem.type);
+      let enumerator = gioApps.enumerate();
+      let possibleHandlers = handlerInfo.possibleApplicationHandlers;
+      while (enumerator.hasMoreElements()) {
+        let handler = enumerator.getNext().QueryInterface(Ci.nsIHandlerApp);
+        // OS handler share the same name, it's most likely the same app, skipping...
+        if (handler.name == handlerInfo.defaultDescription) {
+          continue;
+        }
+        // Check if the handler is already in possibleHandlers
+        let appAlreadyInHandlers = false;
+        for (let i = possibleHandlers.length - 1; i >= 0; --i) {
+          let app = possibleHandlers.queryElementAt(i, Ci.nsIHandlerApp);
+          // nsGIOMimeApp::Equals is able to compare with Ci.nsILocalHandlerApp
+          if (handler.equals(app)) {
+            appAlreadyInHandlers = true;
+            break;
+          }
+        }
+        if (!appAlreadyInHandlers) {
+          let menuItem = document.createElement("menuitem");
+          menuItem.setAttribute("action", Ci.nsIHandlerInfo.useHelperApp);
+          let label = this._prefsBundle.getFormattedString("useApp", [handler.name]);
+          menuItem.setAttribute("label", label);
+          menuItem.setAttribute("tooltiptext", label);
+          menuItem.setAttribute("image", this._getIconURLForHandlerApp(handler));
+
+          // Attach the handler app object to the menu item so we can use it
+          // to make changes to the datastore when the user selects the item.
+          menuItem.handlerApp = handler;
+
+          menuPopup.appendChild(menuItem);
+          possibleAppMenuItems.push(menuItem);
+        }
+      }
+    }
+
     // Create a menu item for the plugin.
     if (handlerInfo.plugin) {
       let pluginMenuItem = document.createElement("menuitem");
       pluginMenuItem.setAttribute("class", "handler-action");
       pluginMenuItem.setAttribute("value", kActionUsePlugin);
       let label = this._prefsBundle.getFormattedString("usePluginIn",
                                                        [handlerInfo.plugin.name,
                                                         this._brandShortName]);