Bug 995737 - Adapt seamonkey for the addressbook remote content policy change; use the permission manager instead of address book property r=IanN moa=Mnyromyr

This commit is contained in:
Philip Chee 2015-06-03 01:19:28 +08:00
Родитель 496acf32a0
Коммит c4fd716931
10 изменённых файлов: 126 добавлений и 134 удалений

Просмотреть файл

@ -48,14 +48,6 @@
<!ENTITY ScreenName.label "Screen Name:">
<!ENTITY ScreenName.accesskey "S">
<!ENTITY allowRemoteContent1.label "Allow remote content.">
<!ENTITY allowRemoteContent1.accesskey "r">
<!ENTITY allowRemoteContent1.tooltip "In HTML messages it is possible to
embed content from remote sources. Opening such a message will open a
connection to this external source. This may allow tracking of the
message being read. Checking this box will allow such external embedded
content in HTML messages from this contact.">
<!ENTITY WorkPhone.label "Work:">
<!ENTITY WorkPhone.accesskey "k">
<!ENTITY HomePhone.label "Home:">

Просмотреть файл

@ -445,6 +445,12 @@
<!ENTITY junkButton.tooltip "Mark the selected messages as junk">
<!ENTITY notJunkButton.tooltip "Mark the selected messages as not junk">
<!-- Remote Content Button Popup -->
<!ENTITY remoteContentOptionsAllowForMsg.label "Show remote content in this message">
<!ENTITY remoteContentOptionsAllowForMsg.accesskey "S">
<!ENTITY editRemoteContentSettings.label "Edit permissions for remote content…">
<!ENTITY editRemoteContentSettings.accesskey "E">
<!-- Statusbar -->
<!ENTITY statusText.label "Done">

Просмотреть файл

@ -414,9 +414,6 @@ confirmPhishingTitle=Email Scam Alert
confirmPhishingUrl1=%1$S thinks this website is suspicious! It may be trying to impersonate the web page you want to visit. Most legitimate websites use names instead of numbers. Are you sure you want to visit %2$S?
confirmPhishingUrl2=%1$S thinks this website is suspicious! It may be trying to impersonate the web page you want to visit. Are you sure you want to visit %2$S?
#LOCALIZATION NOTE %1$S is the e-mail address of the person we will allow remote content for
alwaysLoadRemoteContentForSender=Click here to always load remote content from %1$S.
#LOCALIZATION NOTE(mdnBarMessageNormal) %1$S is the name of the sender
mdnBarMessageNormal=%1$S has asked to be notified when you read this message.
#LOCALIZATION NOTE(mdnBarMessageAddressDiffers) %1$S is the name of the sender, %2$S is the address(es) to send return receipt to
@ -467,8 +464,11 @@ junkBarInfoButton=?
junkBarInfoButtonKey=?
# LOCALIZATION NOTE (remoteContentBarMessage): %S is the brandname
remoteContentBarMessage=To protect your privacy, %S has blocked remote content in this message.
remoteContentBarButton=Show Remote Content
remoteContentBarButtonKey=S
remoteContentPrefLabel=Options
remoteContentPrefAccesskey=O
# LOCALIZATION NOTE(remoteContentAllow): %S is host name
remoteContentAllow=Allow remote content for %S
# LOCALIZATION NOTE (phishingBarMessage): %S is the brandname
phishingBarMessage=%S regards this message as an e-mail scam.
phishingBarIgnoreButton=Ignore Warning

Просмотреть файл

