From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../actors/AboutMessagePreviewChild.sys.mjs | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 browser/components/messagepreview/actors/AboutMessagePreviewChild.sys.mjs (limited to 'browser/components/messagepreview/actors/AboutMessagePreviewChild.sys.mjs') diff --git a/browser/components/messagepreview/actors/AboutMessagePreviewChild.sys.mjs b/browser/components/messagepreview/actors/AboutMessagePreviewChild.sys.mjs new file mode 100644 index 0000000000..15c100328b --- /dev/null +++ b/browser/components/messagepreview/actors/AboutMessagePreviewChild.sys.mjs @@ -0,0 +1,58 @@ +/* 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/. */ + +import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; + +export class AboutMessagePreviewChild extends JSWindowActorChild { + handleEvent(event) { + console.log(`Received page event ${event.type}`); + } + + actorCreated() { + this.exportFunctions(); + } + + exportFunctions() { + if (this.contentWindow) { + for (const name of ["MPShowMessage", "MPIsEnabled", "MPShouldShowHint"]) { + Cu.exportFunction(this[name].bind(this), this.contentWindow, { + defineAs: name, + }); + } + } + } + + /** + * Check if the Message Preview feature is enabled. This reflects the value of + * the pref `browser.newtabpage.activity-stream.asrouter.devtoolsEnabled`. + * + * @returns {boolean} + */ + MPIsEnabled() { + return Services.prefs.getBoolPref( + "browser.newtabpage.activity-stream.asrouter.devtoolsEnabled", + false + ); + } + + /** + * Route a message to the parent process to be displayed with the relevant + * messaging surface. + * + * @param {object} message + */ + MPShowMessage(message) { + this.sendAsyncMessage(`MessagePreview:SHOW_MESSAGE`, message); + } + + /** + * Check if a hint should be shown about how to enable Message Preview. The + * hint is only displayed in local/unofficial builds. + * + * @returns {boolean} + */ + MPShouldShowHint() { + return !this.MPIsEnabled() && !AppConstants.MOZILLA_OFFICIAL; + } +} -- cgit v1.2.3