browser(firefox): add Download.cancel (#7390)

This commit is contained in:
Max Schmitt 2021-06-30 01:29:58 +02:00 committed by GitHub
parent fc0b8ad3f0
commit 18266722a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 64 additions and 12 deletions

View file

@ -1,2 +1,2 @@
1265 1266
Changed: max@schmitt.mx Mon Jun 28 22:40:00 UTC 2021 Changed: max@schmitt.mx Tue Jun 29 22:44:52 UTC 2021

View file

@ -12,6 +12,8 @@ const {NetUtil} = ChromeUtils.import('resource://gre/modules/NetUtil.jsm');
const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm"); const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
const {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm"); const {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm");
const Cr = Components.results;
const helper = new Helper(); const helper = new Helper();
const IDENTITY_NAME = 'JUGGLER '; const IDENTITY_NAME = 'JUGGLER ';
@ -26,6 +28,7 @@ class DownloadInterceptor {
constructor(registry) { constructor(registry) {
this._registry = registry this._registry = registry
this._handlerToUuid = new Map(); this._handlerToUuid = new Map();
this._uuidToHandler = new Map();
} }
// //
@ -60,6 +63,7 @@ class DownloadInterceptor {
} }
outFile.value = file; outFile.value = file;
this._handlerToUuid.set(externalAppHandler, uuid); this._handlerToUuid.set(externalAppHandler, uuid);
this._uuidToHandler.set(uuid, externalAppHandler);
const downloadInfo = { const downloadInfo = {
uuid, uuid,
browserContextId: browserContext.browserContextId, browserContextId: browserContext.browserContextId,
@ -76,16 +80,24 @@ class DownloadInterceptor {
if (!uuid) if (!uuid)
return; return;
this._handlerToUuid.delete(externalAppHandler); this._handlerToUuid.delete(externalAppHandler);
this._uuidToHandler.delete(uuid);
const downloadInfo = { const downloadInfo = {
uuid, uuid,
error: errorName,
}; };
if (errorName === 'NS_BINDING_ABORTED') { if (canceled === 'NS_BINDING_ABORTED') {
downloadInfo.canceled = true; downloadInfo.canceled = true;
} else {
downloadInfo.error = errorName;
} }
this._registry.emit(TargetRegistry.Events.DownloadFinished, downloadInfo); this._registry.emit(TargetRegistry.Events.DownloadFinished, downloadInfo);
} }
async cancelDownload(uuid) {
const externalAppHandler = this._uuidToHandler.get(uuid);
if (!externalAppHandler) {
return;
}
await externalAppHandler.cancel(Cr.NS_BINDING_ABORTED);
}
} }
const screencastService = Cc['@mozilla.org/juggler/screencast;1'].getService(Ci.nsIScreencastService); const screencastService = Cc['@mozilla.org/juggler/screencast;1'].getService(Ci.nsIScreencastService);
@ -227,13 +239,18 @@ class TargetRegistry {
}; };
const extHelperAppSvc = Cc["@mozilla.org/uriloader/external-helper-app-service;1"].getService(Ci.nsIExternalHelperAppService); const extHelperAppSvc = Cc["@mozilla.org/uriloader/external-helper-app-service;1"].getService(Ci.nsIExternalHelperAppService);
extHelperAppSvc.setDownloadInterceptor(new DownloadInterceptor(this)); this._downloadInterceptor = new DownloadInterceptor(this);
extHelperAppSvc.setDownloadInterceptor(this._downloadInterceptor);
Services.wm.addListener({ onOpenWindow, onCloseWindow }); Services.wm.addListener({ onOpenWindow, onCloseWindow });
for (const win of Services.wm.getEnumerator(null)) for (const win of Services.wm.getEnumerator(null))
onOpenWindow(win); onOpenWindow(win);
} }
async cancelDownload(options) {
this._downloadInterceptor.cancelDownload(options.uuid);
}
setBrowserProxy(proxy) { setBrowserProxy(proxy) {
this._browserProxy = proxy; this._browserProxy = proxy;
} }

View file

@ -125,6 +125,10 @@ class BrowserHandler {
this._session.emitEvent('Browser.downloadFinished', downloadInfo); this._session.emitEvent('Browser.downloadFinished', downloadInfo);
} }
async ['Browser.cancelDownload']({uuid}) {
await this._targetRegistry.cancelDownload({uuid});
}
async ['Browser.newPage']({browserContextId}) { async ['Browser.newPage']({browserContextId}) {
const targetId = await this._targetRegistry.newPage({browserContextId}); const targetId = await this._targetRegistry.newPage({browserContextId});
return {targetId}; return {targetId};

View file

@ -452,6 +452,11 @@ const Browser = {
height: t.Number, height: t.Number,
}, },
}, },
'cancelDownload': {
params: {
uuid: t.Optional(t.String),
}
}
}, },
}; };

