blob: 15c100328b372020faf150678d5958953d844ad0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
}
}
|