Bug 1173523 - Part 3: Update PluginContent to use new API for nsIPermission, r=mconley

This commit is contained in:
Michael Layzell
2015-06-04 10:56:40 -04:00
committed by Ehsan Akhgari
parent d603235ab6
commit c0dce52dea
3 changed files with 32 additions and 45 deletions

View File

@@ -44,14 +44,14 @@ var gPluginHandler = {
switch (msg.name) {
case "PluginContent:ShowClickToPlayNotification":
this.showClickToPlayNotification(msg.target, msg.data.plugins, msg.data.showNow,
msg.principal, msg.data.host, msg.data.location);
msg.principal, msg.data.location);
break;
case "PluginContent:RemoveNotification":
this.removeNotification(msg.target, msg.data.name);
break;
case "PluginContent:UpdateHiddenPluginUI":
this.updateHiddenPluginUI(msg.target, msg.data.haveInsecure, msg.data.actions,
msg.principal, msg.data.host, msg.data.location);
msg.principal, msg.data.location);
break;
case "PluginContent:HideNotificationBar":
this.hideNotificationBar(msg.target, msg.data.name);
@@ -216,8 +216,8 @@ var gPluginHandler = {
});
},
showClickToPlayNotification: function (browser, plugins, showNow, principal,
host, location) {
showClickToPlayNotification: function (browser, plugins, showNow,
principal, location) {
// It is possible that we've received a message from the frame script to show
// a click to play notification for a principal that no longer matches the one
// that the browser's content now has assigned (ie, the browser has browsed away
@@ -295,7 +295,6 @@ var gPluginHandler = {
primaryPlugin: primaryPluginPermission,
pluginData: pluginData,
principal: principal,
host: host,
};
PopupNotifications.show(browser, "click-to-play-plugins",
"", "plugins-notification-icon",
@@ -316,8 +315,10 @@ var gPluginHandler = {
notificationBox.removeNotification(notification, true);
},
updateHiddenPluginUI: function (browser, haveInsecure, actions, principal,
host, location) {
updateHiddenPluginUI: function (browser, haveInsecure, actions,
principal, location) {
let origin = principal.originNoSuffix;
// It is possible that we've received a message from the frame script to show
// the hidden plugin notification for a principal that no longer matches the one
// that the browser's content now has assigned (ie, the browser has browsed away
@@ -380,22 +381,22 @@ var gPluginHandler = {
case Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY:
message = gNavigatorBundle.getFormattedString(
"pluginActivateNew.message",
[pluginName, host]);
[pluginName, origin]);
break;
case Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE:
message = gNavigatorBundle.getFormattedString(
"pluginActivateOutdated.message",
[pluginName, host, brand]);
[pluginName, origin, brand]);
break;
case Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_NO_UPDATE:
message = gNavigatorBundle.getFormattedString(
"pluginActivateVulnerable.message",
[pluginName, host, brand]);
[pluginName, origin, brand]);
}
} else {
// Multi-plugin
message = gNavigatorBundle.getFormattedString(
"pluginActivateMultiple.message", [host]);
"pluginActivateMultiple.message", [origin]);
}
let buttons = [

View File

@@ -2432,9 +2432,9 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
let normalizedUrl = Services.io.newURI(
"https://" + gBrowser.selectedBrowser.currentURI.hostPort,
null, null);
// Add the current host in the 'trackingprotection' consumer of
// Add the current host/port combination in the 'trackingprotection' consumer of
// the permission manager using a normalized URI. This effectively
// places this host on the tracking protection allowlist.
// places this host/port combination on the tracking protection allowlist.
Services.perms.add(normalizedUrl,
"trackingprotection", Services.perms.ALLOW_ACTION);
BrowserReload();
@@ -2442,10 +2442,13 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
</method>
<method name="enableTrackingContentProtection">
<body><![CDATA[
// Remove the current host from the 'trackingprotection' consumer
// of the permission manager. This effectively removes this host
// Remove the current host/port combination from the 'trackingprotection' consumer
// of the permission manager. This effectively removes this host/port combination
// from the tracking protection allowlist.
Services.perms.remove(gBrowser.selectedBrowser.currentURI,
let normalizedUrl = Services.io.newURI(
"https://" + gBrowser.selectedBrowser.currentURI.hostPort,
null, null);
Services.perms.remove(normalizedUrl,
"trackingprotection");
BrowserReload();
]]></body>
@@ -2561,8 +2564,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
return;
}
let host = this.notification.options.host;
this._setupDescription("pluginActivateMultiple.message", null, host);
let prePath = this.notification.options.principal.URI.prePath;
this._setupDescription("pluginActivateMultiple.message", null, prePath);
var showBox = document.getAnonymousElementByAttribute(this, "anonid", "plugin-notification-showbox");
@@ -2601,7 +2604,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
<method name="_setupSingleState">
<body><![CDATA[
var action = this._items[0].action;
var host = action.pluginPermissionHost;
var prePath = action.pluginPermissionPrePath;
let label, linkLabel, linkUrl, button1, button2;
@@ -2696,7 +2699,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
Cu.reportError(Error("Unexpected blocklist state"));
}
}
this._setupDescription(label, action.pluginName, host);
this._setupDescription(label, action.pluginName, prePath);
this._setupLink(linkLabel, action.detailsLink);
this._primaryButton.label = gNavigatorBundle.getString(button1.label);
@@ -2717,7 +2720,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
<method name="_setupDescription">
<parameter name="baseString" />
<parameter name="pluginName" /> <!-- null for the multiple-plugin case -->
<parameter name="host" />
<parameter name="prePath" />
<body><![CDATA[
var bsn = this._brandShortName;
var span = document.getAnonymousElementByAttribute(this, "anonid", "click-to-play-plugins-notification-description");
@@ -2725,17 +2728,17 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
span.removeChild(span.lastChild);
}
var args = ["__host__", this._brandShortName];
var args = ["__prepath__", this._brandShortName];
if (pluginName) {
args.unshift(pluginName);
}
var bases = gNavigatorBundle.getFormattedString(baseString, args).
split("__host__", 2);
split("__prepath__", 2);
span.appendChild(document.createTextNode(bases[0]));
var hostSpan = document.createElementNS("http://www.w3.org/1999/xhtml", "em");
hostSpan.appendChild(document.createTextNode(host));
span.appendChild(hostSpan);
var prePathSpan = document.createElementNS("http://www.w3.org/1999/xhtml", "em");
prePathSpan.appendChild(document.createTextNode(prePath));
span.appendChild(prePathSpan);
span.appendChild(document.createTextNode(bases[1] + " "));
]]></body>
</method>

