blob: d7c84a87ff91ffd7d6f29c17e4c97032374d73d8 [file] [log] [blame]
Adrià Vilanova Martínezf472d492024-03-05 21:26:53 +01001import {getCurrentColorTheme, kColorThemeMode} from './darkTheme';
2
3const kReportingWidgetThemes = {
4 [kColorThemeMode.Auto]: '0',
5 [kColorThemeMode.Light]: '1',
6 [kColorThemeMode.Dark]: '2',
7};
8
9export default class ReportDialogColorThemeFix {
10 constructor(options) {
11 this.optionsAtPageLoad = options;
12 }
13
14 fixThemeIfReportDialogIframeAndApplicable(iframe) {
15 if (!this.isReportDialogIframe(iframe)) return;
16
17 const currentColorTheme = getCurrentColorTheme(this.optionsAtPageLoad);
18
19 // By default the report dialog is added with the light theme
20 if (currentColorTheme === kColorThemeMode.Light) return;
21
22 console.debug('[reportDialogColorThemeFix] Fixing report dialog iframe');
23 let url = new URL(iframe.src);
24 url.searchParams.set('theme', kReportingWidgetThemes[currentColorTheme]);
25 iframe.src = url.href;
26 }
27
28 isReportDialogIframe(iframe) {
29 return iframe.src?.includes?.('reportingwidget') ?? false;
30 }
31}