1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ABILITY_RUNTIME_NAPI_CONTEXT_H 17 #define OHOS_ABILITY_RUNTIME_NAPI_CONTEXT_H 18 #include "napi_common.h" 19 #include "ability.h" 20 #include "napi/native_api.h" 21 #include "napi/native_common.h" 22 #include "napi/native_node_api.h" 23 #include "js_runtime_utils.h" 24 25 using Ability = OHOS::AppExecFwk::Ability; 26 #define MODE 0771 27 namespace OHOS { 28 namespace AppExecFwk { 29 struct CallAbilityPermissionParam { 30 std::vector<std::string> permission_list; 31 int requestCode = 0; 32 int syncOption = false; 33 }; 34 35 /** 36 * @brief Context NAPI module registration. 37 * 38 * @param env The environment that the Node-API call is invoked under. 39 * @param exports An empty object via the exports parameter as a convenience. 40 * 41 * @return The return value from Init is treated as the exports object for the module. 42 */ 43 napi_value ContextPermissionInit(napi_env env, napi_value exports); 44 45 EXTERN_C_START 46 /** 47 * @brief The interface of onRequestPermissionsFromUserResult provided for ACE to call back to JS. 48 * 49 * @param requestCode Indicates the request code returned after the ability is started. 50 * @param permissions Indicates list of permission. 51 * @param grantResults Indicates List of authorization results. 52 * @param callbackInfo The environment and call back info that the Node-API call is invoked under. 53 */ 54 void CallOnRequestPermissionsFromUserResult(int requestCode, const std::vector<std::string> &permissions, 55 const std::vector<int> &grantResults, OHOS::AppExecFwk::CallbackInfo callbackInfo); 56 EXTERN_C_END 57 napi_value ContextConstructor(napi_env env, napi_callback_info info); 58 59 /** 60 * @brief Obtains information about the current application. 61 * 62 * @param env The environment that the Node-API call is invoked under. 63 * @param info The callback info passed into the callback function. 64 * 65 * @return The return value from NAPI C++ to JS for the module. 66 */ 67 napi_value NAPI_GetApplicationInfo(napi_env env, napi_callback_info info); 68 69 /** 70 * @brief Obtains the elementName object of the current ability. 71 * 72 * @param env The environment that the Node-API call is invoked under. 73 * @param info The callback info passed into the callback function. 74 * 75 * @return The return value from NAPI C++ to JS for the module. 76 */ 77 napi_value NAPI_GetElementName(napi_env env, napi_callback_info info); 78 79 /** 80 * @brief Obtains the process Info this application. 81 * 82 * @param env The environment that the Node-API call is invoked under. 83 * @param info The callback info passed into the callback function. 84 * 85 * @return The return value from NAPI C++ to JS for the module. 86 */ 87 napi_value NAPI_GetProcessInfo(napi_env env, napi_callback_info info); 88 89 /** 90 * @brief Obtains the name of the current process. 91 * 92 * @param env The environment that the Node-API call is invoked under. 93 * @param info The callback info passed into the callback function. 94 * 95 * @return The return value from NAPI C++ to JS for the module. 96 */ 97 napi_value NAPI_GetProcessName(napi_env env, napi_callback_info info); 98 99 /** 100 * @brief Obtains the bundle name of the ability that called the current ability. 101 * 102 * @param env The environment that the Node-API call is invoked under. 103 * @param info The callback info passed into the callback function. 104 * 105 * @return The return value from NAPI C++ to JS for the module. 106 */ 107 napi_value NAPI_GetCallingBundle(napi_env env, napi_callback_info info); 108 109 /** 110 * @brief Set wake up screen screen Permit list. 111 * 112 * @param env The environment that the Node-API call is invoked under. 113 * @param info The callback info passed into the callback function. 114 * 115 * @return The return value from NAPI C++ to JS for the module. 116 */ 117 napi_value NAPI_SetWakeUpScreen(napi_env env, napi_callback_info info); 118 119 /** 120 * @brief Set the display orientation of the main window. 121 * 122 * @param env The environment that the Node-API call is invoked under. 123 * @param info The callback info passed into the callback function. 124 * 125 * @return The return value from NAPI C++ to JS for the module. 126 */ 127 napi_value NAPI_SetDisplayOrientation(napi_env env, napi_callback_info info); 128 #ifdef SUPPORT_GRAPHICS 129 bool UnwrapSetDisplayOrientation(napi_env env, size_t argc, napi_value *argv, AsyncJSCallbackInfo *asyncCallbackInfo); 130 #endif 131 132 /** 133 * @brief Get the display orientation of the main window. 134 * 135 * @param env The environment that the Node-API call is invoked under. 136 * @param info The callback info passed into the callback function. 137 * 138 * @return The return value from NAPI C++ to JS for the module. 139 */ 140 napi_value NAPI_GetDisplayOrientation(napi_env env, napi_callback_info info); 141 142 /** 143 * @brief Get the application context 144 * 145 * @param engine Native JS engine. 146 * 147 * @return The return value from C++ to JS for the module. 148 */ 149 napi_value CreateNapiJSContext(napi_env env); 150 } // namespace AppExecFwk 151 } // namespace OHOS 152 #endif /* OHOS_ABILITY_RUNTIME_NAPI_CONTEXT_H */ 153