Bug 1016875 - Part4: Removing mChannel in ImportLoader. r=mrbkap
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Wed, 16 Jul 2014 14:31:59 +0200
changeset 216290 bbc3281764727eef8307b7f3efde9d457e95f096
parent 216289 c7d87f38aeefa582e9609848328d1b75a132b17a
child 216291 06a6bfac90ae73a2fe7c4d2bada2eb9060138c7a
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 - Part4: Removing mChannel in 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
@@ -173,26 +173,24 @@ ImportLoader::Error(bool aUnblockScripts
   mStopped = true;
   uint32_t count = mLinks.Count();
   for (uint32_t i = 0; i < count; i++) {
     DispatchErrorEvent(mLinks[i]);
   }
   if (aUnblockScripts) {
     UnblockScripts();
   }
-
   ReleaseResources();
 }
 
 // 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;
-  mChannel = nullptr;
   mImportParent = nullptr;
 }
 
 void
 ImportLoader::Open()
 {
   AutoError ae(this, false);
   // Imports should obey to the master documents CSP.
@@ -220,45 +218,50 @@ ImportLoader::Open()
   rv = principal->GetCsp(getter_AddRefs(csp));
   NS_ENSURE_SUCCESS_VOID(rv);
 
   if (csp) {
     channelPolicy = do_CreateInstance("@mozilla.org/nschannelpolicy;1");
     channelPolicy->SetContentSecurityPolicy(csp);
     channelPolicy->SetLoadType(nsIContentPolicy::TYPE_SUBDOCUMENT);
   }
-  rv = NS_NewChannel(getter_AddRefs(mChannel),
+  nsCOMPtr<nsIChannel> channel;
+  rv = NS_NewChannel(getter_AddRefs(channel),
                      mURI,
                      /* ioService = */ nullptr,
                      loadGroup,
                      /* callbacks = */ nullptr,
                      nsIRequest::LOAD_BACKGROUND,
                      channelPolicy);
   NS_ENSURE_SUCCESS_VOID(rv);
 
-  rv = mChannel->AsyncOpen(this, nullptr);
+  rv = channel->AsyncOpen(this, nullptr);
   NS_ENSURE_SUCCESS_VOID(rv);
 
   BlockScripts();
   ae.Pass();
 }
 
 NS_IMETHODIMP
 ImportLoader::OnDataAvailable(nsIRequest* aRequest,
                               nsISupports* aContext,
                               nsIInputStream* aStream,
                               uint64_t aOffset,
                               uint32_t aCount)
 {
   MOZ_ASSERT(mParserStreamListener);
 
   AutoError ae(this);
-  nsresult rv = mParserStreamListener->OnDataAvailable(mChannel, aContext,
-                                                       aStream, aOffset,
-                                                       aCount);
+  nsresult rv;
+  nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  rv = mParserStreamListener->OnDataAvailable(channel, aContext,
+                                              aStream, aOffset,
+                                              aCount);
   NS_ENSURE_SUCCESS(rv, rv);
   ae.Pass();
   return rv;
 }
 
 NS_IMETHODIMP
 ImportLoader::HandleEvent(nsIDOMEvent *aEvent)
 {
@@ -276,23 +279,20 @@ ImportLoader::OnStopRequest(nsIRequest* 
                             nsISupports* aContext,
                             nsresult aStatus)
 {
   // OnStartRequest throws a special error code to let us know that we
   // shouldn't do anything else.
   if (aStatus == NS_ERROR_DOM_ABORT_ERR) {
     // We failed in OnStartRequest, nothing more to do (we've already
     // dispatched an error event) just return here.
-    MOZ_ASSERT(!mChannel);
+    MOZ_ASSERT(mStopped);
     return NS_OK;
   }
 
-  MOZ_ASSERT(aRequest == mChannel,
-             "Wrong channel something went horribly wrong");
-
   if (mParserStreamListener) {
     mParserStreamListener->OnStopRequest(aRequest, aContext, aStatus);
   }
 
   if (!mDocument) {
     // If at this point we don't have a document, then the error was
     // already reported.
     return NS_ERROR_DOM_ABORT_ERR;
@@ -304,26 +304,31 @@ ImportLoader::OnStopRequest(nsIRequest* 
                                   NS_LITERAL_STRING("DOMContentLoaded"),
                                   TrustedEventsAtSystemGroupBubble());
   return NS_OK;
 }
 
 NS_IMETHODIMP
 ImportLoader::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
 {
-  MOZ_ASSERT(aRequest == mChannel,
-             "Wrong channel, something went horribly wrong");
-
   AutoError ae(this);
   nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(mImportParent);
   nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
-  mChannel->SetOwner(principal);
+  if (!sop) {
+    return NS_ERROR_DOM_ABORT_ERR;
+  }
+
+  nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
+  if (!channel) {
+    return NS_ERROR_DOM_ABORT_ERR;
+  }
+  channel->SetOwner(principal);
 
   nsAutoCString type;
-  mChannel->GetContentType(type);
+  channel->GetContentType(type);
   if (!type.EqualsLiteral("text/html")) {
     NS_WARNING("ImportLoader wrong content type");
     return NS_ERROR_DOM_ABORT_ERR;
   }
 
   // The scope object is same for all the imports in an import tree,
   // let's get it form the import parent.
   nsCOMPtr<nsIGlobalObject> global = mImportParent->GetScopeObject();
@@ -339,18 +344,18 @@ ImportLoader::OnStartRequest(nsIRequest*
   // The imported document must know which master document it belongs to.
   mDocument = do_QueryInterface(importDoc);
   nsCOMPtr<nsIDocument> master = mImportParent->MasterDocument();
   mDocument->SetMasterDocument(master);
 
   // We have to connect the blank document we created with the channel we opened.
   nsCOMPtr<nsIStreamListener> listener;
   nsCOMPtr<nsILoadGroup> loadGroup;
-  mChannel->GetLoadGroup(getter_AddRefs(loadGroup));
-  rv = mDocument->StartDocumentLoad("import", mChannel, loadGroup,
+  channel->GetLoadGroup(getter_AddRefs(loadGroup));
+  rv = mDocument->StartDocumentLoad("import", channel, loadGroup,
                                     nullptr, getter_AddRefs(listener),
                                     true);
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_ABORT_ERR);
 
   // Let's start parser.
   mParserStreamListener = listener;
   rv = listener->OnStartRequest(aRequest, aContext);
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_ABORT_ERR);
--- a/content/base/src/ImportManager.h
+++ b/content/base/src/ImportManager.h
@@ -112,17 +112,16 @@ private:
 
   // While the document is being loaded we must block scripts
   // on the import parent document.
   void BlockScripts();
   void UnblockScripts();
 
   nsCOMPtr<nsIDocument> mDocument;
   nsCOMPtr<nsIURI> mURI;
-  nsCOMPtr<nsIChannel> mChannel;
   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;
   bool mStopped;
   bool mBlockingScripts;