UITourChild.sys.mjs (1266B)
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 import { UITourUtils } from "moz-src:///browser/components/uitour/UITourUtils.sys.mjs"; 6 7 export class UITourChild extends JSWindowActorChild { 8 handleEvent(event) { 9 if (!UITourUtils.ensureTrustedOrigin(this.manager)) { 10 return; 11 } 12 13 this.sendAsyncMessage("UITour:onPageEvent", { 14 detail: event.detail, 15 type: event.type, 16 pageVisibilityState: this.document.visibilityState, 17 }); 18 } 19 20 receiveMessage(aMessage) { 21 switch (aMessage.name) { 22 case "UITour:SendPageCallback": 23 this.sendPageEvent("Response", aMessage.data); 24 break; 25 case "UITour:SendPageNotification": 26 this.sendPageEvent("Notification", aMessage.data); 27 break; 28 } 29 } 30 31 sendPageEvent(type, detail) { 32 if (!UITourUtils.ensureTrustedOrigin(this.manager)) { 33 return; 34 } 35 36 let win = this.contentWindow; 37 let eventName = "mozUITour" + type; 38 let event = new win.CustomEvent(eventName, { 39 bubbles: true, 40 detail: Cu.cloneInto(detail, win), 41 }); 42 win.document.dispatchEvent(event); 43 } 44 }