Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: sw=2 ts=8 et : |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 6 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef mozilla_AppProcessChecker_h |
michael@0 | 9 | #define mozilla_AppProcessChecker_h |
michael@0 | 10 | |
michael@0 | 11 | #include <stdint.h> |
michael@0 | 12 | |
michael@0 | 13 | class nsIPrincipal; |
michael@0 | 14 | |
michael@0 | 15 | namespace mozilla { |
michael@0 | 16 | |
michael@0 | 17 | namespace dom { |
michael@0 | 18 | class PBrowserParent; |
michael@0 | 19 | class PContentParent; |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | namespace hal_sandbox { |
michael@0 | 23 | class PHalParent; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | enum AssertAppProcessType { |
michael@0 | 27 | ASSERT_APP_PROCESS_PERMISSION, |
michael@0 | 28 | ASSERT_APP_PROCESS_MANIFEST_URL, |
michael@0 | 29 | ASSERT_APP_HAS_PERMISSION |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | /** |
michael@0 | 33 | * Return true if the specified browser has the specified capability. |
michael@0 | 34 | * If this returns false, the browser didn't have the capability and |
michael@0 | 35 | * will be killed. |
michael@0 | 36 | */ |
michael@0 | 37 | bool |
michael@0 | 38 | AssertAppProcess(mozilla::dom::PBrowserParent* aActor, |
michael@0 | 39 | AssertAppProcessType aType, |
michael@0 | 40 | const char* aCapability); |
michael@0 | 41 | |
michael@0 | 42 | /** |
michael@0 | 43 | * Return true if the specified app has the specified status. |
michael@0 | 44 | * If this returns false, the browser will be killed. |
michael@0 | 45 | */ |
michael@0 | 46 | bool |
michael@0 | 47 | AssertAppStatus(mozilla::dom::PBrowserParent* aActor, |
michael@0 | 48 | unsigned short aStatus); |
michael@0 | 49 | |
michael@0 | 50 | /** |
michael@0 | 51 | * Return true if any of the PBrowsers loaded in this content process |
michael@0 | 52 | * has the specified capability. If this returns false, the process |
michael@0 | 53 | * didn't have the capability and will be killed. |
michael@0 | 54 | */ |
michael@0 | 55 | bool |
michael@0 | 56 | AssertAppProcess(mozilla::dom::PContentParent* aActor, |
michael@0 | 57 | AssertAppProcessType aType, |
michael@0 | 58 | const char* aCapability); |
michael@0 | 59 | |
michael@0 | 60 | /** |
michael@0 | 61 | * Return true if any of the PBrowsers loaded in this content process |
michael@0 | 62 | * has an app with the specified status. If this returns false, the process |
michael@0 | 63 | * didn't have the status and will be killed. |
michael@0 | 64 | */ |
michael@0 | 65 | bool |
michael@0 | 66 | AssertAppStatus(mozilla::dom::PContentParent* aActor, |
michael@0 | 67 | unsigned short aStatus); |
michael@0 | 68 | |
michael@0 | 69 | bool |
michael@0 | 70 | AssertAppProcess(mozilla::hal_sandbox::PHalParent* aActor, |
michael@0 | 71 | AssertAppProcessType aType, |
michael@0 | 72 | const char* aCapability); |
michael@0 | 73 | |
michael@0 | 74 | // NB: when adding capability checks for other IPDL actors, please add |
michael@0 | 75 | // them to this file and have them delegate to the two functions above |
michael@0 | 76 | // as appropriate. For example, |
michael@0 | 77 | // |
michael@0 | 78 | // bool AppProcessHasCapability(PNeckoParent* aActor, AssertAppProcessType aType) { |
michael@0 | 79 | // return AssertAppProcess(aActor->Manager(), aType); |
michael@0 | 80 | // } |
michael@0 | 81 | |
michael@0 | 82 | bool |
michael@0 | 83 | AssertAppPrincipal(mozilla::dom::PContentParent* aParent, |
michael@0 | 84 | nsIPrincipal* aPrincipal); |
michael@0 | 85 | |
michael@0 | 86 | /** |
michael@0 | 87 | * Check if the specified principal is valid, and return the saved permission |
michael@0 | 88 | * value for permission `aPermission' on that principal. |
michael@0 | 89 | * See nsIPermissionManager.idl for possible return values. |
michael@0 | 90 | * |
michael@0 | 91 | * nsIPermissionManager::UNKNOWN_ACTION is retuned if the principal is invalid. |
michael@0 | 92 | */ |
michael@0 | 93 | uint32_t |
michael@0 | 94 | CheckPermission(mozilla::dom::PContentParent* aParent, |
michael@0 | 95 | nsIPrincipal* aPrincipal, const char* aPermission); |
michael@0 | 96 | |
michael@0 | 97 | /** |
michael@0 | 98 | * Inline function for asserting the process's permission. |
michael@0 | 99 | */ |
michael@0 | 100 | template<typename T> |
michael@0 | 101 | inline bool |
michael@0 | 102 | AssertAppProcessPermission(T* aActor, |
michael@0 | 103 | const char* aPermission) { |
michael@0 | 104 | return AssertAppProcess(aActor, |
michael@0 | 105 | ASSERT_APP_PROCESS_PERMISSION, |
michael@0 | 106 | aPermission); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | /** |
michael@0 | 110 | * Inline function for asserting the process's manifest URL. |
michael@0 | 111 | */ |
michael@0 | 112 | template<typename T> |
michael@0 | 113 | inline bool |
michael@0 | 114 | AssertAppProcessManifestURL(T* aActor, |
michael@0 | 115 | const char* aManifestURL) { |
michael@0 | 116 | return AssertAppProcess(aActor, |
michael@0 | 117 | ASSERT_APP_PROCESS_MANIFEST_URL, |
michael@0 | 118 | aManifestURL); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | /** |
michael@0 | 122 | * Inline function for asserting the process's manifest URL. |
michael@0 | 123 | */ |
michael@0 | 124 | template<typename T> |
michael@0 | 125 | inline bool |
michael@0 | 126 | AssertAppHasPermission(T* aActor, |
michael@0 | 127 | const char* aPermission) { |
michael@0 | 128 | return AssertAppProcess(aActor, |
michael@0 | 129 | ASSERT_APP_HAS_PERMISSION, |
michael@0 | 130 | aPermission); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | template<typename T> |
michael@0 | 134 | inline bool |
michael@0 | 135 | AssertAppHasStatus(T* aActor, |
michael@0 | 136 | unsigned short aStatus) { |
michael@0 | 137 | return AssertAppStatus(aActor, aStatus); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | } // namespace mozilla |
michael@0 | 141 | |
michael@0 | 142 | #endif // mozilla_AppProcessChecker_h |