2015-03-12 18:25:32 +03:00
|
|
|
/* 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/. */
|
2014-09-18 00:06:58 +04:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-07-30 06:37:42 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["PluginChild"];
|
|
|
|
|
|
|
|
ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/Timer.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/BrowserUtils.jsm");
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2018-07-30 06:37:42 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "ContextMenuChild",
|
|
|
|
"resource:///actors/ContextMenuChild.jsm");
|
|
|
|
|
2014-09-18 00:06:58 +04:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gNavigatorBundle", function() {
|
|
|
|
const url = "chrome://browser/locale/browser.properties";
|
|
|
|
return Services.strings.createBundle(url);
|
|
|
|
});
|
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "AppConstants",
|
2015-03-12 18:25:32 +03:00
|
|
|
"resource://gre/modules/AppConstants.jsm");
|
|
|
|
|
2017-11-10 19:05:04 +03:00
|
|
|
const OVERLAY_DISPLAY = {
|
|
|
|
HIDDEN: 0, // The overlay will be transparent
|
|
|
|
BLANK: 1, // The overlay will be just a grey box
|
|
|
|
TINY: 2, // The overlay with a 16x16 plugin icon
|
|
|
|
REDUCED: 3, // The overlay with a 32x32 plugin icon
|
|
|
|
NOTEXT: 4, // The overlay with a 48x48 plugin icon and the close button
|
|
|
|
FULL: 5, // The full overlay: 48x48 plugin icon, close button and label
|
|
|
|
};
|
2017-10-31 21:40:04 +03:00
|
|
|
|
2018-07-30 06:37:42 +03:00
|
|
|
class PluginChild extends ActorChild {
|
2018-09-27 00:46:18 +03:00
|
|
|
constructor(dispatcher) {
|
|
|
|
super(dispatcher);
|
2018-07-30 06:37:42 +03:00
|
|
|
|
2014-09-18 00:06:58 +04:00
|
|
|
// Cache of plugin actions for the current page.
|
|
|
|
this.pluginData = new Map();
|
2015-03-28 06:34:15 +03:00
|
|
|
// Cache of plugin crash information sent from the parent
|
|
|
|
this.pluginCrashData = new Map();
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2018-08-16 06:06:49 +03:00
|
|
|
this.mm.addEventListener("pagehide", this, {capture: true, mozSystemGroup: true});
|
|
|
|
this.mm.addEventListener("pageshow", this, {capture: true, mozSystemGroup: true});
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
receiveMessage(msg) {
|
2014-09-18 00:06:58 +04:00
|
|
|
switch (msg.name) {
|
|
|
|
case "BrowserPlugins:ActivatePlugins":
|
|
|
|
this.activatePlugins(msg.data.pluginInfo, msg.data.newState);
|
|
|
|
break;
|
|
|
|
case "BrowserPlugins:ContextMenuCommand":
|
|
|
|
switch (msg.data.command) {
|
|
|
|
case "play":
|
2018-07-30 06:37:42 +03:00
|
|
|
this._showClickToPlayNotification(ContextMenuChild.getTarget(this.mm, msg, "plugin"), true);
|
2014-09-18 00:06:58 +04:00
|
|
|
break;
|
|
|
|
case "hide":
|
2018-07-30 06:37:42 +03:00
|
|
|
this.hideClickToPlayOverlay(ContextMenuChild.getTarget(this.mm, msg, "plugin"));
|
2014-09-18 00:06:58 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2015-03-28 06:34:15 +03:00
|
|
|
case "BrowserPlugins:NPAPIPluginProcessCrashed":
|
|
|
|
this.NPAPIPluginProcessCrashed({
|
|
|
|
pluginName: msg.data.pluginName,
|
|
|
|
runID: msg.data.runID,
|
|
|
|
state: msg.data.state,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "BrowserPlugins:CrashReportSubmitted":
|
|
|
|
this.NPAPIPluginCrashReportSubmitted({
|
|
|
|
runID: msg.data.runID,
|
|
|
|
state: msg.data.state,
|
2017-10-15 21:50:30 +03:00
|
|
|
});
|
2015-03-28 06:34:15 +03:00
|
|
|
break;
|
2015-03-27 23:32:24 +03:00
|
|
|
case "BrowserPlugins:Test:ClearCrashData":
|
|
|
|
// This message should ONLY ever be sent by automated tests.
|
|
|
|
if (Services.prefs.getBoolPref("plugins.testmode")) {
|
|
|
|
this.pluginCrashData.clear();
|
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2018-07-30 06:37:42 +03:00
|
|
|
observe(aSubject, aTopic, aData) {
|
2016-09-09 17:39:58 +03:00
|
|
|
switch (aTopic) {
|
|
|
|
case "decoder-doctor-notification":
|
|
|
|
let data = JSON.parse(aData);
|
2016-11-14 01:57:45 +03:00
|
|
|
let type = data.type.toLowerCase();
|
|
|
|
if (type == "cannot-play" &&
|
|
|
|
this.haveShownNotification &&
|
2016-09-09 17:39:58 +03:00
|
|
|
aSubject.top.document == this.content.document &&
|
|
|
|
data.formats.toLowerCase().includes("application/x-mpegurl", 0)) {
|
2018-07-30 06:37:42 +03:00
|
|
|
this.content.pluginRequiresReload = true;
|
2016-09-09 17:39:58 +03:00
|
|
|
}
|
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2016-09-09 17:39:58 +03:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onPageShow(event) {
|
2014-09-18 00:06:58 +04:00
|
|
|
// Ignore events that aren't from the main document.
|
2014-09-27 01:17:36 +04:00
|
|
|
if (!this.content || event.target != this.content.document) {
|
2014-09-18 00:06:58 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The PluginClickToPlay events are not fired when navigating using the
|
|
|
|
// BF cache. |persisted| is true when the page is loaded from the
|
|
|
|
// BF cache, so this code reshows the notification if necessary.
|
|
|
|
if (event.persisted) {
|
|
|
|
this.reshowClickToPlayNotification();
|
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onPageHide(event) {
|
2014-09-27 01:17:36 +04:00
|
|
|
// Ignore events that aren't from the main document.
|
|
|
|
if (!this.content || event.target != this.content.document) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
this.clearPluginCaches();
|
2016-09-09 17:39:58 +03:00
|
|
|
this.haveShownNotification = false;
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-27 01:17:36 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
getPluginUI(plugin, anonid) {
|
2018-11-22 08:49:54 +03:00
|
|
|
if (plugin.openOrClosedShadowRoot &&
|
|
|
|
plugin.openOrClosedShadowRoot.isUAWidget()) {
|
|
|
|
return plugin.openOrClosedShadowRoot.getElementById(anonid);
|
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
return plugin.ownerDocument.
|
2018-11-22 08:49:54 +03:00
|
|
|
getAnonymousElementByAttribute(plugin, "anonid", anonid);
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_getPluginInfo(pluginElement) {
|
2014-09-18 00:06:58 +04:00
|
|
|
let pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
|
|
|
pluginElement.QueryInterface(Ci.nsIObjectLoadingContent);
|
|
|
|
|
|
|
|
let tagMimetype;
|
|
|
|
let pluginName = gNavigatorBundle.GetStringFromName("pluginInfo.unknownPlugin");
|
|
|
|
let pluginTag = null;
|
|
|
|
let permissionString = null;
|
|
|
|
let fallbackType = null;
|
|
|
|
let blocklistState = null;
|
|
|
|
|
|
|
|
tagMimetype = pluginElement.actualType;
|
|
|
|
if (tagMimetype == "") {
|
|
|
|
tagMimetype = pluginElement.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isKnownPlugin(pluginElement)) {
|
|
|
|
pluginTag = pluginHost.getPluginTagForType(pluginElement.actualType);
|
2014-10-06 19:40:00 +04:00
|
|
|
pluginName = BrowserUtils.makeNicePluginName(pluginTag.name);
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2014-10-29 18:04:51 +03:00
|
|
|
// Convert this from nsIPluginTag so it can be serialized.
|
2015-09-25 00:31:16 +03:00
|
|
|
let properties = ["name", "description", "filename", "version", "enabledState", "niceName"];
|
2014-10-29 18:04:51 +03:00
|
|
|
let pluginTagCopy = {};
|
|
|
|
for (let prop of properties) {
|
|
|
|
pluginTagCopy[prop] = pluginTag[prop];
|
|
|
|
}
|
|
|
|
pluginTag = pluginTagCopy;
|
|
|
|
|
2014-09-18 00:06:58 +04:00
|
|
|
permissionString = pluginHost.getPermissionStringForType(pluginElement.actualType);
|
|
|
|
fallbackType = pluginElement.defaultFallbackType;
|
|
|
|
blocklistState = pluginHost.getBlocklistStateForType(pluginElement.actualType);
|
|
|
|
// Make state-softblocked == state-notblocked for our purposes,
|
|
|
|
// they have the same UI. STATE_OUTDATED should not exist for plugin
|
|
|
|
// items, but let's alias it anyway, just in case.
|
|
|
|
if (blocklistState == Ci.nsIBlocklistService.STATE_SOFTBLOCKED ||
|
|
|
|
blocklistState == Ci.nsIBlocklistService.STATE_OUTDATED) {
|
|
|
|
blocklistState = Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { mimetype: tagMimetype,
|
2016-12-30 02:34:54 +03:00
|
|
|
pluginName,
|
|
|
|
pluginTag,
|
|
|
|
permissionString,
|
|
|
|
fallbackType,
|
|
|
|
blocklistState,
|
2014-09-18 00:06:58 +04:00
|
|
|
};
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-11-14 01:57:45 +03:00
|
|
|
/**
|
|
|
|
* _getPluginInfoForTag is called when iterating the plugins for a document,
|
|
|
|
* and what we get from nsIDOMWindowUtils is an nsIPluginTag, and not an
|
|
|
|
* nsIObjectLoadingContent. This only should happen if the plugin is
|
|
|
|
* click-to-play (see bug 1186948).
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
_getPluginInfoForTag(pluginTag, tagMimetype) {
|
2015-08-04 02:24:35 +03:00
|
|
|
let pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
|
|
|
|
|
|
|
let pluginName = gNavigatorBundle.GetStringFromName("pluginInfo.unknownPlugin");
|
|
|
|
let permissionString = null;
|
|
|
|
let blocklistState = null;
|
|
|
|
|
|
|
|
if (pluginTag) {
|
|
|
|
pluginName = BrowserUtils.makeNicePluginName(pluginTag.name);
|
|
|
|
|
|
|
|
permissionString = pluginHost.getPermissionStringForTag(pluginTag);
|
|
|
|
blocklistState = pluginTag.blocklistState;
|
|
|
|
|
|
|
|
// Convert this from nsIPluginTag so it can be serialized.
|
|
|
|
let properties = ["name", "description", "filename", "version", "enabledState", "niceName"];
|
|
|
|
let pluginTagCopy = {};
|
|
|
|
for (let prop of properties) {
|
|
|
|
pluginTagCopy[prop] = pluginTag[prop];
|
|
|
|
}
|
|
|
|
pluginTag = pluginTagCopy;
|
|
|
|
|
|
|
|
// Make state-softblocked == state-notblocked for our purposes,
|
|
|
|
// they have the same UI. STATE_OUTDATED should not exist for plugin
|
|
|
|
// items, but let's alias it anyway, just in case.
|
|
|
|
if (blocklistState == Ci.nsIBlocklistService.STATE_SOFTBLOCKED ||
|
|
|
|
blocklistState == Ci.nsIBlocklistService.STATE_OUTDATED) {
|
|
|
|
blocklistState = Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { mimetype: tagMimetype,
|
2016-12-30 02:34:54 +03:00
|
|
|
pluginName,
|
|
|
|
pluginTag,
|
|
|
|
permissionString,
|
2016-11-14 01:57:45 +03:00
|
|
|
// Since we should only have entered _getPluginInfoForTag when
|
|
|
|
// examining a click-to-play plugin, we can safely hard-code
|
|
|
|
// this fallback type, since we don't actually have an
|
|
|
|
// nsIObjectLoadingContent to check.
|
|
|
|
fallbackType: Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY,
|
2016-12-30 02:34:54 +03:00
|
|
|
blocklistState,
|
2015-08-04 02:24:35 +03:00
|
|
|
};
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2015-08-04 02:24:35 +03:00
|
|
|
|
2014-09-18 00:06:58 +04:00
|
|
|
/**
|
|
|
|
* Update the visibility of the plugin overlay.
|
|
|
|
*/
|
2017-10-31 21:40:04 +03:00
|
|
|
setVisibility(plugin, overlay, overlayDisplayState) {
|
2017-11-10 19:05:04 +03:00
|
|
|
overlay.classList.toggle("visible", overlayDisplayState != OVERLAY_DISPLAY.HIDDEN);
|
|
|
|
if (overlayDisplayState != OVERLAY_DISPLAY.HIDDEN) {
|
2015-07-14 17:47:00 +03:00
|
|
|
overlay.removeAttribute("dismissed");
|
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
|
|
|
/**
|
2017-11-10 19:05:04 +03:00
|
|
|
* Adjust the style in which the overlay will be displayed. It might be adjusted
|
|
|
|
* based on its size, or if there's some other element covering all corners of
|
|
|
|
* the overlay.
|
|
|
|
*
|
|
|
|
* This function will handle adjusting the style of the overlay, but will
|
|
|
|
* not handle hiding it. That is done by setVisibility with the return value
|
|
|
|
* from this function.
|
2014-09-18 00:06:58 +04:00
|
|
|
*
|
2017-11-10 19:05:04 +03:00
|
|
|
* @returns A value from OVERLAY_DISPLAY.
|
2014-09-18 00:06:58 +04:00
|
|
|
*/
|
2017-11-10 19:05:04 +03:00
|
|
|
computeAndAdjustOverlayDisplay(plugin, overlay) {
|
2017-10-31 21:40:04 +03:00
|
|
|
let fallbackType = plugin.pluginFallbackType;
|
|
|
|
if (plugin.pluginFallbackTypeOverride !== undefined) {
|
|
|
|
fallbackType = plugin.pluginFallbackTypeOverride;
|
|
|
|
}
|
|
|
|
if (fallbackType == Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY_QUIET) {
|
2017-11-10 19:05:04 +03:00
|
|
|
return OVERLAY_DISPLAY.HIDDEN;
|
2017-10-31 21:40:04 +03:00
|
|
|
}
|
|
|
|
|
2014-09-18 00:06:58 +04:00
|
|
|
// If the overlay size is 0, we haven't done layout yet. Presume that
|
|
|
|
// plugins are visible until we know otherwise.
|
|
|
|
if (overlay.scrollWidth == 0) {
|
2017-11-10 19:05:04 +03:00
|
|
|
return OVERLAY_DISPLAY.FULL;
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
|
|
|
|
2017-11-10 19:05:04 +03:00
|
|
|
let overlayDisplay = OVERLAY_DISPLAY.FULL;
|
|
|
|
|
2014-09-18 00:06:58 +04:00
|
|
|
// Is the <object>'s size too small to hold what we want to show?
|
|
|
|
let pluginRect = plugin.getBoundingClientRect();
|
2017-11-10 19:05:04 +03:00
|
|
|
let pluginWidth = Math.ceil(pluginRect.width);
|
|
|
|
let pluginHeight = Math.ceil(pluginRect.height);
|
|
|
|
|
|
|
|
// We must set the attributes while here inside this function in order
|
|
|
|
// for a possible re-style to occur, which will make the scrollWidth/Height
|
|
|
|
// checks below correct. Otherwise, we would be requesting e.g. a TINY
|
|
|
|
// overlay here, but the default styling would be used, and that would make
|
|
|
|
// it overflow, causing it to change to BLANK instead of remaining as TINY.
|
|
|
|
|
|
|
|
if (pluginWidth <= 32 || pluginHeight <= 32) {
|
|
|
|
overlay.setAttribute("sizing", "blank");
|
|
|
|
overlayDisplay = OVERLAY_DISPLAY.BLANK;
|
|
|
|
} else if (pluginWidth <= 80 || pluginHeight <= 60) {
|
|
|
|
overlayDisplay = OVERLAY_DISPLAY.TINY;
|
|
|
|
overlay.setAttribute("sizing", "tiny");
|
|
|
|
overlay.setAttribute("notext", "notext");
|
|
|
|
} else if (pluginWidth <= 120 || pluginHeight <= 80) {
|
|
|
|
overlayDisplay = OVERLAY_DISPLAY.REDUCED;
|
|
|
|
overlay.setAttribute("sizing", "reduced");
|
|
|
|
overlay.setAttribute("notext", "notext");
|
|
|
|
} else if (pluginWidth <= 240 || pluginHeight <= 160) {
|
|
|
|
overlayDisplay = OVERLAY_DISPLAY.NOTEXT;
|
|
|
|
overlay.removeAttribute("sizing");
|
|
|
|
overlay.setAttribute("notext", "notext");
|
|
|
|
} else {
|
|
|
|
overlayDisplay = OVERLAY_DISPLAY.FULL;
|
|
|
|
overlay.removeAttribute("sizing");
|
|
|
|
overlay.removeAttribute("notext");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-18 00:06:58 +04:00
|
|
|
// XXX bug 446693. The text-shadow on the submitted-report text at
|
|
|
|
// the bottom causes scrollHeight to be larger than it should be.
|
2017-11-10 19:05:04 +03:00
|
|
|
let overflows = (overlay.scrollWidth > pluginWidth) ||
|
|
|
|
(overlay.scrollHeight - 5 > pluginHeight);
|
2014-09-18 00:06:58 +04:00
|
|
|
if (overflows) {
|
2017-11-10 19:05:04 +03:00
|
|
|
overlay.setAttribute("sizing", "blank");
|
|
|
|
return OVERLAY_DISPLAY.BLANK;
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Is the plugin covered up by other content so that it is not clickable?
|
|
|
|
// Floating point can confuse .elementFromPoint, so inset just a bit
|
|
|
|
let left = pluginRect.left + 2;
|
|
|
|
let right = pluginRect.right - 2;
|
|
|
|
let top = pluginRect.top + 2;
|
|
|
|
let bottom = pluginRect.bottom - 2;
|
|
|
|
let centerX = left + (right - left) / 2;
|
|
|
|
let centerY = top + (bottom - top) / 2;
|
|
|
|
let points = [[left, top],
|
|
|
|
[left, bottom],
|
|
|
|
[right, top],
|
|
|
|
[right, bottom],
|
|
|
|
[centerX, centerY]];
|
|
|
|
|
2016-07-16 11:20:04 +03:00
|
|
|
let contentWindow = plugin.ownerGlobal;
|
2018-07-25 02:47:41 +03:00
|
|
|
let cwu = contentWindow.windowUtils;
|
2014-09-18 00:06:58 +04:00
|
|
|
|
|
|
|
for (let [x, y] of points) {
|
2017-10-17 17:10:31 +03:00
|
|
|
if (x < 0 || y < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
let el = cwu.elementFromPoint(x, y, true, true);
|
2017-10-17 17:10:31 +03:00
|
|
|
if (el === plugin) {
|
2017-11-10 19:05:04 +03:00
|
|
|
return overlayDisplay;
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-10 19:05:04 +03:00
|
|
|
overlay.setAttribute("sizing", "blank");
|
|
|
|
return OVERLAY_DISPLAY.BLANK;
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
addLinkClickCallback(linkNode, callbackName /* callbackArgs...*/) {
|
2014-09-18 00:06:58 +04:00
|
|
|
// XXX just doing (callback)(arg) was giving a same-origin error. bug?
|
|
|
|
let self = this;
|
|
|
|
let callbackArgs = Array.prototype.slice.call(arguments).slice(2);
|
|
|
|
linkNode.addEventListener("click",
|
|
|
|
function(evt) {
|
|
|
|
if (!evt.isTrusted)
|
|
|
|
return;
|
|
|
|
evt.preventDefault();
|
|
|
|
if (callbackArgs.length == 0)
|
|
|
|
callbackArgs = [ evt ];
|
|
|
|
(self[callbackName]).apply(self, callbackArgs);
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
|
|
|
|
linkNode.addEventListener("keydown",
|
|
|
|
function(evt) {
|
|
|
|
if (!evt.isTrusted)
|
|
|
|
return;
|
|
|
|
if (evt.keyCode == evt.DOM_VK_RETURN) {
|
|
|
|
evt.preventDefault();
|
|
|
|
if (callbackArgs.length == 0)
|
|
|
|
callbackArgs = [ evt ];
|
|
|
|
evt.preventDefault();
|
|
|
|
(self[callbackName]).apply(self, callbackArgs);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true);
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
|
|
|
// Helper to get the binding handler type from a plugin object
|
2016-12-30 02:34:54 +03:00
|
|
|
_getBindingType(plugin) {
|
2014-09-18 00:06:58 +04:00
|
|
|
if (!(plugin instanceof Ci.nsIObjectLoadingContent))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
switch (plugin.pluginFallbackType) {
|
|
|
|
case Ci.nsIObjectLoadingContent.PLUGIN_UNSUPPORTED:
|
|
|
|
return "PluginNotFound";
|
|
|
|
case Ci.nsIObjectLoadingContent.PLUGIN_DISABLED:
|
|
|
|
return "PluginDisabled";
|
|
|
|
case Ci.nsIObjectLoadingContent.PLUGIN_BLOCKLISTED:
|
|
|
|
return "PluginBlocklisted";
|
|
|
|
case Ci.nsIObjectLoadingContent.PLUGIN_OUTDATED:
|
|
|
|
return "PluginOutdated";
|
|
|
|
case Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY:
|
2017-10-31 21:40:04 +03:00
|
|
|
case Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY_QUIET:
|
2014-09-18 00:06:58 +04:00
|
|
|
return "PluginClickToPlay";
|
|
|
|
case Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE:
|
|
|
|
return "PluginVulnerableUpdatable";
|
|
|
|
case Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_NO_UPDATE:
|
|
|
|
return "PluginVulnerableNoUpdate";
|
|
|
|
default:
|
|
|
|
// Not all states map to a handler
|
|
|
|
return null;
|
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
handleEvent(event) {
|
2014-09-18 00:06:58 +04:00
|
|
|
let eventType = event.type;
|
|
|
|
|
2014-09-27 01:17:36 +04:00
|
|
|
if (eventType == "pagehide") {
|
|
|
|
this.onPageHide(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventType == "pageshow") {
|
|
|
|
this.onPageShow(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-18 00:06:58 +04:00
|
|
|
if (eventType == "click") {
|
|
|
|
this.onOverlayClick(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventType == "PluginCrashed" &&
|
|
|
|
!(event.target instanceof Ci.nsIObjectLoadingContent)) {
|
|
|
|
// If the event target is not a plugin object (i.e., an <object> or
|
|
|
|
// <embed> element), this call is for a window-global plugin.
|
2015-03-28 06:34:15 +03:00
|
|
|
this.onPluginCrashed(event.target, event);
|
2014-09-18 00:06:58 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-04 02:24:35 +03:00
|
|
|
if (eventType == "HiddenPlugin") {
|
2018-05-24 13:23:48 +03:00
|
|
|
let pluginTag = event.tag.QueryInterface(Ci.nsIPluginTag);
|
|
|
|
if (event.target.defaultView.top.document != this.content.document) {
|
|
|
|
return;
|
2015-08-04 02:24:35 +03:00
|
|
|
}
|
2018-05-24 13:23:48 +03:00
|
|
|
this._showClickToPlayNotification(pluginTag, false);
|
2015-08-04 02:24:35 +03:00
|
|
|
}
|
|
|
|
|
2014-09-18 00:06:58 +04:00
|
|
|
let plugin = event.target;
|
|
|
|
|
|
|
|
if (!(plugin instanceof Ci.nsIObjectLoadingContent))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (eventType == "PluginBindingAttached") {
|
|
|
|
// The plugin binding fires this event when it is created.
|
|
|
|
// As an untrusted event, ensure that this object actually has a binding
|
|
|
|
// and make sure we don't handle it twice
|
|
|
|
let overlay = this.getPluginUI(plugin, "main");
|
|
|
|
if (!overlay || overlay._bindingHandled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
overlay._bindingHandled = true;
|
|
|
|
|
|
|
|
// Lookup the handler for this binding
|
|
|
|
eventType = this._getBindingType(plugin);
|
|
|
|
if (!eventType) {
|
|
|
|
// Not all bindings have handlers
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let shouldShowNotification = false;
|
|
|
|
switch (eventType) {
|
|
|
|
case "PluginCrashed":
|
2015-03-28 06:34:15 +03:00
|
|
|
this.onPluginCrashed(plugin, event);
|
2014-09-18 00:06:58 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "PluginNotFound": {
|
2014-09-18 21:01:23 +04:00
|
|
|
/* NOP */
|
2014-09-18 00:06:58 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "PluginBlocklisted":
|
|
|
|
case "PluginOutdated":
|
|
|
|
shouldShowNotification = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "PluginVulnerableUpdatable":
|
|
|
|
let updateLink = this.getPluginUI(plugin, "checkForUpdatesLink");
|
2016-07-01 18:01:07 +03:00
|
|
|
let { pluginTag } = this._getPluginInfo(plugin);
|
|
|
|
this.addLinkClickCallback(updateLink, "forwardCallback",
|
|
|
|
"openPluginUpdatePage", pluginTag);
|
2014-09-18 00:06:58 +04:00
|
|
|
/* FALLTHRU */
|
|
|
|
|
|
|
|
case "PluginVulnerableNoUpdate":
|
|
|
|
case "PluginClickToPlay":
|
|
|
|
this._handleClickToPlayEvent(plugin);
|
|
|
|
let pluginName = this._getPluginInfo(plugin).pluginName;
|
2017-11-09 23:27:49 +03:00
|
|
|
let messageString = gNavigatorBundle.formatStringFromName("PluginClickToActivate2", [pluginName], 1);
|
2014-09-18 00:06:58 +04:00
|
|
|
let overlayText = this.getPluginUI(plugin, "clickToPlay");
|
|
|
|
overlayText.textContent = messageString;
|
|
|
|
if (eventType == "PluginVulnerableUpdatable" ||
|
|
|
|
eventType == "PluginVulnerableNoUpdate") {
|
|
|
|
let vulnerabilityString = gNavigatorBundle.GetStringFromName(eventType);
|
|
|
|
let vulnerabilityText = this.getPluginUI(plugin, "vulnerabilityStatus");
|
|
|
|
vulnerabilityText.textContent = vulnerabilityString;
|
|
|
|
}
|
|
|
|
shouldShowNotification = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "PluginDisabled":
|
|
|
|
let manageLink = this.getPluginUI(plugin, "managePluginsLink");
|
|
|
|
this.addLinkClickCallback(manageLink, "forwardCallback", "managePlugins");
|
|
|
|
shouldShowNotification = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "PluginInstantiated":
|
|
|
|
shouldShowNotification = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show the in-content UI if it's not too big. The crashed plugin handler already did this.
|
2015-07-14 17:47:00 +03:00
|
|
|
let overlay = this.getPluginUI(plugin, "main");
|
2014-09-18 00:06:58 +04:00
|
|
|
if (eventType != "PluginCrashed") {
|
|
|
|
if (overlay != null) {
|
|
|
|
this.setVisibility(plugin, overlay,
|
2017-11-10 19:05:04 +03:00
|
|
|
this.computeAndAdjustOverlayDisplay(plugin, overlay));
|
2016-11-16 06:58:30 +03:00
|
|
|
let resizeListener = () => {
|
2014-09-18 00:06:58 +04:00
|
|
|
this.setVisibility(plugin, overlay,
|
2017-11-10 19:05:04 +03:00
|
|
|
this.computeAndAdjustOverlayDisplay(plugin, overlay));
|
2014-09-18 00:06:58 +04:00
|
|
|
};
|
|
|
|
plugin.addEventListener("overflow", resizeListener);
|
|
|
|
plugin.addEventListener("underflow", resizeListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let closeIcon = this.getPluginUI(plugin, "closeIcon");
|
|
|
|
if (closeIcon) {
|
2016-11-16 06:58:30 +03:00
|
|
|
closeIcon.addEventListener("click", clickEvent => {
|
|
|
|
if (clickEvent.button == 0 && clickEvent.isTrusted) {
|
2014-09-18 00:06:58 +04:00
|
|
|
this.hideClickToPlayOverlay(plugin);
|
2015-07-14 17:47:00 +03:00
|
|
|
overlay.setAttribute("dismissed", "true");
|
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldShowNotification) {
|
|
|
|
this._showClickToPlayNotification(plugin, false);
|
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
isKnownPlugin(objLoadingContent) {
|
2014-09-18 00:06:58 +04:00
|
|
|
return (objLoadingContent.getContentTypeForMIMEType(objLoadingContent.actualType) ==
|
|
|
|
Ci.nsIObjectLoadingContent.TYPE_PLUGIN);
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
canActivatePlugin(objLoadingContent) {
|
2014-09-18 00:06:58 +04:00
|
|
|
// if this isn't a known plugin, we can't activate it
|
|
|
|
// (this also guards pluginHost.getPermissionStringForType against
|
|
|
|
// unexpected input)
|
|
|
|
if (!this.isKnownPlugin(objLoadingContent))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
let pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
|
|
|
let permissionString = pluginHost.getPermissionStringForType(objLoadingContent.actualType);
|
2016-07-16 11:20:04 +03:00
|
|
|
let principal = objLoadingContent.ownerGlobal.top.document.nodePrincipal;
|
2014-09-18 00:06:58 +04:00
|
|
|
let pluginPermission = Services.perms.testPermissionFromPrincipal(principal, permissionString);
|
|
|
|
|
|
|
|
let isFallbackTypeValid =
|
|
|
|
objLoadingContent.pluginFallbackType >= Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY &&
|
2017-10-31 21:40:04 +03:00
|
|
|
objLoadingContent.pluginFallbackType <= Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY_QUIET;
|
2014-09-18 00:06:58 +04:00
|
|
|
|
|
|
|
return !objLoadingContent.activated &&
|
|
|
|
pluginPermission != Ci.nsIPermissionManager.DENY_ACTION &&
|
|
|
|
isFallbackTypeValid;
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
hideClickToPlayOverlay(plugin) {
|
2014-09-18 00:06:58 +04:00
|
|
|
let overlay = this.getPluginUI(plugin, "main");
|
|
|
|
if (overlay) {
|
|
|
|
overlay.classList.remove("visible");
|
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
|
|
|
// Forward a link click callback to the chrome process.
|
2016-12-30 02:34:54 +03:00
|
|
|
forwardCallback(name, pluginTag) {
|
2018-07-30 06:37:42 +03:00
|
|
|
this.mm.sendAsyncMessage("PluginContent:LinkClickCallback",
|
2016-07-01 18:01:07 +03:00
|
|
|
{ name, pluginTag });
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2018-07-30 06:37:42 +03:00
|
|
|
submitReport(plugin) {
|
2015-03-12 18:25:32 +03:00
|
|
|
if (!AppConstants.MOZ_CRASHREPORTER) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-28 06:34:15 +03:00
|
|
|
if (!plugin) {
|
|
|
|
Cu.reportError("Attempted to submit crash report without an associated plugin.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(plugin instanceof Ci.nsIObjectLoadingContent)) {
|
|
|
|
Cu.reportError("Attempted to submit crash report on plugin that does not" +
|
|
|
|
"implement nsIObjectLoadingContent.");
|
|
|
|
return;
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
let runID = plugin.runID;
|
2015-07-17 19:16:00 +03:00
|
|
|
let submitURLOptIn = this.getPluginUI(plugin, "submitURLOptIn").checked;
|
2015-03-28 06:34:15 +03:00
|
|
|
let keyVals = {};
|
|
|
|
let userComment = this.getPluginUI(plugin, "submitComment").value.trim();
|
|
|
|
if (userComment)
|
|
|
|
keyVals.PluginUserComment = userComment;
|
2015-07-17 19:16:00 +03:00
|
|
|
if (submitURLOptIn)
|
2015-03-28 06:34:15 +03:00
|
|
|
keyVals.PluginContentURL = plugin.ownerDocument.URL;
|
|
|
|
|
2018-07-30 06:37:42 +03:00
|
|
|
this.mm.sendAsyncMessage("PluginContent:SubmitReport",
|
2015-03-28 06:34:15 +03:00
|
|
|
{ runID, keyVals, submitURLOptIn });
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
reloadPage() {
|
2018-07-30 06:37:42 +03:00
|
|
|
this.content.location.reload();
|
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
|
|
|
// Event listener for click-to-play plugins.
|
2016-12-30 02:34:54 +03:00
|
|
|
_handleClickToPlayEvent(plugin) {
|
2014-09-18 00:06:58 +04:00
|
|
|
let doc = plugin.ownerDocument;
|
|
|
|
let pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
2018-05-24 13:23:48 +03:00
|
|
|
let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
|
|
|
|
// guard against giving pluginHost.getPermissionStringForType a type
|
|
|
|
// not associated with any known plugin
|
|
|
|
if (!this.isKnownPlugin(objLoadingContent))
|
|
|
|
return;
|
|
|
|
let permissionString = pluginHost.getPermissionStringForType(objLoadingContent.actualType);
|
2014-09-18 00:06:58 +04:00
|
|
|
let principal = doc.defaultView.top.document.nodePrincipal;
|
|
|
|
let pluginPermission = Services.perms.testPermissionFromPrincipal(principal, permissionString);
|
|
|
|
|
|
|
|
let overlay = this.getPluginUI(plugin, "main");
|
|
|
|
|
2017-10-31 21:40:04 +03:00
|
|
|
if (pluginPermission == Ci.nsIPermissionManager.DENY_ACTION ||
|
|
|
|
pluginPermission == Ci.nsIObjectLoadingContent.PLUGIN_PERMISSION_PROMPT_ACTION_QUIET) {
|
2014-09-18 00:06:58 +04:00
|
|
|
if (overlay) {
|
|
|
|
overlay.classList.remove("visible");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (overlay) {
|
|
|
|
overlay.addEventListener("click", this, true);
|
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onOverlayClick(event) {
|
2014-09-18 00:06:58 +04:00
|
|
|
let document = event.target.ownerDocument;
|
|
|
|
let plugin = document.getBindingParent(event.target);
|
2015-07-08 13:45:00 +03:00
|
|
|
let overlay = this.getPluginUI(plugin, "main");
|
2014-09-18 00:06:58 +04:00
|
|
|
// Have to check that the target is not the link to update the plugin
|
2017-09-22 22:55:58 +03:00
|
|
|
if (!(ChromeUtils.getClassName(event.originalTarget) === "HTMLAnchorElement") &&
|
2018-11-22 08:49:54 +03:00
|
|
|
event.originalTarget.getAttribute("anonid") != "closeIcon" &&
|
|
|
|
event.originalTarget.id != "closeIcon" &&
|
2017-01-17 18:48:17 +03:00
|
|
|
!overlay.hasAttribute("dismissed") &&
|
2015-07-08 13:45:00 +03:00
|
|
|
event.button == 0 &&
|
|
|
|
event.isTrusted) {
|
2014-09-18 00:06:58 +04:00
|
|
|
this._showClickToPlayNotification(plugin, true);
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
reshowClickToPlayNotification() {
|
2018-07-30 06:37:42 +03:00
|
|
|
let contentWindow = this.content;
|
2018-07-25 02:47:41 +03:00
|
|
|
let cwu = contentWindow.windowUtils;
|
2014-09-18 00:06:58 +04:00
|
|
|
let plugins = cwu.plugins;
|
|
|
|
for (let plugin of plugins) {
|
|
|
|
let overlay = this.getPluginUI(plugin, "main");
|
|
|
|
if (overlay)
|
|
|
|
overlay.removeEventListener("click", this, true);
|
|
|
|
let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
|
|
|
|
if (this.canActivatePlugin(objLoadingContent))
|
|
|
|
this._handleClickToPlayEvent(plugin);
|
|
|
|
}
|
|
|
|
this._showClickToPlayNotification(null, false);
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Activate the plugins that the user has specified.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
activatePlugins(pluginInfo, newState) {
|
2018-07-30 06:37:42 +03:00
|
|
|
let contentWindow = this.content;
|
2018-07-25 02:47:41 +03:00
|
|
|
let cwu = contentWindow.windowUtils;
|
2014-09-18 00:06:58 +04:00
|
|
|
let plugins = cwu.plugins;
|
|
|
|
let pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
|
|
|
|
|
|
|
let pluginFound = false;
|
|
|
|
for (let plugin of plugins) {
|
|
|
|
plugin.QueryInterface(Ci.nsIObjectLoadingContent);
|
|
|
|
if (!this.isKnownPlugin(plugin)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pluginInfo.permissionString == pluginHost.getPermissionStringForType(plugin.actualType)) {
|
2015-06-30 14:15:00 +03:00
|
|
|
let overlay = this.getPluginUI(plugin, "main");
|
2018-05-24 13:23:48 +03:00
|
|
|
pluginFound = true;
|
2017-10-31 21:40:04 +03:00
|
|
|
if (newState == "block" || newState == "blockalways" || newState == "continueblocking") {
|
2015-06-30 14:15:00 +03:00
|
|
|
if (overlay) {
|
|
|
|
overlay.addEventListener("click", this, true);
|
|
|
|
}
|
2017-10-31 21:40:04 +03:00
|
|
|
plugin.pluginFallbackTypeOverride = pluginInfo.fallbackType;
|
2014-09-18 00:06:58 +04:00
|
|
|
plugin.reload(true);
|
2016-08-12 18:50:35 +03:00
|
|
|
} else if (this.canActivatePlugin(plugin)) {
|
|
|
|
if (overlay) {
|
|
|
|
overlay.removeEventListener("click", this, true);
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
2016-08-12 18:50:35 +03:00
|
|
|
plugin.playPlugin();
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-24 13:23:48 +03:00
|
|
|
// If there are no instances of the plugin on the page any more or if we've
|
|
|
|
// noted that the content needs to be reloaded due to replacing HLS, what the
|
|
|
|
// user probably needs is for us to allow and then refresh.
|
2017-10-31 21:40:04 +03:00
|
|
|
if (newState != "block" && newState != "blockalways" && newState != "continueblocking" &&
|
2018-05-24 13:23:48 +03:00
|
|
|
(!pluginFound || contentWindow.pluginRequiresReload)) {
|
2014-09-18 00:06:58 +04:00
|
|
|
this.reloadPage();
|
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_showClickToPlayNotification(plugin, showNow) {
|
2014-09-18 00:06:58 +04:00
|
|
|
let plugins = [];
|
|
|
|
|
|
|
|
// If plugin is null, that means the user has navigated back to a page with
|
|
|
|
// plugins, and we need to collect all the plugins.
|
|
|
|
if (plugin === null) {
|
2014-09-28 19:01:29 +04:00
|
|
|
let contentWindow = this.content;
|
2018-07-25 02:47:41 +03:00
|
|
|
let cwu = contentWindow.windowUtils;
|
2014-09-18 00:06:58 +04:00
|
|
|
// cwu.plugins may contain non-plugin <object>s, filter them out
|
2016-11-16 06:58:30 +03:00
|
|
|
plugins = cwu.plugins.filter((p) =>
|
|
|
|
p.getContentTypeForMIMEType(p.actualType) == Ci.nsIObjectLoadingContent.TYPE_PLUGIN);
|
2014-09-18 00:06:58 +04:00
|
|
|
|
|
|
|
if (plugins.length == 0) {
|
|
|
|
this.removeNotification("click-to-play-plugins");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
plugins = [plugin];
|
|
|
|
}
|
|
|
|
|
|
|
|
let pluginData = this.pluginData;
|
|
|
|
|
2014-09-28 19:01:29 +04:00
|
|
|
let principal = this.content.document.nodePrincipal;
|
|
|
|
let location = this.content.document.location.href;
|
2014-09-18 00:06:58 +04:00
|
|
|
|
|
|
|
for (let p of plugins) {
|
2015-08-04 02:24:35 +03:00
|
|
|
let pluginInfo;
|
|
|
|
if (p instanceof Ci.nsIPluginTag) {
|
|
|
|
let mimeType = p.getMimeTypes() > 0 ? p.getMimeTypes()[0] : null;
|
|
|
|
pluginInfo = this._getPluginInfoForTag(p, mimeType);
|
|
|
|
} else {
|
|
|
|
pluginInfo = this._getPluginInfo(p);
|
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
if (pluginInfo.permissionString === null) {
|
|
|
|
Cu.reportError("No permission string for active plugin.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pluginData.has(pluginInfo.permissionString)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let permissionObj = Services.perms.
|
|
|
|
getPermissionObject(principal, pluginInfo.permissionString, false);
|
|
|
|
if (permissionObj) {
|
2015-06-04 17:56:40 +03:00
|
|
|
pluginInfo.pluginPermissionPrePath = permissionObj.principal.originNoSuffix;
|
2014-09-18 00:06:58 +04:00
|
|
|
pluginInfo.pluginPermissionType = permissionObj.expireType;
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2015-06-04 17:56:40 +03:00
|
|
|
pluginInfo.pluginPermissionPrePath = principal.originNoSuffix;
|
2014-09-18 00:06:58 +04:00
|
|
|
pluginInfo.pluginPermissionType = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.pluginData.set(pluginInfo.permissionString, pluginInfo);
|
|
|
|
}
|
|
|
|
|
2016-09-09 17:39:58 +03:00
|
|
|
this.haveShownNotification = true;
|
|
|
|
|
2018-07-30 06:37:42 +03:00
|
|
|
this.mm.sendAsyncMessage("PluginContent:ShowClickToPlayNotification", {
|
2016-11-11 02:12:47 +03:00
|
|
|
plugins: [...this.pluginData.values()],
|
2016-12-30 02:34:54 +03:00
|
|
|
showNow,
|
|
|
|
location,
|
2014-09-18 00:06:58 +04:00
|
|
|
}, null, principal);
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
removeNotification(name) {
|
2018-07-30 06:37:42 +03:00
|
|
|
this.mm.sendAsyncMessage("PluginContent:RemoveNotification", { name });
|
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
clearPluginCaches() {
|
2014-09-18 00:06:58 +04:00
|
|
|
this.pluginData.clear();
|
2015-03-28 06:34:15 +03:00
|
|
|
this.pluginCrashData.clear();
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-13 21:44:39 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
**/
|
2016-12-30 02:34:54 +03:00
|
|
|
isWithinFullScreenElement(fullScreenElement, domElement) {
|
2016-12-13 21:44:39 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 => {
|
2017-01-17 18:48:17 +03:00
|
|
|
if (typeof fullScreenIframe.contentDocument !== "undefined" && fullScreenIframe.contentDocument.mozFullScreenElement) {
|
2016-12-13 21:44:39 +03:00
|
|
|
return getTrueFullScreenElement(fullScreenIframe.contentDocument.mozFullScreenElement);
|
|
|
|
}
|
|
|
|
return fullScreenIframe;
|
2017-10-15 21:50:30 +03:00
|
|
|
};
|
2016-12-13 21:44:39 +03:00
|
|
|
|
|
|
|
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;
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2016-12-13 21:44:39 +03:00
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
/**
|
|
|
|
* The PluginCrashed event handler. Note that the PluginCrashed event is
|
|
|
|
* fired for both NPAPI and Gecko Media plugins. In the latter case, the
|
|
|
|
* target of the event is the document that the GMP is being used in.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
onPluginCrashed(target, aEvent) {
|
2014-10-22 08:41:32 +04:00
|
|
|
if (!(aEvent instanceof this.content.PluginCrashedEvent))
|
2014-09-18 00:06:58 +04:00
|
|
|
return;
|
|
|
|
|
2016-12-13 21:44:39 +03:00
|
|
|
let fullScreenElement = this.content.document.mozFullScreenElement;
|
|
|
|
if (fullScreenElement) {
|
|
|
|
if (this.isWithinFullScreenElement(fullScreenElement, target)) {
|
|
|
|
this.content.document.mozCancelFullScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
if (aEvent.gmpPlugin) {
|
|
|
|
this.GMPCrashed(aEvent);
|
|
|
|
return;
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
if (!(target instanceof Ci.nsIObjectLoadingContent))
|
|
|
|
return;
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
let crashData = this.pluginCrashData.get(target.runID);
|
|
|
|
if (!crashData) {
|
|
|
|
// We haven't received information from the parent yet about
|
|
|
|
// this crash, so we should hold off showing the crash report
|
|
|
|
// UI.
|
|
|
|
return;
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
crashData.instances.delete(target);
|
|
|
|
if (crashData.instances.length == 0) {
|
|
|
|
this.pluginCrashData.delete(target.runID);
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
this.setCrashedNPAPIPluginState({
|
|
|
|
plugin: target,
|
|
|
|
state: crashData.state,
|
|
|
|
message: crashData.message,
|
|
|
|
});
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
NPAPIPluginProcessCrashed({pluginName, runID, state}) {
|
2015-03-28 06:34:15 +03:00
|
|
|
let message =
|
|
|
|
gNavigatorBundle.formatStringFromName("crashedpluginsMessage.title",
|
|
|
|
[pluginName], 1);
|
2015-03-28 06:34:15 +03:00
|
|
|
|
2018-07-30 06:37:42 +03:00
|
|
|
let contentWindow = this.content;
|
2018-07-25 02:47:41 +03:00
|
|
|
let cwu = contentWindow.windowUtils;
|
2015-03-28 06:34:15 +03:00
|
|
|
let plugins = cwu.plugins;
|
|
|
|
|
|
|
|
for (let plugin of plugins) {
|
|
|
|
if (plugin instanceof Ci.nsIObjectLoadingContent &&
|
|
|
|
plugin.runID == runID) {
|
|
|
|
// The parent has told us that the plugin process has died.
|
|
|
|
// It's possible that this content process hasn't yet noticed,
|
|
|
|
// in which case we need to stash this data around until the
|
|
|
|
// PluginCrashed events get sent up.
|
|
|
|
if (plugin.pluginFallbackType == Ci.nsIObjectLoadingContent.PLUGIN_CRASHED) {
|
|
|
|
// This plugin has already been put into the crashed state by the
|
|
|
|
// content process, so we can tweak its crash UI without delay.
|
|
|
|
this.setCrashedNPAPIPluginState({plugin, state, message});
|
|
|
|
} else {
|
|
|
|
// The content process hasn't yet determined that the plugin has crashed.
|
|
|
|
// Stash the data in our map, and throw the plugin into a WeakSet. When
|
|
|
|
// the PluginCrashed event fires on the <object>/<embed>, we'll retrieve
|
|
|
|
// the information we need from the Map and remove the instance from the
|
|
|
|
// WeakSet. Once the WeakSet is empty, we can clear the map.
|
|
|
|
if (!this.pluginCrashData.has(runID)) {
|
|
|
|
this.pluginCrashData.set(runID, {
|
2016-12-30 02:34:54 +03:00
|
|
|
state,
|
|
|
|
message,
|
2015-03-28 06:34:15 +03:00
|
|
|
instances: new WeakSet(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
let crashData = this.pluginCrashData.get(runID);
|
|
|
|
crashData.instances.add(plugin);
|
2015-04-09 14:11:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2015-03-28 06:34:15 +03:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
setCrashedNPAPIPluginState({plugin, state, message}) {
|
2015-03-28 06:34:15 +03:00
|
|
|
// Force a layout flush so the binding is attached.
|
|
|
|
plugin.clientTop;
|
|
|
|
let overlay = this.getPluginUI(plugin, "main");
|
|
|
|
let statusDiv = this.getPluginUI(plugin, "submitStatus");
|
|
|
|
let optInCB = this.getPluginUI(plugin, "submitURLOptIn");
|
2015-03-28 06:34:15 +03:00
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
this.getPluginUI(plugin, "submitButton")
|
|
|
|
.addEventListener("click", (event) => {
|
|
|
|
if (event.button != 0 || !event.isTrusted)
|
|
|
|
return;
|
|
|
|
this.submitReport(plugin);
|
|
|
|
});
|
|
|
|
|
|
|
|
let pref = Services.prefs.getBranch("dom.ipc.plugins.reportCrashURL");
|
|
|
|
optInCB.checked = pref.getBoolPref("");
|
|
|
|
|
|
|
|
statusDiv.setAttribute("status", state);
|
|
|
|
|
|
|
|
let helpIcon = this.getPluginUI(plugin, "helpIcon");
|
|
|
|
this.addLinkClickCallback(helpIcon, "openHelpPage");
|
|
|
|
|
|
|
|
let crashText = this.getPluginUI(plugin, "crashedText");
|
|
|
|
crashText.textContent = message;
|
|
|
|
|
|
|
|
let link = this.getPluginUI(plugin, "reloadLink");
|
|
|
|
this.addLinkClickCallback(link, "reloadPage");
|
|
|
|
|
2017-11-10 19:05:04 +03:00
|
|
|
let overlayDisplayState = this.computeAndAdjustOverlayDisplay(plugin, overlay);
|
2015-03-28 06:34:15 +03:00
|
|
|
|
|
|
|
// Is the <object>'s size too small to hold what we want to show?
|
2017-11-10 19:05:04 +03:00
|
|
|
if (overlayDisplayState != OVERLAY_DISPLAY.FULL) {
|
2015-03-28 06:34:15 +03:00
|
|
|
// First try hiding the crash report submission UI.
|
|
|
|
statusDiv.removeAttribute("status");
|
|
|
|
|
2017-11-10 19:05:04 +03:00
|
|
|
overlayDisplayState = this.computeAndAdjustOverlayDisplay(plugin, overlay);
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
2017-10-31 21:40:04 +03:00
|
|
|
this.setVisibility(plugin, overlay, overlayDisplayState);
|
2015-03-28 06:34:15 +03:00
|
|
|
|
|
|
|
let doc = plugin.ownerDocument;
|
|
|
|
let runID = plugin.runID;
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2017-11-10 19:05:04 +03:00
|
|
|
if (overlayDisplayState == OVERLAY_DISPLAY.FULL) {
|
2014-09-18 00:06:58 +04:00
|
|
|
doc.mozNoPluginCrashedNotification = true;
|
2016-04-01 00:47:34 +03:00
|
|
|
|
|
|
|
// Notify others that the crash reporter UI is now ready.
|
|
|
|
// Currently, this event is only used by tests.
|
2018-07-25 02:47:41 +03:00
|
|
|
let winUtils = this.content.windowUtils;
|
2016-04-01 00:47:34 +03:00
|
|
|
let event = new this.content.CustomEvent("PluginCrashReporterDisplayed", {bubbles: true});
|
|
|
|
winUtils.dispatchEventToChromeOnly(plugin, event);
|
2016-08-12 18:50:35 +03:00
|
|
|
} else if (!doc.mozNoPluginCrashedNotification) {
|
2014-09-18 00:06:58 +04:00
|
|
|
// If another plugin on the page was large enough to show our UI, we don't
|
|
|
|
// want to show a notification bar.
|
2018-07-30 06:37:42 +03:00
|
|
|
this.mm.sendAsyncMessage("PluginContent:ShowPluginCrashedNotification",
|
2016-08-12 18:50:35 +03:00
|
|
|
{ messageString: message, pluginID: runID });
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
NPAPIPluginCrashReportSubmitted({ runID, state }) {
|
2015-03-28 06:34:15 +03:00
|
|
|
this.pluginCrashData.delete(runID);
|
2018-07-30 06:37:42 +03:00
|
|
|
let contentWindow = this.content;
|
2018-07-25 02:47:41 +03:00
|
|
|
let cwu = contentWindow.windowUtils;
|
2015-03-28 06:34:15 +03:00
|
|
|
let plugins = cwu.plugins;
|
2015-04-09 14:11:32 +03:00
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
for (let plugin of plugins) {
|
|
|
|
if (plugin instanceof Ci.nsIObjectLoadingContent &&
|
|
|
|
plugin.runID == runID) {
|
|
|
|
let statusDiv = this.getPluginUI(plugin, "submitStatus");
|
|
|
|
statusDiv.setAttribute("status", state);
|
2014-09-18 00:06:58 +04:00
|
|
|
}
|
2015-03-28 06:34:15 +03:00
|
|
|
}
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
GMPCrashed(aEvent) {
|
2015-03-28 06:34:15 +03:00
|
|
|
let target = aEvent.target;
|
|
|
|
let pluginName = aEvent.pluginName;
|
|
|
|
let gmpPlugin = aEvent.gmpPlugin;
|
2015-04-27 22:10:54 +03:00
|
|
|
let pluginID = aEvent.pluginID;
|
2015-03-28 06:34:15 +03:00
|
|
|
let doc = target.document;
|
2014-09-18 00:06:58 +04:00
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
if (!gmpPlugin || !doc) {
|
|
|
|
// TODO: Throw exception? How did we get here?
|
|
|
|
return;
|
|
|
|
}
|
2015-04-09 14:11:32 +03:00
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
let messageString =
|
|
|
|
gNavigatorBundle.formatStringFromName("crashedpluginsMessage.title",
|
|
|
|
[pluginName], 1);
|
2015-04-09 14:11:32 +03:00
|
|
|
|
2018-07-30 06:37:42 +03:00
|
|
|
this.mm.sendAsyncMessage("PluginContent:ShowPluginCrashedNotification",
|
2015-04-27 22:10:54 +03:00
|
|
|
{ messageString, pluginID });
|
2015-04-09 14:11:32 +03:00
|
|
|
|
2015-03-28 06:34:15 +03:00
|
|
|
// Remove the notification when the page is reloaded.
|
|
|
|
doc.defaultView.top.addEventListener("unload", event => {
|
|
|
|
this.hideNotificationBar("plugin-crashed");
|
2017-01-17 13:50:25 +03:00
|
|
|
});
|
2018-07-30 06:37:42 +03:00
|
|
|
}
|
|
|
|
}
|