1 /*
2  * Copyright (c) 2024 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 #ifndef OHOS_ABILITY_RUNTIME_JS_APPLICATION_H
16 #define OHOS_ABILITY_RUNTIME_JS_APPLICATION_H
17 
18 #include "context.h"
19 #include "napi/native_api.h"
20 #include "ipc_skeleton.h"
21 #include "js_runtime.h"
22 #include "js_runtime_utils.h"
23 #include "tokenid_kit.h"
24 
25 namespace OHOS {
26 namespace AbilityRuntime {
27 class JsApplication {
28 public:
JsApplication()29     explicit JsApplication()
30     {}
31     virtual ~JsApplication() = default;
32 
33     static void Finalizer(napi_env env, void *data, void *hint);
34     static napi_value CreateModuleContext(napi_env env, napi_callback_info info);
35     static napi_value CreateBundleContext(napi_env env, napi_callback_info info);
36     static napi_value GetApplicationContext(napi_env env, napi_callback_info info);
37 
38 private:
39     napi_value OnCreateModuleContext(napi_env env, NapiCallbackInfo &info);
40     napi_value OnCreateBundleContext(napi_env env, NapiCallbackInfo &info);
41     napi_value CreateJsContext(napi_env env, const std::shared_ptr<Context> &context);
42     void SetCreateCompleteCallback(std::shared_ptr<std::shared_ptr<Context>> contextPtr,
43         NapiAsyncTask::CompleteCallback &complete);
44     bool CheckCallerIsSystemApp();
45     bool CheckCallerPermission(const std::string &permission);
46     napi_value OnGetApplicationContext(napi_env env, NapiCallbackInfo &info);
47 };
48 
49 napi_value ApplicationInit(napi_env env, napi_value exportObj);
50 } // namespace AbilityRuntime
51 } // namespace OHOS
52 #endif //OHOS_ABILITY_RUNTIME_JS_APPLICATION_H