Bug 1503735 - Port bug 1490257: Add system principal to loadURI() calls, C++ part. rs=bustage-fix
authorJorg K <jorgk@jorgk.com>
Thu, 01 Nov 2018 09:42:39 +0100
changeset 25126 b0459a76e42075f3b2b861fb0121c4c0efa1bcb4
parent 25125 d5940f87ebd34bdd50c664682e06fcfda2f10bb1
child 25127 4c2c4bf909f769f75c51339349a0b28497b015e4
push id15082
push usermozilla@jorgk.com
push dateThu, 01 Nov 2018 08:44:00 +0000
treeherdercomm-central@b0459a76e420 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbustage-fix
bugs1503735, 1490257
Bug 1503735 - Port bug 1490257: Add system principal to loadURI() calls, C++ part. rs=bustage-fix
mailnews/base/src/nsMessenger.cpp
mailnews/base/util/nsMsgMailNewsUrl.cpp
mailnews/imap/src/nsImapService.cpp
mailnews/local/src/nsMailboxService.cpp
mailnews/news/src/nsNntpService.cpp
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -590,16 +590,17 @@ nsMessenger::LoadURL(mozIDOMWindowProxy 
 
   AddMsgUrlToNavigateHistory(aURL);
   mNavigatingToUri.Truncate();
   mLastDisplayURI = aURL; // Remember the last uri we displayed.
   RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState();
   loadState->SetURI(uri);
   loadState->SetLoadFlags(nsIWebNavigation::LOAD_FLAGS_NONE);
   loadState->SetFirstParty(true);
+  loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
   return mDocShell->LoadURI(loadState);
 }
 
 NS_IMETHODIMP nsMessenger::SaveAttachmentToFile(nsIFile *aFile,
                                                 const nsACString &aURL,
                                                 const nsACString &aMessageUri,
                                                 const nsACString &aContentType,
                                                 nsIUrlListener *aListener)
--- a/mailnews/base/util/nsMsgMailNewsUrl.cpp
+++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp
@@ -23,16 +23,17 @@
 #include "nsIFile.h"
 #include "prmem.h"
 #include <time.h>
 #include "nsMsgUtils.h"
 #include "mozilla/Services.h"
 #include "nsProxyRelease.h"
 #include "mozilla/Encoding.h"
 #include "nsDocShellLoadState.h"
