Bug 1173523 - Part 3: Update PluginContent to use new API for nsIPermission

This commit is contained in:
janekptacijarabaci 2018-04-26 10:38:41 +02:00 • committed by Roy Tam
commit deb1d55084
2 changed files with 12 additions and 28 deletions

View file

@ -470,28 +470,12 @@ var gPluginHandler = {
} }
}, },
// Match the behaviour of nsPermissionManager
_getHostFromPrincipal: function PH_getHostFromPrincipal(principal) {
if (!principal.URI || principal.URI.schemeIs("moz-nullprincipal")) {
return "(null)";
}
try {
if (principal.URI.host)
return principal.URI.host;
} catch (e) {}
return principal.origin;
},
_makeCenterActions: function PH_makeCenterActions(notification) { _makeCenterActions: function PH_makeCenterActions(notification) {
let contentWindow = notification.browser.contentWindow; let contentWindow = notification.browser.contentWindow;
let cwu = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor) let cwu = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils); .getInterface(Ci.nsIDOMWindowUtils);
let principal = contentWindow.document.nodePrincipal; let principal = contentWindow.document.nodePrincipal;
// This matches the behavior of nsPermssionManager, used for display purposes only
let principalHost = this._getHostFromPrincipal(principal);
let centerActions = []; let centerActions = [];
let pluginsFound = new Set(); let pluginsFound = new Set();
@ -517,11 +501,11 @@ var gPluginHandler = {
let permissionObj = Services.perms. let permissionObj = Services.perms.
getPermissionObject(principal, pluginInfo.permissionString, false); getPermissionObject(principal, pluginInfo.permissionString, false);
if (permissionObj) { if (permissionObj) {
pluginInfo.pluginPermissionHost = permissionObj.host; pluginInfo.pluginPermissionPrePath = permissionObj.principal.originNoSuffix;
pluginInfo.pluginPermissionType = permissionObj.expireType; pluginInfo.pluginPermissionType = permissionObj.expireType;
} }
else { else {
pluginInfo.pluginPermissionHost = principalHost; pluginInfo.pluginPermissionPrePath = principal.originNoSuffix;
pluginInfo.pluginPermissionType = undefined; pluginInfo.pluginPermissionType = undefined;
} }

View file

@ -1356,8 +1356,8 @@
return; return;
} }
let host = gPluginHandler._getHostFromPrincipal(this.notification.browser.contentWindow.document.nodePrincipal); let prePath = this.notification.browser.contentWindow.document.nodePrincipal.URI.prePath;
this._setupDescription("pluginActivateMultiple.message", null, host); this._setupDescription("pluginActivateMultiple.message", null, prePath);
var showBox = document.getAnonymousElementByAttribute(this, "anonid", "plugin-notification-showbox"); var showBox = document.getAnonymousElementByAttribute(this, "anonid", "plugin-notification-showbox");
@ -1396,7 +1396,7 @@
<method name="_setupSingleState"> <method name="_setupSingleState">
<body><![CDATA[ <body><![CDATA[
var action = this.notification.options.centerActions[0]; var action = this.notification.options.centerActions[0];
var host = action.pluginPermissionHost; var prePath = action.pluginPermissionPrePath;
let label, linkLabel, linkUrl, button1, button2; let label, linkLabel, linkUrl, button1, button2;
@ -1491,7 +1491,7 @@
Cu.reportError(Error("Unexpected blocklist state")); Cu.reportError(Error("Unexpected blocklist state"));
} }
} }
this._setupDescription(label, action.pluginName, host); this._setupDescription(label, action.pluginName, prePath);
this._setupLink(linkLabel, action.detailsLink); this._setupLink(linkLabel, action.detailsLink);
this._primaryButton.label = gNavigatorBundle.getString(button1.label); this._primaryButton.label = gNavigatorBundle.getString(button1.label);
@ -1512,7 +1512,7 @@
<method name="_setupDescription"> <method name="_setupDescription">
<parameter name="baseString" /> <parameter name="baseString" />
<parameter name="pluginName" /> <!-- null for the multiple-plugin case --> <parameter name="pluginName" /> <!-- null for the multiple-plugin case -->
<parameter name="host" /> <parameter name="prePath" />
<body><![CDATA[ <body><![CDATA[
var bsn = this._brandShortName; var bsn = this._brandShortName;
var span = document.getAnonymousElementByAttribute(this, "anonid", "click-to-play-plugins-notification-description"); var span = document.getAnonymousElementByAttribute(this, "anonid", "click-to-play-plugins-notification-description");
@ -1520,17 +1520,17 @@
span.removeChild(span.lastChild); span.removeChild(span.lastChild);
} }
var args = ["__host__", this._brandShortName]; var args = ["__prepath__", this._brandShortName];
if (pluginName) { if (pluginName) {
args.unshift(pluginName); args.unshift(pluginName);
} }
var bases = gNavigatorBundle.getFormattedString(baseString, args). var bases = gNavigatorBundle.getFormattedString(baseString, args).
split("__host__", 2); split("__prepath__", 2);
span.appendChild(document.createTextNode(bases[0])); span.appendChild(document.createTextNode(bases[0]));
var hostSpan = document.createElementNS("http://www.w3.org/1999/xhtml", "em"); var prePathSpan = document.createElementNS("http://www.w3.org/1999/xhtml", "em");
hostSpan.appendChild(document.createTextNode(host)); prePathSpan.appendChild(document.createTextNode(prePath));
span.appendChild(hostSpan); span.appendChild(prePathSpan);
span.appendChild(document.createTextNode(bases[1] + " ")); span.appendChild(document.createTextNode(bases[1] + " "));
]]></body> ]]></body>
</method> </method>