Bug 1099587 - Make JS callers of ios.newChannel call ios.newChannel2 in mailnews/ r=rkent

This commit is contained in:
Stefan Sitter 2015-05-18 20:41:56 +02:00
Родитель b8f0faa5e5
Коммит bd92d1097f
11 изменённых файлов: 113 добавлений и 18 удалений

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

@ -66,7 +66,12 @@ function readURLasUTF8(uri)
{
assert(uri instanceof Ci.nsIURI, "uri must be an nsIURI");
try {
let chan = Services.io.newChannelFromURI(uri);
let chan = Services.io.newChannelFromURI2(uri,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
let is = Cc["@mozilla.org/intl/converter-input-stream;1"]
.createInstance(Ci.nsIConverterInputStream);
is.init(chan.open(), "UTF-8", 1024,

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

@ -24,6 +24,7 @@
#include "nsMsgCompose.h"
#include "nsMsgMailNewsUrl.h"
#include "mozilla/Services.h"
#include "nsIScriptSecurityManager.h"
NS_IMPL_ISUPPORTS(nsMsgQuoteListener, nsIMsgQuoteListener,
nsIMimeStreamConverterListener)
@ -172,11 +173,25 @@ nsMsgQuote::QuoteMessage(const char *msgURI, bool quoteHeaders,
NS_IF_RELEASE(supports);
// now we want to create a necko channel for this url and we want to open it
nsCOMPtr<nsIScriptSecurityManager> secMan(
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIPrincipal> systemPrincipal;
rv = secMan->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
NS_ENSURE_SUCCESS(rv,rv);
mQuoteChannel = nullptr;
nsCOMPtr<nsIIOService> netService =
mozilla::services::GetIOService();
nsCOMPtr<nsIIOService> netService = mozilla::services::GetIOService();
NS_ENSURE_TRUE(netService, NS_ERROR_UNEXPECTED);
rv = netService->NewChannelFromURI(aURL, getter_AddRefs(mQuoteChannel));
rv = netService->NewChannelFromURI2(aURL,
nullptr,
systemPrincipal,
nullptr,
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
getter_AddRefs(mQuoteChannel));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISupports> ctxt = do_QueryInterface(aURL);

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

@ -19,6 +19,7 @@ load("resources/glodaTestHelper.js");
Components.utils.import("resource:///modules/MailUtils.js");
Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
// Whether we can expect fulltext results
var expectFulltextResults = true;
@ -471,7 +472,13 @@ function verify_attributes_fundamental(smsg, gmsg) {
// because it's unreliable and depends on the platform
do_check_true(Math.abs(attInfos.size - expectedSize) <= 2);
// check that the attachment URLs are correct
let channel = NetUtil.newChannel(attInfos.url);
let channel = NetUtil.newChannel({
uri: attInfos.url,
loadingPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
securityFlags: Ci.nsILoadInfo.SEC_NORMAL,
contentPolicyType: Ci.nsIContentPolicy.TYPE_OTHER
});
try {
// will throw if the URL is invalid
channel.open();
@ -515,7 +522,12 @@ function test_moved_message_attributes() {
// verify the url has changed
do_check_neq(fundamentalGlodaMsgAttachmentUrls[i], attInfos.url);
// and verify that the new url is still valid
let channel = NetUtil.newChannel(attInfos.url);
let channel = NetUtil.newChannel({
uri: attInfos.url,
loadingPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
securityFlags: Ci.nsILoadInfo.SEC_NORMAL,
contentPolicyType: Ci.nsIContentPolicy.TYPE_OTHER
});
try {
channel.open();
} catch (e) {

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

@ -44,7 +44,13 @@ function TrainingData() {
{
var oUri = Services.io.newFileURI(oFile);
// open stream (channel)
var oStream = Services.io.newChannelFromURI(oUri).open();
let channel = Services.io.newChannelFromURI2(oUri,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var oStream = channel.open();
// buffer it
var oBufStream = Cc["@mozilla.org/network/buffered-input-stream;1"].
createInstance(Ci.nsIBufferedInputStream);

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

@ -70,7 +70,12 @@ function verifyContentLength()
imapS.GetUrlForUri("imap-message://user@localhost/INBOX#1", uri, null);
// Get a channel from this URI, and check its content length
let channel = Services.io.newChannelFromURI(uri.value);
let channel = Services.io.newChannelFromURI2(uri.value,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
dump(channel + "\n");
@ -87,7 +92,12 @@ function verifyContentLength()
// Now try an attachment. &part=1.2
// let attachmentURL = Services.io.newURI(neckoURL.value.spec + "&part=1.2",
// null, null);
// let attachmentChannel = Services.io.newChannelFromURI(attachmentURL);
// let attachmentChannel = Services.io.newChannelFromURI2(attachmentURL,
// null,
// Services.scriptSecurityManager.getSystemPrincipal(),
// null,
// Ci.nsILoadInfo.SEC_NORMAL,
// Ci.nsIContentPolicy.TYPE_OTHER);
// Currently attachments have their content length set to the length of the
// entire message
// do_check_eq(attachmentChannel.contentLength, gFile.fileSize);

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

@ -81,7 +81,12 @@ function streamMessages() {
let uri = {};
imapS.GetUrlForUri("imap-message://user@localhost/INBOX#" + i,uri,null);
uri.value.spec += "?header=quotebody";
let channel = Services.io.newChannelFromURI(uri.value);
let channel = Services.io.newChannelFromURI2(uri.value,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
channel.asyncOpen(gStreamListener, null);
yield false;
let buf = gStreamListener._data;

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

@ -65,13 +65,23 @@ function verifyContentLength() {
let urlToRun = Services.io.newURI(neckoURL.value.spec, null, null);
// Get a channel from this URI, and check its content length
let channel = Services.io.newChannelFromURI(urlToRun);
let channel = Services.io.newChannelFromURI2(urlToRun,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
do_check_eq(channel.contentLength, gFile.fileSize);
// Now try an attachment. &part=1.2
let attachmentURL = Services.io.newURI(neckoURL.value.spec + "&part=1.2",
null, null);
let attachmentChannel = Services.io.newChannelFromURI(attachmentURL);
let attachmentChannel = Services.io.newChannelFromURI2(attachmentURL,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
// Currently attachments have their content length set to the length of the
// entire message
do_check_eq(attachmentChannel.contentLength, gFile.fileSize);

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

@ -36,13 +36,23 @@ function verifyContentLength(aMessageHeaderKeys, aStatus)
let urlToRun = Services.io.newURI(neckoURL.value.spec, null, null);
// Get a channel from this URI, and check its content length
let channel = Services.io.newChannelFromURI(urlToRun);
let channel = Services.io.newChannelFromURI2(urlToRun,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
do_check_eq(channel.contentLength, gFile.fileSize);
// Now try an attachment. &part=1.2
let attachmentURL = Services.io.newURI(neckoURL.value.spec + "&part=1.2",
null, null);
let attachmentChannel = Services.io.newChannelFromURI(attachmentURL);
let attachmentChannel = Services.io.newChannelFromURI2(attachmentURL,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
// Currently attachments have their content length set to the length of the
// entire message
do_check_eq(channel.contentLength, gFile.fileSize);

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

@ -20,7 +20,12 @@ function run_test() {
do_check_eq(newsUri.folder, null);
// Run the URI and make sure we get the message
let channel = Services.io.newChannelFromURI(uri);
let channel = Services.io.newChannelFromURI2(uri,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
channel.asyncOpen(articleTextListener, null);
// Run the server

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

@ -48,14 +48,24 @@ function run_test() {
let urlToRun = Services.io.newURI(neckoURL.value.spec, null, null);
// Get a channel from this URI, and check its content length
let channel = Services.io.newChannelFromURI(urlToRun);
let channel = Services.io.newChannelFromURI2(urlToRun,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
do_check_eq(channel.contentLength, kSimpleNewsArticle.length);
// Now try an attachment. &part=1.2
// XXX the message doesn't really have an attachment
let attachmentURL = Services.io.newURI(neckoURL.value.spec + "&part=1.2",
null, null);
let attachmentChannel = Services.io.newChannelFromURI(attachmentURL);
let attachmentChannel = Services.io.newChannelFromURI2(attachmentURL,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
// Currently attachments have their content length set to the length of the
// entire message
do_check_eq(channel.contentLength, kSimpleNewsArticle.length);

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

@ -362,7 +362,14 @@ function imapMessage(URI, uid, flags) {
}
imapMessage.prototype = {
get channel() {
return Services.io.newChannel(this._URI, null, null);
return Services.io.newChannel2(this._URI,
null,
null,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
},
setFlag : function (flag) {
if (this.flags.indexOf(flag) == -1)