gecko-dev/browser/actors/PluginChild.jsm

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

97 lines
3.0 KiB
JavaScript
Raw Normal View History

/* 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/. */
"use strict";
var EXPORTED_SYMBOLS = ["PluginChild"];
// Handle GMP crashes
Bug 1505913 - make plugin click-to-play and crash handling fission-compatible, r=mconley At a high level, this change does the following: - move the pluginchild actor to be a JSWindowActorChild - move the parent handling from browser-plugins into a JSWindowActorParent - move the crash handling from ContentCrashHandlers.jsm to the parent actor, using a `PluginManager` object. It needs to talk to the actors (and vice versa), so this seemed a better fit than spreading actor implementation details to other JSMs. - switch to using plugin IDs to identify plugins cross-process, instead of combinations of names or other properties of the plugin tag. As part of that, ensured plugin IDs are unique between "fake" plugins and the other ones. - drop support for having a notification for more than 1 plugin. We only support Flash, in practice, so there didn't seem to be much point in the added complexity of trying to support more than 1 thing. Some notes: - the previous implementation mixes runIDs (for NPAPI plugin process "runs") and GMP pluginIDs when doing crashreporting. AFAICT there is no guarantee these don't conflict, so I've split them out to avoid issues. There's a pluginCrashID object I pass around instead that has either a runID or pluginID. Happy to rename some more for clarity. - the previous implementation used `pluginInfo` and `plugin` for a bunch of different types of variables. I've tried to be consistent, where: * `pluginElement` is a DOM element for a plugin * `activationInfo` is a JS object used to track click to play state for a plugin * `plugin` is a plugintag as returned by the pluginhost service * `pluginCrashID` is an identifier for a crashed plugin (see previous point). - I'm still using broadcastAsyncMessage to tell the content processes about gmp plugin crashes and plugin crash submission updates, because there's no guarantee the actors are instantiated (for gmp plugins) nor can the parent easily find out which actors to talk to (for either gmp or npapi plugins). Open to suggestions there, too. I think our best bet might be moving that to IPDL-based IPC within the GMP code, but that feels like a separate bug. Differential Revision: https://phabricator.services.mozilla.com/D37665 --HG-- rename : browser/base/content/browser-plugins.js => browser/actors/PluginParent.jsm extra : moz-landing-system : lando
2019-07-23 22:04:40 +00:00
class PluginChild extends JSWindowActorChild {
handleEvent(event) {
Bug 1505913 - make plugin click-to-play and crash handling fission-compatible, r=mconley At a high level, this change does the following: - move the pluginchild actor to be a JSWindowActorChild - move the parent handling from browser-plugins into a JSWindowActorParent - move the crash handling from ContentCrashHandlers.jsm to the parent actor, using a `PluginManager` object. It needs to talk to the actors (and vice versa), so this seemed a better fit than spreading actor implementation details to other JSMs. - switch to using plugin IDs to identify plugins cross-process, instead of combinations of names or other properties of the plugin tag. As part of that, ensured plugin IDs are unique between "fake" plugins and the other ones. - drop support for having a notification for more than 1 plugin. We only support Flash, in practice, so there didn't seem to be much point in the added complexity of trying to support more than 1 thing. Some notes: - the previous implementation mixes runIDs (for NPAPI plugin process "runs") and GMP pluginIDs when doing crashreporting. AFAICT there is no guarantee these don't conflict, so I've split them out to avoid issues. There's a pluginCrashID object I pass around instead that has either a runID or pluginID. Happy to rename some more for clarity. - the previous implementation used `pluginInfo` and `plugin` for a bunch of different types of variables. I've tried to be consistent, where: * `pluginElement` is a DOM element for a plugin * `activationInfo` is a JS object used to track click to play state for a plugin * `plugin` is a plugintag as returned by the pluginhost service * `pluginCrashID` is an identifier for a crashed plugin (see previous point). - I'm still using broadcastAsyncMessage to tell the content processes about gmp plugin crashes and plugin crash submission updates, because there's no guarantee the actors are instantiated (for gmp plugins) nor can the parent easily find out which actors to talk to (for either gmp or npapi plugins). Open to suggestions there, too. I think our best bet might be moving that to IPDL-based IPC within the GMP code, but that feels like a separate bug. Differential Revision: https://phabricator.services.mozilla.com/D37665 --HG-- rename : browser/base/content/browser-plugins.js => browser/actors/PluginParent.jsm extra : moz-landing-system : lando
2019-07-23 22:04:40 +00:00
// Ignore events for other frames.
let eventDoc = event.target.ownerDocument || event.target.document;
if (eventDoc && eventDoc != this.document) {
return;
}
let eventType = event.type;
if (eventType == "PluginCrashed") {
this.onPluginCrashed(event);
}
}
/**
* Determines whether or not the crashed plugin is contained within current
* full screen DOM element.
* @param fullScreenElement (DOM element)
* The DOM element that is currently full screen, or null.
* @param domElement
* The DOM element which contains the crashed plugin, or the crashed plugin
* itself.
* @returns bool
* True if the plugin is a descendant of the full screen DOM element, false otherwise.
**/
isWithinFullScreenElement(fullScreenElement, domElement) {
/**
* Traverses down iframes until it find a non-iframe full screen DOM element.
* @param fullScreenIframe
* Target iframe to begin searching from.
* @returns DOM element
* The full screen DOM element contained within the iframe (could be inner iframe), or the original iframe if no inner DOM element is found.
**/
let getTrueFullScreenElement = fullScreenIframe => {
if (
typeof fullScreenIframe.contentDocument !== "undefined" &&
fullScreenIframe.contentDocument.mozFullScreenElement
) {
return getTrueFullScreenElement(
fullScreenIframe.contentDocument.mozFullScreenElement
);
}
return fullScreenIframe;
};
if (fullScreenElement.tagName === "IFRAME") {
fullScreenElement = getTrueFullScreenElement(fullScreenElement);
}
if (fullScreenElement.contains(domElement)) {
return true;
}
let parentIframe = domElement.ownerGlobal.frameElement;
if (parentIframe) {
return this.isWithinFullScreenElement(fullScreenElement, parentIframe);
}
return false;
}
/**
* The PluginCrashed event handler. The target of the event is the
* document that GMP is being used in.
*/
async onPluginCrashed(aEvent) {
Bug 1505913 - make plugin click-to-play and crash handling fission-compatible, r=mconley At a high level, this change does the following: - move the pluginchild actor to be a JSWindowActorChild - move the parent handling from browser-plugins into a JSWindowActorParent - move the crash handling from ContentCrashHandlers.jsm to the parent actor, using a `PluginManager` object. It needs to talk to the actors (and vice versa), so this seemed a better fit than spreading actor implementation details to other JSMs. - switch to using plugin IDs to identify plugins cross-process, instead of combinations of names or other properties of the plugin tag. As part of that, ensured plugin IDs are unique between "fake" plugins and the other ones. - drop support for having a notification for more than 1 plugin. We only support Flash, in practice, so there didn't seem to be much point in the added complexity of trying to support more than 1 thing. Some notes: - the previous implementation mixes runIDs (for NPAPI plugin process "runs") and GMP pluginIDs when doing crashreporting. AFAICT there is no guarantee these don't conflict, so I've split them out to avoid issues. There's a pluginCrashID object I pass around instead that has either a runID or pluginID. Happy to rename some more for clarity. - the previous implementation used `pluginInfo` and `plugin` for a bunch of different types of variables. I've tried to be consistent, where: * `pluginElement` is a DOM element for a plugin * `activationInfo` is a JS object used to track click to play state for a plugin * `plugin` is a plugintag as returned by the pluginhost service * `pluginCrashID` is an identifier for a crashed plugin (see previous point). - I'm still using broadcastAsyncMessage to tell the content processes about gmp plugin crashes and plugin crash submission updates, because there's no guarantee the actors are instantiated (for gmp plugins) nor can the parent easily find out which actors to talk to (for either gmp or npapi plugins). Open to suggestions there, too. I think our best bet might be moving that to IPDL-based IPC within the GMP code, but that feels like a separate bug. Differential Revision: https://phabricator.services.mozilla.com/D37665 --HG-- rename : browser/base/content/browser-plugins.js => browser/actors/PluginParent.jsm extra : moz-landing-system : lando
2019-07-23 22:04:40 +00:00
if (!(aEvent instanceof this.contentWindow.PluginCrashedEvent)) {
return;
}
let { target, gmpPlugin, pluginID } = aEvent;
Bug 1505913 - make plugin click-to-play and crash handling fission-compatible, r=mconley At a high level, this change does the following: - move the pluginchild actor to be a JSWindowActorChild - move the parent handling from browser-plugins into a JSWindowActorParent - move the crash handling from ContentCrashHandlers.jsm to the parent actor, using a `PluginManager` object. It needs to talk to the actors (and vice versa), so this seemed a better fit than spreading actor implementation details to other JSMs. - switch to using plugin IDs to identify plugins cross-process, instead of combinations of names or other properties of the plugin tag. As part of that, ensured plugin IDs are unique between "fake" plugins and the other ones. - drop support for having a notification for more than 1 plugin. We only support Flash, in practice, so there didn't seem to be much point in the added complexity of trying to support more than 1 thing. Some notes: - the previous implementation mixes runIDs (for NPAPI plugin process "runs") and GMP pluginIDs when doing crashreporting. AFAICT there is no guarantee these don't conflict, so I've split them out to avoid issues. There's a pluginCrashID object I pass around instead that has either a runID or pluginID. Happy to rename some more for clarity. - the previous implementation used `pluginInfo` and `plugin` for a bunch of different types of variables. I've tried to be consistent, where: * `pluginElement` is a DOM element for a plugin * `activationInfo` is a JS object used to track click to play state for a plugin * `plugin` is a plugintag as returned by the pluginhost service * `pluginCrashID` is an identifier for a crashed plugin (see previous point). - I'm still using broadcastAsyncMessage to tell the content processes about gmp plugin crashes and plugin crash submission updates, because there's no guarantee the actors are instantiated (for gmp plugins) nor can the parent easily find out which actors to talk to (for either gmp or npapi plugins). Open to suggestions there, too. I think our best bet might be moving that to IPDL-based IPC within the GMP code, but that feels like a separate bug. Differential Revision: https://phabricator.services.mozilla.com/D37665 --HG-- rename : browser/base/content/browser-plugins.js => browser/actors/PluginParent.jsm extra : moz-landing-system : lando
2019-07-23 22:04:40 +00:00
let fullScreenElement = this.contentWindow.top.document
.mozFullScreenElement;
if (fullScreenElement) {
if (this.isWithinFullScreenElement(fullScreenElement, target)) {
Bug 1505913 - make plugin click-to-play and crash handling fission-compatible, r=mconley At a high level, this change does the following: - move the pluginchild actor to be a JSWindowActorChild - move the parent handling from browser-plugins into a JSWindowActorParent - move the crash handling from ContentCrashHandlers.jsm to the parent actor, using a `PluginManager` object. It needs to talk to the actors (and vice versa), so this seemed a better fit than spreading actor implementation details to other JSMs. - switch to using plugin IDs to identify plugins cross-process, instead of combinations of names or other properties of the plugin tag. As part of that, ensured plugin IDs are unique between "fake" plugins and the other ones. - drop support for having a notification for more than 1 plugin. We only support Flash, in practice, so there didn't seem to be much point in the added complexity of trying to support more than 1 thing. Some notes: - the previous implementation mixes runIDs (for NPAPI plugin process "runs") and GMP pluginIDs when doing crashreporting. AFAICT there is no guarantee these don't conflict, so I've split them out to avoid issues. There's a pluginCrashID object I pass around instead that has either a runID or pluginID. Happy to rename some more for clarity. - the previous implementation used `pluginInfo` and `plugin` for a bunch of different types of variables. I've tried to be consistent, where: * `pluginElement` is a DOM element for a plugin * `activationInfo` is a JS object used to track click to play state for a plugin * `plugin` is a plugintag as returned by the pluginhost service * `pluginCrashID` is an identifier for a crashed plugin (see previous point). - I'm still using broadcastAsyncMessage to tell the content processes about gmp plugin crashes and plugin crash submission updates, because there's no guarantee the actors are instantiated (for gmp plugins) nor can the parent easily find out which actors to talk to (for either gmp or npapi plugins). Open to suggestions there, too. I think our best bet might be moving that to IPDL-based IPC within the GMP code, but that feels like a separate bug. Differential Revision: https://phabricator.services.mozilla.com/D37665 --HG-- rename : browser/base/content/browser-plugins.js => browser/actors/PluginParent.jsm extra : moz-landing-system : lando
2019-07-23 22:04:40 +00:00
this.contentWindow.top.document.mozCancelFullScreen();
}
}
Bug 1505913 - make plugin click-to-play and crash handling fission-compatible, r=mconley At a high level, this change does the following: - move the pluginchild actor to be a JSWindowActorChild - move the parent handling from browser-plugins into a JSWindowActorParent - move the crash handling from ContentCrashHandlers.jsm to the parent actor, using a `PluginManager` object. It needs to talk to the actors (and vice versa), so this seemed a better fit than spreading actor implementation details to other JSMs. - switch to using plugin IDs to identify plugins cross-process, instead of combinations of names or other properties of the plugin tag. As part of that, ensured plugin IDs are unique between "fake" plugins and the other ones. - drop support for having a notification for more than 1 plugin. We only support Flash, in practice, so there didn't seem to be much point in the added complexity of trying to support more than 1 thing. Some notes: - the previous implementation mixes runIDs (for NPAPI plugin process "runs") and GMP pluginIDs when doing crashreporting. AFAICT there is no guarantee these don't conflict, so I've split them out to avoid issues. There's a pluginCrashID object I pass around instead that has either a runID or pluginID. Happy to rename some more for clarity. - the previous implementation used `pluginInfo` and `plugin` for a bunch of different types of variables. I've tried to be consistent, where: * `pluginElement` is a DOM element for a plugin * `activationInfo` is a JS object used to track click to play state for a plugin * `plugin` is a plugintag as returned by the pluginhost service * `pluginCrashID` is an identifier for a crashed plugin (see previous point). - I'm still using broadcastAsyncMessage to tell the content processes about gmp plugin crashes and plugin crash submission updates, because there's no guarantee the actors are instantiated (for gmp plugins) nor can the parent easily find out which actors to talk to (for either gmp or npapi plugins). Open to suggestions there, too. I think our best bet might be moving that to IPDL-based IPC within the GMP code, but that feels like a separate bug. Differential Revision: https://phabricator.services.mozilla.com/D37665 --HG-- rename : browser/base/content/browser-plugins.js => browser/actors/PluginParent.jsm extra : moz-landing-system : lando
2019-07-23 22:04:40 +00:00
if (!gmpPlugin || !target.document) {
// TODO: Throw exception? How did we get here?
return;
}
Bug 1505913 - make plugin click-to-play and crash handling fission-compatible, r=mconley At a high level, this change does the following: - move the pluginchild actor to be a JSWindowActorChild - move the parent handling from browser-plugins into a JSWindowActorParent - move the crash handling from ContentCrashHandlers.jsm to the parent actor, using a `PluginManager` object. It needs to talk to the actors (and vice versa), so this seemed a better fit than spreading actor implementation details to other JSMs. - switch to using plugin IDs to identify plugins cross-process, instead of combinations of names or other properties of the plugin tag. As part of that, ensured plugin IDs are unique between "fake" plugins and the other ones. - drop support for having a notification for more than 1 plugin. We only support Flash, in practice, so there didn't seem to be much point in the added complexity of trying to support more than 1 thing. Some notes: - the previous implementation mixes runIDs (for NPAPI plugin process "runs") and GMP pluginIDs when doing crashreporting. AFAICT there is no guarantee these don't conflict, so I've split them out to avoid issues. There's a pluginCrashID object I pass around instead that has either a runID or pluginID. Happy to rename some more for clarity. - the previous implementation used `pluginInfo` and `plugin` for a bunch of different types of variables. I've tried to be consistent, where: * `pluginElement` is a DOM element for a plugin * `activationInfo` is a JS object used to track click to play state for a plugin * `plugin` is a plugintag as returned by the pluginhost service * `pluginCrashID` is an identifier for a crashed plugin (see previous point). - I'm still using broadcastAsyncMessage to tell the content processes about gmp plugin crashes and plugin crash submission updates, because there's no guarantee the actors are instantiated (for gmp plugins) nor can the parent easily find out which actors to talk to (for either gmp or npapi plugins). Open to suggestions there, too. I think our best bet might be moving that to IPDL-based IPC within the GMP code, but that feels like a separate bug. Differential Revision: https://phabricator.services.mozilla.com/D37665 --HG-- rename : browser/base/content/browser-plugins.js => browser/actors/PluginParent.jsm extra : moz-landing-system : lando
2019-07-23 22:04:40 +00:00
this.sendAsyncMessage("PluginContent:ShowPluginCrashedNotification", {
pluginCrashID: { pluginID },
});
}
}