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