Bug 1016875 - Part10: Principal() for ImportLoader. r=mrbkap
☠☠ backed out by f6881097d888 ☠ ☠
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Wed, 16 Jul 2014 14:32:00 +0200
changeset 216296 ffa4255ebaa776508973182fd972e50bbcc7b3a4
parent 216295 3b9951da1581fd6b7ef22b279364047087226ed8
child 216297 d69317ef2dea4a6e5f996c5d3f4e660b295e6a2a
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: Principal() for ImportLoader. 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
@@ -110,16 +110,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;