Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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/. */
7 #ifndef __SECURITY_SANDBOX_SANDBOXTARGET_H__
8 #define __SECURITY_SANDBOX_SANDBOXTARGET_H__
10 #ifdef TARGET_SANDBOX_EXPORTS
11 #define TARGET_SANDBOX_EXPORT __declspec(dllexport)
12 #else
13 #define TARGET_SANDBOX_EXPORT __declspec(dllimport)
14 #endif
15 namespace mozilla {
18 class TARGET_SANDBOX_EXPORT SandboxTarget
19 {
20 public:
21 typedef void (*StartSandboxPtr)();
23 /**
24 * Obtains a pointer to the singleton instance
25 */
26 static SandboxTarget* Instance()
27 {
28 static SandboxTarget sb;
29 return &sb;
30 }
32 /**
33 * Called by the application that will lower the sandbox token
34 *
35 * @param aStartSandboxCallback A callback function which will lower privs
36 */
37 void SetStartSandboxCallback(StartSandboxPtr aStartSandboxCallback)
38 {
39 mStartSandboxCallback = aStartSandboxCallback;
40 }
42 /**
43 * Called by the library that wants to start the sandbox, which in turn
44 * calls into the previously set StartSandboxCallback.
45 */
46 void StartSandbox()
47 {
48 if (mStartSandboxCallback) {
49 mStartSandboxCallback();
50 }
51 }
53 protected:
54 SandboxTarget() :
55 mStartSandboxCallback(nullptr)
56 {
57 }
59 StartSandboxPtr mStartSandboxCallback;
60 };
63 } // mozilla
65 #endif