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 771992 3a4199b30530b866ac5420bffab1e64a2113461a
parent 771991 eacb92cb35175e0bbc9c9581aa4c96c6db06145e
child 771993 f2dd14ef816f02a2333fe62cdd3fba870eee288c
push id103820
push userbmo:emilio@crisal.io
push dateSat, 24 Mar 2018 13:51:22 +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
@@ -1452,17 +1452,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
@@ -1107,64 +1107,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;
   }
 
@@ -4102,20 +4054,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.
@@ -4390,20 +4338,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());