Collect telemetry in the viewer on whether a PDF is tagged.

This commit is contained in:
Brendan Dahl 2020-10-23 17:21:08 -07:00
parent f5c821e9c3
commit 8a8b4f9697

View File

@ -242,6 +242,7 @@ const PDFViewerApplication = {
triggerDelayedFallback: null,
_saveInProgress: false,
_wheelUnusedTicks: 0,
_idleCallbacks: new Set(),
// Called once when the document is loaded.
async initialize(appConfig) {
@ -738,6 +739,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();
@ -1329,12 +1334,39 @@ 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);
this._initializeMetadata(pdfDocument);
},
/**
* 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
*/