Bug 860782 - Move Android permission install to first run, from install. r=wesj, r=fabrice

* * *
Bug 860782 - Use app when requesting permissions. r=mfinkle
* * *
Bug 860782 - Disable permissions tests on platforms where they shouldn't work. r=mfinkle
This commit is contained in:
James Hugman 2013-06-20 12:51:18 -04:00
parent 7771020b67
commit fd318a565f
3 changed files with 46 additions and 31 deletions

View File

@ -258,6 +258,8 @@ this.DOMApplicationRegistry = {
// Install the permissions for this app, as if we were updating
// to cleanup the old ones if needed.
// TODO It's not clear what this should do when there are multiple profiles.
#ifdef MOZ_B2G
this._readManifests([{ id: aId }], (function(aResult) {
let data = aResult[0];
PermissionsInstaller.installPermissions({
@ -268,6 +270,7 @@ this.DOMApplicationRegistry = {
debug("Error installing permissions for " + aId);
});
}).bind(this));
#endif
},
updateOfflineCacheForApp: function updateOfflineCacheForApp(aId) {
@ -1237,11 +1240,13 @@ this.DOMApplicationRegistry = {
this._saveApps((function() {
// Update the handlers and permissions for this app.
this.updateAppHandlers(aOldManifest, aData, app);
#ifdef MOZ_B2G
PermissionsInstaller.installPermissions(
{ manifest: aData,
origin: app.origin,
manifestURL: app.manifestURL },
true);
#endif
this.broadcastMessage("Webapps:PackageEvent",
{ type: "applied",
manifestURL: app.manifestURL,
@ -1462,13 +1467,14 @@ this.DOMApplicationRegistry = {
this._writeFile(manFile, JSON.stringify(aNewManifest), function() { });
manifest = new ManifestHelper(aNewManifest, app.origin);
#ifdef MOZ_B2G
// Update the permissions for this app.
PermissionsInstaller.installPermissions({
manifest: app.manifest,
origin: app.origin,
manifestURL: aData.manifestURL
}, true);
#endif
app.name = manifest.name;
app.csp = manifest.csp || "";
app.updateTime = Date.now();
@ -2012,12 +2018,14 @@ this.DOMApplicationRegistry = {
// For package apps, the permissions are not in the mini-manifest, so
// don't update the permissions yet.
if (!aData.isPackage) {
#ifdef MOZ_B2G
PermissionsInstaller.installPermissions({ origin: appObject.origin,
manifestURL: appObject.manifestURL,
manifest: jsonManifest },
isReinstall, (function() {
this.uninstall(aData, aData.mm);
}).bind(this));
#endif
}
["installState", "downloadAvailable",
@ -2075,12 +2083,13 @@ this.DOMApplicationRegistry = {
app.downloadAvailable = false;
this._saveApps((function() {
this.updateAppHandlers(null, aManifest, appObject);
#ifdef MOZ_B2G
// Update the permissions for this app.
PermissionsInstaller.installPermissions({ manifest: aManifest,
origin: appObject.origin,
manifestURL: appObject.manifestURL },
true);
#endif
debug("About to fire Webapps:PackageEvent 'installed'");
this.broadcastMessage("Webapps:PackageEvent",
{ type: "installed",

View File

@ -28,7 +28,7 @@ MOCHITEST_BROWSER_FILES := \
page_privatestorageevent.html
$(NULL)
ifeq (,$(filter-out Linux WINNT,$(OS_ARCH)))
ifdef MOZ_B2G
MOCHITEST_BROWSER_FILES += \
browser_webapps_permissions.js \
test-webapp.webapp \

View File

@ -8,6 +8,7 @@ let Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://gre/modules/PermissionsInstaller.jsm");
function pref(name, value) {
return {
@ -42,21 +43,23 @@ let WebAppRT = {
// prevent offering to use helper apps for things that this app handles
// i.e. don't show the "Open in market?" popup when we're showing the market app
let uri = Services.io.newURI(aUrl, null, null);
Services.perms.add(uri, "native-intent", Ci.nsIPermissionManager.DENY_ACTION);
Services.perms.add(uri, "offline-app", Ci.nsIPermissionManager.ALLOW_ACTION);
Services.perms.add(uri, "indexedDB", Ci.nsIPermissionManager.ALLOW_ACTION);
Services.perms.add(uri, "indexedDB-unlimited", Ci.nsIPermissionManager.ALLOW_ACTION);
// update the blocklist url to use a different app id
let blocklist = Services.prefs.getCharPref("extensions.blocklist.url");
blocklist = blocklist.replace(/%APP_ID%/g, "webapprt-mobile@mozilla.org");
Services.prefs.setCharPref("extensions.blocklist.url", blocklist);
this.getManifestFor(aUrl, function (aManifest, aApp) {
if (aManifest) {
PermissionsInstaller.installPermissions(aApp, true);
}
});
}
this.findManifestUrlFor(aUrl, aCallback);
},
findManifestUrlFor: function(aUrl, aCallback) {
getManifestFor: function (aUrl, aCallback) {
let request = navigator.mozApps.mgmt.getAll();
request.onsuccess = function() {
let apps = request.result;
@ -64,35 +67,38 @@ let WebAppRT = {
let app = apps[i];
let manifest = new ManifestHelper(app.manifest, app.origin);
// First see if this url matches any manifests we have registered
// If so, get the launchUrl from the manifest and we'll launch with that
//let app = DOMApplicationRegistry.getAppByManifestURL(aUrl);
if (app.manifestURL == aUrl) {
BrowserApp.manifest = app.manifest;
BrowserApp.manifestUrl = aUrl;
aCallback(manifest.fullLaunchPath());
return;
}
// Otherwise, see if the apps launch path is this url
if (manifest.fullLaunchPath() == aUrl) {
BrowserApp.manifest = app.manifest;
BrowserApp.manifestUrl = app.manifestURL;
aCallback(aUrl);
// if this is a path to the manifest, or the launch path, then we have a hit.
if (app.manifestURL == aUrl || manifest.fullLaunchPath() == aUrl) {
aCallback(manifest, app);
return;
}
}
// Finally, just attempt to open the webapp as a normal web page
aCallback(aUrl);
// Otherwise, once we loop through all of them, we have a miss.
aCallback(undefined);
};
request.onerror = function() {
// Attempt to open the webapp as a normal web page
aCallback(aUrl);
// Treat an error like a miss. We can't find the manifest.
aCallback(undefined);
};
},
findManifestUrlFor: function(aUrl, aCallback) {
this.getManifestFor(aUrl, function(aManifest, aApp) {
if (!aManifest) {
// we can't find the manifest, so open it like a web page
aCallback(aUrl);
return;
}
BrowserApp.manifest = aManifest;
BrowserApp.manifestUrl = aApp.manifestURL;
aCallback(aManifest.fullLaunchPath());
});
},
getDefaultPrefs: function() {
// read default prefs from the disk
try {
@ -134,7 +140,7 @@ let WebAppRT = {
handleEvent: function(event) {
let target = event.target;
// walk up the tree to find the nearest link tag
while (target && !(target instanceof HTMLAnchorElement)) {
target = target.parentNode;
@ -143,15 +149,15 @@ let WebAppRT = {
if (!target || target.getAttribute("target") != "_blank") {
return;
}
let uri = Services.io.newURI(target.href, target.ownerDocument.characterSet, null);
// Direct the URL to the browser.
Cc["@mozilla.org/uriloader/external-protocol-service;1"].
getService(Ci.nsIExternalProtocolService).
getProtocolHandlerInfo(uri.scheme).
launchWithURI(uri);
// Prevent the runtime from loading the URL. We do this after directing it
// to the browser to give the runtime a shot at handling the URL if we fail
// to direct it to the browser for some reason.