Bug 1538948 - Add missing LoadInfo in NNTP code. r+a=jorgk
authorBen Campbell <benc@thunderbird.net>
Sat, 10 Aug 2019 11:12:14 +1200
changeset 35288 064d9eae4999cb48ca01a7b15ece76780592dc6e
parent 35287 d16312466cccd7771275d32ee45d88474f7f6c83
child 35289 4d87c1eeaf459c63c013e206c36252dc75a7bac0
push id2477
push usermozilla@jorgk.com
push dateTue, 13 Aug 2019 21:14:23 +0000
treeherdercomm-beta@436d8b620b6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1538948
Bug 1538948 - Add missing LoadInfo in NNTP code. r+a=jorgk
mailnews/news/src/nsNntpIncomingServer.cpp
mailnews/news/test/unit/test_server.js
--- a/mailnews/news/src/nsNntpIncomingServer.cpp
+++ b/mailnews/news/src/nsNntpIncomingServer.cpp
@@ -28,16 +28,17 @@
 #include "nsNetUtil.h"
 #include "nsISimpleEnumerator.h"
 #include "nsMsgUtils.h"
 #include "mozilla/Services.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/XULTreeElement.h"
 #include "mozilla/dom/DataTransfer.h"
+#include "mozilla/LoadInfo.h"
 
 #define INVALID_VERSION 0
 #define VALID_VERSION 2
 #define NEW_NEWS_DIR_NAME "News"
 #define PREF_MAIL_NEWSRC_ROOT "mail.newsrc_root"
 #define PREF_MAIL_NEWSRC_ROOT_REL "mail.newsrc_root-rel"
 #define PREF_MAILNEWS_VIEW_DEFAULT_CHARSET "mailnews.view_default_charset"
 #define HOSTINFO_FILE_NAME "hostinfo.dat"
@@ -547,23 +548,36 @@ nsNntpIncomingServer::GetNntpChannel(nsI
 
 NS_IMETHODIMP
 nsNntpIncomingServer::LoadNewsUrl(nsIURI *aURI, nsIMsgWindow *aMsgWindow,
                                   nsISupports *aConsumer) {
   nsCOMPtr<nsINNTPProtocol> protocol;
   nsresult rv = GetNntpConnection(aURI, aMsgWindow, getter_AddRefs(protocol));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  if (protocol) return protocol->LoadNewsUrl(aURI, aConsumer);
+  nsCOMPtr<nsILoadInfo> loadInfo = new mozilla::net::LoadInfo(
+      nsContentUtils::GetSystemPrincipal(), nullptr, nullptr,
+      nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
+      nsIContentPolicy::TYPE_OTHER);
+
+  if (protocol) {
+    nsCOMPtr<nsIChannel> chan = do_QueryInterface(protocol, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = chan->SetLoadInfo(loadInfo);
+    NS_ENSURE_SUCCESS(rv, rv);
+    return protocol->LoadNewsUrl(aURI, aConsumer);
+  }
 
   // No protocol? We need our mock channel.
   nsNntpMockChannel *channel =
       new nsNntpMockChannel(aURI, aMsgWindow, aConsumer);
   if (!channel) return NS_ERROR_OUT_OF_MEMORY;
 
+  rv = channel->SetLoadInfo(loadInfo);
+  NS_ENSURE_SUCCESS(rv, rv);
   m_queuedChannels.AppendElement(channel);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNntpIncomingServer::PrepareForNextUrl(nsNNTPProtocol *aConnection) {
   NS_ENSURE_ARG(aConnection);
 
--- a/mailnews/news/test/unit/test_server.js
+++ b/mailnews/news/test/unit/test_server.js
@@ -83,26 +83,30 @@ function testRFC977() {
   var thread = gThreadManager.currentThread;
   while (thread.hasPendingEvents())
     thread.processNextEvent(true);
 }
 
 function testConnectionLimit() {
   var server = makeServer(NNTP_RFC977_handler, daemon);
   server.start(NNTP_PORT);
+  // 1 is the default, but other tests do change it, so let's be explicit.
+  _server.maximumConnectionsNumber = 1;
 
   var prefix = "news://localhost:" + NNTP_PORT + "/";
 
   // To test make connections limit, we run two URIs simultaneously.
   var url = Services.io.newURI(prefix + "*");
   _server.loadNewsUrl(url, null, null);
   setupProtocolTest(NNTP_PORT, prefix + "TSS1@nntp.invalid");
   server.performTest();
   // We should have length one... which means this must be a transaction object,
   // containing only us and them
+  // (playTransactions() returns an array of transaction objects if there is
+  // more than one of them, so this assert will fail in that case).
   Assert.ok("us" in server.playTransaction());
   server.stop();
 
   var thread = gThreadManager.currentThread;
   while (thread.hasPendingEvents())
     thread.processNextEvent(true);
 }