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 
16 #ifndef FENCEEXTENSION_JS_FENCE_EXTENSION_CONTEXT_H
17 #define FENCEEXTENSION_JS_FENCE_EXTENSION_CONTEXT_H
18 #include "fence_extension_context.h"
19 
20 #include "napi/native_api.h"
21 #include "native_engine/native_engine.h"
22 #include "js_extension_context.h"
23 #include "js_runtime_utils.h"
24 #include "js_error_utils.h"
25 #include "js_runtime.h"
26 #include "napi/native_api.h"
27 #include "napi_common_want.h"
28 #include "want.h"
29 #include "ability_business_error.h"
30 
31 namespace OHOS {
32 namespace Location {
33 using namespace OHOS::AbilityRuntime;
34 class JsFenceExtensionContext {
35 public:
36     explicit JsFenceExtensionContext(const std::shared_ptr<FenceExtensionContext> &context);
37 
38     ~JsFenceExtensionContext();
39 
40     static ::napi_value CreateJsFenceExtensionContext(
41         const ::napi_env &env, std::shared_ptr<FenceExtensionContext> context);
42 
StartAbility(napi_env env,napi_callback_info info)43     static ::napi_value StartAbility(napi_env env, napi_callback_info info)
44     {
45         GET_NAPI_INFO_AND_CALL(env, info, JsFenceExtensionContext, OnStartAbility);
46     }
47 
48 private:
49     ::napi_value OnStartExtensionAbility(AAFwk::Want want, napi_env env, AbilityRuntime::NapiCallbackInfo &info);
50     ::napi_value OnStartAbility(napi_env env, AbilityRuntime::NapiCallbackInfo &info);
51     static void Finalizer(::napi_env env, void *data, void *hint);
52 
53     std::weak_ptr<FenceExtensionContext> context_;
54 };
55 }  // namespace Location
56 }  // namespace OHOS
57 #endif  // FENCEEXTENSION_JS_FENCE_EXTENSION_CONTEXT_H
58