Bug 1420680: Remove the mechanism to buffer CSP violations. r?bz draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 23 Mar 2018 16:11:52 +0100
changeset 775946 4633f292922f8cc5dff2709811317e82c6b5c731
parent 775945 ef0b29b7af9a177abea919fcb40a692b8d79b4af
child 775947 a12a879089ce5722f6af658fbcd8c0a9294fc173
push id104762
push userbmo:emilio@crisal.io
push dateMon, 02 Apr 2018 03:56:19 +0000
reviewersbz
bugs1420680
milestone61.0a1
Bug 1420680: Remove the mechanism to buffer CSP violations. r?bz With the previous patch it's unused. MozReview-Commit-ID: 4EKufeNu0Jz
dom/base/nsDocument.cpp
dom/base/nsIDocument.h
dom/security/nsCSPContext.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1424,17 +1424,16 @@ nsIDocument::nsIDocument()
     mFontFaceSetDirty(true),
     mGetUserFontSetCalled(false),
     mDidFireDOMContentLoaded(true),
     mHasScrollLinkedEffect(false),
     mFrameRequestCallbacksScheduled(false),
     mIsTopLevelContentDocument(false),
     mIsContentDocument(false),
     mDidCallBeginLoad(false),
-    mBufferingCSPViolations(false),
     mAllowPaymentRequest(false),
     mEncodingMenuDisabled(false),
     mIsShadowDOMEnabled(false),
     mIsSVGGlyphsDocument(false),
     mAllowUnsafeHTML(false),
     mInDestructor(false),
     mIsGoingAway(false),
     mInXBLUpdate(false),
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -1105,64 +1105,16 @@ public:
    * @see nsSandboxFlags.h for the possible flags
    */
   void SetSandboxFlags(uint32_t sandboxFlags)
   {
     mSandboxFlags = sandboxFlags;
   }
 
   /**
-   * After calling this function, any CSP violation reports will be buffered up
-   * by the document (by calling BufferCSPViolation) instead of being sent
-   * immediately.
-   *
-   * This facility is used by the user font cache, which wants to pre-emptively
-   * check whether a given font load would violate CSP directives, and so
-   * shouldn't immediately send the report.
-   */
-  void StartBufferingCSPViolations()
-  {
-    MOZ_ASSERT(!mBufferingCSPViolations);
-    mBufferingCSPViolations = true;
-  }
-
-  /**
-   * Stops buffering CSP violation reports, and stores any buffered reports in
-   * aResult.
-   */
-  void StopBufferingCSPViolations(nsTArray<nsCOMPtr<nsIRunnable>>& aResult)
-  {
-    MOZ_ASSERT(mBufferingCSPViolations);
-    mBufferingCSPViolations = false;
-
-    aResult.SwapElements(mBufferedCSPViolations);
-    mBufferedCSPViolations.Clear();
-  }
-
-  /**
-   * Returns whether we are currently buffering CSP violation reports.
-   */
-  bool ShouldBufferCSPViolations() const
-  {
-    return mBufferingCSPViolations;
-  }
-
-  /**
-   * Called when a CSP violation is encountered that would generate a report
-   * while buffering is enabled.
-   */
-  void BufferCSPViolation(nsIRunnable* aReportingRunnable)
-  {
-    MOZ_ASSERT(mBufferingCSPViolations);
-
-    // Dropping the CSP violation report seems preferable to OOMing.
-    mBufferedCSPViolations.AppendElement(aReportingRunnable, mozilla::fallible);
-  }
-
-  /**
    * Called when the document was decoded as UTF-8 and decoder encountered no
    * errors.
    */
   void DisableEncodingMenu()
   {
     mEncodingMenuDisabled = true;
   }
 
@@ -4022,20 +3974,16 @@ protected:
 
   bool mIsTopLevelContentDocument : 1;
 
   bool mIsContentDocument : 1;
 
   // True if we have called BeginLoad and are expecting a paired EndLoad call.
   bool mDidCallBeginLoad : 1;
 
-  // True if any CSP violation reports for this doucment will be buffered in
-  // mBufferedCSPViolations instead of being sent immediately.
-  bool mBufferingCSPViolations : 1;
-
   // True if the document is allowed to use PaymentRequest.
   bool mAllowPaymentRequest : 1;
 
   // True if the encoding menu should be disabled.
   bool mEncodingMenuDisabled : 1;
 
   // True if dom.webcomponents.shadowdom.enabled pref is set when document is
   // created.
@@ -4312,20 +4260,16 @@ protected:
 
   RefPtr<mozilla::dom::DocGroup> mDocGroup;
 
   // The set of all the tracking script URLs.  URLs are added to this set by
   // calling NoteScriptTrackingStatus().  Currently we assume that a URL not
   // existing in the set means the corresponding script isn't a tracking script.
   nsTHashtable<nsCStringHashKey> mTrackingScripts;
 
-  // CSP violation reports that have been buffered up due to a call to
-  // StartBufferingCSPViolations.
-  nsTArray<nsCOMPtr<nsIRunnable>> mBufferedCSPViolations;
-
   // List of ancestor principals.  This is set at the point a document
   // is connected to a docshell and not mutated thereafter.
   nsTArray<nsCOMPtr<nsIPrincipal>> mAncestorPrincipals;
   // List of ancestor outerWindowIDs that correspond to the ancestor principals.
   nsTArray<uint64_t> mAncestorOuterWindowIDs;
 
   // Pointer to our parser if we're currently in the process of being
   // parsed into.
--- a/dom/security/nsCSPContext.cpp
+++ b/dom/security/nsCSPContext.cpp
@@ -1379,24 +1379,16 @@ nsCSPContext::AsyncReportViolation(nsISu
                                 mPolicies[aViolatedPolicyIndex]->getReportOnlyFlag(),
                                 aViolatedDirective,
                                 aObserverSubject,
                                 aSourceFile,
                                 aScriptSample,
                                 aLineNum,
                                 this);
 
-  // If the document is currently buffering up CSP violation reports, send the
-  // runnable to it instead of dispatching it immediately.
-  nsCOMPtr<nsIDocument> doc = do_QueryReferent(mLoadingContext);
-  if (doc && doc->ShouldBufferCSPViolations()) {
-    doc->BufferCSPViolation(task);
-    return NS_OK;
-  }
-
   if (XRE_IsContentProcess()) {
     if (mEventTarget) {
       mEventTarget->Dispatch(task.forget(), NS_DISPATCH_NORMAL);
       return NS_OK;
     }
   }
 
   NS_DispatchToMainThread(task.forget());