Bug 1823763 - Convert toolkit/components/reader to ES modules. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D173183
This commit is contained in:
Mark Banner 2023-03-23 12:11:43 +00:00
parent 475d4dd995
commit 07446898da
10 changed files with 22 additions and 41 deletions

View file

@ -216,7 +216,7 @@ toolkit/components/reader/Readability-readerable.js
toolkit/components/reader/JSDOMParser.js
# Uses preprocessing
toolkit/components/reader/Readerable.jsm
toolkit/components/reader/Readerable.sys.mjs
# Generated & special files in cld2
toolkit/components/translation/cld2/

View file

@ -35,7 +35,7 @@ const known_scripts = {
"resource:///actors/LinkHandlerChild.sys.mjs",
"resource:///actors/SearchSERPTelemetryChild.sys.mjs",
"resource://gre/actors/ContentMetaChild.sys.mjs",
"resource://gre/modules/Readerable.jsm",
"resource://gre/modules/Readerable.sys.mjs",
// Telemetry
"resource://gre/modules/TelemetryControllerBase.sys.mjs", // bug 1470339

View file

@ -80,7 +80,7 @@ class EventListener extends Handler {
!content.document.body.classList.contains("loaded")
) {
// Don't restore the scroll position of an about:reader page at this
// point; listen for the custom event dispatched from AboutReader.jsm.
// point; listen for the custom event dispatched from AboutReader.sys.mjs.
content.addEventListener("AboutReaderContentReady", this);
return;
}

View file

@ -2,20 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = ["AboutReader"];
const { ReaderMode } = ChromeUtils.import(
"resource://gre/modules/ReaderMode.jsm"
);
const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
@ -59,7 +50,7 @@ const zoomOnMeta =
Services.prefs.getIntPref("mousewheel.with_meta.action", 1) == 3;
const isAppLocaleRTL = Services.locale.isAppLocaleRTL;
var AboutReader = function(
export var AboutReader = function(
actor,
articlePromise,
docContentType = "document",

View file

@ -2,9 +2,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = ["ReaderMode"];
// Constants for telemetry.
const DOWNLOAD_SUCCESS = 0;
@ -31,9 +28,7 @@ const CLASSES_TO_PRESERVE = [
"wp-smiley",
];
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
@ -57,7 +52,7 @@ const gIsFirefoxDesktop =
Services.telemetry.setEventRecordingEnabled("readermode", true);
var ReaderMode = {
export var ReaderMode = {
DEBUG: 0,
// For time spent telemetry

View file

@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/**
* Interface to a dedicated thread handling readability parsing.
*/
@ -12,8 +10,6 @@ const { BasePromiseWorker } = ChromeUtils.import(
"resource://gre/modules/PromiseWorker.jsm"
);
var EXPORTED_SYMBOLS = ["ReaderWorker"];
var ReaderWorker = new BasePromiseWorker(
export var ReaderWorker = new BasePromiseWorker(
"resource://gre/modules/reader/ReaderWorker.js"
);

View file

@ -5,7 +5,7 @@
"use strict";
// This file and Readability-readerable.js are merged together into
// Readerable.jsm.
// Readerable.sys.mjs.
/* exported Readerable */
/* import-globals-from Readability-readerable.js */
@ -14,10 +14,6 @@ const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
function isNodeVisible(node) {
return node.clientHeight > 0 && node.clientWidth > 0;
}
var Readerable = {
get isEnabledForParseOnLoad() {
return this.isEnabled;
@ -43,7 +39,11 @@ var Readerable = {
return false;
}
return isProbablyReaderable(doc, isNodeVisible);
return isProbablyReaderable(doc, this._isNodeVisible);
},
_isNodeVisible(node) {
return node.clientHeight > 0 && node.clientWidth > 0;
},
_blockedHosts: [

View file

@ -2,9 +2,8 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = ["Readerable"];
#include Readability-readerable.js
#include Readerable.js
export { Readerable };

View file

@ -7,19 +7,19 @@
JAR_MANIFESTS += ["jar.mn"]
EXTRA_JS_MODULES += [
"AboutReader.jsm",
"ReaderMode.jsm",
"AboutReader.sys.mjs",
"ReaderMode.sys.mjs",
]
EXTRA_PP_JS_MODULES += [
"Readerable.jsm",
"Readerable.sys.mjs",
]
EXTRA_JS_MODULES.reader = [
"JSDOMParser.js",
"Readability.js",
"ReaderWorker.js",
"ReaderWorker.jsm",
"ReaderWorker.sys.mjs",
]
BROWSER_CHROME_MANIFESTS += ["test/browser.ini"]

View file

@ -703,7 +703,7 @@ body.hcm .color-scheme-buttons {
/* Article content */
/* Note that any class names from the original article that we want to match on
* must be added to CLASSES_TO_PRESERVE in ReaderMode.jsm, so that
* must be added to CLASSES_TO_PRESERVE in ReaderMode.sys.mjs, so that
* Readability.js doesn't strip them out */
.container {