Unconditionally report telemetry, in the viewer, regardless of build target
Given the dummy-methods on `DefaultExternalServices`, there's no longer any compelling reason not to (attempt to) report telemetry unconditionally. The only larger change consists of moving the `KNOWN_VERSIONS` and `KNOWN_GENERATORS` arrays ouf of the `PDFViewerApplication._initializeMetadata` method. *Please note:* Most of this patch consists of whitespace-only changes.
This commit is contained in:
parent
625f8a6f51
commit
f9157ec243
254
web/app.js
254
web/app.js
@ -86,6 +86,51 @@ const ViewOnLoad = {
|
|||||||
INITIAL: 1,
|
INITIAL: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Keep these in sync with mozilla-central's Histograms.json.
|
||||||
|
const KNOWN_VERSIONS = [
|
||||||
|
"1.0",
|
||||||
|
"1.1",
|
||||||
|
"1.2",
|
||||||
|
"1.3",
|
||||||
|
"1.4",
|
||||||
|
"1.5",
|
||||||
|
"1.6",
|
||||||
|
"1.7",
|
||||||
|
"1.8",
|
||||||
|
"1.9",
|
||||||
|
"2.0",
|
||||||
|
"2.1",
|
||||||
|
"2.2",
|
||||||
|
"2.3",
|
||||||
|
];
|
||||||
|
// Keep these in sync with mozilla-central's Histograms.json.
|
||||||
|
const KNOWN_GENERATORS = [
|
||||||
|
"acrobat distiller",
|
||||||
|
"acrobat pdfwriter",
|
||||||
|
"adobe livecycle",
|
||||||
|
"adobe pdf library",
|
||||||
|
"adobe photoshop",
|
||||||
|
"ghostscript",
|
||||||
|
"tcpdf",
|
||||||
|
"cairo",
|
||||||
|
"dvipdfm",
|
||||||
|
"dvips",
|
||||||
|
"pdftex",
|
||||||
|
"pdfkit",
|
||||||
|
"itext",
|
||||||
|
"prince",
|
||||||
|
"quarkxpress",
|
||||||
|
"mac os x",
|
||||||
|
"microsoft",
|
||||||
|
"openoffice",
|
||||||
|
"oracle",
|
||||||
|
"luradocument",
|
||||||
|
"pdf-xchange",
|
||||||
|
"antenna house",
|
||||||
|
"aspose.cells",
|
||||||
|
"fpdf",
|
||||||
|
];
|
||||||
|
|
||||||
class DefaultExternalServices {
|
class DefaultExternalServices {
|
||||||
constructor() {
|
constructor() {
|
||||||
throw new Error("Cannot initialize DefaultExternalServices.");
|
throw new Error("Cannot initialize DefaultExternalServices.");
|
||||||
@ -870,55 +915,45 @@ const PDFViewerApplication = {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_delayedFallback(featureId) {
|
_delayedFallback(featureId) {
|
||||||
if (
|
// Ensure that telemetry is always reported, since it's not guaranteed
|
||||||
typeof PDFJSDev === "undefined" ||
|
// that the fallback bar will be shown (depends on user interaction).
|
||||||
PDFJSDev.test("MOZCENTRAL || GENERIC")
|
this.externalServices.reportTelemetry({
|
||||||
) {
|
type: "unsupportedFeature",
|
||||||
// Ensure that telemetry is always reported, since it's not guaranteed
|
featureId,
|
||||||
// that the fallback bar will be shown (depends on user interaction).
|
});
|
||||||
this.externalServices.reportTelemetry({
|
|
||||||
type: "unsupportedFeature",
|
|
||||||
featureId,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!this.triggerDelayedFallback) {
|
if (!this.triggerDelayedFallback) {
|
||||||
this.triggerDelayedFallback = () => {
|
this.triggerDelayedFallback = () => {
|
||||||
this.fallback(featureId);
|
this.fallback(featureId);
|
||||||
this.triggerDelayedFallback = null;
|
this.triggerDelayedFallback = null;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fallback(featureId) {
|
fallback(featureId) {
|
||||||
if (
|
this.externalServices.reportTelemetry({
|
||||||
typeof PDFJSDev === "undefined" ||
|
type: "unsupportedFeature",
|
||||||
PDFJSDev.test("MOZCENTRAL || GENERIC")
|
featureId,
|
||||||
) {
|
});
|
||||||
this.externalServices.reportTelemetry({
|
|
||||||
type: "unsupportedFeature",
|
|
||||||
featureId,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Only trigger the fallback once so we don't spam the user with messages
|
// Only trigger the fallback once so we don't spam the user with messages
|
||||||
// for one PDF.
|
// for one PDF.
|
||||||
if (this.fellback) {
|
if (this.fellback) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
this.fellback = true;
|
|
||||||
this.externalServices.fallback(
|
|
||||||
{
|
|
||||||
featureId,
|
|
||||||
url: this.baseUrl,
|
|
||||||
},
|
|
||||||
function response(download) {
|
|
||||||
if (!download) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PDFViewerApplication.download();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
this.fellback = true;
|
||||||
|
this.externalServices.fallback(
|
||||||
|
{
|
||||||
|
featureId,
|
||||||
|
url: this.baseUrl,
|
||||||
|
},
|
||||||
|
function response(download) {
|
||||||
|
if (!download) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PDFViewerApplication.download();
|
||||||
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1319,7 +1354,6 @@ const PDFViewerApplication = {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let pdfTitle;
|
let pdfTitle;
|
||||||
|
|
||||||
const infoTitle = info && info.Title;
|
const infoTitle = info && info.Title;
|
||||||
if (infoTitle) {
|
if (infoTitle) {
|
||||||
pdfTitle = infoTitle;
|
pdfTitle = infoTitle;
|
||||||
@ -1339,7 +1373,6 @@ const PDFViewerApplication = {
|
|||||||
pdfTitle = metadataTitle;
|
pdfTitle = metadataTitle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdfTitle) {
|
if (pdfTitle) {
|
||||||
this.setTitle(
|
this.setTitle(
|
||||||
`${pdfTitle} - ${contentDispositionFilename || document.title}`
|
`${pdfTitle} - ${contentDispositionFilename || document.title}`
|
||||||
@ -1353,83 +1386,32 @@ const PDFViewerApplication = {
|
|||||||
this._delayedFallback(UNSUPPORTED_FEATURES.forms);
|
this._delayedFallback(UNSUPPORTED_FEATURES.forms);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
// Telemetry labels must be C++ variable friendly.
|
||||||
typeof PDFJSDev === "undefined" ||
|
let versionId = "other";
|
||||||
PDFJSDev.test("MOZCENTRAL || GENERIC")
|
if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
|
||||||
) {
|
versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
|
||||||
// Telemetry labels must be C++ variable friendly.
|
}
|
||||||
let versionId = "other";
|
let generatorId = "other";
|
||||||
// Keep these in sync with mozilla central's Histograms.json.
|
if (info.Producer) {
|
||||||
const KNOWN_VERSIONS = [
|
const producer = info.Producer.toLowerCase();
|
||||||
"1.0",
|
KNOWN_GENERATORS.some(function (generator) {
|
||||||
"1.1",
|
if (!producer.includes(generator)) {
|
||||||
"1.2",
|
return false;
|
||||||
"1.3",
|
}
|
||||||
"1.4",
|
generatorId = generator.replace(/[ .\-]/g, "_");
|
||||||
"1.5",
|
return true;
|
||||||
"1.6",
|
|
||||||
"1.7",
|
|
||||||
"1.8",
|
|
||||||
"1.9",
|
|
||||||
"2.0",
|
|
||||||
"2.1",
|
|
||||||
"2.2",
|
|
||||||
"2.3",
|
|
||||||
];
|
|
||||||
if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
|
|
||||||
versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let generatorId = "other";
|
|
||||||
// Keep these in sync with mozilla central's Histograms.json.
|
|
||||||
const KNOWN_GENERATORS = [
|
|
||||||
"acrobat distiller",
|
|
||||||
"acrobat pdfwriter",
|
|
||||||
"adobe livecycle",
|
|
||||||
"adobe pdf library",
|
|
||||||
"adobe photoshop",
|
|
||||||
"ghostscript",
|
|
||||||
"tcpdf",
|
|
||||||
"cairo",
|
|
||||||
"dvipdfm",
|
|
||||||
"dvips",
|
|
||||||
"pdftex",
|
|
||||||
"pdfkit",
|
|
||||||
"itext",
|
|
||||||
"prince",
|
|
||||||
"quarkxpress",
|
|
||||||
"mac os x",
|
|
||||||
"microsoft",
|
|
||||||
"openoffice",
|
|
||||||
"oracle",
|
|
||||||
"luradocument",
|
|
||||||
"pdf-xchange",
|
|
||||||
"antenna house",
|
|
||||||
"aspose.cells",
|
|
||||||
"fpdf",
|
|
||||||
];
|
|
||||||
if (info.Producer) {
|
|
||||||
const producer = info.Producer.toLowerCase();
|
|
||||||
KNOWN_GENERATORS.some(function (generator) {
|
|
||||||
if (!producer.includes(generator)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
generatorId = generator.replace(/[ .\-]/g, "_");
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let formType = null;
|
|
||||||
if (info.IsAcroFormPresent) {
|
|
||||||
formType = info.IsXFAPresent ? "xfa" : "acroform";
|
|
||||||
}
|
|
||||||
this.externalServices.reportTelemetry({
|
|
||||||
type: "documentInfo",
|
|
||||||
version: versionId,
|
|
||||||
generator: generatorId,
|
|
||||||
formType,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
let formType = null;
|
||||||
|
if (info.IsAcroFormPresent) {
|
||||||
|
formType = info.IsXFAPresent ? "xfa" : "acroform";
|
||||||
|
}
|
||||||
|
this.externalServices.reportTelemetry({
|
||||||
|
type: "documentInfo",
|
||||||
|
version: versionId,
|
||||||
|
generator: generatorId,
|
||||||
|
formType,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1642,14 +1624,9 @@ const PDFViewerApplication = {
|
|||||||
|
|
||||||
printService.layout();
|
printService.layout();
|
||||||
|
|
||||||
if (
|
this.externalServices.reportTelemetry({
|
||||||
typeof PDFJSDev === "undefined" ||
|
type: "print",
|
||||||
PDFJSDev.test("MOZCENTRAL || GENERIC")
|
});
|
||||||
) {
|
|
||||||
this.externalServices.reportTelemetry({
|
|
||||||
type: "print",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
afterPrint() {
|
afterPrint() {
|
||||||
@ -2091,22 +2068,17 @@ function webViewerPageRendered(evt) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
PDFViewerApplication.externalServices.reportTelemetry({
|
||||||
typeof PDFJSDev === "undefined" ||
|
type: "pageInfo",
|
||||||
PDFJSDev.test("MOZCENTRAL || GENERIC")
|
timestamp: evt.timestamp,
|
||||||
) {
|
});
|
||||||
|
// It is a good time to report stream and font types.
|
||||||
|
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
|
||||||
PDFViewerApplication.externalServices.reportTelemetry({
|
PDFViewerApplication.externalServices.reportTelemetry({
|
||||||
type: "pageInfo",
|
type: "documentStats",
|
||||||
timestamp: evt.timestamp,
|
stats,
|
||||||
});
|
});
|
||||||
// It is a good time to report stream and font types.
|
});
|
||||||
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
|
|
||||||
PDFViewerApplication.externalServices.reportTelemetry({
|
|
||||||
type: "documentStats",
|
|
||||||
stats,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function webViewerPageMode({ mode }) {
|
function webViewerPageMode({ mode }) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user