Bug 1602318 - Remove nsILoadContext from DocumentLoadListener. r=nika,necko-reviewers,dragana
authorMatt Woodrow <mwoodrow@mozilla.com>
Sun, 26 Apr 2020 00:50:52 +0000
changeset 526102 bd6752b9c333739633d64167630fa338734cfb26
parent 526101 7e2902385a6e05baf46e7f8739299203ff5fb7f5
child 526103 54aff65a2d4f4569704f0f91d80f6abce7e31e44
push id37350
push usernbeleuzu@mozilla.com
push dateSun, 26 Apr 2020 09:43:12 +0000
treeherdermozilla-central@21659f178a12 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika, necko-reviewers, dragana
bugs1602318
milestone77.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 1602318 - Remove nsILoadContext from DocumentLoadListener. r=nika,necko-reviewers,dragana Differential Revision: https://phabricator.services.mozilla.com/D70618
docshell/base/BrowsingContext.cpp
netwerk/ipc/DocumentChannelChild.cpp
netwerk/ipc/DocumentChannelParent.cpp
netwerk/ipc/DocumentChannelParent.h
netwerk/ipc/DocumentLoadListener.cpp
netwerk/ipc/DocumentLoadListener.h
netwerk/ipc/NeckoParent.cpp
netwerk/ipc/NeckoParent.h
netwerk/ipc/PNecko.ipdl
netwerk/ipc/ParentProcessDocumentChannel.cpp
--- a/docshell/base/BrowsingContext.cpp
+++ b/docshell/base/BrowsingContext.cpp
@@ -1264,16 +1264,17 @@ void BrowsingContext::AssertOriginAttrib
   } else {
     MOZ_DIAGNOSTIC_ASSERT(mOriginAttributes.mPrivateBrowsingId ==
                           mPrivateBrowsingId);
   }
 }
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BrowsingContext)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
+  NS_INTERFACE_MAP_ENTRY(nsILoadContext)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(BrowsingContext)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(BrowsingContext)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(BrowsingContext)
 
--- a/netwerk/ipc/DocumentChannelChild.cpp
+++ b/netwerk/ipc/DocumentChannelChild.cpp
@@ -92,33 +92,23 @@ DocumentChannelChild::AsyncOpen(nsIStrea
     ipcClientInfo.emplace(mInitialClientInfo.ref().ToIPC());
   }
   args.initialClientInfo() = ipcClientInfo;
 
   if (mTiming) {
     args.timing() = Some(mTiming);
   }
 
-  nsCOMPtr<nsIBrowserChild> iBrowserChild;
-  NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup,
-                                NS_GET_TEMPLATE_IID(nsIBrowserChild),
-                                getter_AddRefs(iBrowserChild));
-  BrowserChild* browserChild = static_cast<BrowserChild*>(iBrowserChild.get());
-  if (MissingRequiredBrowserChild(browserChild, "documentchannel")) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
   args.hasValidTransientUserAction() =
       GetDocShell()
           ->GetBrowsingContext()
           ->HasValidTransientUserGestureActivation();
 
   gNeckoChild->SendPDocumentChannelConstructor(
-      this, browserChild, GetDocShell()->GetBrowsingContext(),
-      IPC::SerializedLoadContext(this), args);
+      this, GetDocShell()->GetBrowsingContext(), args);
 
   mIsPending = true;
   mWasOpened = true;
   mListener = listener;
 
   return NS_OK;
 }
 
