Skip to content

Commit

Permalink
baseURI -> url
Browse files Browse the repository at this point in the history
  • Loading branch information
AbeJellinek committed Sep 15, 2023
1 parent 9c1bf99 commit c13fd93
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/dom/common/dom-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ abstract class DOMView<State extends DOMViewState, Data> {
}

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:';
Expand Down Expand Up @@ -1078,7 +1078,7 @@ export type DOMViewOptions<State extends DOMViewState, Data> = {
onKeyDown: (event: KeyboardEvent) => void;
data: Data & {
buf?: Uint8Array,
baseURI?: string
url?: string
};
};

Expand Down
6 changes: 3 additions & 3 deletions src/dom/epub/epub-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ class EPUBView extends DOMView<EPUBViewState, EPUBViewData> {
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'
});
}
else if (options.data.book) {
this.book = options.data.book;
}
else {
throw new Error('buf, baseURI, or book is required');
throw new Error('buf, url, or book is required');
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/dom/snapshot/snapshot-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ class SnapshotView extends DOMView<SnapshotViewState, SnapshotViewData> {
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;
Expand All @@ -62,9 +62,9 @@ class SnapshotView extends DOMView<SnapshotViewState, SnapshotViewData> {
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);
}

Expand All @@ -79,14 +79,14 @@ class SnapshotView extends DOMView<SnapshotViewState, SnapshotViewData> {
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
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/pdf/pdf-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c13fd93

Please sign in to comment.