tor-browser

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

sandboxTarget.h (1905B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef __SECURITY_SANDBOX_SANDBOXTARGET_H__
      8 #define __SECURITY_SANDBOX_SANDBOXTARGET_H__
      9 
     10 #include <windows.h>
     11 
     12 #include <functional>
     13 #include <list>
     14 #include <utility>
     15 
     16 #include "mozilla/Assertions.h"
     17 
     18 namespace sandbox {
     19 class TargetServices;
     20 }
     21 
     22 namespace mozilla {
     23 
     24 class SandboxTarget {
     25 public:
     26  /**
     27   * Obtains a pointer to the singleton instance
     28   */
     29  static SandboxTarget* Instance();
     30 
     31  /**
     32   * Used by the application to pass in the target services that provide certain
     33   * functions to the sandboxed code.
     34   * The target services must already be initialized.
     35   *
     36   * @param aTargetServices The target services that will be used
     37   */
     38  void SetTargetServices(sandbox::TargetServices* aTargetServices) {
     39    MOZ_ASSERT(aTargetServices);
     40    MOZ_ASSERT(!mTargetServices,
     41               "Sandbox TargetServices must only be set once.");
     42 
     43    mTargetServices = aTargetServices;
     44  }
     45 
     46  template <typename CallbackT>
     47  void RegisterSandboxStartCallback(CallbackT&& aCallback) {
     48    mStartObservers.push_back(std::forward<CallbackT>(aCallback));
     49  }
     50 
     51  /**
     52   * Called by the library that wants to "start" the sandbox, i.e. change to the
     53   * more secure delayed / lockdown policy.
     54   */
     55  void StartSandbox();
     56 
     57  bool GetComplexLineBreaks(const WCHAR* text, uint32_t length,
     58                            uint8_t* break_before);
     59 
     60 protected:
     61  SandboxTarget() : mTargetServices(nullptr) {}
     62 
     63  sandbox::TargetServices* mTargetServices;
     64 
     65 private:
     66  void NotifyStartObservers();
     67  std::list<std::function<void()>> mStartObservers;
     68 };
     69 
     70 }  // namespace mozilla
     71 
     72 #endif