зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1346009 - Convert 'defer' to 'new Promise' in client/webide; r=tromey
MozReview-Commit-ID: 1adrD8A96Dx --HG-- extra : rebase_source : 9c616dfa39a4d80697e59073d1d8a3b796d51355
This commit is contained in:
Родитель
4d43775859
Коммит
7ae37aa776
|
@ -4,7 +4,6 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const promise = require("promise");
|
||||
const {AddonManager} = require("resource://gre/modules/AddonManager.jsm");
|
||||
const Services = require("Services");
|
||||
const {getJSON} = require("devtools/client/shared/getjson");
|
||||
|
@ -51,24 +50,24 @@ AddonManager.addAddonListener(addonsListener);
|
|||
var GetAvailableAddons_promise = null;
|
||||
var GetAvailableAddons = exports.GetAvailableAddons = function () {
|
||||
if (!GetAvailableAddons_promise) {
|
||||
let deferred = promise.defer();
|
||||
GetAvailableAddons_promise = deferred.promise;
|
||||
let addons = {
|
||||
simulators: [],
|
||||
adb: null
|
||||
};
|
||||
getJSON(ADDONS_URL).then(json => {
|
||||
for (let stability in json) {
|
||||
for (let version of json[stability]) {
|
||||
addons.simulators.push(new SimulatorAddon(stability, version));
|
||||
GetAvailableAddons_promise = new Promise((resolve, reject) => {
|
||||
let addons = {
|
||||
simulators: [],
|
||||
adb: null
|
||||
};
|
||||
getJSON(ADDONS_URL).then(json => {
|
||||
for (let stability in json) {
|
||||
for (let version of json[stability]) {
|
||||
addons.simulators.push(new SimulatorAddon(stability, version));
|
||||
}
|
||||
}
|
||||
}
|
||||
addons.adb = new ADBAddon();
|
||||
addons.adapters = new AdaptersAddon();
|
||||
deferred.resolve(addons);
|
||||
}, e => {
|
||||
GetAvailableAddons_promise = null;
|
||||
deferred.reject(e);
|
||||
addons.adb = new ADBAddon();
|
||||
addons.adapters = new AdaptersAddon();
|
||||
resolve(addons);
|
||||
}, e => {
|
||||
GetAvailableAddons_promise = null;
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
return GetAvailableAddons_promise;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
const {Cu} = require("chrome");
|
||||
|
||||
const promise = require("promise");
|
||||
const {TargetFactory} = require("devtools/client/framework/target");
|
||||
const Services = require("Services");
|
||||
const {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm", {});
|
||||
|
@ -277,7 +276,7 @@ var AppManager = exports.AppManager = {
|
|||
|
||||
reloadTab: function () {
|
||||
if (this.selectedProject && this.selectedProject.type != "tab") {
|
||||
return promise.reject("tried to reload non-tab project");
|
||||
return Promise.reject("tried to reload non-tab project");
|
||||
}
|
||||
return this.getTarget().then(target => {
|
||||
target.activeTab.reload();
|
||||
|
@ -313,7 +312,7 @@ var AppManager = exports.AppManager = {
|
|||
|
||||
let app = this._getProjectFront(this.selectedProject);
|
||||
if (!app) {
|
||||
return promise.reject("Can't find app front for selected project");
|
||||
return Promise.reject("Can't find app front for selected project");
|
||||
}
|
||||
|
||||
return Task.spawn(function* () {
|
||||
|
@ -325,9 +324,9 @@ var AppManager = exports.AppManager = {
|
|||
try {
|
||||
return yield app.getTarget();
|
||||
} catch (e) {}
|
||||
let deferred = promise.defer();
|
||||
setTimeout(deferred.resolve, 500);
|
||||
yield deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, 500);
|
||||
});
|
||||
}
|
||||
|
||||
AppManager.reportError("error_cantConnectToApp", app.manifest.manifestURL);
|
||||
|
@ -460,36 +459,36 @@ var AppManager = exports.AppManager = {
|
|||
|
||||
if (this.connected && this.selectedRuntime === runtime) {
|
||||
// Already connected
|
||||
return promise.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
let deferred = promise.defer();
|
||||
let deferred = new Promise((resolve, reject) => {
|
||||
this.disconnectRuntime().then(() => {
|
||||
this.selectedRuntime = runtime;
|
||||
|
||||
this.disconnectRuntime().then(() => {
|
||||
this.selectedRuntime = runtime;
|
||||
|
||||
let onConnectedOrDisconnected = () => {
|
||||
this.connection.off(Connection.Events.CONNECTED, onConnectedOrDisconnected);
|
||||
this.connection.off(Connection.Events.DISCONNECTED, onConnectedOrDisconnected);
|
||||
if (this.connected) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
deferred.reject();
|
||||
let onConnectedOrDisconnected = () => {
|
||||
this.connection.off(Connection.Events.CONNECTED, onConnectedOrDisconnected);
|
||||
this.connection.off(Connection.Events.DISCONNECTED, onConnectedOrDisconnected);
|
||||
if (this.connected) {
|
||||
resolve();
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
};
|
||||
this.connection.on(Connection.Events.CONNECTED, onConnectedOrDisconnected);
|
||||
this.connection.on(Connection.Events.DISCONNECTED, onConnectedOrDisconnected);
|
||||
try {
|
||||
// Reset the connection's state to defaults
|
||||
this.connection.resetOptions();
|
||||
// Only watch for errors here. Final resolution occurs above, once
|
||||
// we've reached the CONNECTED state.
|
||||
this.selectedRuntime.connect(this.connection)
|
||||
.then(null, e => reject(e));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
};
|
||||
this.connection.on(Connection.Events.CONNECTED, onConnectedOrDisconnected);
|
||||
this.connection.on(Connection.Events.DISCONNECTED, onConnectedOrDisconnected);
|
||||
try {
|
||||
// Reset the connection's state to defaults
|
||||
this.connection.resetOptions();
|
||||
// Only watch for errors here. Final resolution occurs above, once
|
||||
// we've reached the CONNECTED state.
|
||||
this.selectedRuntime.connect(this.connection)
|
||||
.then(null, e => deferred.reject(e));
|
||||
} catch (e) {
|
||||
deferred.reject(e);
|
||||
}
|
||||
}, deferred.reject);
|
||||
}, reject);
|
||||
});
|
||||
|
||||
// Record connection result in telemetry
|
||||
let logResult = result => {
|
||||
|
@ -499,10 +498,10 @@ var AppManager = exports.AppManager = {
|
|||
"_CONNECTION_RESULT", result);
|
||||
}
|
||||
};
|
||||
deferred.promise.then(() => logResult(true), () => logResult(false));
|
||||
deferred.then(() => logResult(true), () => logResult(false));
|
||||
|
||||
// If successful, record connection time in telemetry
|
||||
deferred.promise.then(() => {
|
||||
deferred.then(() => {
|
||||
const timerId = "DEVTOOLS_WEBIDE_CONNECTION_TIME_SECONDS";
|
||||
this._telemetry.startTimer(timerId);
|
||||
this.connection.once(Connection.Events.STATUS_CHANGED, () => {
|
||||
|
@ -514,7 +513,7 @@ var AppManager = exports.AppManager = {
|
|||
// Bug 1121100 may find a better way to silence these.
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
return deferred;
|
||||
},
|
||||
|
||||
_recordRuntimeInfo: Task.async(function* () {
|
||||
|
@ -570,17 +569,18 @@ var AppManager = exports.AppManager = {
|
|||
|
||||
disconnectRuntime: function () {
|
||||
if (!this.connected) {
|
||||
return promise.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
let deferred = promise.defer();
|
||||
this.connection.once(Connection.Events.DISCONNECTED, () => deferred.resolve());
|
||||
this.connection.disconnect();
|
||||
return deferred.promise;
|
||||
|
||||
return new Promise(resolve => {
|
||||
this.connection.once(Connection.Events.DISCONNECTED, () => resolve());
|
||||
this.connection.disconnect();
|
||||
});
|
||||
},
|
||||
|
||||
launchRuntimeApp: function () {
|
||||
if (this.selectedProject && this.selectedProject.type != "runtimeApp") {
|
||||
return promise.reject("attempting to launch a non-runtime app");
|
||||
return Promise.reject("attempting to launch a non-runtime app");
|
||||
}
|
||||
let app = this._getProjectFront(this.selectedProject);
|
||||
return app.launch();
|
||||
|
@ -588,7 +588,7 @@ var AppManager = exports.AppManager = {
|
|||
|
||||
launchOrReloadRuntimeApp: function () {
|
||||
if (this.selectedProject && this.selectedProject.type != "runtimeApp") {
|
||||
return promise.reject("attempting to launch / reload a non-runtime app");
|
||||
return Promise.reject("attempting to launch / reload a non-runtime app");
|
||||
}
|
||||
let app = this._getProjectFront(this.selectedProject);
|
||||
if (!app.running) {
|
||||
|
@ -607,17 +607,17 @@ var AppManager = exports.AppManager = {
|
|||
|
||||
if (!project || (project.type != "packaged" && project.type != "hosted")) {
|
||||
console.error("Can't install project. Unknown type of project.");
|
||||
return promise.reject("Can't install");
|
||||
return Promise.reject("Can't install");
|
||||
}
|
||||
|
||||
if (!this._listTabsResponse) {
|
||||
this.reportError("error_cantInstallNotFullyConnected");
|
||||
return promise.reject("Can't install");
|
||||
return Promise.reject("Can't install");
|
||||
}
|
||||
|
||||
if (!this._appsFront) {
|
||||
console.error("Runtime doesn't have a webappsActor");
|
||||
return promise.reject("Can't install");
|
||||
return Promise.reject("Can't install");
|
||||
}
|
||||
|
||||
return Task.spawn(function* () {
|
||||
|
@ -635,7 +635,7 @@ var AppManager = exports.AppManager = {
|
|||
let installPromise;
|
||||
|
||||
if (project.type != "packaged" && project.type != "hosted") {
|
||||
return promise.reject("Don't know how to install project");
|
||||
return Promise.reject("Don't know how to install project");
|
||||
}
|
||||
|
||||
let response;
|
||||
|
@ -674,15 +674,16 @@ var AppManager = exports.AppManager = {
|
|||
|
||||
let {app} = response;
|
||||
if (!app.running) {
|
||||
let deferred = promise.defer();
|
||||
self.on("app-manager-update", function onUpdate(event, what) {
|
||||
if (what == "project-started") {
|
||||
self.off("app-manager-update", onUpdate);
|
||||
deferred.resolve();
|
||||
}
|
||||
let deferred = new Promise(resolve => {
|
||||
self.on("app-manager-update", function onUpdate(event, what) {
|
||||
if (what == "project-started") {
|
||||
self.off("app-manager-update", onUpdate);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
yield app.launch();
|
||||
yield deferred.promise;
|
||||
yield deferred;
|
||||
} else {
|
||||
yield app.reload();
|
||||
}
|
||||
|
@ -698,7 +699,7 @@ var AppManager = exports.AppManager = {
|
|||
|
||||
validateAndUpdateProject: function (project) {
|
||||
if (!project) {
|
||||
return promise.reject();
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
return Task.spawn(function* () {
|
||||
|
@ -823,7 +824,7 @@ var AppManager = exports.AppManager = {
|
|||
|
||||
writeManifest: function (project) {
|
||||
if (project.type != "packaged") {
|
||||
return promise.reject("Not a packaged app");
|
||||
return Promise.reject("Not a packaged app");
|
||||
}
|
||||
|
||||
if (!project.manifest) {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const {Cc, Ci, Cu, Cr} = require("chrome");
|
||||
const promise = require("promise");
|
||||
|
||||
const EventEmitter = require("devtools/shared/event-emitter");
|
||||
const {generateUUID} = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
|
||||
|
@ -21,145 +20,135 @@ const IDB = {
|
|||
databaseName: "AppProjects",
|
||||
|
||||
open: function () {
|
||||
let deferred = promise.defer();
|
||||
return new Promise((resolve, reject) => {
|
||||
let request = indexedDB.open(IDB.databaseName, 5);
|
||||
request.onerror = function (event) {
|
||||
reject("Unable to open AppProjects indexedDB: " +
|
||||
this.error.name + " - " + this.error.message);
|
||||
};
|
||||
request.onupgradeneeded = function (event) {
|
||||
let db = event.target.result;
|
||||
db.createObjectStore("projects", { keyPath: "location" });
|
||||
};
|
||||
|
||||
let request = indexedDB.open(IDB.databaseName, 5);
|
||||
request.onerror = function (event) {
|
||||
deferred.reject("Unable to open AppProjects indexedDB: " +
|
||||
this.error.name + " - " + this.error.message);
|
||||
};
|
||||
request.onupgradeneeded = function (event) {
|
||||
let db = event.target.result;
|
||||
db.createObjectStore("projects", { keyPath: "location" });
|
||||
};
|
||||
request.onsuccess = function () {
|
||||
let db = IDB._db = request.result;
|
||||
let objectStore = db.transaction("projects").objectStore("projects");
|
||||
let projects = [];
|
||||
let toRemove = [];
|
||||
objectStore.openCursor().onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
if (cursor.value.location) {
|
||||
|
||||
request.onsuccess = function () {
|
||||
let db = IDB._db = request.result;
|
||||
let objectStore = db.transaction("projects").objectStore("projects");
|
||||
let projects = [];
|
||||
let toRemove = [];
|
||||
objectStore.openCursor().onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
if (cursor.value.location) {
|
||||
|
||||
// We need to make sure this object has a `.location` property.
|
||||
// The UI depends on this property.
|
||||
// This should not be needed as we make sure to register valid
|
||||
// projects, but in the past (before bug 924568), we might have
|
||||
// registered invalid objects.
|
||||
// We need to make sure this object has a `.location` property.
|
||||
// The UI depends on this property.
|
||||
// This should not be needed as we make sure to register valid
|
||||
// projects, but in the past (before bug 924568), we might have
|
||||
// registered invalid objects.
|
||||
|
||||
|
||||
// We also want to make sure the location is valid.
|
||||
// If the location doesn't exist, we remove the project.
|
||||
// We also want to make sure the location is valid.
|
||||
// If the location doesn't exist, we remove the project.
|
||||
|
||||
try {
|
||||
let file = FileUtils.File(cursor.value.location);
|
||||
if (file.exists()) {
|
||||
projects.push(cursor.value);
|
||||
} else {
|
||||
toRemove.push(cursor.value.location);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.result == Cr.NS_ERROR_FILE_UNRECOGNIZED_PATH) {
|
||||
// A URL
|
||||
projects.push(cursor.value);
|
||||
try {
|
||||
let file = FileUtils.File(cursor.value.location);
|
||||
if (file.exists()) {
|
||||
projects.push(cursor.value);
|
||||
} else {
|
||||
toRemove.push(cursor.value.location);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.result == Cr.NS_ERROR_FILE_UNRECOGNIZED_PATH) {
|
||||
// A URL
|
||||
projects.push(cursor.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
cursor.continue();
|
||||
} else {
|
||||
let removePromises = [];
|
||||
for (let location of toRemove) {
|
||||
removePromises.push(IDB.remove(location));
|
||||
}
|
||||
Promise.all(removePromises).then(() => {
|
||||
resolve(projects);
|
||||
});
|
||||
}
|
||||
cursor.continue();
|
||||
} else {
|
||||
let removePromises = [];
|
||||
for (let location of toRemove) {
|
||||
removePromises.push(IDB.remove(location));
|
||||
}
|
||||
promise.all(removePromises).then(() => {
|
||||
deferred.resolve(projects);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
},
|
||||
|
||||
add: function (project) {
|
||||
let deferred = promise.defer();
|
||||
|
||||
if (!project.location) {
|
||||
// We need to make sure this object has a `.location` property.
|
||||
deferred.reject("Missing location property on project object.");
|
||||
} else {
|
||||
let transaction = IDB._db.transaction(["projects"], "readwrite");
|
||||
let objectStore = transaction.objectStore("projects");
|
||||
let request = objectStore.add(project);
|
||||
request.onerror = function (event) {
|
||||
deferred.reject("Unable to add project to the AppProjects indexedDB: " +
|
||||
this.error.name + " - " + this.error.message);
|
||||
};
|
||||
request.onsuccess = function () {
|
||||
deferred.resolve();
|
||||
};
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!project.location) {
|
||||
// We need to make sure this object has a `.location` property.
|
||||
reject("Missing location property on project object.");
|
||||
} else {
|
||||
let transaction = IDB._db.transaction(["projects"], "readwrite");
|
||||
let objectStore = transaction.objectStore("projects");
|
||||
let request = objectStore.add(project);
|
||||
request.onerror = function (event) {
|
||||
reject("Unable to add project to the AppProjects indexedDB: " +
|
||||
this.error.name + " - " + this.error.message);
|
||||
};
|
||||
request.onsuccess = function () {
|
||||
resolve();
|
||||
};
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
update: function (project) {
|
||||
let deferred = promise.defer();
|
||||
|
||||
var transaction = IDB._db.transaction(["projects"], "readwrite");
|
||||
var objectStore = transaction.objectStore("projects");
|
||||
var request = objectStore.put(project);
|
||||
request.onerror = function (event) {
|
||||
deferred.reject("Unable to update project to the AppProjects indexedDB: " +
|
||||
this.error.name + " - " + this.error.message);
|
||||
};
|
||||
request.onsuccess = function () {
|
||||
deferred.resolve();
|
||||
};
|
||||
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
var transaction = IDB._db.transaction(["projects"], "readwrite");
|
||||
var objectStore = transaction.objectStore("projects");
|
||||
var request = objectStore.put(project);
|
||||
request.onerror = function (event) {
|
||||
reject("Unable to update project to the AppProjects indexedDB: " +
|
||||
this.error.name + " - " + this.error.message);
|
||||
};
|
||||
request.onsuccess = function () {
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
remove: function (location) {
|
||||
let deferred = promise.defer();
|
||||
|
||||
let request = IDB._db.transaction(["projects"], "readwrite")
|
||||
return new Promise((resolve, reject) => {
|
||||
let request = IDB._db.transaction(["projects"], "readwrite")
|
||||
.objectStore("projects")
|
||||
.delete(location);
|
||||
request.onsuccess = function (event) {
|
||||
deferred.resolve();
|
||||
};
|
||||
request.onerror = function () {
|
||||
deferred.reject("Unable to delete project to the AppProjects indexedDB: " +
|
||||
this.error.name + " - " + this.error.message);
|
||||
};
|
||||
|
||||
return deferred.promise;
|
||||
request.onsuccess = function (event) {
|
||||
resolve();
|
||||
};
|
||||
request.onerror = function () {
|
||||
reject("Unable to delete project to the AppProjects indexedDB: " +
|
||||
this.error.name + " - " + this.error.message);
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var loadDeferred = promise.defer();
|
||||
|
||||
loadDeferred.resolve(IDB.open().then(function (projects) {
|
||||
var loadDeferred = IDB.open().then(function (projects) {
|
||||
AppProjects.projects = projects;
|
||||
AppProjects.emit("ready", projects);
|
||||
}));
|
||||
});
|
||||
|
||||
const AppProjects = {
|
||||
load: function () {
|
||||
return loadDeferred.promise;
|
||||
return loadDeferred;
|
||||
},
|
||||
|
||||
addPackaged: function (folder) {
|
||||
let file = FileUtils.File(folder.path);
|
||||
if (!file.exists()) {
|
||||
return promise.reject("path doesn't exist");
|
||||
return Promise.reject("path doesn't exist");
|
||||
}
|
||||
let existingProject = this.get(folder.path);
|
||||
if (existingProject) {
|
||||
return promise.reject("Already added");
|
||||
return Promise.reject("Already added");
|
||||
}
|
||||
let project = {
|
||||
type: "packaged",
|
||||
|
@ -182,7 +171,7 @@ const AppProjects = {
|
|||
addHosted: function (manifestURL) {
|
||||
let existingProject = this.get(manifestURL);
|
||||
if (existingProject) {
|
||||
return promise.reject("Already added");
|
||||
return Promise.reject("Already added");
|
||||
}
|
||||
let project = {
|
||||
type: "hosted",
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
"use strict";
|
||||
|
||||
var {Ci, Cu, CC} = require("chrome");
|
||||
const promise = require("promise");
|
||||
|
||||
const {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm", {});
|
||||
const Services = require("Services");
|
||||
|
@ -64,46 +63,44 @@ AppValidator.prototype._getPackagedManifestURL = function () {
|
|||
};
|
||||
|
||||
AppValidator.checkManifest = function (manifestURL) {
|
||||
let deferred = promise.defer();
|
||||
let error;
|
||||
return new Promise((resolve, reject) => {
|
||||
let error;
|
||||
|
||||
let req = new XMLHttpRequest();
|
||||
req.overrideMimeType("text/plain");
|
||||
let req = new XMLHttpRequest();
|
||||
req.overrideMimeType("text/plain");
|
||||
|
||||
try {
|
||||
req.open("GET", manifestURL, true);
|
||||
req.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE | Ci.nsIRequest.INHIBIT_CACHING;
|
||||
} catch (e) {
|
||||
error = strings.formatStringFromName("validator.invalidManifestURL", [manifestURL], 1);
|
||||
deferred.reject(error);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
req.onload = function () {
|
||||
let manifest = null;
|
||||
try {
|
||||
manifest = JSON.parse(req.responseText);
|
||||
req.open("GET", manifestURL, true);
|
||||
req.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE | Ci.nsIRequest.INHIBIT_CACHING;
|
||||
} catch (e) {
|
||||
error = strings.formatStringFromName("validator.invalidManifestJSON", [e, manifestURL], 2);
|
||||
deferred.reject(error);
|
||||
error = strings.formatStringFromName("validator.invalidManifestURL", [manifestURL], 1);
|
||||
return reject(error);
|
||||
}
|
||||
|
||||
deferred.resolve({manifest, manifestURL});
|
||||
};
|
||||
req.onload = function () {
|
||||
let manifest = null;
|
||||
try {
|
||||
manifest = JSON.parse(req.responseText);
|
||||
} catch (e) {
|
||||
error = strings.formatStringFromName("validator.invalidManifestJSON", [e, manifestURL], 2);
|
||||
reject(error);
|
||||
}
|
||||
|
||||
req.onerror = function () {
|
||||
error = strings.formatStringFromName("validator.noAccessManifestURL", [req.statusText, manifestURL], 2);
|
||||
deferred.reject(error);
|
||||
};
|
||||
resolve({manifest, manifestURL});
|
||||
};
|
||||
|
||||
try {
|
||||
req.send(null);
|
||||
} catch (e) {
|
||||
error = strings.formatStringFromName("validator.noAccessManifestURL", [e, manifestURL], 2);
|
||||
deferred.reject(error);
|
||||
}
|
||||
req.onerror = function () {
|
||||
error = strings.formatStringFromName("validator.noAccessManifestURL", [req.statusText, manifestURL], 2);
|
||||
reject(error);
|
||||
};
|
||||
|
||||
return deferred.promise;
|
||||
try {
|
||||
req.send(null);
|
||||
} catch (e) {
|
||||
error = strings.formatStringFromName("validator.noAccessManifestURL", [e, manifestURL], 2);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
AppValidator.findManifestAtOrigin = function (manifestURL) {
|
||||
|
@ -112,16 +109,14 @@ AppValidator.findManifestAtOrigin = function (manifestURL) {
|
|||
};
|
||||
|
||||
AppValidator.findManifestPath = function (manifestURL) {
|
||||
let deferred = promise.defer();
|
||||
|
||||
if (manifestURL.endsWith("manifest.webapp")) {
|
||||
deferred.reject();
|
||||
} else {
|
||||
let fixedManifest = manifestURL + "/manifest.webapp";
|
||||
deferred.resolve(AppValidator.checkManifest(fixedManifest));
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
if (manifestURL.endsWith("manifest.webapp")) {
|
||||
reject();
|
||||
} else {
|
||||
let fixedManifest = manifestURL + "/manifest.webapp";
|
||||
resolve(AppValidator.checkManifest(fixedManifest));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
AppValidator.checkAlternateManifest = function (manifestURL) {
|
||||
|
@ -138,24 +133,23 @@ AppValidator.checkAlternateManifest = function (manifestURL) {
|
|||
};
|
||||
|
||||
AppValidator.prototype._fetchManifest = function (manifestURL) {
|
||||
let deferred = promise.defer();
|
||||
this.manifestURL = manifestURL;
|
||||
return new Promise(resolve => {
|
||||
this.manifestURL = manifestURL;
|
||||
|
||||
AppValidator.checkManifest(manifestURL)
|
||||
.then(({manifest, manifestURL}) => {
|
||||
deferred.resolve(manifest);
|
||||
}, error => {
|
||||
AppValidator.checkAlternateManifest(manifestURL)
|
||||
.then(({manifest, manifestURL}) => {
|
||||
this.manifestURL = manifestURL;
|
||||
deferred.resolve(manifest);
|
||||
}, () => {
|
||||
this.error(error);
|
||||
deferred.resolve(null);
|
||||
});
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
AppValidator.checkManifest(manifestURL)
|
||||
.then(({manifest, manifestURL}) => {
|
||||
resolve(manifest);
|
||||
}, error => {
|
||||
AppValidator.checkAlternateManifest(manifestURL)
|
||||
.then(({manifest, manifestURL}) => {
|
||||
this.manifestURL = manifestURL;
|
||||
resolve(manifest);
|
||||
}, () => {
|
||||
this.error(error);
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
AppValidator.prototype._getManifest = function () {
|
||||
|
@ -163,18 +157,18 @@ AppValidator.prototype._getManifest = function () {
|
|||
if (this.type == "packaged") {
|
||||
manifestURL = this._getPackagedManifestURL();
|
||||
if (!manifestURL)
|
||||
return promise.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
} else if (this.type == "hosted") {
|
||||
manifestURL = this.location;
|
||||
try {
|
||||
Services.io.newURI(manifestURL);
|
||||
} catch (e) {
|
||||
this.error(strings.formatStringFromName("validator.invalidHostedManifestURL", [manifestURL, e.message], 2));
|
||||
return promise.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
} else {
|
||||
this.error(strings.formatStringFromName("validator.invalidProjectType", [this.type], 1));
|
||||
return promise.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
return this._fetchManifest(manifestURL);
|
||||
};
|
||||
|
@ -201,57 +195,53 @@ AppValidator.prototype._getOriginURL = function () {
|
|||
};
|
||||
|
||||
AppValidator.prototype.validateLaunchPath = function (manifest) {
|
||||
let deferred = promise.defer();
|
||||
// The launch_path field has to start with a `/`
|
||||
if (manifest.launch_path && manifest.launch_path[0] !== "/") {
|
||||
this.error(strings.formatStringFromName("validator.nonAbsoluteLaunchPath", [manifest.launch_path], 1));
|
||||
deferred.resolve();
|
||||
return deferred.promise;
|
||||
}
|
||||
let origin = this._getOriginURL();
|
||||
let path;
|
||||
if (this.type == "packaged") {
|
||||
path = "." + (manifest.launch_path || "/index.html");
|
||||
} else if (this.type == "hosted") {
|
||||
path = manifest.launch_path || "/";
|
||||
}
|
||||
let indexURL;
|
||||
try {
|
||||
indexURL = Services.io.newURI(path, null, Services.io.newURI(origin)).spec;
|
||||
} catch (e) {
|
||||
this.error(strings.formatStringFromName("validator.accessFailedLaunchPath", [origin + path], 1));
|
||||
deferred.resolve();
|
||||
return deferred.promise;
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
// The launch_path field has to start with a `/`
|
||||
if (manifest.launch_path && manifest.launch_path[0] !== "/") {
|
||||
this.error(strings.formatStringFromName("validator.nonAbsoluteLaunchPath", [manifest.launch_path], 1));
|
||||
resolve();
|
||||
}
|
||||
let origin = this._getOriginURL();
|
||||
let path;
|
||||
if (this.type == "packaged") {
|
||||
path = "." + (manifest.launch_path || "/index.html");
|
||||
} else if (this.type == "hosted") {
|
||||
path = manifest.launch_path || "/";
|
||||
}
|
||||
let indexURL;
|
||||
try {
|
||||
indexURL = Services.io.newURI(path, null, Services.io.newURI(origin)).spec;
|
||||
} catch (e) {
|
||||
this.error(strings.formatStringFromName("validator.accessFailedLaunchPath", [origin + path], 1));
|
||||
return resolve();
|
||||
}
|
||||
|
||||
let req = new XMLHttpRequest();
|
||||
req.overrideMimeType("text/plain");
|
||||
try {
|
||||
req.open("HEAD", indexURL, true);
|
||||
req.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE | Ci.nsIRequest.INHIBIT_CACHING;
|
||||
} catch (e) {
|
||||
this.error(strings.formatStringFromName("validator.accessFailedLaunchPath", [indexURL], 1));
|
||||
deferred.resolve();
|
||||
return deferred.promise;
|
||||
}
|
||||
req.onload = () => {
|
||||
if (req.status >= 400)
|
||||
this.error(strings.formatStringFromName("validator.accessFailedLaunchPathBadHttpCode", [indexURL, req.status], 2));
|
||||
deferred.resolve();
|
||||
};
|
||||
req.onerror = () => {
|
||||
this.error(strings.formatStringFromName("validator.accessFailedLaunchPath", [indexURL], 1));
|
||||
deferred.resolve();
|
||||
};
|
||||
let req = new XMLHttpRequest();
|
||||
req.overrideMimeType("text/plain");
|
||||
try {
|
||||
req.open("HEAD", indexURL, true);
|
||||
req.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE | Ci.nsIRequest.INHIBIT_CACHING;
|
||||
} catch (e) {
|
||||
this.error(strings.formatStringFromName("validator.accessFailedLaunchPath", [indexURL], 1));
|
||||
return resolve();
|
||||
}
|
||||
req.onload = () => {
|
||||
if (req.status >= 400)
|
||||
this.error(strings.formatStringFromName("validator.accessFailedLaunchPathBadHttpCode", [indexURL, req.status], 2));
|
||||
resolve();
|
||||
};
|
||||
req.onerror = () => {
|
||||
this.error(strings.formatStringFromName("validator.accessFailedLaunchPath", [indexURL], 1));
|
||||
resolve();
|
||||
};
|
||||
|
||||
try {
|
||||
req.send(null);
|
||||
} catch (e) {
|
||||
this.error(strings.formatStringFromName("validator.accessFailedLaunchPath", [indexURL], 1));
|
||||
deferred.resolve();
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
try {
|
||||
req.send(null);
|
||||
} catch (e) {
|
||||
this.error(strings.formatStringFromName("validator.accessFailedLaunchPath", [indexURL], 1));
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
AppValidator.prototype.validateType = function (manifest) {
|
||||
|
@ -279,7 +269,7 @@ AppValidator.prototype.validate = function () {
|
|||
|
||||
// Skip validations for add-ons
|
||||
if (manifest.role === "addon" || manifest.manifest_version) {
|
||||
return promise.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
this.validateManifest(manifest);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
const {Cu, Cc, Ci} = require("chrome");
|
||||
|
||||
const promise = require("promise");
|
||||
const { Task } = require("devtools/shared/task");
|
||||
const { OS } = Cu.import("resource://gre/modules/osfile.jsm", {});
|
||||
const Subprocess = require("sdk/system/child_process/subprocess");
|
||||
|
@ -149,31 +148,30 @@ const ProjectBuilding = exports.ProjectBuilding = {
|
|||
// Subprocess changes CWD, we have to save and restore it.
|
||||
let originalCwd = yield OS.File.getCurrentDirectory();
|
||||
try {
|
||||
let defer = promise.defer();
|
||||
Subprocess.call({
|
||||
command: shell,
|
||||
arguments: args,
|
||||
environment: env,
|
||||
workdir: cwd,
|
||||
yield new Promise((resolve, reject) => {
|
||||
Subprocess.call({
|
||||
command: shell,
|
||||
arguments: args,
|
||||
environment: env,
|
||||
workdir: cwd,
|
||||
|
||||
stdout: data =>
|
||||
logger(data),
|
||||
stderr: data =>
|
||||
logger(data),
|
||||
stdout: data =>
|
||||
logger(data),
|
||||
stderr: data =>
|
||||
logger(data),
|
||||
|
||||
done: result => {
|
||||
logger("Terminated with error code: " + result.exitCode);
|
||||
if (result.exitCode == 0) {
|
||||
defer.resolve();
|
||||
} else {
|
||||
defer.reject("pre-package command failed with error code " + result.exitCode);
|
||||
done: result => {
|
||||
logger("Terminated with error code: " + result.exitCode);
|
||||
if (result.exitCode == 0) {
|
||||
resolve();
|
||||
} else {
|
||||
reject("pre-package command failed with error code " + result.exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
defer.promise.then(() => {
|
||||
});
|
||||
}).then(() => {
|
||||
OS.File.setCurrentDirectory(originalCwd);
|
||||
});
|
||||
yield defer.promise;
|
||||
} catch (e) {
|
||||
throw new Error("Unable to run pre-package command '" + command + "' " +
|
||||
args.join(" ") + ":\n" + (e.message || e));
|
||||
|
|
|
@ -7,7 +7,6 @@ const {Cu} = require("chrome");
|
|||
const Services = require("Services");
|
||||
const {AppProjects} = require("devtools/client/webide/modules/app-projects");
|
||||
const {AppManager} = require("devtools/client/webide/modules/app-manager");
|
||||
const promise = require("promise");
|
||||
const EventEmitter = require("devtools/shared/event-emitter");
|
||||
const {Task} = require("devtools/shared/task");
|
||||
const utils = require("devtools/client/webide/modules/utils");
|
||||
|
@ -200,7 +199,7 @@ ProjectList.prototype = {
|
|||
}, true);
|
||||
}
|
||||
|
||||
return promise.resolve();
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
updateApps: function () {
|
||||
|
@ -263,7 +262,7 @@ ProjectList.prototype = {
|
|||
}, true);
|
||||
}
|
||||
|
||||
return promise.resolve();
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
updateCommands: function () {
|
||||
|
@ -299,69 +298,67 @@ ProjectList.prototype = {
|
|||
* what is updated to only those sections.
|
||||
*/
|
||||
update: function (options) {
|
||||
let deferred = promise.defer();
|
||||
|
||||
if (options && options.type === "apps") {
|
||||
return this.updateApps();
|
||||
} else if (options && options.type === "tabs") {
|
||||
return this.updateTabs();
|
||||
}
|
||||
|
||||
let doc = this._doc;
|
||||
let projectsNode = doc.querySelector("#project-panel-projects");
|
||||
return new Promise((resolve, reject) => {
|
||||
let doc = this._doc;
|
||||
let projectsNode = doc.querySelector("#project-panel-projects");
|
||||
|
||||
while (projectsNode.hasChildNodes()) {
|
||||
projectsNode.firstChild.remove();
|
||||
}
|
||||
|
||||
AppProjects.load().then(() => {
|
||||
let projects = AppProjects.projects;
|
||||
for (let i = 0; i < projects.length; i++) {
|
||||
let project = projects[i];
|
||||
let panelItemNode = doc.createElement(this._panelNodeEl);
|
||||
panelItemNode.className = "panel-item";
|
||||
projectsNode.appendChild(panelItemNode);
|
||||
if (!project.validationStatus) {
|
||||
// The result of the validation process (storing names, icons, …) is not stored in
|
||||
// the IndexedDB database when App Manager v1 is used.
|
||||
// We need to run the validation again and update the name and icon of the app.
|
||||
AppManager.validateAndUpdateProject(project).then(() => {
|
||||
this._renderProjectItem({
|
||||
panel: panelItemNode,
|
||||
name: project.name,
|
||||
icon: project.icon
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this._renderProjectItem({
|
||||
panel: panelItemNode,
|
||||
name: project.name || AppManager.DEFAULT_PROJECT_NAME,
|
||||
icon: project.icon || AppManager.DEFAULT_PROJECT_ICON
|
||||
});
|
||||
}
|
||||
panelItemNode.addEventListener("click", () => {
|
||||
AppManager.selectedProject = project;
|
||||
}, true);
|
||||
while (projectsNode.hasChildNodes()) {
|
||||
projectsNode.firstChild.remove();
|
||||
}
|
||||
|
||||
deferred.resolve();
|
||||
}, deferred.reject);
|
||||
AppProjects.load().then(() => {
|
||||
let projects = AppProjects.projects;
|
||||
for (let i = 0; i < projects.length; i++) {
|
||||
let project = projects[i];
|
||||
let panelItemNode = doc.createElement(this._panelNodeEl);
|
||||
panelItemNode.className = "panel-item";
|
||||
projectsNode.appendChild(panelItemNode);
|
||||
if (!project.validationStatus) {
|
||||
// The result of the validation process (storing names, icons, …) is not stored in
|
||||
// the IndexedDB database when App Manager v1 is used.
|
||||
// We need to run the validation again and update the name and icon of the app.
|
||||
AppManager.validateAndUpdateProject(project).then(() => {
|
||||
this._renderProjectItem({
|
||||
panel: panelItemNode,
|
||||
name: project.name,
|
||||
icon: project.icon
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this._renderProjectItem({
|
||||
panel: panelItemNode,
|
||||
name: project.name || AppManager.DEFAULT_PROJECT_NAME,
|
||||
icon: project.icon || AppManager.DEFAULT_PROJECT_ICON
|
||||
});
|
||||
}
|
||||
panelItemNode.addEventListener("click", () => {
|
||||
AppManager.selectedProject = project;
|
||||
}, true);
|
||||
}
|
||||
|
||||
// List remote apps and the main process, if they exist
|
||||
this.updateApps();
|
||||
resolve();
|
||||
}, reject);
|
||||
|
||||
// Build the tab list right now, so it's fast...
|
||||
this.updateTabs();
|
||||
// List remote apps and the main process, if they exist
|
||||
this.updateApps();
|
||||
|
||||
// But re-list them and rebuild, in case any tabs navigated since the last
|
||||
// time they were listed.
|
||||
if (AppManager.connected) {
|
||||
AppManager.listTabs().then(() => {
|
||||
this.updateTabs();
|
||||
}).catch(console.error);
|
||||
}
|
||||
// Build the tab list right now, so it's fast...
|
||||
this.updateTabs();
|
||||
|
||||
return deferred.promise;
|
||||
// But re-list them and rebuild, in case any tabs navigated since the last
|
||||
// time they were listed.
|
||||
if (AppManager.connected) {
|
||||
AppManager.listTabs().then(() => {
|
||||
this.updateTabs();
|
||||
}).catch(console.error);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
|
|
|
@ -9,7 +9,6 @@ const { Cc, Ci, Cu } = require("chrome");
|
|||
|
||||
const Environment = require("sdk/system/environment").env;
|
||||
const EventEmitter = require("devtools/shared/event-emitter");
|
||||
const promise = require("promise");
|
||||
const Subprocess = require("sdk/system/child_process/subprocess");
|
||||
const Services = require("Services");
|
||||
|
||||
|
@ -104,21 +103,21 @@ SimulatorProcess.prototype = {
|
|||
|
||||
// Request a B2G instance kill.
|
||||
kill() {
|
||||
let deferred = promise.defer();
|
||||
if (this.process) {
|
||||
this.once("exit", (e, exitCode) => {
|
||||
this.shuttingDown = false;
|
||||
deferred.resolve(exitCode);
|
||||
});
|
||||
if (!this.shuttingDown) {
|
||||
this.shuttingDown = true;
|
||||
this.emit("kill", null);
|
||||
this.process.kill();
|
||||
return new Promise(resolve => {
|
||||
if (this.process) {
|
||||
this.once("exit", (e, exitCode) => {
|
||||
this.shuttingDown = false;
|
||||
resolve(exitCode);
|
||||
});
|
||||
if (!this.shuttingDown) {
|
||||
this.shuttingDown = true;
|
||||
this.emit("kill", null);
|
||||
this.process.kill();
|
||||
}
|
||||
} else {
|
||||
return resolve(undefined);
|
||||
}
|
||||
return deferred.promise;
|
||||
} else {
|
||||
return promise.resolve(undefined);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Maybe log output messages.
|
||||
|
|
|
@ -12,7 +12,6 @@ loader.lazyRequireGetter(this, "OldAddonSimulatorProcess", "devtools/client/webi
|
|||
loader.lazyRequireGetter(this, "CustomSimulatorProcess", "devtools/client/webide/modules/simulator-process", true);
|
||||
const asyncStorage = require("devtools/shared/async-storage");
|
||||
const EventEmitter = require("devtools/shared/event-emitter");
|
||||
const promise = require("promise");
|
||||
const Services = require("Services");
|
||||
|
||||
const SimulatorRegExp = new RegExp(Services.prefs.getCharPref("devtools.webide.simulatorAddonRegExp"));
|
||||
|
@ -46,18 +45,19 @@ var Simulators = {
|
|||
|
||||
// If the simulator had a reference to an addon, fix it.
|
||||
if (options.addonID) {
|
||||
let deferred = promise.defer();
|
||||
AddonManager.getAddonByID(options.addonID, addon => {
|
||||
simulator.addon = addon;
|
||||
delete simulator.options.addonID;
|
||||
deferred.resolve();
|
||||
let deferred = new Promise(resolve => {
|
||||
AddonManager.getAddonByID(options.addonID, addon => {
|
||||
simulator.addon = addon;
|
||||
delete simulator.options.addonID;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
jobs.push(deferred.promise);
|
||||
jobs.push(deferred);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
yield promise.all(jobs);
|
||||
yield Promise.all(jobs);
|
||||
yield Simulators._addUnusedAddons();
|
||||
Simulators.emitUpdated();
|
||||
return Simulators._simulators;
|
||||
|
@ -79,7 +79,7 @@ var Simulators = {
|
|||
jobs.push(Simulators.addIfUnusedAddon(addon, true));
|
||||
});
|
||||
|
||||
yield promise.all(jobs);
|
||||
yield Promise.all(jobs);
|
||||
}),
|
||||
|
||||
/**
|
||||
|
@ -117,19 +117,19 @@ var Simulators = {
|
|||
* @return Promised addon list.
|
||||
*/
|
||||
findSimulatorAddons() {
|
||||
let deferred = promise.defer();
|
||||
AddonManager.getAllAddons(all => {
|
||||
let addons = [];
|
||||
for (let addon of all) {
|
||||
if (Simulators.isSimulatorAddon(addon)) {
|
||||
addons.push(addon);
|
||||
return new Promise(resolve => {
|
||||
AddonManager.getAllAddons(all => {
|
||||
let addons = [];
|
||||
for (let addon of all) {
|
||||
if (Simulators.isSimulatorAddon(addon)) {
|
||||
addons.push(addon);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Sort simulator addons by name.
|
||||
addons.sort(LocaleCompare);
|
||||
deferred.resolve(addons);
|
||||
// Sort simulator addons by name.
|
||||
addons.sort(LocaleCompare);
|
||||
resolve(addons);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -139,7 +139,7 @@ var Simulators = {
|
|||
let simulators = this._simulators;
|
||||
let matching = simulators.filter(s => s.addon && s.addon.id == addon.id);
|
||||
if (matching.length > 0) {
|
||||
return promise.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
let options = {};
|
||||
options.name = addon.name.replace(" Simulator", "");
|
||||
|
@ -176,7 +176,7 @@ var Simulators = {
|
|||
if (!silently) {
|
||||
this.emitUpdated();
|
||||
}
|
||||
return promise.resolve(simulator);
|
||||
return Promise.resolve(simulator);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -332,13 +332,13 @@ Simulator.prototype = {
|
|||
}
|
||||
this.process.run();
|
||||
|
||||
return promise.resolve(this.options.port);
|
||||
return Promise.resolve(this.options.port);
|
||||
},
|
||||
|
||||
kill() {
|
||||
let process = this.process;
|
||||
if (!process) {
|
||||
return promise.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
this.process = null;
|
||||
return process.kill();
|
||||
|
|
|
@ -7,7 +7,6 @@ const { Cu } = require("chrome");
|
|||
const { TargetFactory } = require("devtools/client/framework/target");
|
||||
const EventEmitter = require("devtools/shared/event-emitter");
|
||||
const { Connection } = require("devtools/shared/client/connection-manager");
|
||||
const promise = require("promise");
|
||||
const { Task } = require("devtools/shared/task");
|
||||
|
||||
const _knownTabStores = new WeakMap();
|
||||
|
@ -95,25 +94,26 @@ TabStore.prototype = {
|
|||
|
||||
listTabs: function () {
|
||||
if (!this._connection || !this._connection.client) {
|
||||
return promise.reject(new Error("Can't listTabs, not connected."));
|
||||
return Promise.reject(new Error("Can't listTabs, not connected."));
|
||||
}
|
||||
let deferred = promise.defer();
|
||||
this._connection.client.listTabs(response => {
|
||||
if (response.error) {
|
||||
this._connection.disconnect();
|
||||
deferred.reject(response.error);
|
||||
return;
|
||||
}
|
||||
let tabsChanged = JSON.stringify(this.tabs) !== JSON.stringify(response.tabs);
|
||||
this.response = response;
|
||||
this.tabs = response.tabs;
|
||||
this._checkSelectedTab();
|
||||
if (tabsChanged) {
|
||||
this.emit("tab-list");
|
||||
}
|
||||
deferred.resolve(response);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this._connection.client.listTabs(response => {
|
||||
if (response.error) {
|
||||
this._connection.disconnect();
|
||||
reject(response.error);
|
||||
return;
|
||||
}
|
||||
let tabsChanged = JSON.stringify(this.tabs) !== JSON.stringify(response.tabs);
|
||||
this.response = response;
|
||||
this.tabs = response.tabs;
|
||||
this._checkSelectedTab();
|
||||
if (tabsChanged) {
|
||||
this.emit("tab-list");
|
||||
}
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
// TODO: Tab "selection" should really take place by creating a TabProject
|
||||
|
|
|
@ -64,12 +64,12 @@ function test() {
|
|||
}
|
||||
|
||||
function connectToLocal(win, docRuntime) {
|
||||
let deferred = promise.defer();
|
||||
win.AppManager.connection.once(
|
||||
return new Promise(resolve => {
|
||||
win.AppManager.connection.once(
|
||||
win.Connection.Events.CONNECTED,
|
||||
() => deferred.resolve());
|
||||
docRuntime.querySelectorAll(".runtime-panel-item-other")[1].click();
|
||||
return deferred.promise;
|
||||
resolve);
|
||||
docRuntime.querySelectorAll(".runtime-panel-item-other")[1].click();
|
||||
});
|
||||
}
|
||||
|
||||
function selectTabProject(win, docProject) {
|
||||
|
|
|
@ -8,7 +8,6 @@ var {utils: Cu, classes: Cc, interfaces: Ci} = Components;
|
|||
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
|
||||
const { FileUtils } = require("resource://gre/modules/FileUtils.jsm");
|
||||
const { gDevTools } = require("devtools/client/framework/devtools");
|
||||
const promise = require("promise");
|
||||
const Services = require("Services");
|
||||
const { Task } = require("devtools/shared/task");
|
||||
const { AppProjects } = require("devtools/client/webide/modules/app-projects");
|
||||
|
@ -71,18 +70,14 @@ var openWebIDE = Task.async(function* (autoInstallAddons) {
|
|||
function closeWebIDE(win) {
|
||||
info("Closing WebIDE");
|
||||
|
||||
let deferred = promise.defer();
|
||||
return new Promise(resolve => {
|
||||
win.addEventListener("unload", function () {
|
||||
info("WebIDE closed");
|
||||
SimpleTest.executeSoon(resolve);
|
||||
}, {once: true});
|
||||
|
||||
win.addEventListener("unload", function () {
|
||||
info("WebIDE closed");
|
||||
SimpleTest.executeSoon(() => {
|
||||
deferred.resolve();
|
||||
});
|
||||
}, {once: true});
|
||||
|
||||
win.close();
|
||||
|
||||
return deferred.promise;
|
||||
win.close();
|
||||
});
|
||||
}
|
||||
|
||||
function removeAllProjects() {
|
||||
|
@ -98,93 +93,87 @@ function removeAllProjects() {
|
|||
}
|
||||
|
||||
function nextTick() {
|
||||
let deferred = promise.defer();
|
||||
SimpleTest.executeSoon(() => {
|
||||
deferred.resolve();
|
||||
return new Promise(resolve => {
|
||||
SimpleTest.executeSoon(resolve);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function waitForUpdate(win, update) {
|
||||
info("Wait: " + update);
|
||||
let deferred = promise.defer();
|
||||
win.AppManager.on("app-manager-update", function onUpdate(e, what) {
|
||||
info("Got: " + what);
|
||||
if (what !== update) {
|
||||
return;
|
||||
}
|
||||
win.AppManager.off("app-manager-update", onUpdate);
|
||||
deferred.resolve(win.UI._updatePromise);
|
||||
return new Promise(resolve => {
|
||||
win.AppManager.on("app-manager-update", function onUpdate(e, what) {
|
||||
info("Got: " + what);
|
||||
if (what !== update) {
|
||||
return;
|
||||
}
|
||||
win.AppManager.off("app-manager-update", onUpdate);
|
||||
resolve(win.UI._updatePromise);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function waitForTime(time) {
|
||||
let deferred = promise.defer();
|
||||
setTimeout(() => {
|
||||
deferred.resolve();
|
||||
}, time);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, time);
|
||||
});
|
||||
}
|
||||
|
||||
function documentIsLoaded(doc) {
|
||||
let deferred = promise.defer();
|
||||
if (doc.readyState == "complete") {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
doc.addEventListener("readystatechange", function onChange() {
|
||||
if (doc.readyState == "complete") {
|
||||
doc.removeEventListener("readystatechange", onChange);
|
||||
deferred.resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
if (doc.readyState == "complete") {
|
||||
resolve();
|
||||
} else {
|
||||
doc.addEventListener("readystatechange", function onChange() {
|
||||
if (doc.readyState == "complete") {
|
||||
doc.removeEventListener("readystatechange", onChange);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function lazyIframeIsLoaded(iframe) {
|
||||
let deferred = promise.defer();
|
||||
iframe.addEventListener("load", function () {
|
||||
deferred.resolve(nextTick());
|
||||
}, {capture: true, once: true});
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
iframe.addEventListener("load", function () {
|
||||
resolve(nextTick());
|
||||
}, {capture: true, once: true});
|
||||
});
|
||||
}
|
||||
|
||||
function addTab(aUrl, aWindow) {
|
||||
info("Adding tab: " + aUrl);
|
||||
|
||||
let deferred = promise.defer();
|
||||
let targetWindow = aWindow || window;
|
||||
let targetBrowser = targetWindow.gBrowser;
|
||||
return new Promise(resolve => {
|
||||
let targetWindow = aWindow || window;
|
||||
let targetBrowser = targetWindow.gBrowser;
|
||||
|
||||
targetWindow.focus();
|
||||
let tab = targetBrowser.selectedTab = targetBrowser.addTab(aUrl);
|
||||
let linkedBrowser = tab.linkedBrowser;
|
||||
targetWindow.focus();
|
||||
let tab = targetBrowser.selectedTab = targetBrowser.addTab(aUrl);
|
||||
let linkedBrowser = tab.linkedBrowser;
|
||||
|
||||
BrowserTestUtils.browserLoaded(linkedBrowser).then(function () {
|
||||
info("Tab added and finished loading: " + aUrl);
|
||||
deferred.resolve(tab);
|
||||
BrowserTestUtils.browserLoaded(linkedBrowser).then(function () {
|
||||
info("Tab added and finished loading: " + aUrl);
|
||||
resolve(tab);
|
||||
});
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function removeTab(aTab, aWindow) {
|
||||
info("Removing tab.");
|
||||
|
||||
let deferred = promise.defer();
|
||||
let targetWindow = aWindow || window;
|
||||
let targetBrowser = targetWindow.gBrowser;
|
||||
let tabContainer = targetBrowser.tabContainer;
|
||||
return new Promise(resolve => {
|
||||
let targetWindow = aWindow || window;
|
||||
let targetBrowser = targetWindow.gBrowser;
|
||||
let tabContainer = targetBrowser.tabContainer;
|
||||
|
||||
tabContainer.addEventListener("TabClose", function (aEvent) {
|
||||
info("Tab removed and finished closing.");
|
||||
deferred.resolve();
|
||||
}, {once: true});
|
||||
tabContainer.addEventListener("TabClose", function (aEvent) {
|
||||
info("Tab removed and finished closing.");
|
||||
resolve();
|
||||
}, {once: true});
|
||||
|
||||
targetBrowser.removeTab(aTab);
|
||||
return deferred.promise;
|
||||
targetBrowser.removeTab(aTab);
|
||||
});
|
||||
}
|
||||
|
||||
function getRuntimeDocument(win) {
|
||||
|
|
|
@ -22,30 +22,26 @@
|
|||
const {Devices} = Cu.import("resource://devtools/shared/apps/Devices.jsm");
|
||||
const {Simulators} = require("devtools/client/webide/modules/simulators");
|
||||
|
||||
let adbAddonsInstalled = promise.defer();
|
||||
Devices.on("addon-status-updated", function onUpdate1() {
|
||||
Devices.off("addon-status-updated", onUpdate1);
|
||||
adbAddonsInstalled.resolve();
|
||||
});
|
||||
let adbAddonsInstalled;
|
||||
|
||||
function getVersion(name) {
|
||||
return name.match(/(\d+\.\d+)/)[0];
|
||||
}
|
||||
|
||||
function onSimulatorInstalled(name) {
|
||||
let deferred = promise.defer();
|
||||
Simulators.on("updated", function onUpdate() {
|
||||
Simulators.findSimulatorAddons().then(addons => {
|
||||
for (let addon of addons) {
|
||||
if (name == addon.name.replace(" Simulator", "")) {
|
||||
Simulators.off("updated", onUpdate);
|
||||
nextTick().then(deferred.resolve);
|
||||
return;
|
||||
return new Promise(resolve => {
|
||||
Simulators.on("updated", function onUpdate() {
|
||||
Simulators.findSimulatorAddons().then(addons => {
|
||||
for (let addon of addons) {
|
||||
if (name == addon.name.replace(" Simulator", "")) {
|
||||
Simulators.off("updated", onUpdate);
|
||||
nextTick().then(resolve);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function installSimulatorFromUI(doc, name) {
|
||||
|
@ -55,39 +51,39 @@
|
|||
}
|
||||
|
||||
function uninstallSimulatorFromUI(doc, name) {
|
||||
let deferred = promise.defer();
|
||||
Simulators.on("updated", function onUpdate() {
|
||||
nextTick().then(() => {
|
||||
let li = doc.querySelector('[status="uninstalled"][addon="simulator-' + getVersion(name) + '"]');
|
||||
if (li) {
|
||||
Simulators.off("updated", onUpdate);
|
||||
deferred.resolve();
|
||||
} else {
|
||||
deferred.reject("Can't find item");
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
Simulators.on("updated", function onUpdate() {
|
||||
nextTick().then(() => {
|
||||
let li = doc.querySelector('[status="uninstalled"][addon="simulator-' + getVersion(name) + '"]');
|
||||
if (li) {
|
||||
Simulators.off("updated", onUpdate);
|
||||
resolve();
|
||||
} else {
|
||||
reject("Can't find item");
|
||||
}
|
||||
});
|
||||
});
|
||||
let li = doc.querySelector('[status="installed"][addon="simulator-' + getVersion(name) + '"]');
|
||||
li.querySelector(".uninstall-button").click();
|
||||
});
|
||||
let li = doc.querySelector('[status="installed"][addon="simulator-' + getVersion(name) + '"]');
|
||||
li.querySelector(".uninstall-button").click();
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function uninstallADBFromUI(doc) {
|
||||
let deferred = promise.defer();
|
||||
Devices.on("addon-status-updated", function onUpdate() {
|
||||
nextTick().then(() => {
|
||||
let li = doc.querySelector('[status="uninstalled"][addon="adb"]');
|
||||
if (li) {
|
||||
Devices.off("addon-status-updated", onUpdate);
|
||||
deferred.resolve();
|
||||
} else {
|
||||
deferred.reject("Can't find item");
|
||||
}
|
||||
})
|
||||
return new Promise((resolve, reject) => {
|
||||
Devices.on("addon-status-updated", function onUpdate() {
|
||||
nextTick().then(() => {
|
||||
let li = doc.querySelector('[status="uninstalled"][addon="adb"]');
|
||||
if (li) {
|
||||
Devices.off("addon-status-updated", onUpdate);
|
||||
resolve();
|
||||
} else {
|
||||
reject("Can't find item");
|
||||
}
|
||||
})
|
||||
});
|
||||
let li = doc.querySelector('[status="installed"][addon="adb"]');
|
||||
li.querySelector(".uninstall-button").click();
|
||||
});
|
||||
let li = doc.querySelector('[status="installed"][addon="adb"]');
|
||||
li.querySelector(".uninstall-button").click();
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
Task.spawn(function*() {
|
||||
|
@ -97,7 +93,12 @@
|
|||
let win = yield openWebIDE(true);
|
||||
let docRuntime = getRuntimeDocument(win);
|
||||
|
||||
yield adbAddonsInstalled.promise;
|
||||
adbAddonsInstalled = new Promise(resolve => {
|
||||
Devices.on("addon-status-updated", function onUpdate1() {
|
||||
Devices.off("addon-status-updated", onUpdate1);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
ok(Devices.helperAddonInstalled, "Helper has been auto-installed");
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
is(connection, win.AppManager.connection, "connection is valid");
|
||||
connection.host = null; // force connectPipe
|
||||
connection.connect();
|
||||
return promise.resolve();
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
get id() {
|
||||
|
|
|
@ -35,12 +35,13 @@
|
|||
let nbox = win.document.querySelector("#notificationbox");
|
||||
let notification = nbox.getNotificationWithValue("webide:errornotification");
|
||||
ok(!notification, "No notification yet");
|
||||
let deferred = promise.defer();
|
||||
nextTick().then(() => {
|
||||
deferred.reject("BOOM!");
|
||||
let deferred = new Promise((resolve, reject) => {
|
||||
nextTick().then(() => {
|
||||
reject("BOOM!");
|
||||
});
|
||||
});
|
||||
try {
|
||||
yield win.UI.busyUntil(deferred.promise, "xx");
|
||||
yield win.UI.busyUntil(deferred, "xx");
|
||||
} catch(e) {/* This *will* fail */}
|
||||
notification = nbox.getNotificationWithValue("webide:errornotification");
|
||||
ok(notification, "Error has been reported");
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
|
||||
<script type="application/javascript">
|
||||
function connectToLocal(win, docRuntime) {
|
||||
let deferred = promise.defer();
|
||||
win.AppManager.connection.once(
|
||||
win.Connection.Events.CONNECTED,
|
||||
() => deferred.resolve());
|
||||
docRuntime.querySelectorAll(".runtime-panel-item-other")[1].click();
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
win.AppManager.connection.once(
|
||||
win.Connection.Events.CONNECTED,
|
||||
resolve);
|
||||
docRuntime.querySelectorAll(".runtime-panel-item-other")[1].click();
|
||||
});
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
|
@ -33,7 +33,7 @@
|
|||
let docRuntime = getRuntimeDocument(win);
|
||||
win.AppManager.update("runtime-list");
|
||||
|
||||
yield connectToLocal(win, docRuntime);
|
||||
connectToLocal(win, docRuntime);
|
||||
|
||||
// Select main process
|
||||
yield waitForUpdate(win, "runtime-targets");
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
is(connection, win.AppManager.connection, "connection is valid");
|
||||
connection.host = null; // force connectPipe
|
||||
connection.connect();
|
||||
return promise.resolve();
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
get name() {
|
||||
|
@ -72,8 +72,7 @@
|
|||
|
||||
win.AppManager.runtimeList.usb.push({
|
||||
connect: function(connection) {
|
||||
let deferred = promise.defer();
|
||||
return deferred.promise;
|
||||
return new Promise(() => {});
|
||||
},
|
||||
|
||||
get name() {
|
||||
|
@ -83,8 +82,7 @@
|
|||
|
||||
win.AppManager.runtimeList.usb.push({
|
||||
connect: function(connection) {
|
||||
let deferred = promise.defer();
|
||||
return deferred.promise;
|
||||
return new Promise(() => {});
|
||||
},
|
||||
|
||||
prolongedConnection: true,
|
||||
|
@ -164,36 +162,35 @@
|
|||
|
||||
Services.prefs.setIntPref("devtools.webide.busyTimeout", 100);
|
||||
|
||||
// Wait for error message since connection never completes
|
||||
let errorDeferred = promise.defer();
|
||||
win.UI.reportError = errorName => {
|
||||
if (errorName === "error_operationTimeout") {
|
||||
errorDeferred.resolve();
|
||||
}
|
||||
};
|
||||
|
||||
// Click the infinite runtime
|
||||
items[1].click();
|
||||
ok(win.document.querySelector("window").className, "busy", "UI is busy");
|
||||
yield errorDeferred.promise;
|
||||
|
||||
// Check for unexpected error message since this is prolonged
|
||||
let noErrorDeferred = promise.defer();
|
||||
win.UI.reportError = errorName => {
|
||||
if (errorName === "error_operationTimeout") {
|
||||
noErrorDeferred.reject();
|
||||
}
|
||||
};
|
||||
// Wait for error message since connection never completes
|
||||
let errorDeferred = new Promise(resolve => {
|
||||
win.UI.reportError = errorName => {
|
||||
if (errorName === "error_operationTimeout") {
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// Click the prolonged runtime
|
||||
items[2].click();
|
||||
ok(win.document.querySelector("window").className, "busy", "UI is busy");
|
||||
|
||||
setTimeout(() => {
|
||||
noErrorDeferred.resolve();
|
||||
}, 1000);
|
||||
// Check for unexpected error message since this is prolonged
|
||||
let noErrorDeferred = new Promise((resolve, reject) => {
|
||||
win.UI.reportError = errorName => {
|
||||
if (errorName === "error_operationTimeout") {
|
||||
reject();
|
||||
}
|
||||
};
|
||||
|
||||
yield noErrorDeferred.promise;
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
SimpleTest.finish();
|
||||
});
|
||||
|
|
|
@ -29,31 +29,31 @@
|
|||
|
||||
function addonStatus(addon, status) {
|
||||
if (addon.status == status) {
|
||||
return promise.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
let deferred = promise.defer();
|
||||
addon.on("update", function onUpdate() {
|
||||
if (addon.status == status) {
|
||||
addon.off("update", onUpdate);
|
||||
nextTick().then(() => deferred.resolve());
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
addon.on("update", function onUpdate() {
|
||||
if (addon.status == status) {
|
||||
addon.off("update", onUpdate);
|
||||
nextTick().then(() => resolve());
|
||||
}
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function waitForUpdate(length) {
|
||||
info(`Wait for update with length ${length}`);
|
||||
let deferred = promise.defer();
|
||||
let handler = (_, data) => {
|
||||
if (data.length != length) {
|
||||
return;
|
||||
}
|
||||
info(`Got update with length ${length}`);
|
||||
Simulators.off("updated", handler);
|
||||
deferred.resolve();
|
||||
};
|
||||
Simulators.on("updated", handler);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
let handler = (_, data) => {
|
||||
if (data.length != length) {
|
||||
return;
|
||||
}
|
||||
info(`Got update with length ${length}`);
|
||||
Simulators.off("updated", handler);
|
||||
resolve();
|
||||
};
|
||||
Simulators.on("updated", handler);
|
||||
});
|
||||
}
|
||||
|
||||
Task.spawn(function* () {
|
||||
|
@ -70,9 +70,9 @@
|
|||
|
||||
// Hack SimulatorProcesses to spy on simulation parameters.
|
||||
|
||||
let runPromise;
|
||||
function fakeRun() {
|
||||
runPromise.resolve({
|
||||
let resolver;
|
||||
function fakeRun() {
|
||||
resolver({
|
||||
path: this.b2gBinary.path,
|
||||
args: this.args
|
||||
});
|
||||
|
@ -85,9 +85,10 @@
|
|||
CustomSimulatorProcess.prototype.run = fakeRun;
|
||||
|
||||
function runSimulator(i) {
|
||||
runPromise = promise.defer();
|
||||
findAll(".runtime-panel-item-simulator")[i].click();
|
||||
return runPromise.promise;
|
||||
return new Promise(resolve => {
|
||||
resolver = resolve;
|
||||
findAll(".runtime-panel-item-simulator")[i].click();
|
||||
});
|
||||
}
|
||||
|
||||
// Install fake "Firefox OS 1.0" simulator addon.
|
||||
|
|
|
@ -42,10 +42,11 @@
|
|||
|
||||
win.AppManager.update("runtime-list");
|
||||
|
||||
let deferred = promise.defer();
|
||||
win.AppManager.connection.once(
|
||||
win.Connection.Events.CONNECTED,
|
||||
() => deferred.resolve());
|
||||
let deferred = new Promise(resolve => {
|
||||
win.AppManager.connection.once(
|
||||
win.Connection.Events.CONNECTED,
|
||||
resolve);
|
||||
});
|
||||
|
||||
docRuntime.querySelectorAll(".runtime-panel-item-other")[1].click();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче