diff --git a/src/dom/common/dom-view.tsx b/src/dom/common/dom-view.tsx index a9a44a0c..fcdf5ae4 100644 --- a/src/dom/common/dom-view.tsx +++ b/src/dom/common/dom-view.tsx @@ -126,16 +126,16 @@ abstract class DOMView { } protected _getCSP(): string { - let baseURI = this._options.data.baseURI ? new URL(this._options.data.baseURI) : null; - // When baseURI is http[s], use the origin - // In the client, though, baseURI will be a zotero: URI and its origin will be the string "null" + let url = this._options.data.url ? new URL(this._options.data.url) : null; + // When url is http[s], use the origin + // In the client, though, url will be a zotero: URI and its origin will be the string "null" // for some reason. In that case, just allow the entire protocol. (In practice zotero:// URIs are always // allowed because the protocol is marked as URI_IS_LOCAL_RESOURCE, which exempts it from CSP, but we want // to be safe here.) // https://bugzilla.mozilla.org/show_bug.cgi?id=1551253 - let origin = baseURI && (baseURI.protocol.startsWith('http') ? baseURI.origin : baseURI.protocol); + let origin = url && (url.protocol.startsWith('http') ? url.origin : url.protocol); - // Allow resources from the same origin as the baseURI + // Allow resources from the same origin as the URL let defaultSrc = origin || "'none'"; // Allow images from data: and blob: URIs and from that origin let imgSrc = (origin || '') + ' data: blob:'; @@ -1078,7 +1078,7 @@ export type DOMViewOptions = { onKeyDown: (event: KeyboardEvent) => void; data: Data & { buf?: Uint8Array, - baseURI?: string + url?: string }; }; diff --git a/src/dom/epub/epub-view.ts b/src/dom/epub/epub-view.ts index f2ab120b..4195c3e9 100644 --- a/src/dom/epub/epub-view.ts +++ b/src/dom/epub/epub-view.ts @@ -91,8 +91,8 @@ class EPUBView extends DOMView { this.book = Epub(options.data.buf.buffer); delete this._options.data.buf; } - else if (options.data.baseURI) { - this.book = Epub(options.data.baseURI, { + else if (options.data.url) { + this.book = Epub(options.data.url, { openAs: 'epub' }); } @@ -100,7 +100,7 @@ class EPUBView extends DOMView { this.book = options.data.book; } else { - throw new Error('buf, baseURI, or book is required'); + throw new Error('buf, url, or book is required'); } } diff --git a/src/dom/snapshot/snapshot-view.ts b/src/dom/snapshot/snapshot-view.ts index 7d8d9c7c..21eb68fa 100644 --- a/src/dom/snapshot/snapshot-view.ts +++ b/src/dom/snapshot/snapshot-view.ts @@ -47,13 +47,13 @@ class SnapshotView extends DOMView { if (this._options.data.srcDoc) { return this._options.data.srcDoc; } - else if (this._options.data.buf || this._options.data.baseURI !== undefined) { + else if (this._options.data.buf || this._options.data.url !== undefined) { let buf; if (this._options.data.buf) { buf = this._options.data.buf; } else { - buf = await fetch(this._options.data.baseURI!).then(r => r.arrayBuffer()); + buf = await fetch(this._options.data.url!).then(r => r.arrayBuffer()); } let text = new TextDecoder('utf-8').decode(buf); delete this._options.data.buf; @@ -62,9 +62,9 @@ class SnapshotView extends DOMView { for (let base of doc.querySelectorAll('base')) { base.remove(); } - if (this._options.data.baseURI !== undefined) { + if (this._options.data.url !== undefined) { let base = doc.createElement('base'); - base.href = this._options.data.baseURI; + base.href = this._options.data.url; doc.head.prepend(base); } @@ -79,14 +79,14 @@ class SnapshotView extends DOMView { return new XMLSerializer().serializeToString(doc); } else { - throw new Error('buf, baseURI, or srcDoc is required'); + throw new Error('buf, url, or srcDoc is required'); } } getData() { return { srcDoc: this._iframe.srcdoc, - baseURI: this._iframeDocument.head.querySelector('base')?.href + url: this._iframeDocument.head.querySelector('base')?.href }; } diff --git a/src/index.dev.js b/src/index.dev.js index ff0d616e..6fa275c5 100644 --- a/src/index.dev.js +++ b/src/index.dev.js @@ -30,7 +30,7 @@ async function createReader() { readOnly: false, data: { buf: new Uint8Array(await res.arrayBuffer()), - baseURI: new URL('/', window.location).toString() + url: new URL('/', window.location).toString() }, // rtl: true, annotations: demo.annotations, diff --git a/src/pdf/pdf-view.js b/src/pdf/pdf-view.js index e8e41439..d258625e 100644 --- a/src/pdf/pdf-view.js +++ b/src/pdf/pdf-view.js @@ -154,7 +154,7 @@ class PDFView { this._iframeWindow.PDFViewerApplication.open({ data: options.data.buf, password: this._password }); } else { - this._iframeWindow.PDFViewerApplication.open({ url: options.data.baseURI, password: this._password }); + this._iframeWindow.PDFViewerApplication.open({ url: options.data.url, password: this._password }); } window.PDFViewerApplication = this._iframeWindow.PDFViewerApplication; window.if = this._iframeWindow;