1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #12525 from brendandahl/mark-info

[api-minor] Implement API to get MarkInfo from the catalog.
This commit is contained in:
Tim van der Meij 2020-10-31 00:05:19 +01:00 committed by GitHub
commit e341e6e542
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 116 additions and 0 deletions

View file

@ -247,6 +247,7 @@ const PDFViewerApplication = {
triggerDelayedFallback: null,
_saveInProgress: false,
_wheelUnusedTicks: 0,
_idleCallbacks: new Set(),
// Called once when the document is loaded.
async initialize(appConfig) {
@ -743,6 +744,10 @@ const PDFViewerApplication = {
this.contentDispositionFilename = null;
this.triggerDelayedFallback = null;
this._saveInProgress = false;
for (const callback of this._idleCallbacks) {
window.cancelIdleCallback(callback);
}
this._idleCallbacks.clear();
this.pdfSidebar.reset();
this.pdfOutlineViewer.reset();
@ -1334,6 +1339,16 @@ const PDFViewerApplication = {
pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
this.pdfLayerViewer.render({ optionalContentConfig, pdfDocument });
});
if ("requestIdleCallback" in window) {
const callback = window.requestIdleCallback(
() => {
this._collectTelemetry(pdfDocument);
this._idleCallbacks.delete(callback);
},
{ timeout: 1000 }
);
this._idleCallbacks.add(callback);
}
});
this._initializePageLabels(pdfDocument);
@ -1398,6 +1413,23 @@ const PDFViewerApplication = {
scripting.createSandbox({ objects, dispatchEventName, calculationOrder });
},
/**
* A place to fetch data for telemetry after one page is rendered and the
* viewer is idle.
* @private
*/
async _collectTelemetry(pdfDocument) {
const markInfo = await this.pdfDocument.getMarkInfo();
if (pdfDocument !== this.pdfDocument) {
return; // Document was closed while waiting for mark info.
}
const tagged = markInfo?.Marked || false;
this.externalServices.reportTelemetry({
type: "tagged",
tagged,
});
},
/**
* @private
*/