Bug 1493629 - Better management of CSP EventListener for workers, r=ckerschb
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 05 Oct 2018 07:41:12 +0200
changeset 495509 dae89dbd2159c0b2a5865389dadab9a8f938e8ee
parent 495508 2a6ec2aae9fdafeb0efd81310a9f16ba5ccfd6dc
child 495510 2558c8ea6ad2075c51b18d79330ec2d59eeabc5a
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1493629
milestone64.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 1493629 - Better management of CSP EventListener for workers, r=ckerschb
dom/workers/WorkerPrivate.cpp
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -1466,19 +1466,19 @@ WorkerPrivate::GetDocument() const
 void
 WorkerPrivate::SetCSP(nsIContentSecurityPolicy* aCSP)
 {
   AssertIsOnMainThread();
   if (!aCSP) {
     return;
   }
   aCSP->EnsureEventTarget(mMainThreadEventTarget);
-  aCSP->SetEventListener(mCSPEventListener);
 
   mLoadInfo.mCSP = aCSP;
+  EnsureCSPEventListener();
 }
 
 nsresult
 WorkerPrivate::SetCSPFromHeaderValues(const nsACString& aCSPHeaderValue,
                                       const nsACString& aCSPReportOnlyHeaderValue)
 {
   AssertIsOnMainThread();
   MOZ_DIAGNOSTIC_ASSERT(!mLoadInfo.mCSP);
@@ -1488,17 +1488,16 @@ WorkerPrivate::SetCSPFromHeaderValues(co
 
   nsCOMPtr<nsIContentSecurityPolicy> csp;
   nsresult rv = mLoadInfo.mPrincipal->EnsureCSP(nullptr, getter_AddRefs(csp));
   if (!csp) {
     return NS_OK;
   }
 
   csp->EnsureEventTarget(mMainThreadEventTarget);
-  csp->SetEventListener(mCSPEventListener);
 
   // If there's a CSP header, apply it.
   if (!cspHeaderValue.IsEmpty()) {
     rv = CSP_AppendCSPFromHeader(csp, cspHeaderValue, false);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   // If there's a report-only CSP header, apply it.
   if (!cspROHeaderValue.IsEmpty()) {
@@ -1510,16 +1509,17 @@ WorkerPrivate::SetCSPFromHeaderValues(co
   bool evalAllowed = false;
   bool reportEvalViolations = false;
   rv = csp->GetAllowsEval(&reportEvalViolations, &evalAllowed);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mLoadInfo.mCSP = csp;
   mLoadInfo.mEvalAllowed = evalAllowed;
   mLoadInfo.mReportCSPViolations = reportEvalViolations;
+  EnsureCSPEventListener();
 
   return NS_OK;
 }
 
 void
 WorkerPrivate::SetReferrerPolicyFromHeaderValue(const nsACString& aReferrerPolicyHeaderValue)
 {
   NS_ConvertUTF8toUTF16 headerValue(aReferrerPolicyHeaderValue);
@@ -3440,19 +3440,21 @@ WorkerPrivate::EnsureClientSource()
   }
 
   return true;
 }
 
 bool
 WorkerPrivate::EnsureCSPEventListener()
 {
-  mCSPEventListener = WorkerCSPEventListener::Create(this);
-  if (NS_WARN_IF(!mCSPEventListener)) {
-    return false;
+  if (!mCSPEventListener) {
+    mCSPEventListener = WorkerCSPEventListener::Create(this);
+    if (NS_WARN_IF(!mCSPEventListener)) {
+      return false;
+    }
   }
 
   if (mLoadInfo.mCSP) {
     mLoadInfo.mCSP->SetEventListener(mCSPEventListener);
   }
 
   return true;
 }