View file

@ -1,2 +1,2 @@
1272 1273
Changed: max@schmitt.mx Mon Jun 28 10:29:55 UTC 2021 Changed: max@schmitt.mx Tue Jun 29 22:39:37 UTC 2021

View file

@ -12,6 +12,8 @@ const {NetUtil} = ChromeUtils.import('resource://gre/modules/NetUtil.jsm');
const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm"); const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
const {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm"); const {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm");
const Cr = Components.results;
const helper = new Helper(); const helper = new Helper();
const IDENTITY_NAME = 'JUGGLER '; const IDENTITY_NAME = 'JUGGLER ';
@ -26,6 +28,7 @@ class DownloadInterceptor {
constructor(registry) { constructor(registry) {
this._registry = registry this._registry = registry
this._handlerToUuid = new Map(); this._handlerToUuid = new Map();
this._uuidToHandler = new Map();
} }
// //
@ -60,6 +63,7 @@ class DownloadInterceptor {
} }
outFile.value = file; outFile.value = file;
this._handlerToUuid.set(externalAppHandler, uuid); this._handlerToUuid.set(externalAppHandler, uuid);
this._uuidToHandler.set(uuid, externalAppHandler);
const downloadInfo = { const downloadInfo = {
uuid, uuid,
browserContextId: browserContext.browserContextId, browserContextId: browserContext.browserContextId,
@ -76,16 +80,24 @@ class DownloadInterceptor {
if (!uuid) if (!uuid)
return; return;
this._handlerToUuid.delete(externalAppHandler); this._handlerToUuid.delete(externalAppHandler);
this._uuidToHandler.delete(uuid);
const downloadInfo = { const downloadInfo = {
uuid, uuid,
error: errorName,
}; };
if (errorName === 'NS_BINDING_ABORTED') { if (canceled === 'NS_BINDING_ABORTED') {
downloadInfo.canceled = true; downloadInfo.canceled = true;
} else {
downloadInfo.error = errorName;
} }
this._registry.emit(TargetRegistry.Events.DownloadFinished, downloadInfo); this._registry.emit(TargetRegistry.Events.DownloadFinished, downloadInfo);
} }
async cancelDownload(uuid) {
const externalAppHandler = this._uuidToHandler.get(uuid);
if (!externalAppHandler) {
return;
}
await externalAppHandler.cancel(Cr.NS_BINDING_ABORTED);
}
} }
const screencastService = Cc['@mozilla.org/juggler/screencast;1'].getService(Ci.nsIScreencastService); const screencastService = Cc['@mozilla.org/juggler/screencast;1'].getService(Ci.nsIScreencastService);
@ -227,13 +239,18 @@ class TargetRegistry {
}; };
const extHelperAppSvc = Cc["@mozilla.org/uriloader/external-helper-app-service;1"].getService(Ci.nsIExternalHelperAppService); const extHelperAppSvc = Cc["@mozilla.org/uriloader/external-helper-app-service;1"].getService(Ci.nsIExternalHelperAppService);
extHelperAppSvc.setDownloadInterceptor(new DownloadInterceptor(this)); this._downloadInterceptor = new DownloadInterceptor(this);
extHelperAppSvc.setDownloadInterceptor(this._downloadInterceptor);
Services.wm.addListener({ onOpenWindow, onCloseWindow }); Services.wm.addListener({ onOpenWindow, onCloseWindow });
for (const win of Services.wm.getEnumerator(null)) for (const win of Services.wm.getEnumerator(null))
onOpenWindow(win); onOpenWindow(win);
} }
async cancelDownload(options) {
this._downloadInterceptor.cancelDownload(options.uuid);
}
setBrowserProxy(proxy) { setBrowserProxy(proxy) {
this._browserProxy = proxy; this._browserProxy = proxy;
} }

View file

@ -125,6 +125,10 @@ class BrowserHandler {
this._session.emitEvent('Browser.downloadFinished', downloadInfo); this._session.emitEvent('Browser.downloadFinished', downloadInfo);
} }
async ['Browser.cancelDownload']({uuid}) {
await this._targetRegistry.cancelDownload({uuid});
}
async ['Browser.newPage']({browserContextId}) { async ['Browser.newPage']({browserContextId}) {
const targetId = await this._targetRegistry.newPage({browserContextId}); const targetId = await this._targetRegistry.newPage({browserContextId});
return {targetId}; return {targetId};

View file

@ -452,6 +452,11 @@ const Browser = {
height: t.Number, height: t.Number,
}, },
}, },
'cancelDownload': {
params: {
uuid: t.Optional(t.String),
}
}
}, },
}; };