TMP - Require explicit NotNull wrapping on RequestOrStream static CreateFrom methods draft
authorLuca Greco <lgreco@mozilla.com>
Mon, 20 Sep 2021 17:34:08 +0200
changeset 3978286 7e1419593016c81c0b0dc59f7ffe3d402d35ed13
parent 3978285 3618a5f946b1a71c6059347d27f45e7e633c5445
child 3978287 3a558ca230fb01422db136edf47556a1a1eb4273
push id731704
push userluca.greco@alcacoop.it
push dateMon, 20 Sep 2021 17:05:39 +0000
treeherdertry@3a558ca230fb [default view] [failures only]
milestone94.0a1
TMP - Require explicit NotNull wrapping on RequestOrStream static CreateFrom methods
netwerk/base/nsBaseChannel.h
netwerk/protocol/res/ExtensionProtocolHandler.cpp
netwerk/protocol/res/PageThumbProtocolHandler.cpp
toolkit/components/places/nsAnnoProtocolHandler.cpp
--- a/netwerk/base/nsBaseChannel.h
+++ b/netwerk/base/nsBaseChannel.h
@@ -31,24 +31,27 @@
 
 class nsIInputStream;
 
 class RequestOrStream {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RequestOrStream)
 
   enum Type { eUninitialized, eRequest, eInputStream };
 
+  template <typename T>
+  using NotNull = mozilla::NotNull<T>;
+
  public:
   static already_AddRefed<RequestOrStream> CreateFromRequest(
-      const nsCOMPtr<nsIRequest>& aRequest) {
+      const NotNull<nsCOMPtr<nsIRequest>>& aRequest) {
     return mozilla::MakeRefPtr<RequestOrStream>(aRequest).forget();
   }
 
   static already_AddRefed<RequestOrStream> CreateFromInputStream(
-      const RefPtr<nsIInputStream>& aInputStream) {
+      const NotNull<nsCOMPtr<nsIInputStream>>& aInputStream) {
     return mozilla::MakeRefPtr<RequestOrStream>(aInputStream).forget();
   }
 
   explicit RequestOrStream(const nsCOMPtr<nsIRequest>& aRequest)
       : mRequest(aRequest), mInputStream(nullptr), mType(Type::eRequest) {
     MOZ_ASSERT(mRequest);
   }
 
--- a/netwerk/protocol/res/ExtensionProtocolHandler.cpp
+++ b/netwerk/protocol/res/ExtensionProtocolHandler.cpp
@@ -244,18 +244,19 @@ GetAsyncPromiseOrReason ExtensionStreamG
     gNeckoChild->SendGetExtensionFD(mURI)->Then(
         mMainThreadEventTarget, __func__,
         [self, outPromise](const FileDescriptor& fd) {
           self->OnFD(fd);
           if (!fd.IsValid()) {
             outPromise->Reject(NS_ERROR_ABORT, __func__);
             return;
           }
-          outPromise->Resolve(
-              RequestOrStream::CreateFromRequest(self->mJarChannel), __func__);
+          outPromise->Resolve(RequestOrStream::CreateFromRequest(
+                                  WrapNotNull(self->mJarChannel)),
+                              __func__);
         },
         [self, outPromise](const mozilla::ipc::ResponseRejectReason) {
           self->OnFD(FileDescriptor());
           outPromise->Reject(NS_ERROR_FILE_ACCESS_DENIED, __func__);
         });
   } else {
     gNeckoChild->SendGetExtensionStream(mURI)->Then(
         mMainThreadEventTarget, __func__,
@@ -263,18 +264,19 @@ GetAsyncPromiseOrReason ExtensionStreamG
           if (!aStream) {
             // NewStream may have failed in the parent process, and in that case
             // it would send us a null stream (See
             // NeckoParent::RecvGetExtensionStream).
             outPromise->Reject(NS_ERROR_ABORT, __func__);
             return;
           }
 
-          outPromise->Resolve(RequestOrStream::CreateFromInputStream(aStream),
-                              __func__);
+          outPromise->Resolve(
+              RequestOrStream::CreateFromInputStream(WrapNotNull(aStream)),
+              __func__);
         },
         [self, outPromise](const mozilla::ipc::ResponseRejectReason) {
           outPromise->Reject(NS_ERROR_FILE_ACCESS_DENIED, __func__);
         });
   }
 
   RefPtr<nsBaseChannel::GetAsyncPromise> promise(outPromise);
   return promise.forget();
