Bug 1402205 - Non-existent background page blocks extension startup draft
authorHaik Aftandilian <haftandilian@mozilla.com>
Mon, 25 Sep 2017 15:48:40 -0700
changeset 670162 670ec2c25b4f6bacbf77ab70542efba662e012e9
parent 670161 36f0294c68bf55584d12952ede8d26a1e540d682
child 733154 4ea2bc0095fb650397a32e4f9aed7d2b6249e9fa
push id81539
push userhaftandilian@mozilla.com
push dateMon, 25 Sep 2017 23:54:03 +0000
bugs1402205
milestone58.0a1
Bug 1402205 - Non-existent background page blocks extension startup MozReview-Commit-ID: Dcg0LDht9B9
netwerk/protocol/res/ExtensionProtocolHandler.cpp
--- a/netwerk/protocol/res/ExtensionProtocolHandler.cpp
+++ b/netwerk/protocol/res/ExtensionProtocolHandler.cpp
@@ -248,49 +248,60 @@ ExtensionStreamGetter::GetAsync(nsIStrea
     },
     [self] (const mozilla::ipc::PromiseRejectReason) {
       self->OnStream(nullptr);
     }
   );
   return Ok();
 }
 
+static void
+CancelRequest(nsIStreamListener* aListener,
+              nsIChannel* aChannel,
+              nsresult aResult)
+{
+  MOZ_ASSERT(aListener);
+  MOZ_ASSERT(aChannel);
+
+  aListener->OnStartRequest(aChannel, nullptr);
+  aListener->OnStopRequest(aChannel, nullptr, aResult);
+  aChannel->Cancel(NS_BINDING_ABORTED);
+}
+
 // Handle an input stream sent from the parent.
 void
 ExtensionStreamGetter::OnStream(nsIInputStream* aStream)
 {
   MOZ_ASSERT(IsNeckoChild());
   MOZ_ASSERT(mListener);
   MOZ_ASSERT(mMainThreadEventTarget);
 
   // We must keep an owning reference to the listener
   // until we pass it on to AsyncRead.
   nsCOMPtr<nsIStreamListener> listener = mListener.forget();
 
   MOZ_ASSERT(mChannel);
 
   if (!aStream) {
     // The parent didn't send us back a stream.
-    listener->OnStartRequest(mChannel, nullptr);
-    listener->OnStopRequest(mChannel, nullptr, NS_ERROR_FILE_ACCESS_DENIED);
-    mChannel->Cancel(NS_BINDING_ABORTED);
+    CancelRequest(listener, mChannel, NS_ERROR_FILE_ACCESS_DENIED);
     return;
   }
 
   nsCOMPtr<nsIInputStreamPump> pump;
   nsresult rv = NS_NewInputStreamPump(getter_AddRefs(pump), aStream, -1, -1, 0,
                                       0, false, mMainThreadEventTarget);
   if (NS_FAILED(rv)) {
-    mChannel->Cancel(NS_BINDING_ABORTED);
+    CancelRequest(listener, mChannel, rv);
     return;
   }
 
   rv = pump->AsyncRead(listener, nullptr);
   if (NS_FAILED(rv)) {
-    mChannel->Cancel(NS_BINDING_ABORTED);
+    CancelRequest(listener, mChannel, rv);
   }
 }
 
 // Handle an FD sent from the parent.
 void
 ExtensionStreamGetter::OnFD(const FileDescriptor& aFD)
 {
   MOZ_ASSERT(IsNeckoChild());
@@ -305,17 +316,17 @@ ExtensionStreamGetter::OnFD(const FileDe
   // We must keep an owning reference to the listener
   // until we pass it on to AsyncOpen2.
   nsCOMPtr<nsIStreamListener> listener = mListener.forget();
 
   RefPtr<FileDescriptorFile> fdFile = new FileDescriptorFile(aFD, mJarFile);
   mJarChannel->SetJarFile(fdFile);
   nsresult rv = mJarChannel->AsyncOpen2(listener);
   if (NS_FAILED(rv)) {
-    mChannel->Cancel(NS_BINDING_ABORTED);
+    CancelRequest(listener, mChannel, rv);
   }
 }
 
 NS_IMPL_QUERY_INTERFACE(ExtensionProtocolHandler, nsISubstitutingProtocolHandler,
                         nsIProtocolHandler, nsIProtocolHandlerWithDynamicFlags,
                         nsISupportsWeakReference)
 NS_IMPL_ADDREF_INHERITED(ExtensionProtocolHandler, SubstitutingProtocolHandler)
 NS_IMPL_RELEASE_INHERITED(ExtensionProtocolHandler, SubstitutingProtocolHandler)