let document = window.document; MozXULElement.insertFTLIfNeeded("browser/unexpectedScript.ftl"); let messageFragment = document.createDocumentFragment(); let message = document.createElement("span"); document.l10n.setAttributes(message, "unexpected-script-load-message", { origin: scriptOrigin, }); messageFragment.appendChild(message); // ---------------------------------------------------------------- let openWindow = action => { let args = { action, scriptName: aScriptName, }; window.gDialogBox.open( "chrome://browser/content/security/unexpectedScriptLoad.xhtml", args ); }; // ---------------------------------------------------------------- let buttons = [ { supportPage: "unexpected-script-load", callback: () => { Glean.unexpectedScriptLoad.moreInfoOpened.record(); }, }, ]; buttons.push({ "l10n-id": "unexpected-script-load-message-button-allow", callback: () => { openWindow("allow"); return true; }, }); buttons.push({ "l10n-id": "unexpected-script-load-message-button-block", callback: () => { openWindow("block"); return true; // Do not close the dialog bar until the user has done so explcitly or taken an action }, }); let notificationBox = window.gNotificationBox; if (!notificationBox.getNotificationWithValue(NOTIFICATION_VALUE)) { await notificationBox.appendNotification( NOTIFICATION_VALUE, { label: messageFragment, priority: notificationBox.PRIORITY_WARNING_HIGH, eventCallback: event => { if (event == "dismissed") { Glean.unexpectedScriptLoad.infobarDismissed.record(); GleanPings.unexpectedScriptLoad.submit(); } }, }, buttons ); } }, // Unregister Callback: // This is needed to remove the notification bar from all the windows // once the user has taken action on one of them, and ensure any open // dialog box is also closed. async window => { window.gNotificationBox .getNotificationWithValue(NOTIFICATION_VALUE) ?.close(); if ( window.gDialogBox?.dialog?._openedURL == "chrome://browser/content/security/unexpectedScriptLoad.xhtml" ) { window.gDialogBox.dialog.close(); } GleanPings.unexpectedScriptLoad.submit(); } ); Glean.unexpectedScriptLoad.infobarShown.record(); this._notificationHasBeenShown = true; }, }; PK