Skip to content

Commit

Permalink
Load experiment modules with a unique path (#53)
Browse files Browse the repository at this point in the history
* Load experiment modules with a unique path
  • Loading branch information
jobisoft authored Dec 2, 2024
1 parent 5098ba3 commit 949200e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ var { cal } = ChromeUtils.importESModule("resource:///modules/calendar/calUtils.

this.calendar_calendars = class extends ExtensionAPI {
getAPI(context) {
const uuid = context.extension.uuid;
const root = `experiments-calendar-${uuid}`;
const query = context.extension.manifest.version;
const {
unwrapCalendar,
getResolvedCalendarById,
isOwnCalendar,
convertCalendar,
} = ChromeUtils.importESModule("resource://tb-experiments-calendar/experiments/calendar/ext-calendar-utils.sys.mjs");
} = ChromeUtils.importESModule(
`resource://${root}/experiments/calendar/ext-calendar-utils.sys.mjs?${query}`
);

return {
calendar: {
Expand Down
7 changes: 6 additions & 1 deletion calendar/experiments/calendar/parent/ext-calendar-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ var { cal } = ChromeUtils.importESModule("resource:///modules/calendar/calUtils.

this.calendar_items = class extends ExtensionAPI {
getAPI(context) {
const uuid = context.extension.uuid;
const root = `experiments-calendar-${uuid}`;
const query = context.extension.manifest.version;
const {
getResolvedCalendarById,
getCachedCalendar,
Expand All @@ -17,7 +20,9 @@ this.calendar_items = class extends ExtensionAPI {
propsToItem,
convertItem,
convertAlarm,
} = ChromeUtils.importESModule("resource://tb-experiments-calendar/experiments/calendar/ext-calendar-utils.sys.mjs");
} = ChromeUtils.importESModule(
`resource://${root}/experiments/calendar/ext-calendar-utils.sys.mjs?${query}`
);

return {
calendar: {
Expand Down
29 changes: 20 additions & 9 deletions calendar/experiments/calendar/parent/ext-calendar-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,15 +496,21 @@ this.calendar_provider = class extends ExtensionAPI {
if (this.extension.manifest.calendar_provider) {
this.onManifestEntry("calendar_provider");
}

const uuid = this.extension.uuid;
const root = `experiments-calendar-${uuid}`;
const query = this.extension.manifest.version;
Services.io
.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler)
.setSubstitution("tb-experiments-calendar", this.extension.rootURI);
.setSubstitution(root, this.extension.rootURI);

const { setupE10sBrowser, unwrapCalendar } = ChromeUtils.importESModule("resource://tb-experiments-calendar/experiments/calendar/ext-calendar-utils.sys.mjs");
const { setupE10sBrowser, unwrapCalendar } = ChromeUtils.importESModule(
`resource://${root}/experiments/calendar/ext-calendar-utils.sys.mjs?${query}`
);

ChromeUtils.registerWindowActor("CalendarProvider", { child: { esModuleURI: "resource://tb-experiments-calendar/experiments/calendar/child/ext-calendar-provider-actor.sys.mjs" } });
ChromeUtils.registerWindowActor(`CalendarProvider-${uuid}`, { child: { esModuleURI:
`resource://${root}/experiments/calendar/child/ext-calendar-provider-actor.sys.mjs?${query}`
}});

ExtensionSupport.registerWindowListener("ext-calendar-provider-properties-" + this.extension.id, {
chromeURLs: ["chrome://calendar/content/calendar-properties-dialog.xhtml"],
Expand Down Expand Up @@ -606,19 +612,19 @@ this.calendar_provider = class extends ExtensionAPI {
if (isAppShutdown) {
return;
}
const uuid = this.extension.uuid;
const root = `experiments-calendar-${uuid}`;
ExtensionSupport.unregisterWindowListener("ext-calendar-provider-creation-" + this.extension.id);
ExtensionSupport.unregisterWindowListener("ext-calendar-provider-properties-" + this.extension.id);
ChromeUtils.unregisterWindowActor("CalendarProvider");
ChromeUtils.unregisterWindowActor(`CalendarProvider-${uuid}`);

if (this.extension.manifest.calendar_provider) {
ExtCalendarProvider.unregister(this.extension);
}

Cu.unload("resource://tb-experiments-calendar/experiments/calendar/ext-calendar-utils.sys.mjs");
Services.io
.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler)
.setSubstitution("tb-experiments-calendar", null);
.setSubstitution(root, null);
Services.obs.notifyObservers(null, "startupcache-invalidate");
}

Expand Down Expand Up @@ -646,11 +652,16 @@ this.calendar_provider = class extends ExtensionAPI {
}

getAPI(context) {
const uuid = context.extension.uuid;
const root = `experiments-calendar-${uuid}`;
const query = context.extension.manifest.version;
const {
propsToItem,
convertItem,
convertCalendar,
} = ChromeUtils.importESModule("resource://tb-experiments-calendar/experiments/calendar/ext-calendar-utils.sys.mjs");
} = ChromeUtils.importESModule(
`resource://${root}/experiments/calendar/ext-calendar-utils.sys.mjs?${query}`
);

return {
calendar: {
Expand Down
14 changes: 12 additions & 2 deletions calendar/experiments/calendar/parent/ext-calendarItemDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ Cu.importGlobalProperties(["URL"]);

this.calendarItemDetails = class extends ExtensionAPI {
onLoadCalendarItemPanel(window, origLoadCalendarItemPanel, iframeId, url) {
const { setupE10sBrowser } = ChromeUtils.importESModule("resource://tb-experiments-calendar/experiments/calendar/ext-calendar-utils.sys.mjs");
const uuid = this.extension.uuid;
const root = `experiments-calendar-${uuid}`;
const query = this.extension.manifest.version;
const { setupE10sBrowser } = ChromeUtils.importESModule(
`resource://${root}/experiments/calendar/ext-calendar-utils.sys.mjs?${query}`
);

const res = origLoadCalendarItemPanel(iframeId, url);
if (!this.extension.manifest.calendar_item_details) {
Expand Down Expand Up @@ -96,7 +101,12 @@ this.calendarItemDetails = class extends ExtensionAPI {
}

onLoadSummary(window) {
const { setupE10sBrowser } = ChromeUtils.importESModule("resource://tb-experiments-calendar/experiments/calendar/ext-calendar-utils.sys.mjs");
const uuid = this.extension.uuid;
const root = `experiments-calendar-${uuid}`;
const query = this.extension.manifest.version;
const { setupE10sBrowser } = ChromeUtils.importESModule(
`resource://${root}/experiments/calendar/ext-calendar-utils.sys.mjs?${query}`
);

const document = window.document;

Expand Down

0 comments on commit 949200e

Please sign in to comment.