Bug 1885489 - Part 5: Add SnapshotIterator::readInt32(). r=iain
[gecko.git] / docshell / test / chrome / DocShellHelpers.sys.mjs
blobf57cdee321745c3cc3dbdeb1201bf47f09a32716
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 export class DocShellHelpersParent extends JSWindowActorParent {
5   static eventListener;
7   // These static variables should be set when registering the actor
8   // (currently doPageNavigation in docshell_helpers.js).
9   static eventsToListenFor;
10   static observers;
12   constructor() {
13     super();
14   }
15   receiveMessage({ name, data }) {
16     if (name == "docshell_helpers:event") {
17       let { event, originalTargetIsHTMLDocument } = data;
19       if (this.constructor.eventsToListenFor.includes(event.type)) {
20         this.constructor.eventListener(event, originalTargetIsHTMLDocument);
21       }
22     } else if (name == "docshell_helpers:observe") {
23       let { topic } = data;
25       this.constructor.observers.get(topic).call();
26     }
27   }
30 export class DocShellHelpersChild extends JSWindowActorChild {
31   constructor() {
32     super();
33   }
34   receiveMessage({ name }) {
35     if (name == "docshell_helpers:preventBFCache") {
36       // Add an RTCPeerConnection to prevent the page from being bfcached.
37       let win = this.contentWindow;
38       win.blockBFCache = new win.RTCPeerConnection();
39     }
40   }
41   handleEvent(event) {
42     if (
43       Document.isInstance(event.originalTarget) &&
44       event.originalTarget.isInitialDocument
45     ) {
46       dump(`TEST: ignoring a ${event.type} event for an initial about:blank\n`);
47       return;
48     }
50     this.sendAsyncMessage("docshell_helpers:event", {
51       event: {
52         type: event.type,
53         persisted: event.persisted,
54         originalTarget: {
55           title: event.originalTarget.title,
56           location: event.originalTarget.location.href,
57           visibilityState: event.originalTarget.visibilityState,
58           hidden: event.originalTarget.hidden,
59         },
60       },
61       originalTargetIsHTMLDocument: HTMLDocument.isInstance(
62         event.originalTarget
63       ),
64     });
65   }
66   observe(subject, topic) {
67     if (Window.isInstance(subject) && subject.document.isInitialDocument) {
68       dump(`TEST: ignoring a topic notification for an initial about:blank\n`);
69       return;
70     }
72     this.sendAsyncMessage("docshell_helpers:observe", { topic });
73   }