@ -5,7 +5,7 @@
const kNonVcardFields =
["NickNameContainer", "SecondaryEmailContainer", "ScreenNameContainer",
"customFields", "allowRemoteContent", "preferDisplayName"];
"customFields", "preferDisplayName"];
const kPhoneticFields =
["PhoneticLastName", "PhoneticLabel1", "PhoneticSpacer1",
@ -109,10 +109,6 @@ function OnLoadNewCard()
gEditCard.card.setProperty("_AimScreenName",
window.arguments[0].aimScreenName);
if ("allowRemoteContent" in window.arguments[0])
gEditCard.card.setProperty("AllowRemoteContent",
window.arguments[0].allowRemoteContent);
if ("okCallback" in window.arguments[0])
gOkCallback = window.arguments[0].okCallback;
@ -273,9 +269,8 @@ function OnLoadEditCard()
document.getElementById(kPhoneticFields[0]).readOnly = true;
document.getElementById(kPhoneticFields[3]).readOnly = true;
// Also disable the mail format popup and allow remote content items.
// Also disable the mail format popup.
document.getElementById("PreferMailFormatPopup").disabled = true;
document.getElementById("allowRemoteContent").disabled = true;
// And the "prefer display name" checkbox.
document.getElementById("preferDisplayName").disabled = true;
@ -283,10 +278,6 @@ function OnLoadEditCard()
document.documentElement.buttons = "accept";
document.documentElement.removeAttribute("ondialogaccept");
}
// hide remote content in HTML field for remote directories
if (directory.isRemote)
document.getElementById('allowRemoteContent').hidden = true;
}
}
}
@ -419,11 +410,6 @@ function NewCardOKButton()
var directory = GetDirectoryFromURI(uri);
gEditCard.card = directory.addCard(gEditCard.card);
NotifySaveListeners(directory);
if ("arguments" in window && window.arguments[0] &&
"allowRemoteContent" in window.arguments[0])
// getProperty may return a "1" or "0" string, we want a boolean
window.arguments[0].allowRemoteContent =
gEditCard.card.getProperty("AllowRemoteContent", false) != false;
}
}
@ -484,11 +470,6 @@ function GetCardValues(cardproperty, doc)
if (popup)
popup.value = cardproperty.getProperty("PreferMailFormat", "");
var allowRemoteContentEl = document.getElementById("allowRemoteContent");
if (allowRemoteContentEl)
// getProperty may return a "1" or "0" string, we want a boolean
allowRemoteContentEl.checked = cardproperty.getProperty("AllowRemoteContent", false) != false;
var preferDisplayNameEl = document.getElementById("preferDisplayName");
if (preferDisplayNameEl)
// getProperty may return a "1" or "0" string, we want a boolean
@ -555,10 +536,6 @@ function CheckAndSetCardValues(cardproperty, doc, check)
if (popup)
cardproperty.setProperty("PreferMailFormat", popup.value);
var allowRemoteContentEl = document.getElementById("allowRemoteContent");
if (allowRemoteContentEl)
cardproperty.setProperty("AllowRemoteContent", allowRemoteContentEl.checked);
var preferDisplayNameEl = document.getElementById("preferDisplayName");
if (preferDisplayNameEl)
cardproperty.setProperty("PreferDisplayName", preferDisplayNameEl.checked);

Просмотреть файл

@ -183,9 +183,6 @@
<menuitem value="2" label="&HTML.label;"/>
</menupopup>
</menulist>
<checkbox id="allowRemoteContent" label="&allowRemoteContent1.label;"
accesskey="&allowRemoteContent1.accesskey;"
tooltiptext="&allowRemoteContent1.tooltip;"/>
</hbox>
</vbox> <!-- End of Name Tab -->

Просмотреть файл

