Skip to content

Commit 668611b

Browse files
committed
Bug 1795090 - Standup about:messagepreview page r=barret
Differential Revision: https://phabricator.services.mozilla.com/D161211
1 parent 651d38f commit 668611b

12 files changed

+211
-0
lines changed

browser/components/BrowserGlue.jsm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,19 @@ let JSWINDOWACTORS = {
249249
remoteTypes: ["privilegedabout"],
250250
},
251251

252+
AboutMessagePreview: {
253+
parent: {
254+
esModuleURI: "resource:///actors/AboutMessagePreviewParent.sys.mjs",
255+
},
256+
child: {
257+
esModuleURI: "resource:///actors/AboutMessagePreviewChild.sys.mjs",
258+
events: {
259+
DOMDocElementInserted: { capture: true },
260+
},
261+
},
262+
matches: ["about:messagepreview", "about:messagepreview?*"],
263+
},
264+
252265
AboutNewTab: {
253266
parent: {
254267
esModuleURI: "resource:///actors/AboutNewTabParent.sys.mjs",

browser/components/about/AboutRedirector.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ 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
110+
{"messagepreview",
111+
"chrome://browser/content/messagepreview/messagepreview.html",
112+
nsIAboutModule::URI_MUST_LOAD_IN_CHILD |
113+
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
114+
nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::HIDE_FROM_ABOUTABOUT},
115+
#endif
109116
{"pocket-saved", "chrome://pocket/content/panels/saved.html",
110117
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
111118
nsIAboutModule::URI_MUST_LOAD_IN_CHILD | nsIAboutModule::ALLOW_SCRIPT |

browser/components/about/components.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pages = [
1313
'logins',
1414
'loginsimportreport',
1515
'firefoxview',
16+
'messagepreview',
1617
'newtab',
1718
'ion',
1819
'pocket-home',
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
export class AboutMessagePreviewChild extends JSWindowActorChild {
6+
handleEvent(event) {
7+
console.log(`Received page event ${event.type}`);
8+
}
9+
10+
actorCreated() {
11+
this.exportFunctions();
12+
}
13+
14+
exportFunctions() {
15+
const window = this.contentWindow;
16+
17+
Cu.exportFunction(this.MPShowMessage.bind(this), window, {
18+
defineAs: "MPShowMessage",
19+
});
20+
}
21+
22+
MPShowMessage(message) {
23+
this.sendAsyncMessage(`MessagePreview:SHOW_MESSAGE`, message);
24+
}
25+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
2+
/* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
7+
import { JsonSchema } from "resource://gre/modules/JsonSchema.sys.mjs";
8+
9+
const lazy = {};
10+
11+
XPCOMUtils.defineLazyModuleGetters(lazy, {
12+
InfoBar: "resource://activity-stream/lib/InfoBar.jsm",
13+
});
14+
15+
export class AboutMessagePreviewParent extends JSWindowActorParent {
16+
showInfoBar(message) {
17+
const browser = this.browsingContext.topChromeWindow.gBrowser
18+
.selectedBrowser;
19+
20+
lazy.InfoBar.showInfoBarMessage(browser, message, () => {});
21+
}
22+
23+
async showMessage(data) {
24+
let message;
25+
try {
26+
message = JSON.parse(data);
27+
} catch (e) {
28+
console.error("Could not parse message", e);
29+
return;
30+
}
31+
32+
const schema = await fetch(
33+
"resource://activity-stream/schemas/MessagingExperiment.schema.json",
34+
{ credentials: "omit" }
35+
).then(rsp => rsp.json());
36+
37+
const result = JsonSchema.validate(message, schema);
38+
if (!result.valid) {
39+
console.error(
40+
`Invalid message: ${JSON.stringify(result.errors, undefined, 2)}`
41+
);
42+
}
43+
44+
switch (message.template) {
45+
case "infobar":
46+
this.showInfoBar(message);
47+
return;
48+
49+
default:
50+
console.error(`Unsupported message template ${message.template}`);
51+
}
52+
}
53+
54+
receiveMessage(message) {
55+
const { name, data } = message;
56+
57+
switch (name) {
58+
case "MessagePreview:SHOW_MESSAGE":
59+
this.showMessage(data);
60+
break;
61+
default:
62+
console.log(`Unexpected event ${name} was not handled.`);
63+
}
64+
}
65+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
browser.jar:
6+
7+
content/browser/messagepreview/messagepreview.html
8+
content/browser/messagepreview/messagepreview.js
9+
content/browser/messagepreview/limelight.svg
10+
content/browser/messagepreview/messagepreview.css
11+
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
html {
6+
position: fixed;
7+
}
8+
9+
html,
10+
body {
11+
height: 100%;
12+
width: 100%;
13+
background: url(chrome://browser/content/messagepreview/limelight.svg)
14+
center/contain no-repeat;
15+
filter: opacity(0.05);
16+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!--
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
-->
6+
<!DOCTYPE html>
7+
8+
<html>
9+
<head>
10+
<meta charset="utf-8" />
11+
<meta
12+
http-equiv="Content-Security-Policy"
13+
content="default-src resource: chrome:; object-src 'none'; img-src data: chrome:;"
14+
>
15+
<title>about:messagepreview</title>
16+
<link
17+
rel="icon"
18+
href="chrome://browser/content/messagepreview/limelight.svg"
19+
>
20+
<link rel="stylesheet" href="chrome://global/skin/in-content/common.css">
21+
<link rel="stylesheet" href="chrome://browser/content/messagepreview/messagepreview.css">
22+
<script src="chrome://browser/content/messagepreview/messagepreview.js"></script>
23+
</head>
24+
25+
<body></body>
26+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
/* global MPShowMessage */
6+
7+
"use strict";
8+
9+
function decodeMessageFromUrl() {
10+
const url = new URL(document.location.href);
11+
12+
if (url.searchParams.has("json")) {
13+
const encodedMessage = url.searchParams.get("json");
14+
15+
return atob(encodedMessage);
16+
}
17+
return null;
18+
}
19+
20+
const message = decodeMessageFromUrl();
21+
22+
if (message) {
23+
MPShowMessage(message);
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2+
# vim: set filetype=python:
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
if CONFIG["NIGHTLY_BUILD"]:
8+
JAR_MANIFESTS += ["jar.mn"]
9+
10+
FINAL_LIBRARY = "browsercomps"
11+
12+
with Files("**"):
13+
BUG_COMPONENT = ("Firefox", "Messaging System")
14+
15+
FINAL_TARGET_FILES.actors += [
16+
"actors/AboutMessagePreviewChild.sys.mjs",
17+
"actors/AboutMessagePreviewParent.sys.mjs",
18+
]

browser/components/moz.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ DIRS += [
3939
"extensions",
4040
"firefoxview",
4141
"ion",
42+
"messagepreview",
4243
"migration",
4344
"newtab",
4445
"originattributes",

0 commit comments

Comments
 (0)