Bug 990395 - Use a url to find browser apps rather than a scheme. r=mfinkle, a=sledru
authorWes Johnston <wjohnston@mozilla.com>
Fri, 11 Apr 2014 14:19:13 -0700
changeset 183754 2ab3be04316ae3d1178ed7ea5870b201e2716f8c
parent 183753 109cc0131968a01f27bf5267cf9d3fed7c9e9f88
child 183755 3a3224245147f2c9775ada56229f5c93cad5c69a
push id3471
push userwjohnston@mozilla.com
push dateMon, 14 Apr 2014 18:11:11 +0000
treeherdermozilla-beta@2ab3be04316a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, sledru
bugs990395
milestone29.0
Bug 990395 - Use a url to find browser apps rather than a scheme. r=mfinkle, a=sledru
mobile/android/modules/HelperApps.jsm
--- a/mobile/android/modules/HelperApps.jsm
+++ b/mobile/android/modules/HelperApps.jsm
@@ -28,33 +28,45 @@ function App(data) {
 App.prototype = {
   launch: function(uri) {
     HelperApps._launchApp(this, uri);
     return false;
   }
 }
 
 var HelperApps =  {
-  get defaultHttpHandlers() {
-    delete this.defaultHttpHandlers;
-    this.defaultHttpHandlers = this.getAppsForProtocol("http");
-    return this.defaultHttpHandlers;
+  get defaultBrowsers() {
+    delete this.defaultBrowsers;
+    this.defaultBrowsers = this._getHandlers("http://www.example.com", {
+      filterBrowsers: false,
+      filterHtml: false
+    });
+    return this.defaultBrowsers;
   },
 
+  // Finds handlers that have registered for text/html pages or urls ending in html. Some apps, like
+  // the Samsung Video player will only appear for these urls, while some Browsers (like Link Bubble)
+  // won't register here because of the text/html mime type.
   get defaultHtmlHandlers() {
     delete this.defaultHtmlHandlers;
-    this.defaultHtmlHandlers = {};
-    let handlers = this.getAppsForUri(Services.io.newURI("http://www.example.com/index.html", null, null), {
+    return this.defaultHtmlHandlers = this._getHandlers("http://www.example.com/index.html", {
+      filterBrowsers: false,
       filterHtml: false
     });
+  },
 
+  _getHandlers: function(url, options) {
+    let values = {};
+
+    let handlers = this.getAppsForUri(Services.io.newURI(url, null, null), options);
     handlers.forEach(function(app) {
-      this.defaultHtmlHandlers[app.name] = app;
+      values[app.name] = app;
     }, this);
-    return this.defaultHtmlHandlers;
+
+    return values;
   },
 
   get protoSvc() {
     delete this.protoSvc;
     return this.protoSvc = Cc["@mozilla.org/uriloader/external-protocol-service;1"].getService(Ci.nsIExternalProtocolService);
   },
 
   get urlHandlerService() {
@@ -79,34 +91,37 @@ var HelperApps =  {
           description: protoApp.detailedDescription,
         });
       } catch(e) {}
     }
 
     return results;
   },
 
-  getAppsForUri: function getAppsForUri(uri, flags = { filterHttp: true, filterHtml: true }) {
-    flags.filterHttp = "filterHttp" in flags ? flags.filterHttp : true;
+  getAppsForUri: function getAppsForUri(uri, flags = { }) {
+    flags.filterBrowsers = "filterBrowsers" in flags ? flags.filterBrowsers : 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.filterBrowsers) {
+      apps = apps.filter((app) => {
+        return app.name && !this.defaultBrowsers[app.name];
+      });
     }
 
+    // Some apps will register for html files (the Samsung Video player) but should be shown
+    // for non-HTML files (like videos). This filters them only if the page has an htm of html
+    // file extension.
     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);
       }