Bug 1016875 - Part10: GetPrincipal for imports. r=mrbkap
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Thu, 17 Jul 2014 10:51:11 +0200
changeset 216582 4aa73f5db7b5e48d194b69b4b2ecf51f54ddf383
parent 216507 42d1935444659dee9ff9ebd21e5dafdadc050fbc
child 216583 cecd74a436449ec6a43eb0bb9e211335d93813e3
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1016875
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1016875 - Part10: GetPrincipal for imports. r=mrbkap
content/base/src/ImportManager.cpp
content/base/src/ImportManager.h
--- a/content/base/src/ImportManager.cpp
+++ b/content/base/src/ImportManager.cpp
@@ -185,24 +185,33 @@ ImportLoader::Error(bool aUnblockScripts
 // Release all the resources we don't need after there is no more
 // data available on the channel, and the parser is done.
 void ImportLoader::ReleaseResources()
 {
   mParserStreamListener = nullptr;
   mImportParent = nullptr;
 }
 
+nsIPrincipal*
+ImportLoader::Principal()
+{
+  MOZ_ASSERT(mImportParent);
+  nsCOMPtr<nsIDocument> master = mImportParent->MasterDocument();
+  nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(master);
+  MOZ_ASSERT(sop);
+  return sop->GetPrincipal();
+}
+
 void
 ImportLoader::Open()
 {
   AutoError ae(this, false);
   // Imports should obey to the master documents CSP.
   nsCOMPtr<nsIDocument> master = mImportParent->MasterDocument();
-  nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(master);
-  nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
+  nsIPrincipal* principal = Principal();
 
   int16_t shouldLoad = nsIContentPolicy::ACCEPT;
   nsresult rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_SCRIPT,
                                           mURI,
                                           principal,
                                           mImportParent,
                                           NS_LITERAL_CSTRING("text/html"),
                                           /* extra = */ nullptr,
@@ -319,21 +328,17 @@ ImportLoader::OnStopRequest(nsIRequest* 
                                   TrustedEventsAtSystemGroupBubble());
   return NS_OK;
 }
 
 NS_IMETHODIMP
 ImportLoader::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
 {
   AutoError ae(this);
-  nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(mImportParent);
-  nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
-  if (!sop) {
-    return NS_ERROR_DOM_ABORT_ERR;
-  }
+  nsIPrincipal* principal = Principal();
 
   nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
   if (!channel) {
     return NS_ERROR_DOM_ABORT_ERR;
   }
 
   if (nsContentUtils::IsSystemPrincipal(principal)) {
     // We should never import non-system documents and run their scripts with system principal!
--- a/content/base/src/ImportManager.h
+++ b/content/base/src/ImportManager.h
@@ -44,16 +44,17 @@
 #include "nsIDOMEventListener.h"
 #include "nsIStreamListener.h"
 #include "nsIWeakReferenceUtils.h"
 #include "nsRefPtrHashtable.h"
 #include "nsURIHashKey.h"
 
 class nsIDocument;
 class nsIChannel;
+class nsIPrincipal;
 class nsINode;
 class AutoError;
 
 namespace mozilla {
 namespace dom {
 
 class ImportManager;
 
@@ -110,16 +111,18 @@ private:
   // that we don't need any longer to hold on.
   void ReleaseResources();
 
   // While the document is being loaded we must block scripts
   // on the import parent document.
   void BlockScripts();
   void UnblockScripts();
 
+  nsIPrincipal* Principal();
+
   nsCOMPtr<nsIDocument> mDocument;
   nsCOMPtr<nsIURI> mURI;
   nsCOMPtr<nsIStreamListener> mParserStreamListener;
   nsCOMPtr<nsIDocument> mImportParent;
   // List of the LinkElements that are referring to this import
   // we need to keep track of them so we can fire event on them.
   nsCOMArray<nsINode> mLinks;
   bool mReady;