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/. */
6 export class PluginChild extends JSWindowActorChild {
8 // Ignore events for other frames.
9 let eventDoc = event.target.ownerDocument || event.target.document;
10 if (eventDoc && eventDoc != this.document) {
14 let eventType = event.type;
15 if (eventType == "PluginCrashed") {
16 this.onPluginCrashed(event);
21 * Determines whether or not the crashed plugin is contained within current
22 * full screen DOM element.
23 * @param fullScreenElement (DOM element)
24 * The DOM element that is currently full screen, or null.
26 * The DOM element which contains the crashed plugin, or the crashed plugin
29 * True if the plugin is a descendant of the full screen DOM element, false otherwise.
31 isWithinFullScreenElement(fullScreenElement, domElement) {
33 * Traverses down iframes until it find a non-iframe full screen DOM element.
34 * @param fullScreenIframe
35 * Target iframe to begin searching from.
36 * @returns DOM element
37 * The full screen DOM element contained within the iframe (could be inner iframe), or the original iframe if no inner DOM element is found.
39 let getTrueFullScreenElement = fullScreenIframe => {
41 typeof fullScreenIframe.contentDocument !== "undefined" &&
42 fullScreenIframe.contentDocument.mozFullScreenElement
44 return getTrueFullScreenElement(
45 fullScreenIframe.contentDocument.mozFullScreenElement
48 return fullScreenIframe;
51 if (fullScreenElement.tagName === "IFRAME") {
52 fullScreenElement = getTrueFullScreenElement(fullScreenElement);
55 if (fullScreenElement.contains(domElement)) {
58 let parentIframe = domElement.ownerGlobal.frameElement;
60 return this.isWithinFullScreenElement(fullScreenElement, parentIframe);
66 * The PluginCrashed event handler. The target of the event is the
67 * document that GMP is being used in.
69 async onPluginCrashed(aEvent) {
70 if (!this.contentWindow.PluginCrashedEvent.isInstance(aEvent)) {
74 let { target, gmpPlugin, pluginID } = aEvent;
75 let fullScreenElement =
76 this.contentWindow.top.document.mozFullScreenElement;
77 if (fullScreenElement) {
78 if (this.isWithinFullScreenElement(fullScreenElement, target)) {
79 this.contentWindow.top.document.mozCancelFullScreen();
83 if (!gmpPlugin || !target.document) {
84 // TODO: Throw exception? How did we get here?
88 this.sendAsyncMessage("PluginContent:ShowPluginCrashedNotification", {
89 pluginCrashID: { pluginID },