Bug 1826265 - Convert lazy load JSM by GeckoViewStartup module to ESM. r=geckoview-reviewers,extension-reviewers,amejiamarmol

Also, GeckoViewStorageController might not use correct principal since
bug 1801338 doesn't consider GeckoView.

So this fix loads correct ESM and use lazy loading.

Differential Revision: https://phabricator.services.mozilla.com/D174557
This commit is contained in:
Makoto Kato 2023-04-11 08:55:43 +00:00
Родитель b1ac56a99e
Коммит dbdf270e6a
19 изменённых файлов: 62 добавлений и 148 удалений

Просмотреть файл

@ -11,14 +11,9 @@
ChromeUtils.defineESModuleGetters(this, {
GeckoViewTabBridge: "resource://gre/modules/GeckoViewTab.sys.mjs",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
mobileWindowTracker: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
});
ChromeUtils.defineModuleGetter(
this,
"mobileWindowTracker",
"resource://gre/modules/GeckoViewWebExtension.jsm"
);
var { EventDispatcher } = ChromeUtils.importESModule(
"resource://gre/modules/Messaging.sys.mjs"
);

Просмотреть файл

@ -6,9 +6,9 @@
"use strict";
XPCOMUtils.defineLazyModuleGetters(this, {
GeckoViewWebExtension: "resource://gre/modules/GeckoViewWebExtension.jsm",
ExtensionActionHelper: "resource://gre/modules/GeckoViewWebExtension.jsm",
ChromeUtils.defineESModuleGetters(this, {
GeckoViewWebExtension: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
ExtensionActionHelper: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
});
const { BrowserActionBase } = ChromeUtils.import(

Просмотреть файл

@ -6,9 +6,7 @@
ChromeUtils.defineESModuleGetters(this, {
DownloadPaths: "resource://gre/modules/DownloadPaths.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(this, {
DownloadTracker: "resource://gre/modules/GeckoViewWebExtension.jsm",
DownloadTracker: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
});
Cu.importGlobalProperties(["PathUtils"]);

Просмотреть файл

@ -6,9 +6,9 @@
"use strict";
XPCOMUtils.defineLazyModuleGetters(this, {
GeckoViewWebExtension: "resource://gre/modules/GeckoViewWebExtension.jsm",
ExtensionActionHelper: "resource://gre/modules/GeckoViewWebExtension.jsm",
ChromeUtils.defineESModuleGetters(this, {
GeckoViewWebExtension: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
ExtensionActionHelper: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
});
const { PageActionBase } = ChromeUtils.import(

Просмотреть файл

@ -9,14 +9,9 @@
ChromeUtils.defineESModuleGetters(this, {
GeckoViewTabBridge: "resource://gre/modules/GeckoViewTab.sys.mjs",
PromiseUtils: "resource://gre/modules/PromiseUtils.sys.mjs",
mobileWindowTracker: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
});
ChromeUtils.defineModuleGetter(
this,
"mobileWindowTracker",
"resource://gre/modules/GeckoViewWebExtension.jsm"
);
const getBrowserWindow = window => {
return window.browsingContext.topChromeWindow;
};

Просмотреть файл

@ -129,11 +129,11 @@ class GeckoViewStartup {
case "content-process-ready-for-script":
case "app-startup": {
GeckoViewUtils.addLazyGetter(this, "GeckoViewConsole", {
module: "resource://gre/modules/GeckoViewConsole.jsm",
module: "resource://gre/modules/GeckoViewConsole.sys.mjs",
});
GeckoViewUtils.addLazyGetter(this, "GeckoViewStorageController", {
module: "resource://gre/modules/GeckoViewStorageController.jsm",
module: "resource://gre/modules/GeckoViewStorageController.sys.mjs",
ged: [
"GeckoView:ClearData",
"GeckoView:ClearSessionContextData",
@ -150,7 +150,7 @@ class GeckoViewStartup {
});
GeckoViewUtils.addLazyGetter(this, "GeckoViewPushController", {
module: "resource://gre/modules/GeckoViewPushController.jsm",
module: "resource://gre/modules/GeckoViewPushController.sys.mjs",
ged: ["GeckoView:PushEvent", "GeckoView:PushSubscriptionChanged"],
});
@ -173,7 +173,7 @@ class GeckoViewStartup {
if (Services.appinfo.sessionHistoryInParent) {
GeckoViewUtils.addLazyGetter(this, "GeckoViewSessionStore", {
module: "resource://gre/modules/GeckoViewSessionStore.jsm",
module: "resource://gre/modules/GeckoViewSessionStore.sys.mjs",
observers: [
"browsing-context-did-set-embedder",
"browsing-context-discarded",
@ -182,7 +182,7 @@ class GeckoViewStartup {
}
GeckoViewUtils.addLazyGetter(this, "GeckoViewWebExtension", {
module: "resource://gre/modules/GeckoViewWebExtension.jsm",
module: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
ged: [
"GeckoView:ActionDelegate:Attached",
"GeckoView:BrowserAction:Click",
@ -211,7 +211,7 @@ class GeckoViewStartup {
});
GeckoViewUtils.addLazyGetter(this, "ChildCrashHandler", {
module: "resource://gre/modules/ChildCrashHandler.jsm",
module: "resource://gre/modules/ChildCrashHandler.sys.mjs",
observers: ["ipc:content-shutdown", "compositor:process-aborted"],
});
@ -224,7 +224,7 @@ class GeckoViewStartup {
case "profile-after-change": {
GeckoViewUtils.addLazyGetter(this, "GeckoViewRemoteDebugger", {
module: "resource://gre/modules/GeckoViewRemoteDebugger.jsm",
module: "resource://gre/modules/GeckoViewRemoteDebugger.sys.mjs",
init: gvrd => gvrd.onInit(),
});
@ -239,7 +239,7 @@ class GeckoViewStartup {
);
GeckoViewUtils.addLazyGetter(this, "DownloadTracker", {
module: "resource://gre/modules/GeckoViewWebExtension.jsm",
module: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
ged: ["GeckoView:WebExtension:DownloadChanged"],
});

Просмотреть файл

@ -101,7 +101,7 @@ public class WebExtension {
private static final String LOGTAG = "WebExtension";
// Keep in sync with GeckoViewWebExtension.jsm
// Keep in sync with GeckoViewWebExtension.sys.mjs
public static class Flags {
/*
* Default flags for this WebExtension.

Просмотреть файл

@ -2,16 +2,8 @@
* 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 = ["ChildCrashHandler"];
const { GeckoViewUtils } = ChromeUtils.importESModule(
"resource://gre/modules/GeckoViewUtils.sys.mjs"
);
const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
const lazy = {};
@ -34,7 +26,7 @@ function getPendingMinidump(id) {
});
}
var ChildCrashHandler = {
export var ChildCrashHandler = {
// The event listener for this is hooked up in GeckoViewStartup.jsm
observe(aSubject, aTopic, aData) {
if (

Просмотреть файл

@ -1,17 +1,12 @@
/* 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 = ["GeckoViewConsole"];
const { GeckoViewUtils } = ChromeUtils.importESModule(
"resource://gre/modules/GeckoViewUtils.sys.mjs"
);
import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
const { debug, warn } = GeckoViewUtils.initLogging("Console");
var GeckoViewConsole = {
export var GeckoViewConsole = {
_isEnabled: false,
get enabled() {

Просмотреть файл

@ -2,16 +2,8 @@
* 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 = ["GeckoViewPushController"];
const { GeckoViewUtils } = ChromeUtils.importESModule(
"resource://gre/modules/GeckoViewUtils.sys.mjs"
);
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
@ -33,7 +25,7 @@ function createScopeAndPrincipal(scopeAndAttrs) {
return [scope, principal];
}
const GeckoViewPushController = {
export const GeckoViewPushController = {
onEvent(aEvent, aData, aCallback) {
debug`onEvent ${aEvent} ${aData}`;

Просмотреть файл

@ -2,16 +2,8 @@
* 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 = ["GeckoViewRemoteDebugger"];
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
const { GeckoViewUtils } = ChromeUtils.importESModule(
"resource://gre/modules/GeckoViewUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
const lazy = {};
@ -34,7 +26,7 @@ XPCOMUtils.defineLazyGetter(lazy, "SocketListener", () => {
const { debug, warn } = GeckoViewUtils.initLogging("RemoteDebugger");
var GeckoViewRemoteDebugger = {
export var GeckoViewRemoteDebugger = {
observe(aSubject, aTopic, aData) {
if (aTopic !== "nsPref:changed") {
return;

Просмотреть файл

@ -2,14 +2,7 @@
* 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 = ["GeckoViewSessionStore"];
const { GeckoViewUtils } = ChromeUtils.importESModule(
"resource://gre/modules/GeckoViewUtils.sys.mjs"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
const lazy = {};
@ -115,7 +108,7 @@ class SHistoryListener {
}
}
var GeckoViewSessionStore = {
export var GeckoViewSessionStore = {
// For each <browser> element, records the SHistoryListener.
_browserSHistoryListener: new WeakMap(),

Просмотреть файл

@ -2,16 +2,16 @@
* 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 = ["GeckoViewStorageController"];
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
E10SUtils: "resource://gre/modules/E10SUtils.sys.mjs",
PrincipalsCollector: "resource://gre/modules/PrincipalsCollector.sys.mjs",
});
XPCOMUtils.defineLazyPreferenceGetter(
lazy,
"serviceMode",
@ -25,15 +25,6 @@ XPCOMUtils.defineLazyPreferenceGetter(
"cookiebanners.service.mode.privateBrowsing",
Ci.nsICookieBannerService.MODE_DISABLED
);
const { GeckoViewUtils } = ChromeUtils.importESModule(
"resource://gre/modules/GeckoViewUtils.sys.mjs"
);
const { PrincipalsCollector } = ChromeUtils.import(
"resource://gre/modules/PrincipalsCollector.jsm"
);
const { E10SUtils } = ChromeUtils.importESModule(
"resource://gre/modules/E10SUtils.sys.mjs"
);
const { debug, warn } = GeckoViewUtils.initLogging(
"GeckoViewStorageController"
@ -112,7 +103,7 @@ function convertFlags(aJavaFlags) {
return flags;
}
const GeckoViewStorageController = {
export const GeckoViewStorageController = {
onEvent(aEvent, aData, aCallback) {
debug`onEvent ${aEvent} ${aData}`;
@ -138,7 +129,7 @@ const GeckoViewStorageController = {
const permissions = rawPerms.map(p => {
return {
uri: Services.io.createExposableURI(p.principal.URI).displaySpec,
principal: E10SUtils.serializePrincipal(p.principal),
principal: lazy.E10SUtils.serializePrincipal(p.principal),
perm: p.type,
value: p.capability,
contextId: p.principal.originAttributes.geckoViewSessionContextId,
@ -163,7 +154,7 @@ const GeckoViewStorageController = {
const permissions = rawPerms.map(p => {
return {
uri: Services.io.createExposableURI(p.principal.URI).displaySpec,
principal: E10SUtils.serializePrincipal(p.principal),
principal: lazy.E10SUtils.serializePrincipal(p.principal),
perm: p.type,
value: p.capability,
contextId: p.principal.originAttributes.geckoViewSessionContextId,
@ -174,7 +165,7 @@ const GeckoViewStorageController = {
break;
}
case "GeckoView:SetPermission": {
const principal = E10SUtils.deserializePrincipal(aData.principal);
const principal = lazy.E10SUtils.deserializePrincipal(aData.principal);
let key = aData.perm;
if (key == "storage-access") {
key = "3rdPartyStorage^" + aData.thirdPartyOrigin;
@ -297,7 +288,7 @@ const GeckoViewStorageController = {
// user interaction, we need to ensure that we only delete those permissions that
// do not have any existing storage.
if (flags & Ci.nsIClearDataService.CLEAR_HISTORY) {
const principalsCollector = new PrincipalsCollector();
const principalsCollector = new lazy.PrincipalsCollector();
const principals = await principalsCollector.getAllPrincipals();
await new Promise(resolve => {
Services.clearData.deleteUserInteractionForClearingHistory(

Просмотреть файл

@ -3,7 +3,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
import { GeckoViewModule } from "resource://gre/modules/GeckoViewModule.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const { ExtensionUtils } = ChromeUtils.import(
"resource://gre/modules/ExtensionUtils.jsm"
@ -15,10 +14,7 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
EventDispatcher: "resource://gre/modules/Messaging.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
mobileWindowTracker: "resource://gre/modules/GeckoViewWebExtension.jsm",
mobileWindowTracker: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
});
class Tab {

Просмотреть файл

@ -89,7 +89,7 @@ export var GeckoViewUtils = {
XPCOMUtils.defineLazyGetter(scope, name, _ => {
let ret = undefined;
if (module) {
ret = ChromeUtils.import(module)[name];
ret = ChromeUtils.importESModule(module)[name];
} else if (service) {
ret = Cc[service].getService(Ci.nsISupports).wrappedJSObject;
} else if (typeof handler === "function") {

Просмотреть файл

@ -2,25 +2,9 @@
* 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 = [
"ExtensionActionHelper",
"GeckoViewConnection",
"GeckoViewWebExtension",
"mobileWindowTracker",
"DownloadTracker",
];
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
const { GeckoViewUtils } = ChromeUtils.importESModule(
"resource://gre/modules/GeckoViewUtils.sys.mjs"
);
const { EventEmitter } = ChromeUtils.importESModule(
"resource://gre/modules/EventEmitter.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
import { EventEmitter } from "resource://gre/modules/EventEmitter.sys.mjs";
const PRIVATE_BROWSING_PERMISSION = {
permissions: ["internal:privateBrowsingAllowed"],
@ -52,9 +36,7 @@ XPCOMUtils.defineLazyServiceGetter(
const { debug, warn } = GeckoViewUtils.initLogging("Console");
const DOWNLOAD_CHANGED_MESSAGE = "GeckoView:WebExtension:DownloadChanged";
var DownloadTracker = new (class extends EventEmitter {
export var DownloadTracker = new (class extends EventEmitter {
constructor() {
super();
@ -99,7 +81,7 @@ var DownloadTracker = new (class extends EventEmitter {
})();
/** Provides common logic between page and browser actions */
class ExtensionActionHelper {
export class ExtensionActionHelper {
constructor({
tabTracker,
windowTracker,
@ -203,7 +185,7 @@ class EmbedderPort {
}
}
class GeckoViewConnection {
export class GeckoViewConnection {
constructor(sender, target, nativeApp, allowContentMessaging) {
this.sender = sender;
this.target = target;
@ -631,7 +613,7 @@ class MobileWindowTracker extends EventEmitter {
}
}
var mobileWindowTracker = new MobileWindowTracker();
export var mobileWindowTracker = new MobileWindowTracker();
async function updatePromptHandler(aInfo) {
const oldPerms = aInfo.existingAddon.userPermissions;
@ -671,7 +653,7 @@ async function updatePromptHandler(aInfo) {
}
}
var GeckoViewWebExtension = {
export var GeckoViewWebExtension = {
observe(aSubject, aTopic, aData) {
debug`observe ${aTopic}`;

Просмотреть файл

@ -7,7 +7,7 @@
EXTRA_JS_MODULES += [
"AndroidLog.jsm",
"BrowserUsageTelemetry.jsm",
"ChildCrashHandler.jsm",
"ChildCrashHandler.sys.mjs",
"DelayedInit.jsm",
"GeckoViewActorChild.sys.mjs",
"GeckoViewActorManager.sys.mjs",
@ -15,7 +15,7 @@ EXTRA_JS_MODULES += [
"GeckoViewAutocomplete.jsm",
"GeckoViewAutofill.jsm",
"GeckoViewChildModule.jsm",
"GeckoViewConsole.jsm",
"GeckoViewConsole.sys.mjs",
"GeckoViewContent.sys.mjs",
"GeckoViewContentBlocking.sys.mjs",
"GeckoViewMediaControl.sys.mjs",
@ -23,17 +23,17 @@ EXTRA_JS_MODULES += [
"GeckoViewNavigation.sys.mjs",
"GeckoViewProcessHangMonitor.sys.mjs",
"GeckoViewProgress.sys.mjs",
"GeckoViewPushController.jsm",
"GeckoViewRemoteDebugger.jsm",
"GeckoViewPushController.sys.mjs",
"GeckoViewRemoteDebugger.sys.mjs",
"GeckoViewSelectionAction.sys.mjs",
"GeckoViewSessionStore.jsm",
"GeckoViewSessionStore.sys.mjs",
"GeckoViewSettings.sys.mjs",
"GeckoViewStorageController.jsm",
"GeckoViewStorageController.sys.mjs",
"GeckoViewTab.sys.mjs",
"GeckoViewTelemetry.jsm",
"GeckoViewTestUtils.jsm",
"GeckoViewUtils.sys.mjs",
"GeckoViewWebExtension.jsm",
"GeckoViewWebExtension.sys.mjs",
"LoadURIDelegate.jsm",
"MediaUtils.jsm",
"Messaging.sys.mjs",

Просмотреть файл

@ -6,19 +6,12 @@
const EXPORTED_SYMBOLS = ["AppUiTestDelegate"];
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
EventDispatcher: "resource://gre/modules/Messaging.sys.mjs",
GeckoViewTabBridge: "resource://gre/modules/GeckoViewTab.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
mobileWindowTracker: "resource://gre/modules/GeckoViewWebExtension.jsm",
mobileWindowTracker: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
});
const TEST_SUPPORT_EXTENSION_ID = "test-runner-support@tests.mozilla.org";

Просмотреть файл

@ -28,6 +28,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
AsyncShutdown: "resource://gre/modules/AsyncShutdown.sys.mjs",
DeferredTask: "resource://gre/modules/DeferredTask.sys.mjs",
DevToolsShim: "chrome://devtools-startup/content/DevToolsShim.sys.mjs",
GeckoViewConnection: "resource://gre/modules/GeckoViewWebExtension.sys.mjs",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
});
@ -36,7 +37,6 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
BroadcastConduit: "resource://gre/modules/ConduitsParent.jsm",
ExtensionData: "resource://gre/modules/Extension.jsm",
ExtensionActivityLog: "resource://gre/modules/ExtensionActivityLog.jsm",
GeckoViewConnection: "resource://gre/modules/GeckoViewWebExtension.jsm",
MessageManagerProxy: "resource://gre/modules/MessageManagerProxy.jsm",
NativeApp: "resource://gre/modules/NativeMessaging.jsm",
PerformanceCounters: "resource://gre/modules/PerformanceCounters.jsm",