diff --git a/browser/components/about/AboutRedirector.cpp b/browser/components/about/AboutRedirector.cpp index 2e9251e43fd2..863715ef19f1 100644 --- a/browser/components/about/AboutRedirector.cpp +++ b/browser/components/about/AboutRedirector.cpp @@ -106,13 +106,11 @@ static const RedirEntry kRedirMap[] = { nsIAboutModule::URI_CAN_LOAD_IN_PRIVILEGEDABOUT_PROCESS | nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | nsIAboutModule::ALLOW_SCRIPT}, -#ifdef NIGHTLY_BUILD {"messagepreview", "chrome://browser/content/messagepreview/messagepreview.html", nsIAboutModule::URI_MUST_LOAD_IN_CHILD | nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::HIDE_FROM_ABOUTABOUT}, -#endif {"pocket-saved", "chrome://pocket/content/panels/saved.html", nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | nsIAboutModule::URI_MUST_LOAD_IN_CHILD | nsIAboutModule::ALLOW_SCRIPT | diff --git a/browser/components/messagepreview/actors/AboutMessagePreviewChild.sys.mjs b/browser/components/messagepreview/actors/AboutMessagePreviewChild.sys.mjs index d233f682a101..15c100328b37 100644 --- a/browser/components/messagepreview/actors/AboutMessagePreviewChild.sys.mjs +++ b/browser/components/messagepreview/actors/AboutMessagePreviewChild.sys.mjs @@ -2,6 +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/. */ +import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; + export class AboutMessagePreviewChild extends JSWindowActorChild { handleEvent(event) { console.log(`Received page event ${event.type}`); @@ -12,14 +14,45 @@ export class AboutMessagePreviewChild extends JSWindowActorChild { } exportFunctions() { - const window = this.contentWindow; - - Cu.exportFunction(this.MPShowMessage.bind(this), window, { - defineAs: "MPShowMessage", - }); + 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; + } } diff --git a/browser/components/messagepreview/jar.mn b/browser/components/messagepreview/jar.mn index 5b7ed90cb717..110476d7944c 100644 --- a/browser/components/messagepreview/jar.mn +++ b/browser/components/messagepreview/jar.mn @@ -3,9 +3,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. browser.jar: -#ifdef NIGHTLY_BUILD content/browser/messagepreview/messagepreview.html content/browser/messagepreview/messagepreview.js content/browser/messagepreview/limelight.svg content/browser/messagepreview/messagepreview.css -#endif diff --git a/browser/components/messagepreview/limelight.svg b/browser/components/messagepreview/limelight.svg index 546393c2baa5..938a17b3b238 100644 --- a/browser/components/messagepreview/limelight.svg +++ b/browser/components/messagepreview/limelight.svg @@ -1,4 +1,4 @@ - + diff --git a/browser/components/messagepreview/messagepreview.css b/browser/components/messagepreview/messagepreview.css index 3ad77ffbed2b..f81c2d262324 100644 --- a/browser/components/messagepreview/messagepreview.css +++ b/browser/components/messagepreview/messagepreview.css @@ -10,15 +10,24 @@ html, body { height: 100%; width: 100%; - background: url(chrome://browser/content/messagepreview/limelight.svg) - center/contain no-repeat; - -moz-context-properties: fill; - fill: var(--in-content-icon-color); - filter: opacity(0.1); } -@media (prefers-color-scheme: dark) { - body { - filter: none; - } +body { + background: url(chrome://browser/content/messagepreview/limelight.svg) + center/contain no-repeat; + -moz-context-properties: fill, fill-opacity; + fill: var(--in-content-icon-color); + fill-opacity: 0.2; +} + +.hint-box { + display: flex; + align-items: center; + justify-content: center; +} + +.hint { + max-width: 40em; + font-size: 1.2em; + text-align: center; } diff --git a/browser/components/messagepreview/messagepreview.js b/browser/components/messagepreview/messagepreview.js index 8748e98280e7..48e5fb1ff571 100644 --- a/browser/components/messagepreview/messagepreview.js +++ b/browser/components/messagepreview/messagepreview.js @@ -2,7 +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/. */ -/* global MPShowMessage */ +/* global MPShowMessage, MPIsEnabled, MPShouldShowHint */ "use strict"; @@ -17,8 +17,23 @@ function decodeMessageFromUrl() { return null; } +function showHint() { + document.body.classList.add("hint-box"); + document.body.innerHTML = `
Message preview is not enabled. Enable it in about:config by setting browser.newtabpage.activity-stream.asrouter.devtoolsEnabled to true.
`; +} + const message = decodeMessageFromUrl(); if (message) { - MPShowMessage(message); + // If message preview is enabled, show the message. + if (MPIsEnabled()) { + MPShowMessage(message); + } else if (MPShouldShowHint()) { + // If running in a local build, show a hint about how to enable preview. + if (document.body) { + showHint(); + } else { + document.addEventListener("DOMContentLoaded", showHint, { once: true }); + } + } }