tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WorkerCSPContext.h (1708B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef mozilla_dom_workers_WorkerCSPContext_h__
      6 #define mozilla_dom_workers_WorkerCSPContext_h__
      7 
      8 #include "mozilla/Result.h"
      9 #include "mozilla/UniquePtr.h"
     10 #include "mozilla/dom/nsCSPUtils.h"
     11 #include "mozilla/ipc/PBackgroundSharedTypes.h"
     12 #include "nscore.h"
     13 
     14 class nsIContentSecurityPolicy;
     15 
     16 namespace mozilla::dom {
     17 
     18 // A minimal version of nsCSPContext that can run on Worker threads.
     19 class WorkerCSPContext final {
     20 public:
     21  explicit WorkerCSPContext(mozilla::ipc::CSPInfo&& aInfo) : mCSPInfo(aInfo) {}
     22 
     23  static Result<UniquePtr<WorkerCSPContext>, nsresult> CreateFromCSP(
     24      nsIContentSecurityPolicy* aCSP);
     25 
     26  const mozilla::ipc::CSPInfo& CSPInfo() const { return mCSPInfo; }
     27  const nsTArray<UniquePtr<const nsCSPPolicy>>& Policies();
     28 
     29  bool IsEvalAllowed(bool& aReportViolation);
     30  bool IsWasmEvalAllowed(bool& aReportViolation);
     31 
     32 private:
     33  void EnsureIPCPoliciesRead();
     34 
     35  // Thread boundaries require us to not only store a CSP object, but also a
     36  // serialized version of the CSP. Reason being: Serializing a CSP to a CSPInfo
     37  // needs to happen on the main thread, but storing the CSPInfo needs to happen
     38  // on the worker thread. We move the CSPInfo into the Client within
     39  // ScriptExecutorRunnable::PreRun().
     40  mozilla::ipc::CSPInfo mCSPInfo;
     41 
     42  // This is created lazily by parsing the policies in CSPInfo on the worker
     43  // thread.
     44  nsTArray<UniquePtr<const nsCSPPolicy>> mPolicies;
     45 };
     46 
     47 }  // namespace mozilla::dom
     48 
     49 #endif  // mozilla_dom_workers_WorkerCSPContext_h__