Bug 1529367 - Part 1: Don't send MIME type when querying external apps for non-local HTML documents. r=geckoview-reviewers,snorp
authorJan Henning <jh+bugzilla@buttercookie.de>
Mon, 25 Feb 2019 20:07:55 +0000
changeset 519076 cd6d699aabde2bb4c4b6d1e70682549e5dc9dcb7
parent 519075 13ac435c29366bfe5688ea06fbc580e7dd96d24d
child 519077 5d81bc61dfb82e34be9517420f90aa93910d42ab
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, snorp
bugs1529367
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1529367 - Part 1: Don't send MIME type when querying external apps for non-local HTML documents. r=geckoview-reviewers,snorp Differential Revision: https://phabricator.services.mozilla.com/D20861
mobile/android/modules/HelperApps.jsm
--- a/mobile/android/modules/HelperApps.jsm
+++ b/mobile/android/modules/HelperApps.jsm
@@ -15,16 +15,21 @@ ChromeUtils.defineModuleGetter(this, "Ev
                                "resource://gre/modules/Messaging.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "ContentAreaUtils", function() {
   let ContentAreaUtils = {};
   Services.scriptloader.loadSubScript("chrome://global/content/contentAreaUtils.js", ContentAreaUtils);
   return ContentAreaUtils;
 });
 
+const NON_FILE_URI_IGNORED_MIME_TYPES = new Set([
+  "text/html",
+  "application/xhtml+xml",
+]);
+
 var EXPORTED_SYMBOLS = ["App", "HelperApps"];
 
 class App {
   constructor(data) {
     this.name = data.name;
     this.isDefault = data.isDefault;
     this.packageName = data.packageName;
     this.activityName = data.activityName;
@@ -52,19 +57,18 @@ var HelperApps =  {
     });
     let httpsHandlers = this._getHandlers("https://www.example.com", {
       filterBrowsers: false,
       filterHtml: false,
     });
     return {...httpHandlers, ...httpsHandlers};
   },
 
-  // 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.
+  // Finds handlers that have registered for urls ending in html. Some apps, like
+  // the Samsung Video player, will only appear for these urls.
   get defaultHtmlHandlers() {
     delete this.defaultHtmlHandlers;
     return this.defaultHtmlHandlers = this._getHandlers("http://www.example.com/index.html", {
       filterBrowsers: false,
       filterHtml: false,
     });
   },
 
@@ -189,16 +193,30 @@ var HelperApps =  {
 
     return apps;
   },
 
   _getMessage(type, uri, options = {}) {
     let mimeType = options.mimeType;
     if (uri && mimeType == undefined) {
       mimeType = ContentAreaUtils.getMIMETypeForURI(uri) || "";
+      if (uri.scheme != "file" && NON_FILE_URI_IGNORED_MIME_TYPES.has(mimeType)) {
+        // We're guessing the MIME type based on the extension, which especially
+        // with non-local HTML documents will yield inconsistent results, as those
+        // commonly use URLs without any sort of extension, too.
+        // At the same time, apps offering to handle certain URLs in lieu of a
+        // browser often don't expect a MIME type to be used, and correspondingly
+        // register their intent filters without a MIME type.
+        // This means that when we *do* guess a non-empty MIME type because this
+        // time the URL *did* end on .(x)htm(l), Android won't offer any apps whose
+        // intent filter doesn't explicitly include that MIME type.
+        // Therefore, if the MIME type looks like something from that category,
+        // don't bother including it in the Intent for non-local files.
+        mimeType = "";
+      }
     }
 
     return {
       type: type,
       mime: mimeType,
       action: options.action || "", // empty action string defaults to android.intent.action.VIEW
       url: uri ? uri.displaySpec : "",
       packageName: options.packageName || "",