asrouter-utils.mjs (2695B)
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 file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 import { MESSAGE_TYPE_HASH as msg } from "../modules/ActorConstants.mjs"; 6 7 export const ASRouterUtils = { 8 addListener(listener) { 9 if (globalThis.ASRouterAddParentListener) { 10 globalThis.ASRouterAddParentListener(listener); 11 } 12 }, 13 removeListener(listener) { 14 if (globalThis.ASRouterRemoveParentListener) { 15 globalThis.ASRouterRemoveParentListener(listener); 16 } 17 }, 18 sendMessage(action) { 19 if (globalThis.ASRouterMessage) { 20 return globalThis.ASRouterMessage(action); 21 } 22 throw new Error(`Unexpected call:\n${JSON.stringify(action, null, 3)}`); 23 }, 24 blockById(id, options) { 25 return ASRouterUtils.sendMessage({ 26 type: msg.BLOCK_MESSAGE_BY_ID, 27 data: { id, ...options }, 28 }); 29 }, 30 modifyMessageJson(content) { 31 return ASRouterUtils.sendMessage({ 32 type: msg.MODIFY_MESSAGE_JSON, 33 data: { content }, 34 }); 35 }, 36 executeAction(button_action) { 37 return ASRouterUtils.sendMessage({ 38 type: msg.USER_ACTION, 39 data: button_action, 40 }); 41 }, 42 unblockById(id) { 43 return ASRouterUtils.sendMessage({ 44 type: msg.UNBLOCK_MESSAGE_BY_ID, 45 data: { id }, 46 }); 47 }, 48 unblockAll() { 49 return ASRouterUtils.sendMessage({ 50 type: msg.UNBLOCK_ALL, 51 }); 52 }, 53 resetGroupImpressions() { 54 return ASRouterUtils.sendMessage({ 55 type: msg.RESET_GROUPS_STATE, 56 }); 57 }, 58 resetMessageImpressions() { 59 return ASRouterUtils.sendMessage({ 60 type: msg.RESET_MESSAGE_STATE, 61 }); 62 }, 63 resetScreenImpressions() { 64 return ASRouterUtils.sendMessage({ 65 type: msg.RESET_SCREEN_IMPRESSIONS, 66 }); 67 }, 68 blockBundle(bundle) { 69 return ASRouterUtils.sendMessage({ 70 type: msg.BLOCK_BUNDLE, 71 data: { bundle }, 72 }); 73 }, 74 unblockBundle(bundle) { 75 return ASRouterUtils.sendMessage({ 76 type: msg.UNBLOCK_BUNDLE, 77 data: { bundle }, 78 }); 79 }, 80 overrideMessage(id) { 81 return ASRouterUtils.sendMessage({ 82 type: msg.OVERRIDE_MESSAGE, 83 data: { id }, 84 }); 85 }, 86 editState(key, value) { 87 return ASRouterUtils.sendMessage({ 88 type: msg.EDIT_STATE, 89 data: { [key]: value }, 90 }); 91 }, 92 openPBWindow(content) { 93 ASRouterUtils.sendMessage({ 94 type: "FORCE_PRIVATE_BROWSING_WINDOW", 95 data: { message: { content } }, 96 }); 97 }, 98 sendTelemetry(ping) { 99 return ASRouterUtils.sendMessage({ 100 type: msg.AS_ROUTER_TELEMETRY_USER_EVENT, 101 data: ping, 102 }); 103 }, 104 getPreviewEndpoint() { 105 return null; 106 }, 107 };