Bug 911904 - Remove html handlers from helper apps. r=margaret a=lsblakk
authorWes Johnston <wjohnston@mozilla.com>
Tue, 11 Feb 2014 15:10:00 -0800
changeset 176391 718fe43eeed117d07e98414efebb2e6e78117b88
parent 176390 07e9d1f64d55d4a307299cfb50d3fb130bfef217
child 176392 525d9af770e738d9f4c8c0a2c22ba876bac2a669
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret, lsblakk
bugs911904
milestone28.0
Bug 911904 - Remove html handlers from helper apps. r=margaret a=lsblakk
mobile/android/modules/HelperApps.jsm
--- a/mobile/android/modules/HelperApps.jsm
+++ b/mobile/android/modules/HelperApps.jsm
@@ -30,17 +30,31 @@ App.prototype = {
     HelperApps._launchApp(this, uri);
     return false;
   }
 }
 
 var HelperApps =  {
   get defaultHttpHandlers() {
     delete this.defaultHttpHandlers;
-    return this.defaultHttpHandlers = this.getAppsForProtocol("http");
+    this.defaultHttpHandlers = this.getAppsForProtocol("http");
+    return this.defaultHttpHandlers;
+  },
+
+  get defaultHtmlHandlers() {
+    delete this.defaultHtmlHandlers;
+    this.defaultHtmlHandlers = {};
+    let handlers = this.getAppsForUri(Services.io.newURI("http://www.example.com/index.html", null, null), {
+      filterHtml: false
+    });
+
+    handlers.forEach(function(app) {
+      this.defaultHtmlHandlers[app.name] = app;
+    }, this);
+    return this.defaultHtmlHandlers;
   },
 
   get protoSvc() {
     delete this.protoSvc;
     return this.protoSvc = Cc["@mozilla.org/uriloader/external-protocol-service;1"].getService(Ci.nsIExternalProtocolService);
   },
 
   get urlHandlerService() {
@@ -65,33 +79,44 @@ var HelperApps =  {
           description: protoApp.detailedDescription,
         });
       } catch(e) {}
     }
 
     return results;
   },
 
-  getAppsForUri: function getAppsForUri(uri, flags = { filterHttp: true }) {
+  getAppsForUri: function getAppsForUri(uri, flags = { filterHttp: true, filterHtml: true }) {
     flags.filterHttp = "filterHttp" in flags ? flags.filterHttp : true;
+    flags.filterHtml = "filterHtml" in flags ? flags.filterHtml : true;
 
     // Query for apps that can/can't handle the mimetype
     let msg = this._getMessage("Intent:GetHandlers", uri, flags);
     let data = this._sendMessage(msg);
     if (!data)
       return [];
 
     let apps = this._parseApps(data.apps);
 
     if (flags.filterHttp) {
       apps = apps.filter(function(app) {
         return app.name && !this.defaultHttpHandlers[app.name];
       }, this);
     }
 
+    if (flags.filterHtml) {
+      // Matches from the first '.' to the end of the string, '?', or '#'
+      let ext = /\.([^\?#]*)/.exec(uri.path);
+      if (ext && (ext[1] === "html" || ext[1] === "htm")) {
+        apps = apps.filter(function(app) {
+          return app.name && !this.defaultHtmlHandlers[app.name];
+        }, this);
+      }
+    }
+
     return apps;
   },
 
   launchUri: function launchUri(uri) {
     let msg = this._getMessage("Intent:Open", uri);
     this._sendMessage(msg);
   },