AboutTorChild.sys.mjs (1835B)
1 /** 2 * Actor child class for the about:tor page. 3 */ 4 export class AboutTorChild extends JSWindowActorChild { 5 handleEvent(event) { 6 switch (event.type) { 7 case "DOMContentLoaded": 8 this.sendQuery("AboutTor:GetInitialData").then(data => { 9 if (data) { 10 this.#dispatchInitialData(data); 11 } 12 }); 13 break; 14 case "SubmitSearchOnionize": 15 this.sendAsyncMessage("AboutTor:SetSearchOnionize", !!event.detail); 16 break; 17 case "SurveyDismissed": 18 // event.detail is the survey version. 19 this.sendAsyncMessage("AboutTor:SurveyDismissed", event.detail); 20 break; 21 case "L10nMutationsFinished": 22 // Pass on chrome-only event for completed localization to content. 23 this.contentWindow.dispatchEvent( 24 new this.contentWindow.CustomEvent("L10nMutationsFinished") 25 ); 26 break; 27 case "UserDismissedYEC": 28 // YEC banner was closed. Persist this for the rest of this session. 29 // See tor-browser#42188. 30 this.sendAsyncMessage("AboutTor:UserDismissedYEC"); 31 break; 32 } 33 } 34 35 receiveMessage(message) { 36 switch (message.name) { 37 case "AboutTor:DelayedInitialData": 38 this.#dispatchInitialData(message.data); 39 break; 40 case "AboutTor:DismissYEC": { 41 this.contentWindow.dispatchEvent( 42 new this.contentWindow.CustomEvent("DismissYEC") 43 ); 44 break; 45 } 46 } 47 return undefined; 48 } 49 50 /** 51 * Send the initial data to the page. 52 * 53 * @param {object} data - The data to send. 54 */ 55 #dispatchInitialData(data) { 56 const initialDataEvent = new this.contentWindow.CustomEvent("InitialData", { 57 detail: Cu.cloneInto(data, this.contentWindow), 58 }); 59 this.contentWindow.dispatchEvent(initialDataEvent); 60 } 61 }