Skip to content

Commit d058b82

Browse files
committed
Bug 1821821 - Enable about:messagepreview in release and beta. r=emcminn,omc-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D173569
1 parent 84a3608 commit d058b82

File tree

6 files changed

+70
-17
lines changed

6 files changed

+70
-17
lines changed

browser/components/about/AboutRedirector.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,11 @@ static const RedirEntry kRedirMap[] = {
106106
nsIAboutModule::URI_CAN_LOAD_IN_PRIVILEGEDABOUT_PROCESS |
107107
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
108108
nsIAboutModule::ALLOW_SCRIPT},
109-
#ifdef NIGHTLY_BUILD
110109
{"messagepreview",
111110
"chrome://browser/content/messagepreview/messagepreview.html",
112111
nsIAboutModule::URI_MUST_LOAD_IN_CHILD |
113112
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
114113
nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::HIDE_FROM_ABOUTABOUT},
115-
#endif
116114
{"pocket-saved", "chrome://pocket/content/panels/saved.html",
117115
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
118116
nsIAboutModule::URI_MUST_LOAD_IN_CHILD | nsIAboutModule::ALLOW_SCRIPT |

browser/components/messagepreview/actors/AboutMessagePreviewChild.sys.mjs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5+
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
6+
57
export class AboutMessagePreviewChild extends JSWindowActorChild {
68
handleEvent(event) {
79
console.log(`Received page event ${event.type}`);
@@ -12,14 +14,45 @@ export class AboutMessagePreviewChild extends JSWindowActorChild {
1214
}
1315

1416
exportFunctions() {
15-
const window = this.contentWindow;
17+
if (this.contentWindow) {
18+
for (const name of ["MPShowMessage", "MPIsEnabled", "MPShouldShowHint"]) {
19+
Cu.exportFunction(this[name].bind(this), this.contentWindow, {
20+
defineAs: name,
21+
});
22+
}
23+
}
24+
}
1625

17-
Cu.exportFunction(this.MPShowMessage.bind(this), window, {
18-
defineAs: "MPShowMessage",
19-
});
26+
/**
27+
* Check if the Message Preview feature is enabled. This reflects the value of
28+
* the pref `browser.newtabpage.activity-stream.asrouter.devtoolsEnabled`.
29+
*
30+
* @returns {boolean}
31+
*/
32+
MPIsEnabled() {
33+
return Services.prefs.getBoolPref(
34+
"browser.newtabpage.activity-stream.asrouter.devtoolsEnabled",
35+
false
36+
);
2037
}
2138

39+
/**
40+
* Route a message to the parent process to be displayed with the relevant
41+
* messaging surface.
42+
*
43+
* @param {object} message
44+
*/
2245
MPShowMessage(message) {
2346
this.sendAsyncMessage(`MessagePreview:SHOW_MESSAGE`, message);
2447
}
48+
49+
/**
50+
* Check if a hint should be shown about how to enable Message Preview. The
51+
* hint is only displayed in local/unofficial builds.
52+
*
53+
* @returns {boolean}
54+
*/
55+
MPShouldShowHint() {
56+
return !this.MPIsEnabled() && !AppConstants.MOZILLA_OFFICIAL;
57+
}
2558
}

browser/components/messagepreview/jar.mn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

55
browser.jar:
6-
#ifdef NIGHTLY_BUILD
76
content/browser/messagepreview/messagepreview.html
87
content/browser/messagepreview/messagepreview.js
98
content/browser/messagepreview/limelight.svg
109
content/browser/messagepreview/messagepreview.css
11-
#endif
Lines changed: 1 addition & 1 deletion
Loading

browser/components/messagepreview/messagepreview.css

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,24 @@ html,
1010
body {
1111
height: 100%;
1212
width: 100%;
13+
}
14+
15+
body {
1316
background: url(chrome://browser/content/messagepreview/limelight.svg)
1417
center/contain no-repeat;
15-
-moz-context-properties: fill;
18+
-moz-context-properties: fill, fill-opacity;
1619
fill: var(--in-content-icon-color);
17-
filter: opacity(0.1);
20+
fill-opacity: 0.2;
21+
}
22+
23+
.hint-box {
24+
display: flex;
25+
align-items: center;
26+
justify-content: center;
1827
}
1928

20-
@media (prefers-color-scheme: dark) {
21-
body {
22-
filter: none;
23-
}
29+
.hint {
30+
max-width: 40em;
31+
font-size: 1.2em;
32+
text-align: center;
2433
}

browser/components/messagepreview/messagepreview.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
/* global MPShowMessage */
5+
/* global MPShowMessage, MPIsEnabled, MPShouldShowHint */
66

77
"use strict";
88

@@ -17,8 +17,23 @@ function decodeMessageFromUrl() {
1717
return null;
1818
}
1919

20+
function showHint() {
21+
document.body.classList.add("hint-box");
22+
document.body.innerHTML = `<div class="hint">Message preview is not enabled. Enable it in about:config by setting <code>browser.newtabpage.activity-stream.asrouter.devtoolsEnabled</code> to true.</div>`;
23+
}
24+
2025
const message = decodeMessageFromUrl();
2126

2227
if (message) {
23-
MPShowMessage(message);
28+
// If message preview is enabled, show the message.
29+
if (MPIsEnabled()) {
30+
MPShowMessage(message);
31+
} else if (MPShouldShowHint()) {
32+
// If running in a local build, show a hint about how to enable preview.
33+
if (document.body) {
34+
showHint();
35+
} else {
36+
document.addEventListener("DOMContentLoaded", showHint, { once: true });
37+
}
38+
}
2439
}

0 commit comments

Comments
 (0)