+#include "nsContentUtils.h"
 
 nsMsgMailNewsUrl::nsMsgMailNewsUrl()
 {
   // nsIURI specific state
   m_runningUrl = false;
   m_updatingFolder = false;
   m_msgIsInLocalCache = false;
   m_suppressErrorMsgs = false;
@@ -795,16 +796,17 @@ NS_IMETHODIMP nsMsgMailNewsUrl::LoadURI(
                                         uint32_t aLoadFlags)
 {
   NS_ENSURE_ARG_POINTER(docShell);
   RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState();
   loadState->SetURI(this);
   loadState->SetLoadFlags(aLoadFlags);
   loadState->SetLoadType(MAKE_LOAD_TYPE(LOAD_NORMAL, aLoadFlags));
   loadState->SetFirstParty(false);
+  loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
   return docShell->LoadURI(loadState);
 }
 
 #define SAVE_BUF_SIZE FILE_IO_BUFFER_SIZE
 class nsMsgSaveAsListener : public nsIStreamListener
 {
 public:
   NS_DECL_ISUPPORTS
--- a/mailnews/imap/src/nsImapService.cpp
+++ b/mailnews/imap/src/nsImapService.cpp
@@ -59,16 +59,17 @@
 #include "nsIStreamConverterService.h"
 #include "nsIAutoSyncManager.h"
 #include "nsThreadUtils.h"
 #include "nsNetUtil.h"
 #include "nsMsgMessageFlags.h"
 #include "nsIMsgPluggableStore.h"
 #include "../../base/src/MailnewsLoadContextInfo.h"
 #include "nsDocShellLoadState.h"
+#include "nsContentUtils.h"
 
 #define PREF_MAIL_ROOT_IMAP "mail.root.imap"            // old - for backward compatibility only
 #define PREF_MAIL_ROOT_IMAP_REL "mail.root.imap-rel"
 
 static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID);
 static NS_DEFINE_CID(kCImapMockChannel, NS_IMAPMOCKCHANNEL_CID);
 
 static const char sequenceString[] = "SEQUENCE";
@@ -627,16 +628,17 @@ nsresult nsImapService::FetchMimePart(ns
       RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState();
       loadState->SetURI(url);
       loadState->SetLoadFlags(aImapAction == nsImapUrl::nsImapOpenMimePart
                                 ? nsIWebNavigation::LOAD_FLAGS_IS_LINK
                                 : nsIWebNavigation::LOAD_FLAGS_NONE);
       if (aImapAction == nsImapUrl::nsImapOpenMimePart)
         loadState->SetLoadType(LOAD_LINK);
       loadState->SetFirstParty(false);
+      loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
       rv = docShell->LoadURI(loadState);
     }
     else
     {
       nsCOMPtr<nsIStreamListener> aStreamListener = do_QueryInterface(aDisplayConsumer, &rv);
       if (NS_SUCCEEDED(rv) && aStreamListener)
       {
         nsCOMPtr<nsIChannel> aChannel;
@@ -1061,16 +1063,17 @@ nsresult nsImapService::GetMessageFromUr
   }
   if (NS_SUCCEEDED(rv) && docShell)
   {
     NS_ASSERTION(!aConvertDataToText, "can't convert to text when using docshell");
     RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState();
     loadState->SetURI(url);
     loadState->SetLoadFlags(nsIWebNavigation::LOAD_FLAGS_NONE);
     loadState->SetFirstParty(false);
+    loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
     rv = docShell->LoadURI(loadState);
   }
   else
   {
     nsCOMPtr<nsIStreamListener> streamListener = do_QueryInterface(aDisplayConsumer, &rv);
     nsCOMPtr<nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(aImapUrl, &rv);
     if (aMsgWindow && mailnewsUrl)
       mailnewsUrl->SetMsgWindow(aMsgWindow);
--- a/mailnews/local/src/nsMailboxService.cpp
+++ b/mailnews/local/src/nsMailboxService.cpp
@@ -23,16 +23,17 @@
 #include "nsNetUtil.h"
 #include "nsIWebNavigation.h"
 #include "prprf.h"
 #include "nsIMsgHdr.h"
 #include "nsIFileURL.h"
 #include "mozilla/RefPtr.h"
 #include "nsDocShellLoadState.h"
 #include "nsIRDFService.h"
+#include "nsContentUtils.h"
 
 nsMailboxService::nsMailboxService()
 {
     mPrintingOperation = false;
 }
 
 nsMailboxService::~nsMailboxService()
 {}
@@ -238,16 +239,17 @@ nsresult nsMailboxService::FetchMessage(
     RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState();
     loadState->SetURI(url);
     loadState->SetLoadFlags(mailboxAction == nsIMailboxUrl::ActionFetchPart
                               ? nsIWebNavigation::LOAD_FLAGS_IS_LINK
                               : nsIWebNavigation::LOAD_FLAGS_NONE);
     if (mailboxAction == nsIMailboxUrl::ActionFetchPart)
       loadState->SetLoadType(LOAD_LINK);
     loadState->SetFirstParty(false);
+    loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
     rv = docShell->LoadURI(loadState);
   }
   else
     rv = RunMailboxUrl(url, aDisplayConsumer);
 
   if (aURL && mailboxurl)
     CallQueryInterface(mailboxurl, aURL);
 
@@ -367,16 +369,17 @@ NS_IMETHODIMP nsMailboxService::OpenAtta
     // DIRTY LITTLE HACK --> since we are opening an attachment we want the docshell to
     // treat this load as if it were a user click event. Then the dispatching stuff will be much
     // happier.
     RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState();
     loadState->SetURI(URL);
     loadState->SetLoadFlags(nsIWebNavigation::LOAD_FLAGS_IS_LINK);
     loadState->SetLoadType(LOAD_LINK);
     loadState->SetFirstParty(false);
+    loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
     return docShell->LoadURI(loadState);
   }
   return RunMailboxUrl(URL, aDisplayConsumer);
 
 }
 
 
 NS_IMETHODIMP
--- a/mailnews/news/src/nsNntpService.cpp
+++ b/mailnews/news/src/nsNntpService.cpp
@@ -39,16 +39,17 @@
 #include "nsIMsgMailSession.h"
 #include "nsISupportsPrimitives.h"
 #include "nsArrayUtils.h"
 #include "nsIStreamListener.h"
 #include "nsIInputStream.h"
 #include "nsIURIMutator.h"
 #include "nsTArray.h"
 #include "nsDocShellLoadState.h"
+#include "nsContentUtils.h"
 
 #include "../../base/src/MailnewsLoadContextInfo.h"
 
 #undef GetPort  // XXX Windows!
 #undef SetPort  // XXX Windows!
 
 #define PREF_MAIL_ROOT_NNTP   "mail.root.nntp"        // old - for backward compatibility only
 #define PREF_MAIL_ROOT_NNTP_REL   "mail.root.nntp-rel"
@@ -311,16 +312,17 @@ nsresult nsNntpService::GetMessageFromUr
     RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState();
     loadState->SetURI(aUrl);
     loadState->SetLoadFlags(mOpenAttachmentOperation
                               ? nsIWebNavigation::LOAD_FLAGS_IS_LINK
                               : nsIWebNavigation::LOAD_FLAGS_NONE);
     if (mOpenAttachmentOperation)
       loadState->SetLoadType(LOAD_LINK);
     loadState->SetFirstParty(false);
+    loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
     rv = docShell->LoadURI(loadState);
   }
   else
   {
     nsCOMPtr<nsIStreamListener> aStreamListener(do_QueryInterface(aDisplayConsumer, &rv));
     if (NS_SUCCEEDED(rv))
     {
       nsCOMPtr<nsIChannel> aChannel;
@@ -447,16 +449,17 @@ NS_IMETHODIMP nsNntpService::OpenAttachm
 
     nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aDisplayConsumer, &rv));
     if (NS_SUCCEEDED(rv) && docShell) {
       RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState();
       loadState->SetURI(url);
       loadState->SetLoadFlags(nsIWebNavigation::LOAD_FLAGS_IS_LINK);
       loadState->SetLoadType(LOAD_LINK);
       loadState->SetFirstParty(false);
+      loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
       return docShell->LoadURI(loadState);
     } else {
       return RunNewsUrl(url, aMsgWindow, aDisplayConsumer);
     }
   }
   return NS_OK;
 }