@ -2537,7 +2537,7 @@ function HandleJunkStatusChanged(folder)
}
}
var gMessageNotificationBar =
var gMessageNotificationBar =
{
get mStringBundle()
{
@ -2607,49 +2607,39 @@ var gMessageNotificationBar =
}
},
setRemoteContentMsg: function(aMsgHdr)
{
var headerParser = Components.classes["@mozilla.org/messenger/headerparser;1"]
.getService(Components.interfaces.nsIMsgHeaderParser);
var emailAddress = headerParser.extractHeaderAddressMailboxes(aMsgHdr.author);
remoteHosts: null,
var oldNotif = this.mMsgNotificationBar.getNotificationWithValue("remoteContent");
if (!oldNotif)
{
let displayName = headerParser.extractHeaderAddressName(aMsgHdr.author);
let brandName = this.mBrandBundle.getString('brandShortName');
let remoteContentMsg = this.mStringBundle.getFormattedString('remoteContentBarMessage',
[brandName]);
let buttons = [{
label: this.mStringBundle.getString('remoteContentBarButton'),
accessKey: this.mStringBundle.getString('remoteContentBarButtonKey'),
popup: null,
callback: function()
{
LoadMsgWithRemoteContent();
}
}];
setRemoteContentMsg: function(aMsgHdr, aContentURI)
{
// remoteHosts is a Set of all blockable hosts.
if (!this.remoteHosts)
this.remoteHosts = new Set();
this.remoteHosts.add(aContentURI.host);
let bar =
this.mMsgNotificationBar.appendNotification(remoteContentMsg, "remoteContent",
null, this.mMsgNotificationBar.PRIORITY_WARNING_MEDIUM, buttons);
if (this.mMsgNotificationBar.getNotificationWithValue("remoteContent"))
return;
if (emailAddress)
{
let XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
let linkLabel = bar.ownerDocument.createElementNS(XULNS, "label");
let addedLink = this.mStringBundle.getFormattedString('alwaysLoadRemoteContentForSender',
[emailAddress]);
var headerParser = MailServices.headerParser;
// update the allow remote content for sender string
var mailbox = headerParser.extractHeaderAddressMailboxes(aMsgHdr.author);
var emailAddress = mailbox || aMsgHdr.author;
var displayName = headerParser.extractHeaderAddressName(aMsgHdr.author);
var brandName = this.mBrandBundle.getString("brandShortName");
var remoteContentMsg = this.mStringBundle
.getFormattedString("remoteContentBarMessage",
[brandName]);
var buttons = [{
label: this.mStringBundle.getString("remoteContentPrefLabel"),
accessKey: this.mStringBundle.getString("remoteContentPrefAccesskey"),
popup: "remoteContentOptions"
}];
linkLabel.className = "text-link";
linkLabel.textContent = addedLink;
linkLabel.flex = 1;
linkLabel.onclick = function() { allowRemoteContentForSender(emailAddress,
displayName); };
bar.insertBefore(linkLabel, bar.firstChild);
}
}
this.mMsgNotificationBar
.appendNotification(remoteContentMsg,
"remoteContent",
null,
this.mMsgNotificationBar.PRIORITY_WARNING_MEDIUM,
buttons);
},
// aUrl is the nsIURI for the message currently loaded in the message pane
@ -2753,6 +2743,68 @@ function LoadMsgWithRemoteContent()
window.content.focus();
}
/**
* Populate the remote content options for the current message.
*/
function onRemoteContentOptionsShowing(aEvent)
{
var hosts = [...gMessageNotificationBar.remoteHosts];
var addresses = {};
MailServices.headerParser.parseHeadersWithArray(
gMessageDisplay.displayedMessage.author, addresses, {}, {});
var authorEmailAddress = addresses.value[0];
if (authorEmailAddress)
hosts.unshift(authorEmailAddress);
// Out with the old...
let childNodes = aEvent.target.querySelectorAll(".allow-remote-uri");
for (let child of childNodes)
child.remove();
var messengerBundle = gMessageNotificationBar.mStringBundle;
var separator = document.getElementById("remoteContentSettingsMenuSeparator")
// ... and in with the new.
for (let host of hosts)
{
let menuitem = document.createElement("menuitem");
menuitem.setAttribute("label",
messengerBundle.getFormattedString("remoteContentAllow", [host]));
menuitem.setAttribute("host", host);
menuitem.setAttribute("class", "allow-remote-uri");
aEvent.target.insertBefore(menuitem, separator);
}
}
/**
* Add privileges to display remote content for the given uri.
* @param aItem |nsIDOMNode| Item that was selected. The host
* is extracted and converted to a uri and used to add
* permissions for the site.
*/
function allowRemoteContentForURI(aItem)
{
var host = aItem.getAttribute("host");
if (!host)
return;
var scheme = host.includes("@") ? "mailto:" : "http://";
var uri = Services.io.newURI(scheme + host, null, null);
Services.perms.add(uri, "image", Services.perms.ALLOW_ACTION);
ReloadMessage();
}
/**
* Displays fine-grained, per-site permissions for remote content.
*/
function editRemoteContentSettings()
{
toDataManager("|permissions");
if (!Services.prefs.getBoolPref("browser.preferences.instantApply"))
ReloadMessage();
}
/**
* msgHdrForCurrentMessage
* Returns the msg hdr associated with the current loaded message.
@ -2763,57 +2815,6 @@ function msgHdrForCurrentMessage()
return (msgURI && !(/type=application\/x-message-display/.test(msgURI))) ? messenger.msgHdrFromURI(msgURI) : null;
}
/**
* Reloads the message after adjusting the remote content policy for the sender.
* Iterate through the local address books looking for a card with the same e-mail address as the
* sender of the current loaded message. If we find a card, update the allow remote content field.
* If we can't find a card, prompt the user with a new AB card dialog, pre-selecting the remote content field.
*/
function allowRemoteContentForSender(aAuthorEmailAddress, aAuthorDisplayName)
{
// search through all of our local address books looking for a match.
var enumerator = Components.classes["@mozilla.org/abmanager;1"]
.getService(Components.interfaces.nsIAbManager)
.directories;
var cardForEmailAddress = null;
var addrbook = null;
while (!cardForEmailAddress && enumerator.hasMoreElements())
{
addrbook = enumerator.getNext()
.QueryInterface(Components.interfaces.nsIAbDirectory);
// Try/catch because cardForEmailAddress will throw if not implemented.
try
{
// If it's a read-only book, don't find a card as we won't be able
// to modify the card.
if (!addrbook.readOnly)
cardForEmailAddress = addrbook.cardForEmailAddress(authorEmailAddress);
} catch (e) {}
}
var allowRemoteContent = false;
if (cardForEmailAddress)
{
// set the property for remote content
cardForEmailAddress.setProperty("AllowRemoteContent", true);
addrbook.modifyCard(cardForEmailAddress);
allowRemoteContent = true;
}
else
{
var args = {primaryEmail:aAuthorEmailAddress, displayName:aAuthorDisplayName,
allowRemoteContent:true};
// create a new card and set the property
window.openDialog("chrome://messenger/content/addressbook/abNewCardDialog.xul",
"", "chrome,resizable=no,titlebar,modal,centerscreen", args);
allowRemoteContent = args.allowRemoteContent;
}
// reload the message if we've updated the remote content policy for the sender
if (allowRemoteContent)
ReloadMessage();
}
function MsgIsNotAScam()
{
// we want to get the msg hdr for the currently selected message
@ -2921,6 +2922,9 @@ function OnMsgLoaded(aUrl)
var msgHdr = msgHdrForCurrentMessage();
gMessageNotificationBar.setJunkMsg(msgHdr);
// Reset the blocked hosts so we can populate it again for this message.
// Reset to null so it's only a Set if there's something in the Set.
gMessageNotificationBar.remoteHosts = null;
var markReadAutoMode = Services.prefs.getBoolPref("mailnews.mark_message_read.auto");

Просмотреть файл

@ -876,6 +876,20 @@
gContextMenu.linkText());"/>
</menupopup>
<menupopup id="remoteContentOptions"
onpopupshowing="onRemoteContentOptionsShowing(event);"
oncommand="allowRemoteContentForURI(event.target);">
<menuitem id="remoteContentOptionAllowForMsg"
label="&remoteContentOptionsAllowForMsg.label;"
accesskey="&remoteContentOptionsAllowForMsg.accesskey;"
oncommand="LoadMsgWithRemoteContent();"/>
<menuseparator id="remoteContentSettingsMenuSeparator"/>
<menuitem id="editRemoteContentSettings"
label="&editRemoteContentSettings.label;"
accesskey="&editRemoteContentSettings.accesskey;"
oncommand="editRemoteContentSettings();"/>
</menupopup>
<toolbar type="menubar"
id="mail-toolbar-menubar2"
class="chromeclass-menubar"

Просмотреть файл

@ -91,6 +91,7 @@
<menupopup id="messageIdContext"/>
<menupopup id="emailAddressPopup"/>
<menupopup id="toolbar-context-menu"/>
<menupopup id="remoteContentOptions"/>
<tooltip id="aHTMLTooltip"
onpopupshowing="return FillInHTMLTooltip(document.tooltipNode);"/>
<panel id="customizeToolbarSheetPopup"/>

Просмотреть файл

@ -109,6 +109,7 @@
onpopupshowing="return FillInHTMLTooltip(document.tooltipNode);"/>
<panel id="customizeToolbarSheetPopup"/>
<menupopup id="networkProperties"/>
<menupopup id="remoteContentOptions"/>
</popupset>
<vbox id="titlebar"/>

Просмотреть файл

@ -618,9 +618,9 @@ var messageHeaderSink = {
OnMsgLoaded(url);
},
onMsgHasRemoteContent: function(aMsgHdr)
onMsgHasRemoteContent: function(aMsgHdr, aContentURI)
{
gMessageNotificationBar.setRemoteContentMsg(aMsgHdr);
gMessageNotificationBar.setRemoteContentMsg(aMsgHdr, aContentURI);
},
mSecurityInfo : null,