Bug 1245599 - Implement chrome.downloads.onCreated r=kmag

MozReview-Commit-ID: 53yhKZYHDrD
This commit is contained in:
Andrew Swan
2016-03-07 16:54:08 -08:00
parent dc76f92520
commit a2b7a30348
4 changed files with 204 additions and 3 deletions

View File

@@ -141,7 +141,8 @@ const DownloadMap = {
let self = this;
return list.addView({
onDownloadAdded(download) {
self.newFromDownload(download, null);
const item = self.newFromDownload(download, null);
self.emit("create", item);
},
onDownloadRemoved(download) {
@@ -478,7 +479,20 @@ extensions.registerSchemaAPI("downloads", "downloads", (extension, context) => {
};
}).api(),
onCreated: ignoreEvent(context, "downloads.onCreated"),
onCreated: new SingletonEventManager(context, "downloads.onCreated", fire => {
const handler = (what, item) => {
runSafeSync(context, fire, item.serialize());
};
let registerPromise = DownloadMap.getDownloadList().then(() => {
DownloadMap.on("create", handler);
});
return () => {
registerPromise.then(() => {
DownloadMap.off("create", handler);
});
};
}).api(),
onErased: ignoreEvent(context, "downloads.onErased"),
onDeterminingFilename: ignoreEvent(context, "downloads.onDeterminingFilename"),
},