Merge pull request #18448 from Snuffleupagus/AppOptions-more-browser-params

Include additional data when fetching browser preferences in the PDF Viewer (bug 1908401)
This commit is contained in:
Jonas Jenwald 2024-07-18 14:19:50 +02:00 committed by GitHub
commit 5be66580e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 56 deletions

View file

@ -155,7 +155,6 @@ const PDFViewerApplication = {
isViewerEmbedded: window.parent !== window, isViewerEmbedded: window.parent !== window,
url: "", url: "",
baseUrl: "", baseUrl: "",
_allowedGlobalEventsPromise: null,
_downloadUrl: "", _downloadUrl: "",
_eventBusAbortController: null, _eventBusAbortController: null,
_windowAbortController: null, _windowAbortController: null,
@ -175,32 +174,13 @@ const PDFViewerApplication = {
_printAnnotationStoragePromise: null, _printAnnotationStoragePromise: null,
_touchInfo: null, _touchInfo: null,
_isCtrlKeyDown: false, _isCtrlKeyDown: false,
_nimbusDataPromise: null,
_caretBrowsing: null, _caretBrowsing: null,
_isScrolling: false, _isScrolling: false,
// Called once when the document is loaded. // Called once when the document is loaded.
async initialize(appConfig) { async initialize(appConfig) {
let l10nPromise;
// In the (various) extension builds, where the locale is set automatically,
// initialize the `L10n`-instance as soon as possible.
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
l10nPromise = this.externalServices.createL10n();
if (PDFJSDev.test("MOZCENTRAL")) {
this._allowedGlobalEventsPromise =
this.externalServices.getGlobalEventNames();
}
}
this.appConfig = appConfig; this.appConfig = appConfig;
if (
typeof PDFJSDev === "undefined"
? window.isGECKOVIEW
: PDFJSDev.test("GECKOVIEW")
) {
this._nimbusDataPromise = this.externalServices.getNimbusExperimentData();
}
// Ensure that `Preferences`, and indirectly `AppOptions`, have initialized // Ensure that `Preferences`, and indirectly `AppOptions`, have initialized
// before creating e.g. the various viewer components. // before creating e.g. the various viewer components.
try { try {
@ -229,10 +209,7 @@ const PDFViewerApplication = {
// Ensure that the `L10n`-instance has been initialized before creating // Ensure that the `L10n`-instance has been initialized before creating
// e.g. the various viewer components. // e.g. the various viewer components.
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { this.l10n = await this.externalServices.createL10n();
l10nPromise = this.externalServices.createL10n();
}
this.l10n = await l10nPromise;
document.getElementsByTagName("html")[0].dir = this.l10n.getDirection(); document.getElementsByTagName("html")[0].dir = this.l10n.getDirection();
// Connect Fluent, when necessary, and translate what we already have. // Connect Fluent, when necessary, and translate what we already have.
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
@ -394,11 +371,10 @@ const PDFViewerApplication = {
let eventBus; let eventBus;
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
eventBus = AppOptions.eventBus = new FirefoxEventBus( eventBus = AppOptions.eventBus = new FirefoxEventBus(
await this._allowedGlobalEventsPromise, AppOptions.get("allowedGlobalEvents"),
externalServices, externalServices,
AppOptions.get("isInAutomation") AppOptions.get("isInAutomation")
); );
this._allowedGlobalEventsPromise = null;
} else { } else {
eventBus = new EventBus(); eventBus = new EventBus();
} }
@ -564,11 +540,10 @@ const PDFViewerApplication = {
? window.isGECKOVIEW ? window.isGECKOVIEW
: PDFJSDev.test("GECKOVIEW") : PDFJSDev.test("GECKOVIEW")
) { ) {
this.toolbar = new Toolbar( const nimbusData = JSON.parse(
appConfig.toolbar, AppOptions.get("nimbusDataStr") || "null"
eventBus,
await this._nimbusDataPromise
); );
this.toolbar = new Toolbar(appConfig.toolbar, eventBus, nimbusData);
} else { } else {
this.toolbar = new Toolbar( this.toolbar = new Toolbar(
appConfig.toolbar, appConfig.toolbar,

View file

@ -56,6 +56,11 @@ const OptionKind = {
* primitive types and cannot rely on any imported types. * primitive types and cannot rely on any imported types.
*/ */
const defaultOptions = { const defaultOptions = {
allowedGlobalEvents: {
/** @type {Object} */
value: null,
kind: OptionKind.BROWSER,
},
canvasMaxAreaInBytes: { canvasMaxAreaInBytes: {
/** @type {number} */ /** @type {number} */
value: -1, value: -1,
@ -66,6 +71,16 @@ const defaultOptions = {
value: false, value: false,
kind: OptionKind.BROWSER, kind: OptionKind.BROWSER,
}, },
localeProperties: {
/** @type {Object} */
value: null,
kind: OptionKind.BROWSER,
},
nimbusDataStr: {
/** @type {string} */
value: "",
kind: OptionKind.BROWSER,
},
supportsCaretBrowsingMode: { supportsCaretBrowsingMode: {
/** @type {boolean} */ /** @type {boolean} */
value: false, value: false,

View file

@ -45,12 +45,6 @@ class BaseExternalServices {
throw new Error("Not implemented: updateEditorStates"); throw new Error("Not implemented: updateEditorStates");
} }
async getNimbusExperimentData() {}
async getGlobalEventNames() {
return null;
}
dispatchGlobalEvent(_event) {} dispatchGlobalEvent(_event) {}
} }

View file

@ -14,6 +14,7 @@
*/ */
import { isPdfFile, PDFDataRangeTransport } from "pdfjs-lib"; import { isPdfFile, PDFDataRangeTransport } from "pdfjs-lib";
import { AppOptions } from "./app_options.js";
import { BaseExternalServices } from "./external_services.js"; import { BaseExternalServices } from "./external_services.js";
import { BasePreferences } from "./preferences.js"; import { BasePreferences } from "./preferences.js";
import { DEFAULT_SCALE_VALUE } from "./ui_utils.js"; import { DEFAULT_SCALE_VALUE } from "./ui_utils.js";
@ -400,32 +401,14 @@ class ExternalServices extends BaseExternalServices {
} }
async createL10n() { async createL10n() {
const [localeProperties] = await Promise.all([ await document.l10n.ready;
FirefoxCom.requestAsync("getLocaleProperties", null), return new L10n(AppOptions.get("localeProperties"), document.l10n);
document.l10n.ready,
]);
return new L10n(localeProperties, document.l10n);
} }
createScripting() { createScripting() {
return FirefoxScripting; return FirefoxScripting;
} }
async getNimbusExperimentData() {
if (!PDFJSDev.test("GECKOVIEW")) {
return null;
}
const nimbusData = await FirefoxCom.requestAsync(
"getNimbusExperimentData",
null
);
return nimbusData && JSON.parse(nimbusData);
}
async getGlobalEventNames() {
return FirefoxCom.requestAsync("getGlobalEventNames", null);
}
dispatchGlobalEvent(event) { dispatchGlobalEvent(event) {
FirefoxCom.request("dispatchGlobalEvent", event); FirefoxCom.request("dispatchGlobalEvent", event);
} }