From 8b313cdda5b40d1a6208aaef11c7014c200418ff Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Tue, 26 Jun 2012 11:56:03 -0700 Subject: [PATCH] Bug 766297 - Create a default prefs.js for webapps. r=mfinkle --- mobile/android/app/mobile.js | 3 -- mobile/android/base/GeckoApp.java | 2 +- mobile/android/base/GeckoAppShell.java | 29 +++++++++++++++++++ mobile/android/base/GeckoProfile.java | 8 +++++ mobile/android/base/Makefile.in | 6 +++- .../base/resources/raw/webapp_prefs_js | 22 ++++++++++++++ 6 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 mobile/android/base/resources/raw/webapp_prefs_js diff --git a/mobile/android/app/mobile.js b/mobile/android/app/mobile.js index 4f7a35ea5c9..9c724c97aa6 100644 --- a/mobile/android/app/mobile.js +++ b/mobile/android/app/mobile.js @@ -26,11 +26,8 @@ pref("toolkit.browser.contentViewExpire", 3000); pref("toolkit.defaultChromeURI", "chrome://browser/content/browser.xul"); pref("browser.chromeURL", "chrome://browser/content/"); -pref("browser.tabs.warnOnClose", true); pref("browser.tabs.remote", false); -pref("toolkit.screen.lock", false); - // From libpref/src/init/all.js, extended to allow a slightly wider zoom range. pref("zoom.minPercent", 20); pref("zoom.maxPercent", 400); diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index 8d5b8cbaa7d..5ef58013789 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -1228,7 +1228,7 @@ abstract public class GeckoApp String launchPath = message.getString("launchPath"); String iconURL = message.getString("iconURL"); String uniqueURI = message.getString("uniqueURI"); - GeckoAppShell.createShortcut(name, launchPath, uniqueURI, iconURL, "webapp"); + GeckoAppShell.installWebApp(name, launchPath, uniqueURI, iconURL); } 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 9f1082798bd..0358a3f4e55 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -845,6 +845,35 @@ 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/GeckoProfile.java b/mobile/android/base/GeckoProfile.java index d34d89f5f03..88c9ea6add3 100644 --- a/mobile/android/base/GeckoProfile.java +++ b/mobile/android/base/GeckoProfile.java @@ -143,6 +143,14 @@ public final class GeckoProfile { return mDir; } + public File getFile(String aFile) { + File f = getDir(); + if (f == null) + return null; + + return new File(f, aFile); + } + public File getFilesDir() { return mContext.getFilesDir(); } diff --git a/mobile/android/base/Makefile.in b/mobile/android/base/Makefile.in index f826b9a30e6..5ca0324faf7 100644 --- a/mobile/android/base/Makefile.in +++ b/mobile/android/base/Makefile.in @@ -870,6 +870,10 @@ 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 @@ -926,7 +930,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_LAYOUT_SW600DP) $(RES_VALUES) $(RES_VALUES_V11) $(RES_VALUES_XLARGE) $(RES_VALUES_SW600DP) $(RES_VALUES_LAND_V14) $(RES_VALUES_SW600DP_V14) $(RES_XML) $(RES_ANIM) $(RES_DRAWABLE_NODPI) $(RES_DRAWABLE_BASE) $(RES_DRAWABLE_LDPI) $(RES_DRAWABLE_HDPI) $(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_DRAWABLE_SW600DP_MDPI) $(RES_DRAWABLE_SW600DP_HDPI) $(RES_DRAWABLE_SW600DP_XHDPI) $(RES_COLOR) $(RES_MENU) +RESOURCES=$(RES_LAYOUT) $(RES_LAYOUT_LAND_V14) $(RES_LAYOUT_XLARGE) $(RES_LAYOUT_SW600DP) $(RES_VALUES) $(RES_VALUES_V11) $(RES_VALUES_XLARGE) $(RES_VALUES_SW600DP) $(RES_VALUES_LAND_V14) $(RES_VALUES_SW600DP_V14) $(RES_XML) $(RES_ANIM) $(RES_DRAWABLE_NODPI) $(RES_DRAWABLE_BASE) $(RES_DRAWABLE_LDPI) $(RES_DRAWABLE_HDPI) $(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_DRAWABLE_SW600DP_MDPI) $(RES_DRAWABLE_SW600DP_HDPI) $(RES_DRAWABLE_SW600DP_XHDPI) $(RES_COLOR) $(RES_MENU) $(RES_RAW) RES_DIRS= \ res/layout \ diff --git a/mobile/android/base/resources/raw/webapp_prefs_js b/mobile/android/base/resources/raw/webapp_prefs_js new file mode 100644 index 00000000000..6c878a0d38c --- /dev/null +++ b/mobile/android/base/resources/raw/webapp_prefs_js @@ -0,0 +1,22 @@ +/* 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%");