Skip to content

Commit

Permalink
Unconditionally report telemetry, in the viewer, regardless of build …
Browse files Browse the repository at this point in the history
…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, is moving the `KNOWN_VERSIONS` and `KNOWN_GENERATORS` arrays ouf of the `PDFViewerApplication._initializeMetadata`.

*Please note:* Most of this patch consists of whitespace-only changes.
  • Loading branch information
Snuffleupagus committed Jul 8, 2020
1 parent 625f8a6 commit 9e0000f
Showing 1 changed file with 113 additions and 141 deletions.
254 changes: 113 additions & 141 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,51 @@ const ViewOnLoad = {
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 {
constructor() {
throw new Error("Cannot initialize DefaultExternalServices.");
Expand Down Expand Up @@ -870,55 +915,45 @@ const PDFViewerApplication = {
* @private
*/
_delayedFallback(featureId) {
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("MOZCENTRAL || GENERIC")
) {
// Ensure that telemetry is always reported, since it's not guaranteed
// that the fallback bar will be shown (depends on user interaction).
this.externalServices.reportTelemetry({
type: "unsupportedFeature",
featureId,
});
// Ensure that telemetry is always reported, since it's not guaranteed
// that the fallback bar will be shown (depends on user interaction).
this.externalServices.reportTelemetry({
type: "unsupportedFeature",
featureId,
});

if (!this.triggerDelayedFallback) {
this.triggerDelayedFallback = () => {
this.fallback(featureId);
this.triggerDelayedFallback = null;
};
}
if (!this.triggerDelayedFallback) {
this.triggerDelayedFallback = () => {
this.fallback(featureId);
this.triggerDelayedFallback = null;
};
}
},

fallback(featureId) {
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("MOZCENTRAL || GENERIC")
) {
this.externalServices.reportTelemetry({
type: "unsupportedFeature",
featureId,
});
this.externalServices.reportTelemetry({
type: "unsupportedFeature",
featureId,
});

// Only trigger the fallback once so we don't spam the user with messages
// for one PDF.
if (this.fellback) {
return;
}
this.fellback = true;
this.externalServices.fallback(
{
featureId,
url: this.baseUrl,
},
function response(download) {
if (!download) {
return;
}
PDFViewerApplication.download();
}
);
// Only trigger the fallback once so we don't spam the user with messages
// for one PDF.
if (this.fellback) {
return;
}
this.fellback = true;
this.externalServices.fallback(
{
featureId,
url: this.baseUrl,
},
function response(download) {
if (!download) {
return;
}
PDFViewerApplication.download();
}
);
},

/**
Expand Down Expand Up @@ -1319,7 +1354,6 @@ const PDFViewerApplication = {
);

let pdfTitle;

const infoTitle = info && info.Title;
if (infoTitle) {
pdfTitle = infoTitle;
Expand All @@ -1339,7 +1373,6 @@ const PDFViewerApplication = {
pdfTitle = metadataTitle;
}
}

if (pdfTitle) {
this.setTitle(
`${pdfTitle} - ${contentDispositionFilename || document.title}`
Expand All @@ -1353,83 +1386,32 @@ const PDFViewerApplication = {
this._delayedFallback(UNSUPPORTED_FEATURES.forms);
}

if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("MOZCENTRAL || GENERIC")
) {
// Telemetry labels must be C++ variable friendly.
let versionId = "other";
// 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",
];
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,
// Telemetry labels must be C++ variable friendly.
let versionId = "other";
if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
}
let generatorId = "other";
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,
});
},

/**
Expand Down Expand Up @@ -1642,14 +1624,9 @@ const PDFViewerApplication = {

printService.layout();

if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("MOZCENTRAL || GENERIC")
) {
this.externalServices.reportTelemetry({
type: "print",
});
}
this.externalServices.reportTelemetry({
type: "print",
});
},

afterPrint() {
Expand Down Expand Up @@ -2091,22 +2068,17 @@ function webViewerPageRendered(evt) {
});
}

if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("MOZCENTRAL || GENERIC")
) {
PDFViewerApplication.externalServices.reportTelemetry({
type: "pageInfo",
timestamp: evt.timestamp,
});
// It is a good time to report stream and font types.
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
PDFViewerApplication.externalServices.reportTelemetry({
type: "pageInfo",
timestamp: evt.timestamp,
type: "documentStats",
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 }) {
Expand Down

0 comments on commit 9e0000f

Please sign in to comment.