summaryrefslogtreecommitdiffstats
path: root/mobile/android/actors/ContentDelegateParent.sys.mjs
blob: d621c801047af0f00326871dd584fb42f7918520 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
import { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs";

const { debug, warn } = GeckoViewUtils.initLogging("ContentDelegateParent");

export class ContentDelegateParent extends GeckoViewActorParent {
  didDestroy() {
    this._didDestroy = true;
  }

  async receiveMessage(aMsg) {
    debug`receiveMessage: ${aMsg.name}`;

    switch (aMsg.name) {
      case "GeckoView:DOMFullscreenExit": {
        if (!this.#hasBeenDestroyed() && !this.#requestOrigin) {
          this.#requestOrigin = this;
        }
        this.window.windowUtils.remoteFrameFullscreenReverted();
        return null;
      }

      case "GeckoView:DOMFullscreenRequest": {
        this.#requestOrigin = this;
        this.window.windowUtils.remoteFrameFullscreenChanged(this.browser);
        return null;
      }
    }

    return super.receiveMessage(aMsg);
  }

  // This is a copy of browser/actors/DOMFullscreenParent.sys.mjs
  get #requestOrigin() {
    const chromeBC = this.browsingContext.topChromeWindow?.browsingContext;
    const requestOrigin = chromeBC?.fullscreenRequestOrigin;
    return requestOrigin && requestOrigin.get();
  }

  // This is a copy of browser/actors/DOMFullscreenParent.sys.mjs
  set #requestOrigin(aActor) {
    const chromeBC = this.browsingContext.topChromeWindow?.browsingContext;
    if (!chromeBC) {
      debug`not able to get browsingContext for chrome window.`;
      return;
    }

    if (aActor) {
      chromeBC.fullscreenRequestOrigin = Cu.getWeakReference(aActor);
      return;
    }
    delete chromeBC.fullscreenRequestOrigin;
  }

  // This is a copy of browser/actors/DOMFullscreenParent.sys.mjs
  #hasBeenDestroyed() {
    if (this._didDestroy) {
      return true;
    }

    // The 'didDestroy' callback is not always getting called.
    // So we can't rely on it here. Instead, we will try to access
    // the browsing context to judge wether the actor has
    // been destroyed or not.
    try {
      return !this.browsingContext;
    } catch {
      return true;
    }
  }
}