--- a/netwerk/ipc/DocumentChannelParent.cpp
+++ b/netwerk/ipc/DocumentChannelParent.cpp
@@ -13,23 +13,23 @@
 extern mozilla::LazyLogModule gDocumentChannelLog;
 #define LOG(fmt) MOZ_LOG(gDocumentChannelLog, mozilla::LogLevel::Verbose, fmt)
 
 using namespace mozilla::dom;
 
 namespace mozilla {
 namespace net {
 
-DocumentChannelParent::DocumentChannelParent(CanonicalBrowsingContext* aContext,
-                                             nsILoadContext* aLoadContext) {
+DocumentChannelParent::DocumentChannelParent(
+    CanonicalBrowsingContext* aContext) {
   LOG(("DocumentChannelParent ctor [this=%p]", this));
   // Sometime we can get this called without a BrowsingContext, so that we have
   // an actor to call SendFailedAsyncOpen on.
   if (aContext) {
-    mParent = new DocumentLoadListener(aContext, aLoadContext, this);
+    mParent = new DocumentLoadListener(aContext, this);
   }
 }
 
 DocumentChannelParent::~DocumentChannelParent() {
   LOG(("DocumentChannelParent dtor [this=%p]", this));
 }
 
 bool DocumentChannelParent::Init(const DocumentChannelCreationArgs& aArgs) {
--- a/netwerk/ipc/DocumentChannelParent.h
+++ b/netwerk/ipc/DocumentChannelParent.h
@@ -21,18 +21,17 @@ namespace net {
  * to DocumentChannelChild, the nsIChannel implementation owned by a content
  * process docshell.
  */
 class DocumentChannelParent final : public ADocumentChannelBridge,
                                     public PDocumentChannelParent {
  public:
   NS_INLINE_DECL_REFCOUNTING(DocumentChannelParent, override);
 
-  explicit DocumentChannelParent(dom::CanonicalBrowsingContext* aContext,
-                                 nsILoadContext* aLoadContext);
+  explicit DocumentChannelParent(dom::CanonicalBrowsingContext* aContext);
 
   bool Init(const DocumentChannelCreationArgs& aArgs);
 
   // PDocumentChannelParent
   bool RecvCancel(const nsresult& aStatus) {
     if (mParent) {
       mParent->Cancel(aStatus);
     }
--- a/netwerk/ipc/DocumentLoadListener.cpp
+++ b/netwerk/ipc/DocumentLoadListener.cpp
@@ -235,22 +235,21 @@ NS_INTERFACE_MAP_BEGIN(DocumentLoadListe
   NS_INTERFACE_MAP_ENTRY(nsIParentChannel)
   NS_INTERFACE_MAP_ENTRY(nsIAsyncVerifyRedirectReadyCallback)
   NS_INTERFACE_MAP_ENTRY(nsIChannelEventSink)
   NS_INTERFACE_MAP_ENTRY(nsIMultiPartChannelListener)
   NS_INTERFACE_MAP_ENTRY_CONCRETE(DocumentLoadListener)
 NS_INTERFACE_MAP_END
 
 DocumentLoadListener::DocumentLoadListener(
-    CanonicalBrowsingContext* aBrowsingContext, nsILoadContext* aLoadContext,
-    ADocumentChannelBridge* aBridge)
-    : mDocumentChannelBridge(aBridge), mLoadContext(aLoadContext) {
+    CanonicalBrowsingContext* aBrowsingContext, ADocumentChannelBridge* aBridge)
+    : mDocumentChannelBridge(aBridge) {
   LOG(("DocumentLoadListener ctor [this=%p]", this));
   mParentChannelListener = new ParentChannelListener(
-      this, aBrowsingContext, aLoadContext->UsePrivateBrowsing());
+      this, aBrowsingContext, aBrowsingContext->UsePrivateBrowsing());
 }
 
 DocumentLoadListener::~DocumentLoadListener() {
   LOG(("DocumentLoadListener dtor [this=%p]", this));
 }
 
 net::LastVisitInfo DocumentLoadListener::LastVisitInfo() const {
   nsCOMPtr<nsIURI> previousURI;
@@ -295,17 +294,17 @@ already_AddRefed<LoadInfo> DocumentLoadL
   RefPtr<LoadInfo> loadInfo;
   if (aBrowsingContext->GetParent()) {
     // Build LoadInfo for TYPE_SUBDOCUMENT
     loadInfo = new LoadInfo(aBrowsingContext, aLoadState->TriggeringPrincipal(),
                             aOuterWindowId, securityFlags, sandboxFlags);
   } else {
     // Build LoadInfo for TYPE_DOCUMENT
     OriginAttributes attrs;
-    mLoadContext->GetOriginAttributes(attrs);
+    aBrowsingContext->GetOriginAttributes(attrs);
     loadInfo = new LoadInfo(aBrowsingContext, aLoadState->TriggeringPrincipal(),
                             attrs, aOuterWindowId, securityFlags, sandboxFlags);
   }
 
   loadInfo->SetHasValidUserGestureActivation(
       aLoadState->HasValidUserGestureActivation());
 
   return loadInfo.forget();
@@ -355,17 +354,17 @@ bool DocumentLoadListener::Open(
     nsDOMNavigationTiming* aTiming, Maybe<ClientInfo>&& aInfo,
     uint64_t aOuterWindowId, bool aHasGesture, nsresult* aRv) {
   LOG(("DocumentLoadListener Open [this=%p, uri=%s]", this,
        aLoadState->URI()->GetSpecOrDefault().get()));
   RefPtr<CanonicalBrowsingContext> browsingContext =
       mParentChannelListener->GetBrowsingContext();
 
   OriginAttributes attrs;
-  mLoadContext->GetOriginAttributes(attrs);
+  browsingContext->GetOriginAttributes(attrs);
 
   RefPtr<WindowGlobalParent> embedderWGP =
       browsingContext->GetParentWindowGlobal();
   if (browsingContext->GetParent() && !embedderWGP) {
     // this is a race, bug 1331295
     NS_WARNING(
         "We don't have an embedder WindowGlobalParent, probably because of a "
         "race");
@@ -1452,20 +1451,20 @@ NS_IMETHODIMP
 DocumentLoadListener::SetParentListener(
     mozilla::net::ParentChannelListener* listener) {
   // We don't need this (do we?)
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentLoadListener::GetInterface(const nsIID& aIID, void** result) {
-  // Only support nsILoadContext if child channel's callbacks did too
-  if (aIID.Equals(NS_GET_IID(nsILoadContext)) && mLoadContext) {
-    nsCOMPtr<nsILoadContext> copy = mLoadContext;
-    copy.forget(result);
+  RefPtr<CanonicalBrowsingContext> browsingContext =
+      mParentChannelListener->GetBrowsingContext();
+  if (aIID.Equals(NS_GET_IID(nsILoadContext)) && browsingContext) {
+    browsingContext.forget(result);
     return NS_OK;
   }
 
   return QueryInterface(aIID, result);
 }
 
 // Rather than forwarding all these nsIParentChannel functions to the child,
 // we cache a list of them, and then ask the 'real' channel to forward them
--- a/netwerk/ipc/DocumentLoadListener.h
+++ b/netwerk/ipc/DocumentLoadListener.h
@@ -86,17 +86,16 @@ class LoadInfo;
 class DocumentLoadListener : public nsIInterfaceRequestor,
                              public nsIAsyncVerifyRedirectReadyCallback,
                              public nsIParentChannel,
                              public nsIChannelEventSink,
                              public HttpChannelSecurityWarningReporter,
                              public nsIMultiPartChannelListener {
  public:
   explicit DocumentLoadListener(dom::CanonicalBrowsingContext* aBrowsingContext,
-                                nsILoadContext* aLoadContext,
                                 ADocumentChannelBridge* aBridge);
 
   // Creates the channel, and then calls AsyncOpen on it.
   bool Open(nsDocShellLoadState* aLoadState, nsLoadFlags aLoadFlags,
             uint32_t aCacheKey, const uint64_t& aChannelId,
             const TimeStamp& aAsyncOpenTime, nsDOMNavigationTiming* aTiming,
             Maybe<dom::ClientInfo>&& aInfo, uint64_t aOuterWindowId,
             bool aHasGesture, nsresult* aRv);
@@ -329,18 +328,16 @@ class DocumentLoadListener : public nsII
   RefPtr<ParentChannelListener> mParentChannelListener;
 
   // The bridge to the nsIChannel in the originating docshell.
   // This reference forms a cycle with the bridge, and we expect
   // the bridge to call DisonnectDocumentChannelBridge when it
   // shuts down to break this.
   RefPtr<ADocumentChannelBridge> mDocumentChannelBridge;
 
-  nsCOMPtr<nsILoadContext> mLoadContext;
-
   // The original URI of the current channel. If there are redirects,
   // then the value on the channel gets overwritten with the original
   // URI of the first channel in the redirect chain, so we cache the
   // value we need here.
   nsCOMPtr<nsIURI> mChannelCreationURI;
 
   // The original navigation timing information containing various timestamps
   // such as when the original load started.
--- a/netwerk/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -395,53 +395,33 @@ mozilla::ipc::IPCResult NeckoParent::Rec
   if (!p->Init(aOpenArgs)) {
     return IPC_FAIL_NO_REASON(this);
   }
   return IPC_OK();
 }
 
 already_AddRefed<PDocumentChannelParent>
 NeckoParent::AllocPDocumentChannelParent(
-    PBrowserParent* aBrowser, const MaybeDiscarded<BrowsingContext>& aContext,
-    const SerializedLoadContext& aSerialized,
+    const MaybeDiscarded<BrowsingContext>& aContext,
     const DocumentChannelCreationArgs& args) {
   // We still create the actor even if the BrowsingContext isn't available,
   // so that we can send the reject message using it from
   // RecvPDocumentChannelConstructor
   CanonicalBrowsingContext* context = nullptr;
   if (!aContext.IsNullOrDiscarded()) {
     context = aContext.get_canonical();
   }
 
-  nsCOMPtr<nsIPrincipal> requestingPrincipal;
-  // We only have the requesting principal in case of TYPE_SUBDOCUMENT.
-  // If we don't have an embedder window global, then it is probably a race and
-  // we will deal with that later in the code path.
-  if (context && !aContext.IsDiscarded() && context->GetParent()) {
-    if (RefPtr<WindowGlobalParent> embedderWGP =
-            context->GetParentWindowGlobal()) {
-      requestingPrincipal = embedderWGP->DocumentPrincipal();
-    }
-  }
-
-  nsCOMPtr<nsILoadContext> loadContext;
-  const char* error = CreateChannelLoadContext(
-      aBrowser, Manager(), aSerialized, requestingPrincipal, loadContext);
-  if (error) {
-    return nullptr;
-  }
-  RefPtr<DocumentChannelParent> p =
-      new DocumentChannelParent(context, loadContext);
+  RefPtr<DocumentChannelParent> p = new DocumentChannelParent(context);
   return p.forget();
 }
 
 mozilla::ipc::IPCResult NeckoParent::RecvPDocumentChannelConstructor(
-    PDocumentChannelParent* aActor, PBrowserParent* aBrowser,
+    PDocumentChannelParent* aActor,
     const MaybeDiscarded<BrowsingContext>& aContext,
-    const SerializedLoadContext& aSerialized,
     const DocumentChannelCreationArgs& aArgs) {
   DocumentChannelParent* p = static_cast<DocumentChannelParent*>(aActor);
 
   if (aContext.IsNullOrDiscarded()) {
     Unused << p->SendFailedAsyncOpen(NS_ERROR_FAILURE);
     return IPC_OK();
   }
 
--- a/netwerk/ipc/NeckoParent.h
+++ b/netwerk/ipc/NeckoParent.h
@@ -121,24 +121,21 @@ class NeckoParent : public PNeckoParent 
   PWebSocketParent* AllocPWebSocketParent(
       const PBrowserOrId& browser, const SerializedLoadContext& aSerialized,
       const uint32_t& aSerial);
   bool DeallocPWebSocketParent(PWebSocketParent*);
   PTCPSocketParent* AllocPTCPSocketParent(const nsString& host,
                                           const uint16_t& port);
 
   already_AddRefed<PDocumentChannelParent> AllocPDocumentChannelParent(
-      PBrowserParent* aBrowser,
       const dom::MaybeDiscarded<dom::BrowsingContext>& aContext,
-      const SerializedLoadContext& aSerialized,
       const DocumentChannelCreationArgs& args);
   virtual mozilla::ipc::IPCResult RecvPDocumentChannelConstructor(
-      PDocumentChannelParent* aActor, PBrowserParent* aBrowser,
+      PDocumentChannelParent* aActor,
       const dom::MaybeDiscarded<dom::BrowsingContext>& aContext,
-      const SerializedLoadContext& aSerialized,
       const DocumentChannelCreationArgs& aArgs) override;
   bool DeallocPDocumentChannelParent(PDocumentChannelParent* channel);
 
   bool DeallocPTCPSocketParent(PTCPSocketParent*);
   PTCPServerSocketParent* AllocPTCPServerSocketParent(
       const uint16_t& aLocalPort, const uint16_t& aBacklog,
       const bool& aUseArrayBuffers);
   virtual mozilla::ipc::IPCResult RecvPTCPServerSocketConstructor(
--- a/netwerk/ipc/PNecko.ipdl
+++ b/netwerk/ipc/PNecko.ipdl
@@ -83,19 +83,17 @@ parent:
   async PWebSocket(PBrowserOrId browser, SerializedLoadContext loadContext,
                    uint32_t aSerialID);
   async PTCPServerSocket(uint16_t localPort, uint16_t backlog, bool useArrayBuffers);
   async PUDPSocket(nsIPrincipal principal, nsCString filter);
 
   async PDNSRequest(nsCString hostName, nsCString trrServer, uint16_t type,
                     OriginAttributes originAttributes, uint32_t flags);
 
-  async PDocumentChannel(PBrowser browser,
-                         MaybeDiscardedBrowsingContext browsingContext,
-                         SerializedLoadContext loadContext,
+  async PDocumentChannel(MaybeDiscardedBrowsingContext browsingContext,
                          DocumentChannelCreationArgs args);
 
   async PWebSocketEventListener(uint64_t aInnerWindowID);
 
   /* Predictor Methods */
   async PredPredict(nsIURI targetURI, nsIURI sourceURI,
                     uint32_t reason, OriginAttributes originAttributes,
                     bool hasVerifier);
--- a/netwerk/ipc/ParentProcessDocumentChannel.cpp
+++ b/netwerk/ipc/ParentProcessDocumentChannel.cpp
@@ -102,21 +102,18 @@ ParentProcessDocumentChannel::OnRedirect
   mPromise.ResolveIfExists(aResult, __func__);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP ParentProcessDocumentChannel::AsyncOpen(
     nsIStreamListener* aListener) {
   LOG(("ParentProcessDocumentChannel AsyncOpen [this=%p]", this));
-  nsCOMPtr<nsILoadContext> loadContext;
-  NS_QueryNotificationCallbacks(this, loadContext);
-
   mDocumentLoadListener = new DocumentLoadListener(
-      GetDocShell()->GetBrowsingContext()->Canonical(), loadContext, this);
+      GetDocShell()->GetBrowsingContext()->Canonical(), this);
   LOG(("Created PPDocumentChannel with listener=%p",
        mDocumentLoadListener.get()));
 
   // Add observers.
   nsCOMPtr<nsIObserverService> observerService =
       mozilla::services::GetObserverService();
   if (observerService) {
     MOZ_ALWAYS_SUCCEEDS(observerService->AddObserver(
@@ -197,9 +194,9 @@ ParentProcessDocumentChannel::Observe(ns
   }
 
   return NS_OK;
 }
 
 }  // namespace net
 }  // namespace mozilla
 
-#undef LOG
\ No newline at end of file
+#undef LOG