Bug 1625366 - Remove CSPViolation from DocumentChannel. r=jya
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 10 Apr 2020 22:16:43 +0000
changeset 523454 0c1282c8e9e912eda894c7bd6c0e8ba906658640
parent 523453 02bc984b5cd3275d122fe4b531a67e89c093d845
child 523455 a09288e4e3c6cfacfac24202177de4226d18ad1d
push id37302
push usercbrindusan@mozilla.com
push dateSat, 11 Apr 2020 09:34:41 +0000
treeherdermozilla-central@06ee15775ba8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1625366
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 1625366 - Remove CSPViolation from DocumentChannel. r=jya Differential Revision: https://phabricator.services.mozilla.com/D69912
netwerk/ipc/ADocumentChannelBridge.h
netwerk/ipc/DocumentChannelChild.cpp
netwerk/ipc/DocumentChannelChild.h
netwerk/ipc/DocumentChannelParent.cpp
netwerk/ipc/DocumentChannelParent.h
netwerk/ipc/PDocumentChannel.ipdl
--- a/netwerk/ipc/ADocumentChannelBridge.h
+++ b/netwerk/ipc/ADocumentChannelBridge.h
@@ -33,28 +33,16 @@ class ADocumentChannelBridge {
   // We do this so we can remove using NS_BINDING_RETARGETED, but still have
   // the channel not be in an error state.
   virtual void DisconnectChildListeners(nsresult aStatus,
                                         nsresult aLoadGroupStatus) = 0;
 
   // Delete the bridge, and drop any refs to the DocumentLoadListener
   virtual void Delete() = 0;
 
-  // Report a CSP violation event in the originating process, using
-  // nsCSPContext::AsyncReportViolation.
-  // aIsCspToInherit is true if aContext is the CSP to inherit (from
-  // the nsDocShellLoadState), which is used to determine the right
-  // loading Document when deserializing aContext. This should no longer be
-  // necessary after bug 1625366.
-  virtual void CSPViolation(
-      nsCSPContext* aContext, bool aIsCspToInherit, nsIURI* aBlockedURI,
-      nsCSPContext::BlockedContentSource aBlockedContentSource,
-      nsIURI* aOriginalURI, const nsAString& aViolatedDirective,
-      uint32_t aViolatedPolicyIndex, const nsAString& aObserverSubject) = 0;
-
   // Initate a switch from the DocumentChannel to the protocol-specific
   // real channel.
   virtual RefPtr<PDocumentChannelParent::RedirectToRealChannelPromise>
   RedirectToRealChannel(
       nsTArray<ipc::Endpoint<extensions::PStreamFilterParent>>&&
           aStreamFilterEndpoints,
       uint32_t aRedirectFlags, uint32_t aLoadFlags) = 0;
 
--- a/netwerk/ipc/DocumentChannelChild.cpp
+++ b/netwerk/ipc/DocumentChannelChild.cpp
@@ -360,69 +360,16 @@ DocumentChannelChild::OnRedirectVerifyCa
   // IPDL holds the last reference.  Don't rely on |this| existing after here!
   if (CanSend()) {
     Send__delete__(this);
   }
 
   return NS_OK;
 }
 
-mozilla::ipc::IPCResult DocumentChannelChild::RecvCSPViolation(
-    const CSPInfo& aCSP, bool aIsCspToInherit, nsIURI* aBlockedURI,
-    uint32_t aBlockedContentSource, nsIURI* aOriginalURI,
-    const nsAString& aViolatedDirective, uint32_t aViolatedPolicyIndex,
-    const nsAString& aObserverSubject) {
-  if (aBlockedContentSource > nsCSPContext::BlockedContentSource::eSelf) {
-    return IPC_FAIL(this, "Invalid BlockedContentSource value");
-  }
-  nsCSPContext::BlockedContentSource blockedContentSource =
-      static_cast<nsCSPContext::BlockedContentSource>(aBlockedContentSource);
-
-  RefPtr<dom::Document> cspLoadingDocument;
-  if (aIsCspToInherit) {
-    // If this is the cspToInherit from the loadstate, then it should match
-    // the csp from the load state. Copy across the loading context from
-    // that policy.
-    nsCOMPtr<nsIContentSecurityPolicy> policy = mLoadState->Csp();
-    MOZ_ASSERT(policy,
-               "How is this a CSP to inherit violation if we didn't have a "
-               "policy to inherit!");
-    nsWeakPtr ctx =
-        static_cast<nsCSPContext*>(policy.get())->GetLoadingContext();
-    cspLoadingDocument = do_QueryReferent(ctx);
-  } else {
-    // Otherwise we're the normal csp (preload csp is never used for
-    // Documents), so the loading context is that of our embedder
-    // Element. Note that this won't necessarily work with fission
-    // enabled, since the embedder Element might be OOP, bug 1625366
-    // is filed to fix this.
-    nsCOMPtr<nsINode> loadingContext;
-    RefPtr<BrowsingContext> frameBrowsingContext =
-        GetDocShell()->GetBrowsingContext();
-    if (frameBrowsingContext) {
-      loadingContext = frameBrowsingContext->GetEmbedderElement();
-      if (loadingContext) {
-        cspLoadingDocument = loadingContext->OwnerDoc();
-      }
-    }
-  }
-  nsCOMPtr<nsIContentSecurityPolicy> csp =
-      CSPInfoToCSP(aCSP, cspLoadingDocument);
-  if (!csp) {
-    return IPC_OK();
-  }
-
-  nsCSPContext::AsyncReportViolation(
-      static_cast<nsCSPContext*>(csp.get()), nullptr, nullptr, aBlockedURI,
-      blockedContentSource, aOriginalURI, aViolatedDirective,
-      aViolatedPolicyIndex, aObserverSubject, nsString(), nsString(), 0, 0);
-
-  return IPC_OK();
-}
-
 NS_IMETHODIMP
 DocumentChannelChild::Cancel(nsresult aStatusCode) {
   if (mCanceled) {
     return NS_OK;
   }
 
   mCanceled = true;
   if (CanSend()) {
--- a/netwerk/ipc/DocumentChannelChild.h
+++ b/netwerk/ipc/DocumentChannelChild.h
@@ -42,22 +42,16 @@ class DocumentChannelChild final : publi
 
   mozilla::ipc::IPCResult RecvDeleteSelf();
 
   mozilla::ipc::IPCResult RecvRedirectToRealChannel(
       RedirectToRealChannelArgs&& aArgs,
       nsTArray<Endpoint<extensions::PStreamFilterParent>>&& aEndpoints,
       RedirectToRealChannelResolver&& aResolve);
 
-  mozilla::ipc::IPCResult RecvCSPViolation(
-      const CSPInfo& aCSP, bool aIsCspToInherit, nsIURI* aBlockedURI,
-      uint32_t aBlockedContentSource, nsIURI* aOriginalURI,
-      const nsAString& aViolatedDirective, uint32_t aViolatedPolicyIndex,
-      const nsAString& aObserverSubject);
-
  private:
   void ShutdownListeners(nsresult aStatusCode);
 
   ~DocumentChannelChild();
 
   nsCOMPtr<nsIChannel> mRedirectChannel;
 
   RedirectToRealChannelResolver mRedirectResolver;
--- a/netwerk/ipc/DocumentChannelParent.cpp
+++ b/netwerk/ipc/DocumentChannelParent.cpp
@@ -71,25 +71,12 @@ DocumentChannelParent::RedirectToRealCha
     return PDocumentChannelParent::RedirectToRealChannelPromise::
         CreateAndReject(ResponseRejectReason::ChannelClosed, __func__);
   }
   RedirectToRealChannelArgs args;
   mParent->SerializeRedirectData(args, false, aRedirectFlags, aLoadFlags);
   return SendRedirectToRealChannel(args, std::move(aStreamFilterEndpoints));
 }
 
