tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

BrowserTestUtilsParent.sys.mjs (1142B)


      1 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 export class BrowserTestUtilsParent extends JSWindowActorParent {
      7  receiveMessage(aMessage) {
      8    switch (aMessage.name) {
      9      case "DOMContentLoaded":
     10      case "load": {
     11        // Don't dispatch events that came from stale actors.
     12        let bc = this.browsingContext;
     13        if (
     14          (bc.embedderElement && bc.embedderElement.browsingContext != bc) ||
     15          !(this.manager && this.manager.isCurrentGlobal)
     16        ) {
     17          return;
     18        }
     19 
     20        let event = new CustomEvent(
     21          `BrowserTestUtils:ContentEvent:${aMessage.name}`,
     22          {
     23            detail: {
     24              browsingContext: this.browsingContext,
     25              ...aMessage.data,
     26            },
     27          }
     28        );
     29 
     30        let browser = this.browsingContext.top.embedderElement;
     31        if (browser) {
     32          browser.dispatchEvent(event);
     33        }
     34 
     35        break;
     36      }
     37    }
     38  }
     39 }