diff --git a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java index d481f66b72bc..eaf64d0f86ca 100644 --- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java +++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java @@ -764,6 +764,7 @@ public class BrowserApp extends GeckoApp "Telemetry:Gather", "Download:AndroidDownloadManager", "Website:AppInstalled", + "Website:AppInstallFailed", "Website:Metadata", null); @@ -1519,6 +1520,7 @@ public class BrowserApp extends GeckoApp "Telemetry:Gather", "Download:AndroidDownloadManager", "Website:AppInstalled", + "Website:AppInstallFailed", "Website:Metadata", null); @@ -2041,6 +2043,12 @@ public class BrowserApp extends GeckoApp 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. diff --git a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java index 42db038390f4..7fff56dc3997 100644 --- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java +++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java @@ -2016,23 +2016,28 @@ public abstract class GeckoApp 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) { diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 6976f8907064..b1f800d5d1e1 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -1676,7 +1676,7 @@ var BrowserApp = { switch (event) { case "Browser:LoadManifest": { - installManifest(browser, data.manifestUrl, data.iconSize); + installManifest(browser, data); break; } @@ -2206,11 +2206,11 @@ var BrowserApp = { }, }; -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, @@ -2220,6 +2220,12 @@ async function installManifest(browser, manifestUrl, iconSize) { }); } 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 + }); } }