--- a/netwerk/protocol/res/PageThumbProtocolHandler.cpp
+++ b/netwerk/protocol/res/PageThumbProtocolHandler.cpp
@@ -106,18 +106,19 @@ GetAsyncPromiseOrReason PageThumbStreamG
       [self, outPromise](const RefPtr<nsIInputStream>& aStream) {
         if (!aStream) {
           // NewStream may have failed in the parent process, and in that case
           // it would send us a null stream (See
           // NeckoParent::RecvGetPageThumbStream).
           outPromise->Reject(NS_ERROR_ABORT, __func__);
           return;
         }
-        outPromise->Resolve(RequestOrStream::CreateFromInputStream(aStream),
-                            __func__);
+        outPromise->Resolve(
+            RequestOrStream::CreateFromInputStream(WrapNotNull(aStream)),
+            __func__);
       },
       [self, outPromise](const mozilla::ipc::ResponseRejectReason) {
         // The parent didn't send us back a stream.
         CancelRequest(self->mListener, self->mChannel,
                       NS_ERROR_FILE_ACCESS_DENIED);
         outPromise->Reject(NS_ERROR_FILE_ACCESS_DENIED, __func__);
       });
 
--- a/toolkit/components/places/nsAnnoProtocolHandler.cpp
+++ b/toolkit/components/places/nsAnnoProtocolHandler.cpp
@@ -145,18 +145,19 @@ class faviconAsyncLoader : public AsyncS
         /*RefPtr<nsInputStreamPump> pump;
         rv = nsInputStreamPump::Create(getter_AddRefs(pump), stream, 0, 0, true,
                                        target);
         MOZ_ASSERT(NS_SUCCEEDED(rv));
         if (NS_SUCCEEDED(rv)) {
           return pump->AsyncRead(mListener);
         }*/
         MOZ_ASSERT(!mGetAsyncPromiseHolder.IsEmpty());
-        mGetAsyncPromiseHolder.Resolve(
-            RequestOrStream::CreateFromInputStream(std::move(stream)), __func__);
+        mGetAsyncPromiseHolder.Resolve(RequestOrStream::CreateFromInputStream(
+                                           WrapNotNull(std::move(stream))),
+                                       __func__);
         return NS_OK;
       }
     }
 
     // Fallback to the default favicon.
     // we should pass the loadInfo of the original channel along
     // to the new channel. Note that mChannel can not be null,
     // constructor checks that.
@@ -171,18 +172,19 @@ class faviconAsyncLoader : public AsyncS
     }
     rv = newChannel->AsyncOpen(mListener);
     if (NS_FAILED(rv)) {
       // TODO should this call mListener->OnStartRequest/OnStopRequest too?
       MOZ_ASSERT(!mGetAsyncPromiseHolder.IsEmpty());
       mGetAsyncPromiseHolder.Reject(rv, __func__);
     } else {
       MOZ_ASSERT(!mGetAsyncPromiseHolder.IsEmpty());
-      mGetAsyncPromiseHolder.Resolve(
-          RequestOrStream::CreateFromRequest(std::move(newChannel)), __func__);
+      mGetAsyncPromiseHolder.Resolve(RequestOrStream::CreateFromRequest(
+                                         WrapNotNull(std::move(newChannel))),
+                                     __func__);
     }
 
     return rv;
   }
 
  protected:
   virtual ~faviconAsyncLoader() = default;
 
@@ -298,18 +300,19 @@ nsresult nsAnnoProtocolHandler::NewFavic
 
           rv = chan->AsyncOpen(listener);
           NS_ENSURE_SUCCESS(rv, Err(rv));
 
           // Request an input stream for this moz-extension URI
           RefPtr<nsBaseChannel::GetAsyncPromise::Private> fallbackPromise =
               new nsBaseChannel::GetAsyncPromise::Private(__func__);
 
-          fallbackPromise->Resolve(RequestOrStream::CreateFromRequest(std::move(chan)),
-                                   __func__);
+          fallbackPromise->Resolve(
+              RequestOrStream::CreateFromRequest(WrapNotNull(std::move(chan))),
+              __func__);
 
           RefPtr<nsBaseChannel::GetAsyncPromise> promise(fallbackPromise);
           return promise.forget();
         };
 
         // Now we go ahead and get our data asynchronously for the favicon.
         // Ignore the ref part of the URI before querying the database because
         // we may have added a size fragment for rendering purposes.