summaryrefslogtreecommitdiffstats
path: root/browser/components/asrouter/content-src/asrouter-utils.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
commit086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch)
treea4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /browser/components/asrouter/content-src/asrouter-utils.mjs
parentAdding debian version 124.0.1-1. (diff)
downloadfirefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz
firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/asrouter/content-src/asrouter-utils.mjs')
-rw-r--r--browser/components/asrouter/content-src/asrouter-utils.mjs81
1 files changed, 81 insertions, 0 deletions
diff --git a/browser/components/asrouter/content-src/asrouter-utils.mjs b/browser/components/asrouter/content-src/asrouter-utils.mjs
new file mode 100644
index 0000000000..989d864e71
--- /dev/null
+++ b/browser/components/asrouter/content-src/asrouter-utils.mjs
@@ -0,0 +1,81 @@
+/* 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/. */
+
+// eslint-disable-next-line mozilla/reject-import-system-module-from-non-system
+import { MESSAGE_TYPE_HASH as msg } from "../modules/ActorConstants.sys.mjs";
+// eslint-disable-next-line mozilla/reject-import-system-module-from-non-system
+import { actionCreators as ac } from "../../newtab/common/Actions.sys.mjs";
+
+export const ASRouterUtils = {
+ addListener(listener) {
+ if (globalThis.ASRouterAddParentListener) {
+ globalThis.ASRouterAddParentListener(listener);
+ }
+ },
+ removeListener(listener) {
+ if (globalThis.ASRouterRemoveParentListener) {
+ globalThis.ASRouterRemoveParentListener(listener);
+ }
+ },
+ sendMessage(action) {
+ if (globalThis.ASRouterMessage) {
+ return globalThis.ASRouterMessage(action);
+ }
+ throw new Error(`Unexpected call:\n${JSON.stringify(action, null, 3)}`);
+ },
+ blockById(id, options) {
+ return ASRouterUtils.sendMessage({
+ type: msg.BLOCK_MESSAGE_BY_ID,
+ data: { id, ...options },
+ });
+ },
+ modifyMessageJson(content) {
+ return ASRouterUtils.sendMessage({
+ type: msg.MODIFY_MESSAGE_JSON,
+ data: { content },
+ });
+ },
+ executeAction(button_action) {
+ return ASRouterUtils.sendMessage({
+ type: msg.USER_ACTION,
+ data: button_action,
+ });
+ },
+ unblockById(id) {
+ return ASRouterUtils.sendMessage({
+ type: msg.UNBLOCK_MESSAGE_BY_ID,
+ data: { id },
+ });
+ },
+ blockBundle(bundle) {
+ return ASRouterUtils.sendMessage({
+ type: msg.BLOCK_BUNDLE,
+ data: { bundle },
+ });
+ },
+ unblockBundle(bundle) {
+ return ASRouterUtils.sendMessage({
+ type: msg.UNBLOCK_BUNDLE,
+ data: { bundle },
+ });
+ },
+ overrideMessage(id) {
+ return ASRouterUtils.sendMessage({
+ type: msg.OVERRIDE_MESSAGE,
+ data: { id },
+ });
+ },
+ editState(key, value) {
+ return ASRouterUtils.sendMessage({
+ type: msg.EDIT_STATE,
+ data: { [key]: value },
+ });
+ },
+ sendTelemetry(ping) {
+ return ASRouterUtils.sendMessage(ac.ASRouterUserEvent(ping));
+ },
+ getPreviewEndpoint() {
+ return null;
+ },
+};