Bug 710548 - Add offline-app and webapp-manage permissions to pre-installed apps r=cjones DONTBUILD since this is b2g/ only

This commit is contained in:
Vivien Nicolas 2011-12-14 21:02:48 +01:00
parent 1ab4c87fe8
commit a486f20abe
2 changed files with 27 additions and 7 deletions

View File

@ -66,6 +66,7 @@ pref("image.cache.size", 1048576); // bytes
/* offline cache prefs */
pref("browser.offline-apps.notify", false);
pref("browser.cache.offline.enable", false);
/* protocol warning prefs */
pref("network.protocol-handler.warn-external.tel", false);

View File

@ -72,11 +72,19 @@ function startupHttpd(baseDir, port) {
server.start(port);
}
// XXX until we have a security model, just let the pre-installed
// app used indexedDB.
function allowIndexedDB(url) {
let uri = Services.io.newURI(url, null, null);
Services.perms.add(uri, 'indexedDB', Ci.nsIPermissionManager.ALLOW_ACTION);
// FIXME Bug 707625
// until we have a proper security model, add some rights to
// the pre-installed web applications
function addPermissions(urls) {
let permissions = ['indexedDB', 'webapps-manage', 'offline-app'];
urls.forEach(function(url) {
let uri = Services.io.newURI(url, null, null);
let allow = Ci.nsIPermissionManager.ALLOW_ACTION;
permissions.forEach(function(permission) {
Services.perms.add(uri, permission, allow);
});
});
}
@ -135,7 +143,7 @@ var shell = {
let baseHost = 'http://localhost';
homeURL = homeURL.replace(baseDir, baseHost + ':' + SERVER_PORT);
}
allowIndexedDB(homeURL);
addPermissions([homeURL]);
} catch (e) {
let msg = 'Fatal error during startup: [' + e + '[' + homeURL + ']';
return alert(msg);
@ -200,6 +208,9 @@ var shell = {
break;
case 'MozApplicationManifest':
try {
if (!Services.prefs.getBoolPref('browser.cache.offline.enable'))
return;
let contentWindow = evt.originalTarget.defaultView;
let documentElement = contentWindow.document.documentElement;
if (!documentElement)
@ -210,10 +221,18 @@ var shell = {
return;
let documentURI = contentWindow.document.documentURIObject;
let manifestURI = Services.io.newURI(manifest, null, documentURI);
if (!Services.perms.testPermission(documentURI, 'offline-app')) {
if (Services.prefs.getBoolPref('browser.offline-apps.notify')) {
// FIXME Bug 710729 - Add a UI for offline cache notifications
return;
}
return;
}
Services.perms.add(documentURI, 'offline-app',
Ci.nsIPermissionManager.ALLOW_ACTION);
let manifestURI = Services.io.newURI(manifest, null, documentURI);
let updateService = Cc['@mozilla.org/offlinecacheupdate-service;1']
.getService(Ci.nsIOfflineCacheUpdateService);
updateService.scheduleUpdate(manifestURI, documentURI, window);