• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     static napi_value CreatePluginModuleContext(napi_env env, napi_callback_info info);
38     static napi_value PromoteCurrentToCandidateMasterProcess(napi_env env, napi_callback_info info);
39     static napi_value DemoteCurrentFromCandidateMasterProcess(napi_env env, napi_callback_info info);
40     static napi_value CreatePluginModuleContextForBundle(napi_env env, napi_callback_info info);
41 
42 private:
43     napi_value OnCreateModuleContext(napi_env env, NapiCallbackInfo &info);
44     napi_value OnCreateBundleContext(napi_env env, NapiCallbackInfo &info);
45     napi_value OnCreatePluginModuleContext(napi_env env, NapiCallbackInfo &info);
46     napi_value OnCreatePluginModuleContextForBundle(napi_env env, NapiCallbackInfo &info);
47     napi_value CreateJsContext(napi_env env, const std::shared_ptr<Context> &context);
48     void SetCreateCompleteCallback(std::shared_ptr<std::shared_ptr<Context>> contextPtr,
49         NapiAsyncTask::CompleteCallback &complete);
50     bool CheckCallerIsSystemApp();
51     bool CheckCallerPermission(const std::string &permission);
52     napi_value OnGetApplicationContext(napi_env env, NapiCallbackInfo &info);
53     napi_value OnPromoteCurrentToCandidateMasterProcess(napi_env env, NapiCallbackInfo& info);
54     napi_value OnDemoteCurrentFromCandidateMasterProcess(napi_env env, NapiCallbackInfo& info);
55     bool VerifyCreatePluginContextParams(napi_env env, NapiCallbackInfo &info, std::string &moduleName,
56         std::string &pluginBundleName, std::string &hostBundleName);
57 };
58 
59 napi_value ApplicationInit(napi_env env, napi_value exportObj);
60 } // namespace AbilityRuntime
61 } // namespace OHOS
62 #endif //OHOS_ABILITY_RUNTIME_JS_APPLICATION_H