Merge pull request #15663 from Snuffleupagus/viewer-classes-private-fields
Use private fields in a few more viewer classes
This commit is contained in:
commit
0b27d703fa
@ -47,9 +47,7 @@ function download(blobUrl, filename) {
|
||||
* @implements {IDownloadManager}
|
||||
*/
|
||||
class DownloadManager {
|
||||
constructor() {
|
||||
this._openBlobUrls = new WeakMap();
|
||||
}
|
||||
#openBlobUrls = new WeakMap();
|
||||
|
||||
downloadUrl(url, filename) {
|
||||
if (!createValidAbsoluteUrl(url, "http://example.com")) {
|
||||
@ -74,10 +72,10 @@ class DownloadManager {
|
||||
const contentType = isPdfData ? "application/pdf" : "";
|
||||
|
||||
if (isPdfData) {
|
||||
let blobUrl = this._openBlobUrls.get(element);
|
||||
let blobUrl = this.#openBlobUrls.get(element);
|
||||
if (!blobUrl) {
|
||||
blobUrl = URL.createObjectURL(new Blob([data], { type: contentType }));
|
||||
this._openBlobUrls.set(element, blobUrl);
|
||||
this.#openBlobUrls.set(element, blobUrl);
|
||||
}
|
||||
let viewerUrl;
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
@ -101,7 +99,7 @@ class DownloadManager {
|
||||
// Release the `blobUrl`, since opening it failed, and fallback to
|
||||
// downloading the PDF file.
|
||||
URL.revokeObjectURL(blobUrl);
|
||||
this._openBlobUrls.delete(element);
|
||||
this.#openBlobUrls.delete(element);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,9 +75,7 @@ function waitOnEventOrTimeout({ target, name, delay = 0 }) {
|
||||
* and `off` methods. To raise an event, the `dispatch` method shall be used.
|
||||
*/
|
||||
class EventBus {
|
||||
constructor() {
|
||||
this._listeners = Object.create(null);
|
||||
}
|
||||
#listeners = Object.create(null);
|
||||
|
||||
/**
|
||||
* @param {string} eventName
|
||||
@ -108,7 +106,7 @@ class EventBus {
|
||||
* @param {Object} data
|
||||
*/
|
||||
dispatch(eventName, data) {
|
||||
const eventListeners = this._listeners[eventName];
|
||||
const eventListeners = this.#listeners[eventName];
|
||||
if (!eventListeners || eventListeners.length === 0) {
|
||||
return;
|
||||
}
|
||||
@ -139,7 +137,7 @@ class EventBus {
|
||||
* @ignore
|
||||
*/
|
||||
_on(eventName, listener, options = null) {
|
||||
const eventListeners = (this._listeners[eventName] ||= []);
|
||||
const eventListeners = (this.#listeners[eventName] ||= []);
|
||||
eventListeners.push({
|
||||
listener,
|
||||
external: options?.external === true,
|
||||
@ -151,7 +149,7 @@ class EventBus {
|
||||
* @ignore
|
||||
*/
|
||||
_off(eventName, listener, options = null) {
|
||||
const eventListeners = this._listeners[eventName];
|
||||
const eventListeners = this.#listeners[eventName];
|
||||
if (!eventListeners) {
|
||||
return;
|
||||
}
|
||||
|
@ -100,9 +100,7 @@ class FirefoxCom {
|
||||
}
|
||||
|
||||
class DownloadManager {
|
||||
constructor() {
|
||||
this._openBlobUrls = new WeakMap();
|
||||
}
|
||||
#openBlobUrls = new WeakMap();
|
||||
|
||||
downloadUrl(url, filename) {
|
||||
FirefoxCom.request("download", {
|
||||
@ -132,10 +130,10 @@ class DownloadManager {
|
||||
const contentType = isPdfData ? "application/pdf" : "";
|
||||
|
||||
if (isPdfData) {
|
||||
let blobUrl = this._openBlobUrls.get(element);
|
||||
let blobUrl = this.#openBlobUrls.get(element);
|
||||
if (!blobUrl) {
|
||||
blobUrl = URL.createObjectURL(new Blob([data], { type: contentType }));
|
||||
this._openBlobUrls.set(element, blobUrl);
|
||||
this.#openBlobUrls.set(element, blobUrl);
|
||||
}
|
||||
// Let Firefox's content handler catch the URL and display the PDF.
|
||||
const viewerUrl = blobUrl + "#filename=" + encodeURIComponent(filename);
|
||||
@ -148,7 +146,7 @@ class DownloadManager {
|
||||
// Release the `blobUrl`, since opening it failed, and fallback to
|
||||
// downloading the PDF file.
|
||||
URL.revokeObjectURL(blobUrl);
|
||||
this._openBlobUrls.delete(element);
|
||||
this.#openBlobUrls.delete(element);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user