dom/ipc/AppProcessChecker.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial