diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index a35c58f5380e..764efefefc97 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -1256,7 +1256,7 @@ abstract public class GeckoApp String launchPath = message.getString("launchPath"); String iconURL = message.getString("iconURL"); String uniqueURI = message.getString("uniqueURI"); - GeckoAppShell.installWebApp(name, launchPath, uniqueURI, iconURL); + GeckoAppShell.createShortcut(name, launchPath, uniqueURI, iconURL, "webapp"); } else if (event.equals("WebApps:Uninstall")) { String uniqueURI = message.getString("uniqueURI"); GeckoAppShell.uninstallWebApp(uniqueURI); diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index 6ef8ddf5ae96..10c2b8b43eb5 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -852,35 +852,6 @@ public class GeckoAppShell }); } - public static void installWebApp(String aTitle, String aURI, String aUniqueURI, String aIconURL) { - int index = WebAppAllocator.getInstance(GeckoApp.mAppContext).findAndAllocateIndex(aUniqueURI); - GeckoProfile profile = GeckoProfile.get(GeckoApp.mAppContext, "webapp" + index); - File prefs = profile.getFile("prefs.js"); - - InputStream in = null; - OutputStream out = null; - try { - in = GeckoApp.mAppContext.getResources().openRawResource(R.raw.webapp_prefs_js); - out = new FileOutputStream(prefs); - byte buf[]=new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - } catch(FileNotFoundException ex) { - } catch(IOException ex) { - } finally { - try { - if (out != null) - out.close(); - if (in != null) - in.close(); - } catch(IOException ex) { - } - } - createShortcut(aTitle, aURI, aUniqueURI, aIconURL, "webapp"); - } - public static void uninstallWebApp(final String uniqueURI) { // On uninstall, we need to do a couple of things: // 1. nuke the running app process. diff --git a/mobile/android/base/Makefile.in b/mobile/android/base/Makefile.in index 735f4ab464e7..92c2767829db 100644 --- a/mobile/android/base/Makefile.in +++ b/mobile/android/base/Makefile.in @@ -848,10 +848,6 @@ RES_MENU = \ res/menu/titlebar_contextmenu.xml \ $(NULL) -RES_RAW = \ - res/raw/webapp_prefs_js \ - $(NULL) - JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar ifdef MOZ_CRASHREPORTER @@ -911,7 +907,7 @@ MOZ_ANDROID_DRAWABLES += \ MOZ_ANDROID_DRAWABLES += $(shell if test -e $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/android-resources.mn; then cat $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/android-resources.mn | tr '\n' ' '; fi) -RESOURCES=$(RES_LAYOUT) $(RES_LAYOUT_LAND_V14) $(RES_LAYOUT_XLARGE) $(RES_VALUES) $(RES_VALUES_V11) $(RES_VALUES_XLARGE) $(RES_VALUES_LAND_V14) $(RES_VALUES_XLARGE_V14) $(RES_XML) $(RES_ANIM) $(RES_DRAWABLE_NODPI) $(RES_DRAWABLE_BASE) $(RES_DRAWABLE_LDPI) $(RES_DRAWABLE_HDPI) $(RES_DRAWABLE_XHDPI) $(RES_DRAWABLE_MDPI_V11) $(RES_DRAWABLE_HDPI_V11) $(RES_DRAWABLE_XHDPI_V11) $(RES_DRAWABLE_LAND_V14) $(RES_DRAWABLE_LAND_MDPI_V14) $(RES_DRAWABLE_LAND_HDPI_V14) $(RES_DRAWABLE_LAND_XHDPI_V14) $(RES_DRAWABLE_XLARGE_MDPI) $(RES_DRAWABLE_XLARGE_HDPI) $(RES_DRAWABLE_XLARGE_XHDPI) $(RES_COLOR) $(RES_MENU) $(RES_RAW) +RESOURCES=$(RES_LAYOUT) $(RES_LAYOUT_LAND_V14) $(RES_LAYOUT_XLARGE) $(RES_VALUES) $(RES_VALUES_V11) $(RES_VALUES_XLARGE) $(RES_VALUES_LAND_V14) $(RES_VALUES_XLARGE_V14) $(RES_XML) $(RES_ANIM) $(RES_DRAWABLE_NODPI) $(RES_DRAWABLE_BASE) $(RES_DRAWABLE_LDPI) $(RES_DRAWABLE_HDPI) $(RES_DRAWABLE_XHDPI) $(RES_DRAWABLE_MDPI_V11) $(RES_DRAWABLE_HDPI_V11) $(RES_DRAWABLE_XHDPI_V11) $(RES_DRAWABLE_LAND_V14) $(RES_DRAWABLE_LAND_MDPI_V14) $(RES_DRAWABLE_LAND_HDPI_V14) $(RES_DRAWABLE_LAND_XHDPI_V14) $(RES_DRAWABLE_XLARGE_MDPI) $(RES_DRAWABLE_XLARGE_HDPI) $(RES_DRAWABLE_XLARGE_XHDPI) $(RES_COLOR) $(RES_MENU) RES_DIRS= \ res/layout \ diff --git a/mobile/android/base/resources/raw/webapp_prefs_js b/mobile/android/base/resources/raw/webapp_prefs_js deleted file mode 100644 index e9d3df284be1..000000000000 --- a/mobile/android/base/resources/raw/webapp_prefs_js +++ /dev/null @@ -1,25 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -pref("browser.download.folderList", 1); - -// Disable all add-on locations other than the profile (which can't be disabled this way) -pref("extensions.enabledScopes", 1); -// Auto-disable any add-ons that are "dropped in" to the profile -pref("extensions.autoDisableScopes", 1); -// Disable add-on installation via the web-exposed APIs -pref("xpinstall.enabled", false); - -// Blocklist preferences -pref("extensions.blocklist.enabled", true); -pref("extensions.blocklist.interval", 86400); -// Controls what level the blocklist switches from warning about items to forcibly -// blocking them. -pref("extensions.blocklist.level", 2); -pref("extensions.blocklist.url", "https://addons.mozilla.org/blocklist/3/%APP_ID%/%APP_VERSION%/%PRODUCT%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/%PING_COUNT%/%TOTAL_PING_COUNT%/%DAYS_SINCE_LAST_PING%/"); -pref("extensions.blocklist.detailsURL", "https://www.mozilla.com/%LOCALE%/blocklist/"); -pref("extensions.blocklist.itemURL", "https://addons.mozilla.org/%LOCALE%/%APP%/blocked/%blockID%"); - -// Disable the telemetry prompt in webapps -pref("toolkit.telemetry.prompted", true); diff --git a/mobile/android/chrome/content/WebAppRT.js b/mobile/android/chrome/content/WebAppRT.js index 6a61c15941ac..4618867fc58c 100644 --- a/mobile/android/chrome/content/WebAppRT.js +++ b/mobile/android/chrome/content/WebAppRT.js @@ -7,10 +7,45 @@ let Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); +function pref(name, value) { + return { + name: name, + value: value + } +} + var WebAppRT = { - init: function() { + prefs: [ + // Disable all add-on locations other than the profile (which can't be disabled this way) + pref("extensions.enabledScopes", 1), + // Auto-disable any add-ons that are "dropped in" to the profile + pref("extensions.autoDisableScopes", 1), + // Disable add-on installation via the web-exposed APIs + pref("xpinstall.enabled", false), + // Disable the telemetry prompt in webapps + pref("toolkit.telemetry.prompted", true) + ], + + init: function(isUpdate) { this.deck = document.getElementById("browsers"); this.deck.addEventListener("click", this, false, true); + + // on first run, update any prefs + if (isUpdate == "new") { + this.prefs.forEach(function(aPref) { + switch (typeof aPref.value) { + case "string": + Services.prefs.setCharPref(aPref.name, aPref.value); + break; + case "boolean": + Services.prefs.setBoolPref(aPref.name, aPref.value); + break; + case "number": + Services.prefs.setIntPref(aPref.name, aPref.value); + break; + } + }); + } }, handleEvent: function(event) { diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index ea975e7d34d3..64e03f6276f2 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -242,6 +242,10 @@ var BrowserApp = { pinned = window.arguments[4]; } + let updated = this.isAppUpdated(); + if (pinned) + WebAppRT.init(updated); + if (url == "about:empty") loadParams.flags = Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_HISTORY; @@ -310,10 +314,7 @@ var BrowserApp = { #endif } - if (pinned) - WebAppRT.init(); - - if (this.isAppUpdated()) + if (updated) this.onAppUpdated(); // notify java that gecko has loaded