Bug 1347616 - Fall back to bookmark when manifest invalid. r=sebastian
authorDale Harvey <dale@arandomurl.com>
Tue, 28 Mar 2017 21:42:22 +0100
changeset 350264 07bba24c4f671b46b351f6ae0c1bdc60fd419c8f
parent 350146 272ce6c2572164f5f6a9fba2a980ba9ccf50770c
child 350265 4233e7174cb8dfdf344ceb027f2061b10038c2f2
push id31570
push userryanvm@gmail.com
push dateWed, 29 Mar 2017 13:42:06 +0000
treeherdermozilla-central@6ea713ccc9ab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1347616
milestone55.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 1347616 - Fall back to bookmark when manifest invalid. r=sebastian
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -759,16 +759,17 @@ public class BrowserApp extends GeckoApp
             "Experiments:ClearOverride",
             "Favicon:Request",
             "Feedback:MaybeLater",
             "Sanitize:ClearHistory",
             "Sanitize:ClearSyncedTabs",
             "Telemetry:Gather",
             "Download:AndroidDownloadManager",
             "Website:AppInstalled",
+            "Website:AppInstallFailed",
             "Website:Metadata",
             null);
 
         getAppEventDispatcher().registerUiThreadListener(this, "Prompt:ShowTop");
 
         final GeckoProfile profile = getProfile();
 
         // We want to upload the telemetry core ping as soon after startup as possible. It relies on the
@@ -1514,16 +1515,17 @@ public class BrowserApp extends GeckoApp
             "Experiments:ClearOverride",
             "Favicon:Request",
             "Feedback:MaybeLater",
             "Sanitize:ClearHistory",
             "Sanitize:ClearSyncedTabs",
             "Telemetry:Gather",
             "Download:AndroidDownloadManager",
             "Website:AppInstalled",
+            "Website:AppInstallFailed",
             "Website:Metadata",
             null);
 
         getAppEventDispatcher().unregisterUiThreadListener(this, "Prompt:ShowTop");
 
         if (AppConstants.MOZ_ANDROID_BEAM) {
             NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
             if (nfc != null) {
@@ -2036,16 +2038,22 @@ public class BrowserApp extends GeckoApp
                 final String startUrl = message.getString("start_url");
                 final String manifestPath = message.getString("manifest_path");
                 final Bitmap icon = FaviconDecoder
                     .decodeDataURI(getContext(), message.getString("icon"))
                     .getBestBitmap(GeckoAppShell.getPreferredIconSize());
                 createAppShortcut(name, startUrl, manifestPath, icon);
                 break;
 
+            case "Website:AppInstallFailed":
+                final String title = message.getString("title");
+                final String bookmarkUrl = message.getString("url");
+                createBrowserShortcut(title, bookmarkUrl);
+                break;
+
             case "Updater:Launch":
                 /**
                  * Launch UI that lets the user update Firefox.
                  *
                  * This depends on the current channel: Release and Beta both direct to
                  * the Google Play Store. If updating is enabled, Aurora, Nightly, and
                  * custom builds open about:, which provides an update interface.
                  *
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -2011,33 +2011,38 @@ public abstract class GeckoApp
         final Tab selectedTab = Tabs.getInstance().getSelectedTab();
         final String manifestUrl = selectedTab.getManifestUrl();
 
         if (manifestUrl != null) {
             // If a page has associated manifest, lets install it
             final GeckoBundle message = new GeckoBundle();
             message.putInt("iconSize", GeckoAppShell.getPreferredIconSize());
             message.putString("manifestUrl", manifestUrl);
+            message.putString("originalUrl", url);
+            message.putString("originalTitle", title);
             EventDispatcher.getInstance().dispatch("Browser:LoadManifest", message);
             return;
         }
 
-        // Otherwise we try to pick best icon from favicons etc
-        Icons.with(this)
-                .pageUrl(url)
-                .skipNetwork()
-                .skipMemory()
-                .forLauncherIcon()
-                .build()
-                .execute(new IconCallback() {
-                    @Override
-                    public void onIconResponse(IconResponse response) {
-                        createShortcut(title, url, response.getBitmap());
-                    }
-                });
+        createBrowserShortcut(title, url);
+    }
+
+    public void createBrowserShortcut(final String title, final String url) {
+      Icons.with(this)
+              .pageUrl(url)
+              .skipNetwork()
+              .skipMemory()
+              .forLauncherIcon()
+              .build()
+              .execute(new IconCallback() {
+                  @Override
+                  public void onIconResponse(IconResponse response) {
+                      createShortcut(title, url, response.getBitmap());
+                  }
+              });
     }
 
     public void createShortcut(final String aTitle, final String aURI, final Bitmap aIcon) {
         Intent shortcutIntent = new Intent();
         shortcutIntent.setAction(GeckoApp.ACTION_HOMESCREEN_SHORTCUT);
         shortcutIntent.setData(Uri.parse(aURI));
         shortcutIntent.setClassName(AppConstants.ANDROID_PACKAGE_NAME,
                 AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -1671,17 +1671,17 @@ var BrowserApp = {
     Services.prefs.setComplexValue(pref, Ci.nsIPrefLocalizedString, pls);
   },
 
   onEvent: function (event, data, callback) {
     let browser = this.selectedBrowser;
 
     switch (event) {
       case "Browser:LoadManifest": {
-        installManifest(browser, data.manifestUrl, data.iconSize);
+        installManifest(browser, data);
         break;
       }
 
       case "Browser:Quit":
         this.quit(data);
         break;
 
       case "Fonts:Reload":
@@ -2201,30 +2201,36 @@ var BrowserApp = {
 
     return {
       "historyItems": listitems,
       "toIndex": toIndex
     };
   },
 };
 
-async function installManifest(browser, manifestUrl, iconSize) {
+async function installManifest(browser, data) {
   try {
-    const manifest = await Manifests.getManifest(browser, manifestUrl);
+    const manifest = await Manifests.getManifest(browser, data.manifestUrl);
     await manifest.install();
-    const icon = await manifest.icon(iconSize);
+    const icon = await manifest.icon(data.iconSize);
     GlobalEventDispatcher.sendRequest({
       type: "Website:AppInstalled",
       icon,
       name: manifest.name,
       start_url: manifest.start_url,
       manifest_path: manifest.path
     });
   } catch (err) {
     Cu.reportError("Failed to install: " + err.message);
+    // If we fail to install via the manifest, we will fall back to a standard bookmark
+    GlobalEventDispatcher.sendRequest({
+      type: "Website:AppInstallFailed",
+      url: data.originalUrl,
+      title: data.originalTitle
+    });
   }
 }
 
 var NativeWindow = {
   init: function() {
     GlobalEventDispatcher.registerListener(this, [
       "Doorhanger:Reply",
       "Menu:Clicked",