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) { switch (msg.name) {
case "PluginContent:ShowClickToPlayNotification": case "PluginContent:ShowClickToPlayNotification":
this.showClickToPlayNotification(msg.target, msg.data.plugins, msg.data.showNow, this.showClickToPlayNotification(msg.target, msg.data.plugins, msg.data.showNow,
msg.principal, msg.data.host, msg.data.location); msg.principal, msg.data.location);
break; break;
case "PluginContent:RemoveNotification": case "PluginContent:RemoveNotification":
this.removeNotification(msg.target, msg.data.name); this.removeNotification(msg.target, msg.data.name);
break; break;
case "PluginContent:UpdateHiddenPluginUI": case "PluginContent:UpdateHiddenPluginUI":
this.updateHiddenPluginUI(msg.target, msg.data.haveInsecure, msg.data.actions, this.updateHiddenPluginUI(msg.target, msg.data.haveInsecure, msg.data.actions,
msg.principal, msg.data.host, msg.data.location); msg.principal, msg.data.location);
break; break;
case "PluginContent:HideNotificationBar": case "PluginContent:HideNotificationBar":
this.hideNotificationBar(msg.target, msg.data.name); this.hideNotificationBar(msg.target, msg.data.name);
@@ -216,8 +216,8 @@ var gPluginHandler = {
}); });
}, },
showClickToPlayNotification: function (browser, plugins, showNow, principal, showClickToPlayNotification: function (browser, plugins, showNow,
host, location) { principal, location) {
// It is possible that we've received a message from the frame script to show // 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 // 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 // that the browser's content now has assigned (ie, the browser has browsed away
@@ -295,7 +295,6 @@ var gPluginHandler = {
primaryPlugin: primaryPluginPermission, primaryPlugin: primaryPluginPermission,
pluginData: pluginData, pluginData: pluginData,
principal: principal, principal: principal,
host: host,
}; };
PopupNotifications.show(browser, "click-to-play-plugins", PopupNotifications.show(browser, "click-to-play-plugins",
"", "plugins-notification-icon", "", "plugins-notification-icon",
@@ -316,8 +315,10 @@ var gPluginHandler = {
notificationBox.removeNotification(notification, true); notificationBox.removeNotification(notification, true);
}, },
updateHiddenPluginUI: function (browser, haveInsecure, actions, principal, updateHiddenPluginUI: function (browser, haveInsecure, actions,
host, location) { principal, location) {
let origin = principal.originNoSuffix;
// It is possible that we've received a message from the frame script to show // 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 // 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 // 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: case Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY:
message = gNavigatorBundle.getFormattedString( message = gNavigatorBundle.getFormattedString(
"pluginActivateNew.message", "pluginActivateNew.message",
[pluginName, host]); [pluginName, origin]);
break; break;
case Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE: case Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE:
message = gNavigatorBundle.getFormattedString( message = gNavigatorBundle.getFormattedString(
"pluginActivateOutdated.message", "pluginActivateOutdated.message",
[pluginName, host, brand]); [pluginName, origin, brand]);
break; break;
case Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_NO_UPDATE: case Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_NO_UPDATE:
message = gNavigatorBundle.getFormattedString( message = gNavigatorBundle.getFormattedString(
"pluginActivateVulnerable.message", "pluginActivateVulnerable.message",
[pluginName, host, brand]); [pluginName, origin, brand]);
} }
} else { } else {
// Multi-plugin // Multi-plugin
message = gNavigatorBundle.getFormattedString( message = gNavigatorBundle.getFormattedString(
"pluginActivateMultiple.message", [host]); "pluginActivateMultiple.message", [origin]);
} }
let buttons = [ 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( let normalizedUrl = Services.io.newURI(
"https://" + gBrowser.selectedBrowser.currentURI.hostPort, "https://" + gBrowser.selectedBrowser.currentURI.hostPort,
null, null); 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 // 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, Services.perms.add(normalizedUrl,
"trackingprotection", Services.perms.ALLOW_ACTION); "trackingprotection", Services.perms.ALLOW_ACTION);
BrowserReload(); BrowserReload();
@@ -2442,10 +2442,13 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
</method> </method>
<method name="enableTrackingContentProtection"> <method name="enableTrackingContentProtection">
<body><![CDATA[ <body><![CDATA[
// Remove the current host from the 'trackingprotection' consumer // Remove the current host/port combination from the 'trackingprotection' consumer
// of the permission manager. This effectively removes this host // of the permission manager. This effectively removes this host/port combination
// from the tracking protection allowlist. // 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"); "trackingprotection");
BrowserReload(); BrowserReload();
]]></body> ]]></body>
@@ -2561,8 +2564,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
return; return;
} }
let host = this.notification.options.host; let prePath = this.notification.options.principal.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");
@@ -2601,7 +2604,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
<method name="_setupSingleState"> <method name="_setupSingleState">
<body><![CDATA[ <body><![CDATA[
var action = this._items[0].action; var action = this._items[0].action;
var host = action.pluginPermissionHost; var prePath = action.pluginPermissionPrePath;
let label, linkLabel, linkUrl, button1, button2; 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")); 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);
@@ -2717,7 +2720,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
<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");
@@ -2725,17 +2728,17 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
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>

View File

@@ -695,20 +695,6 @@ PluginContent.prototype = {
this._showClickToPlayNotification(null, false); 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. * Activate the plugins that the user has specified.
*/ */
@@ -776,7 +762,6 @@ PluginContent.prototype = {
let pluginData = this.pluginData; let pluginData = this.pluginData;
let principal = this.content.document.nodePrincipal; let principal = this.content.document.nodePrincipal;
let principalHost = this._getHostFromPrincipal(principal);
let location = this.content.document.location.href; let location = this.content.document.location.href;
for (let p of plugins) { for (let p of plugins) {
@@ -792,11 +777,11 @@ PluginContent.prototype = {
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;
} }
@@ -806,7 +791,6 @@ PluginContent.prototype = {
this.global.sendAsyncMessage("PluginContent:ShowClickToPlayNotification", { this.global.sendAsyncMessage("PluginContent:ShowClickToPlayNotification", {
plugins: [... this.pluginData.values()], plugins: [... this.pluginData.values()],
showNow: showNow, showNow: showNow,
host: principalHost,
location: location, location: location,
}, null, principal); }, null, principal);
}, },
@@ -889,7 +873,6 @@ PluginContent.prototype = {
this.global.sendAsyncMessage("PluginContent:UpdateHiddenPluginUI", { this.global.sendAsyncMessage("PluginContent:UpdateHiddenPluginUI", {
haveInsecure: haveInsecure, haveInsecure: haveInsecure,
actions: [... actions.values()], actions: [... actions.values()],
host: this._getHostFromPrincipal(principal),
location: location, location: location,
}, null, principal); }, null, principal);
}, },