Bug 1493629 - Better management of CSP EventListener for workers. r=ckerschb, a=pascalc
☠☠ backed out by 9671f6ac6cbe ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 05 Oct 2018 07:41:12 +0200
changeset 490182 01237eeedfac765312a1322b28719782c3a71731
parent 490181 135174a61d2db7777a05677af493e2ed23b8fe31
child 490183 b1b3f1e5ec42a960fddf10f10ae8a0ecba93f784
push id9937
push userryanvm@gmail.com
push dateFri, 05 Oct 2018 15:10:08 +0000
treeherdermozilla-beta@01237eeedfac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb, pascalc
bugs1493629
milestone63.0
Bug 1493629 - Better management of CSP EventListener for workers. r=ckerschb, a=pascalc
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;
+    }
   }
 
   return true;
 }
 
 void
 WorkerPrivate::EnsurePerformanceStorage()
 {