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 192804 e29246e8b6707414eb20899e567d61de76a9c679
parent 192803 2a597beb4be711f511e7e5666ac8bb7eacfa536d
child 192805 1ee93f1f8259a874d9b5739e817dea5ecf642b6b
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, sledru
bugs990395
milestone30.0a2
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
@@ -30,33 +30,45 @@ App.prototype = {
   // callback will be null if a result is not requested
   launch: function(uri, callback) {
     HelperApps._launchApp(this, uri, callback);
     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() {
@@ -81,36 +93,39 @@ var HelperApps =  {
           description: protoApp.detailedDescription,
         });
       } catch(e) {}
     }
 
     return results;
   },
 
-  getAppsForUri: function getAppsForUri(uri, flags = { filterHttp: true, filterHtml: true }, callback) {
-    flags.filterHttp = "filterHttp" in flags ? flags.filterHttp : true;
+  getAppsForUri: function getAppsForUri(uri, flags = { }, callback) {
+    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 parseData = (d) => {
       let apps = []
 
       if (!d)
         return apps;
 
       apps = this._parseApps(d.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);
         }