tor-browser

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

ContentDelegateParent.sys.mjs (3223B)


      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 { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
      6 import { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs";
      7 
      8 const { debug, warn } = GeckoViewUtils.initLogging("ContentDelegateParent");
      9 
     10 export class ContentDelegateParent extends GeckoViewActorParent {
     11  didDestroy() {
     12    this._didDestroy = true;
     13  }
     14 
     15  async receiveMessage(aMsg) {
     16    debug`receiveMessage: ${aMsg.name}`;
     17 
     18    switch (aMsg.name) {
     19      case "GeckoView:DOMFullscreenExit": {
     20        if (!this.#hasBeenDestroyed() && !this.#requestOrigin) {
     21          this.#requestOrigin = this;
     22        }
     23        this.window.windowUtils.remoteFrameFullscreenReverted();
     24        return null;
     25      }
     26 
     27      case "GeckoView:DOMFullscreenRequest": {
     28        this.#requestOrigin = this;
     29        this.window.windowUtils.remoteFrameFullscreenChanged(this.browser);
     30        return null;
     31      }
     32 
     33      case "GeckoView:DOMMetaViewportFit": {
     34        return this.eventDispatcher.sendRequest({
     35          viewportfit: aMsg.data,
     36          type: "GeckoView:DOMMetaViewportFit",
     37        });
     38      }
     39 
     40      case "GeckoView:ContextMenu": {
     41        return this.eventDispatcher.sendRequest({
     42          ...aMsg.data,
     43          type: "GeckoView:ContextMenu",
     44        });
     45      }
     46 
     47      case "GeckoView:WebAppManifest": {
     48        return this.eventDispatcher.sendRequest({
     49          manifest: aMsg.data,
     50          type: "GeckoView:WebAppManifest",
     51        });
     52      }
     53 
     54      case "GeckoView:FirstContentfulPaint": {
     55        return this.eventDispatcher.sendRequest({
     56          type: "GeckoView:FirstContentfulPaint",
     57        });
     58      }
     59 
     60      case "GeckoView:PaintStatusReset": {
     61        return this.eventDispatcher.sendRequest({
     62          type: "GeckoView:PaintStatusReset",
     63        });
     64      }
     65    }
     66 
     67    return super.receiveMessage(aMsg);
     68  }
     69 
     70  // This is a copy of browser/actors/DOMFullscreenParent.sys.mjs
     71  get #requestOrigin() {
     72    const chromeBC = this.browsingContext.topChromeWindow?.browsingContext;
     73    const requestOrigin = chromeBC?.fullscreenRequestOrigin;
     74    return requestOrigin && requestOrigin.get();
     75  }
     76 
     77  // This is a copy of browser/actors/DOMFullscreenParent.sys.mjs
     78  set #requestOrigin(aActor) {
     79    const chromeBC = this.browsingContext.topChromeWindow?.browsingContext;
     80    if (!chromeBC) {
     81      debug`not able to get browsingContext for chrome window.`;
     82      return;
     83    }
     84 
     85    if (aActor) {
     86      chromeBC.fullscreenRequestOrigin = Cu.getWeakReference(aActor);
     87      return;
     88    }
     89    delete chromeBC.fullscreenRequestOrigin;
     90  }
     91 
     92  // This is a copy of browser/actors/DOMFullscreenParent.sys.mjs
     93  #hasBeenDestroyed() {
     94    if (this._didDestroy) {
     95      return true;
     96    }
     97 
     98    // The 'didDestroy' callback is not always getting called.
     99    // So we can't rely on it here. Instead, we will try to access
    100    // the browsing context to judge wether the actor has
    101    // been destroyed or not.
    102    try {
    103      return !this.browsingContext;
    104    } catch {
    105      return true;
    106    }
    107  }
    108 }