• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_JS_INSIGHT_INTENT_CONTEXT_H
17 #define OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_CONTEXT_H
18 
19 #include "native_engine/native_engine.h"
20 #include "insight_intent_context.h"
21 #include "js_runtime_utils.h"
22 
23 namespace OHOS {
24 namespace AbilityRuntime {
25 /**
26  * @class JsInsightIntentContext
27  * JsInsightIntentContext provides a context for insightintent to execute certain tasks.
28  */
29 class JsInsightIntentContext final {
30 public:
JsInsightIntentContext(const std::shared_ptr<InsightIntentContext> & context)31     explicit JsInsightIntentContext(const std::shared_ptr<InsightIntentContext>& context) : context_(context) {}
32     ~JsInsightIntentContext() = default;
33 
34     static void Finalizer(napi_env env, void* data, void* hint);
35 
36     /**
37      * Starts a new ability. Only such ability in the same application with the caller
38      * can be started.
39      *
40      * @param env, the napi environment.
41      * @param info, the params passed from js caller.
42      *
43      * @return result of StartAbility.
44      */
45     static napi_value StartAbiity(napi_env env, napi_callback_info info);
46 
47 private:
48     napi_value OnStartAbility(napi_env env, NapiCallbackInfo& info);
49 
50     std::weak_ptr<InsightIntentContext> context_;
51 };
52 
53 /**
54  * Creates an js object for specific insight intent context.
55  *
56  * @param env, the napi environment.
57  * @param context, the specific insight intent context object.
58  *
59  * @return result of StartAbility.
60  */
61 napi_value CreateJsInsightIntentContext(napi_env env, const std::shared_ptr<InsightIntentContext>& context);
62 
63 /**
64  * Function of check startAbiliryParam parammeters.
65  *
66  * @param env, the napi environment.
67  * @param info, Indicates the parameters from js.
68  * @param want, the want of the ability to start.
69  *
70  * @return result of check startAbiliryParam parammeters.
71  */
72 bool CheckStartAbilityParam(napi_env env, NapiCallbackInfo& info, AAFwk::Want& want);
73 
74 }  // namespace AbilityRuntime
75 }  // namespace OHOS
76 #endif // OHOS_ABILITY_RUNTIME_JS_INSIGHT_INTENT_CONTEXT_H
77