Merge fx-team to m-c. a=merge

This commit is contained in:
Ryan VanderMeulen 2014-06-07 13:32:47 -04:00
commit fc2fc5d260
5 changed files with 167 additions and 119 deletions

View File

@ -510,6 +510,8 @@
background-repeat: no-repeat;
background-position: 0, 1px, 2px;
}
#toolbox-buttons:empty + #toolbox-controls-separator,
#toolbox-controls-separator[invisible] {
visibility: hidden;
}

View File

@ -1333,12 +1333,12 @@ this.DOMApplicationRegistry = {
let app = this.webapps[id];
if (!app) {
debug("startDownload: No app found for " + aManifestURL);
return;
throw new Error("NO_SUCH_APP");
}
if (app.downloading) {
debug("app is already downloading. Ignoring.");
return;
throw new Error("APP_IS_DOWNLOADING");
}
// If the caller is trying to start a download but we have nothing to
@ -1352,7 +1352,7 @@ this.DOMApplicationRegistry = {
eventType: "downloaderror",
manifestURL: app.manifestURL
});
return;
throw new Error("NO_DOWNLOAD_AVAILABLE");
}
// First of all, we check if the download is supposed to update an
@ -1409,7 +1409,7 @@ this.DOMApplicationRegistry = {
if (!json) {
debug("startDownload: No update manifest found at " + file.path + " " +
aManifestURL);
return;
throw new Error("MISSING_UPDATE_MANIFEST");
}
let manifest = new ManifestHelper(json, app.manifestURL);
@ -1450,16 +1450,19 @@ this.DOMApplicationRegistry = {
}
}),
applyDownload: function applyDownload(aManifestURL) {
applyDownload: Task.async(function*(aManifestURL) {
debug("applyDownload for " + aManifestURL);
let id = this._appIdForManifestURL(aManifestURL);
let app = this.webapps[id];
if (!app || (app && !app.readyToApplyDownload)) {
return;
if (!app) {
throw new Error("NO_SUCH_APP");
}
if (!app.readyToApplyDownload) {
throw new Error("NOT_READY_TO_APPLY_DOWNLOAD");
}
// We need to get the old manifest to unregister web activities.
this.getManifestFor(aManifestURL).then((aOldManifest) => {
let oldManifest = yield this.getManifestFor(aManifestURL);
// Move the application.zip and manifest.webapp files out of TmpD
let tmpDir = FileUtils.getDir("TmpD", ["webapps", id], true, true);
let manFile = tmpDir.clone();
@ -1497,7 +1500,7 @@ this.DOMApplicationRegistry = {
Services.obs.notifyObservers(zipFile, "flush-cache-entry", null);
// Get the manifest, and set properties.
this.getManifestFor(aManifestURL).then((aData) => {
let newManifest = yield this.getManifestFor(aManifestURL);
app.downloading = false;
app.downloadAvailable = false;
app.downloadSize = 0;
@ -1515,39 +1518,35 @@ this.DOMApplicationRegistry = {
delete app.retryingDownload;
// Update the asm.js scripts we need to compile.
ScriptPreloader.preload(app, aData)
.then(() => this._saveApps()).then(() => {
yield ScriptPreloader.preload(app, newManifest);
yield this._saveApps();
// Update the handlers and permissions for this app.
this.updateAppHandlers(aOldManifest, aData, app);
this.updateAppHandlers(oldManifest, newManifest, app);
AppsUtils.loadJSONAsync(staged.path).then((aUpdateManifest) => {
let updateManifest = yield AppsUtils.loadJSONAsync(staged.path);
let appObject = AppsUtils.cloneAppObject(app);
appObject.updateManifest = aUpdateManifest;
this.notifyUpdateHandlers(appObject, aData, appFile.path);
});
appObject.updateManifest = updateManifest;
this.notifyUpdateHandlers(appObject, newManifest, appFile.path);
if (supportUseCurrentProfile()) {
PermissionsInstaller.installPermissions(
{ manifest: aData,
{ manifest: newManifest,
origin: app.origin,
manifestURL: app.manifestURL },
true);
}
this.updateDataStore(this.webapps[id].localId, app.origin,
app.manifestURL, aData, app.appStatus);
app.manifestURL, newManifest, app.appStatus);
this.broadcastMessage("Webapps:UpdateState", {
app: app,
manifest: aData,
manifest: newManifest,
manifestURL: app.manifestURL
});
this.broadcastMessage("Webapps:FireEvent", {
eventType: "downloadapplied",
manifestURL: app.manifestURL
});
});
});
});
},
}),
startOfflineCacheDownload: function(aManifest, aApp, aProfileDir, aIsUpdate) {
if (!aManifest.appcache_path) {
@ -2773,9 +2772,11 @@ this.DOMApplicationRegistry = {
if (oldPackage) {
debug("package's etag or hash unchanged; sending 'applied' event");
// The package's Etag or hash has not changed.
// We send a "applied" event right away.
// We send an "applied" event right away so code awaiting that event
// can proceed to access the app. We also throw an error to alert
// the caller that the package wasn't downloaded.
this._sendAppliedEvent(aNewApp, oldApp, id);
return;
throw new Error("PACKAGE_UNCHANGED");
}
let newManifest = yield this._openAndReadPackage(zipFile, oldApp, aNewApp,
@ -3488,6 +3489,8 @@ this.DOMApplicationRegistry = {
});
});
AppDownloadManager.remove(aNewApp.manifestURL);
throw aError;
},
doUninstall: function(aData, aMm) {

View File

@ -19,7 +19,9 @@ import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.NativeEventListener;
import org.mozilla.gecko.util.NativeJSObject;
import org.mozilla.gecko.util.ThreadUtils;
import android.content.Context;
@ -27,7 +29,7 @@ import android.graphics.Bitmap;
import android.net.Uri;
import android.util.Log;
public class InstallHelper implements GeckoEventListener {
public class InstallHelper implements NativeEventListener {
private static final String LOGTAG = "GeckoWebappInstallHelper";
private static final String[] INSTALL_EVENT_NAMES = new String[] {"Webapps:Postinstall"};
private final Context mContext;
@ -36,7 +38,7 @@ public class InstallHelper implements GeckoEventListener {
public static interface InstallCallback {
// on the GeckoThread
void installCompleted(InstallHelper installHelper, String event, JSONObject message);
void installCompleted(InstallHelper installHelper, String event, NativeJSObject message);
// on the GeckoBackgroundThread
void installErrored(InstallHelper installHelper, Exception exception);
@ -162,7 +164,7 @@ public class InstallHelper implements GeckoEventListener {
}
@Override
public void handleMessage(String event, JSONObject message) {
public void handleMessage(String event, NativeJSObject message, EventCallback callback) {
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, INSTALL_EVENT_NAMES);
if (mCallback != null) {

View File

@ -18,6 +18,7 @@ import org.mozilla.gecko.GeckoThread;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.util.NativeJSObject;
import org.mozilla.gecko.webapp.InstallHelper.InstallCallback;
import android.content.Intent;
@ -325,13 +326,13 @@ public class WebappImpl extends GeckoApp implements InstallCallback {
}
@Override
public void installCompleted(InstallHelper installHelper, String event, JSONObject message) {
public void installCompleted(InstallHelper installHelper, String event, NativeJSObject message) {
if (event == null) {
return;
}
if (event.equals("Webapps:Postinstall")) {
String origin = message.optString("origin");
String origin = message.optString("origin", null);
launchWebapp(origin);
}
}

View File

@ -158,37 +158,46 @@ this.WebappManager = {
return deferred.promise;
},
askInstall: function(aData) {
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(aData.profilePath);
_deleteAppcachePath: function(aManifest) {
// We don't yet support pre-installing an appcache because it isn't clear
// how to do it without degrading the user experience (since users expect
// apps to be available after the system tells them they've been installed,
// which has already happened) and because nsCacheService shuts down
// when we trigger the native install dialog and doesn't re-init itself
// afterward (TODO: file bug about this behavior).
if ("appcache_path" in aData.app.manifest) {
debug("deleting appcache_path from manifest: " + aData.app.manifest.appcache_path);
delete aData.app.manifest.appcache_path;
if ("appcache_path" in aManifest) {
debug("deleting appcache_path from manifest: " + aManifest.appcache_path);
delete aManifest.appcache_path;
}
},
askInstall: function(aData) {
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(aData.profilePath);
this._deleteAppcachePath(aData.app.manifest);
DOMApplicationRegistry.registryReady.then(() => {
DOMApplicationRegistry.confirmInstall(aData, file, (function(aManifest) {
let localeManifest = new ManifestHelper(aManifest, aData.app.origin);
// aData.app.origin may now point to the app: url that hosts this app.
sendMessageToJava({
type: "Webapps:Postinstall",
apkPackageName: aData.app.apkPackageName,
origin: aData.app.origin,
});
this.writeDefaultPrefs(file, localeManifest);
this._postInstall(aData.profilePath, aManifest, aData.app.origin, aData.app.apkPackageName);
}).bind(this));
});
},
_postInstall: function(aProfilePath, aNewManifest, aOrigin, aApkPackageName) {
// aOrigin may now point to the app: url that hosts this app.
sendMessageToJava({
type: "Webapps:Postinstall",
apkPackageName: aApkPackageName,
origin: aOrigin,
});
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(aProfilePath);
let localeManifest = new ManifestHelper(aNewManifest, aOrigin);
this.writeDefaultPrefs(file, localeManifest);
},
launch: function({ manifestURL, origin }) {
debug("launchWebapp: " + manifestURL);
@ -211,11 +220,16 @@ this.WebappManager = {
},
autoInstall: function(aData) {
let oldApp = DOMApplicationRegistry.getAppByManifestURL(aData.manifestURL);
if (oldApp) {
debug("autoInstall " + aData.manifestURL);
// If the app is already installed, update the existing installation.
this._autoUpdate(aData, oldApp);
return;
// We should be able to use DOMApplicationRegistry.getAppByManifestURL,
// but it returns a mozIApplication, while _autoUpdate needs the original
// object from DOMApplicationRegistry.webapps in order to modify it.
for (let [ , app] in Iterator(DOMApplicationRegistry.webapps)) {
if (app.manifestURL == aData.manifestURL) {
return this._autoUpdate(aData, app);
}
}
let mm = {
@ -276,13 +290,39 @@ this.WebappManager = {
}
if (aData.type == "hosted") {
this._deleteAppcachePath(aData.manifest);
let oldManifest = yield DOMApplicationRegistry.getManifestFor(aData.manifestURL);
DOMApplicationRegistry.updateHostedApp(aData, aOldApp.id, aOldApp, oldManifest, aData.manifest);
yield DOMApplicationRegistry.updateHostedApp(aData, aOldApp.id, aOldApp, oldManifest, aData.manifest);
} else {
DOMApplicationRegistry.updatePackagedApp(aData, aOldApp.id, aOldApp, aData.manifest);
yield this._autoUpdatePackagedApp(aData, aOldApp);
}
this._postInstall(aData.profilePath, aData.manifest, aOldApp.origin, aOldApp.apkPackageName);
}).bind(this)); },
_autoUpdatePackagedApp: Task.async(function*(aData, aOldApp) {
debug("_autoUpdatePackagedApp: " + aData.manifestURL);
if (aData.updateManifest && aData.zipFilePath) {
aData.updateManifest.package_path = aData.zipFilePath;
}
// updatePackagedApp just prepares the update, after which we must
// download the package via the misnamed startDownload and then apply it
// via applyDownload.
yield DOMApplicationRegistry.updatePackagedApp(aData, aOldApp.id, aOldApp, aData.updateManifest);
try {
yield DOMApplicationRegistry.startDownload(aData.manifestURL);
} catch (ex if ex.message == "PACKAGE_UNCHANGED") {
debug("package unchanged");
// If the package is unchanged, then there's nothing more to do.
return;
}
yield DOMApplicationRegistry.applyDownload(aData.manifestURL);
}),
_checkingForUpdates: false,
checkForUpdates: function(userInitiated) { return Task.spawn((function*() {