View File

@@ -695,20 +695,6 @@ PluginContent.prototype = {
this._showClickToPlayNotification(null, false);
},
// Match the behaviour of nsPermissionManager
_getHostFromPrincipal: function (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;
},
/**
* Activate the plugins that the user has specified.
*/
@@ -776,7 +762,6 @@ PluginContent.prototype = {
let pluginData = this.pluginData;
let principal = this.content.document.nodePrincipal;
let principalHost = this._getHostFromPrincipal(principal);
let location = this.content.document.location.href;
for (let p of plugins) {
@@ -792,11 +777,11 @@ PluginContent.prototype = {
let permissionObj = Services.perms.
getPermissionObject(principal, pluginInfo.permissionString, false);
if (permissionObj) {
pluginInfo.pluginPermissionHost = permissionObj.host;
pluginInfo.pluginPermissionPrePath = permissionObj.principal.originNoSuffix;
pluginInfo.pluginPermissionType = permissionObj.expireType;
}
else {
pluginInfo.pluginPermissionHost = principalHost;
pluginInfo.pluginPermissionPrePath = principal.originNoSuffix;
pluginInfo.pluginPermissionType = undefined;
}
@@ -806,7 +791,6 @@ PluginContent.prototype = {
this.global.sendAsyncMessage("PluginContent:ShowClickToPlayNotification", {
plugins: [... this.pluginData.values()],
showNow: showNow,
host: principalHost,
location: location,
}, null, principal);
},
@@ -889,7 +873,6 @@ PluginContent.prototype = {
this.global.sendAsyncMessage("PluginContent:UpdateHiddenPluginUI", {
haveInsecure: haveInsecure,
actions: [... actions.values()],
host: this._getHostFromPrincipal(principal),
location: location,
}, null, principal);
},