-void DocumentChannelParent::CSPViolation(
-    nsCSPContext* aContext, bool aIsCspToInherit, nsIURI* aBlockedURI,
-    nsCSPContext::BlockedContentSource aBlockedContentSource,
-    nsIURI* aOriginalURI, const nsAString& aViolatedDirective,
-    uint32_t aViolatedPolicyIndex, const nsAString& aObserverSubject) {
-  CSPInfo cspInfo;
-  Unused << NS_WARN_IF(NS_FAILED(CSPToCSPInfo(aContext, &cspInfo)));
-  Unused << SendCSPViolation(
-      cspInfo, aIsCspToInherit, aBlockedURI, aBlockedContentSource,
-      aOriginalURI, PromiseFlatString(aViolatedDirective), aViolatedPolicyIndex,
-      PromiseFlatString(aObserverSubject));
-}
-
 }  // namespace net
 }  // namespace mozilla
 
 #undef LOG
--- a/netwerk/ipc/DocumentChannelParent.h
+++ b/netwerk/ipc/DocumentChannelParent.h
@@ -56,23 +56,16 @@ class DocumentChannelParent final : publ
   }
 
   void Delete() override {
     if (CanSend()) {
       Unused << SendDeleteSelf();
     }
   }
 
-  void CSPViolation(nsCSPContext* aContext, bool aIsCspToInherit,
-                    nsIURI* aBlockedURI,
-                    nsCSPContext::BlockedContentSource aBlockedContentSource,
-                    nsIURI* aOriginalURI, const nsAString& aViolatedDirective,
-                    uint32_t aViolatedPolicyIndex,
-                    const nsAString& aObserverSubject) override;
-
   virtual ProcessId OtherPid() const override { return IProtocol::OtherPid(); }
 
   RefPtr<PDocumentChannelParent::RedirectToRealChannelPromise>
   RedirectToRealChannel(
       nsTArray<ipc::Endpoint<extensions::PStreamFilterParent>>&&
           aStreamFilterEndpoints,
       uint32_t aRedirectFlags, uint32_t aLoadFlags) override;
 
--- a/netwerk/ipc/PDocumentChannel.ipdl
+++ b/netwerk/ipc/PDocumentChannel.ipdl
@@ -48,21 +48,16 @@ child:
   // channel not be in an error state.
   async DisconnectChildListeners(nsresult aStatus, nsresult aLoadGroupReason);
 
   // Triggers replacing this DocumentChannel with a 'real' channel (like PHttpChannel),
   // and notifies the listener via a redirect to the new channel.
   async RedirectToRealChannel(RedirectToRealChannelArgs args, Endpoint<PStreamFilterParent>[] aEndpoint)
       returns (nsresult rv);
 
-  async CSPViolation(CSPInfo aCSP, bool aIsCspToInherit,
-    nsIURI aBlockedURI, uint32_t aBlockedContentSource,
-    nsIURI aOriginalURI, nsString aViolatedDirective, uint32_t aViolatedPolicyIndex,
-    nsString aObserverSubject);
-
   // Tell child to delete channel (all IPDL deletes must be done from child to
   // avoid races: see bug 591708).
   async DeleteSelf();
 
 };
 
 } // namespace net
 } // namespace mozilla