1 /*
2  * Copyright (c) 2023-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 OHOS_ABILITY_RUNTIME_JS_AUTO_FILL_EXTENSION_UTIL_H
17 #define OHOS_ABILITY_RUNTIME_JS_AUTO_FILL_EXTENSION_UTIL_H
18 #include "js_extension_common.h"
19 #include "native_engine/native_engine.h"
20 #include "session_info.h"
21 #include "view_data.h"
22 
23 namespace OHOS {
24 namespace AbilityRuntime {
25 using Want = OHOS::AAFwk::Want;
26 class JsRuntime;
27 struct FillResponse {
28     AbilityBase::ViewData viewData;
29 };
30 struct PopupSize {
31     int32_t width = 0;
32     int32_t height = 0;
33 };
34 
35 enum AutoFillCommand {
36     NONE,
37     FILL,
38     SAVE,
39     UPDATE,
40     RESIZE,
41     INPUT,
42     RELOAD_IN_MODAL
43 };
44 
45 struct CustomData {
46     AAFwk::WantParams data;
47 };
48 /**
49  * @brief Js autofill extension base.
50  */
51 class JsAutoFillExtensionUtil {
52 public:
53     explicit JsAutoFillExtensionUtil(const std::unique_ptr<Runtime> &runtime);
54     virtual ~JsAutoFillExtensionUtil();
55     static napi_value WrapFillRequest(const AAFwk::Want &want, const napi_env env);
56     static napi_value WrapUpdateRequest(const AAFwk::WantParams &wantParams, const napi_env env);
57     static napi_value WrapViewData(const napi_env env, const AbilityBase::ViewData &viewData);
58     static napi_value WrapPageNodeInfo(const napi_env env, const AbilityBase::PageNodeInfo &pageNodeInfo);
59     static napi_value WrapRectData(const napi_env env, const AbilityBase::Rect &rect);
60     static napi_value WrapCustomData(const napi_env env, const AAFwk::WantParams &param);
61     static void UnwrapViewData(const napi_env env, const napi_value value, AbilityBase::ViewData &viewData);
62     static void UnwrapPageNodeInfo(const napi_env env, const napi_value jsProValue, AbilityBase::PageNodeInfo &node);
63     static void UnwrapRectData(const napi_env env, const napi_value value, AbilityBase::Rect &rect);
64     static void UnwrapFillResponse(const napi_env env, const napi_value value, FillResponse &response);
65     static void UnwrapPopupSize(const napi_env env, const napi_value value, PopupSize &popupSize);
66 
67     enum AutoFillResultCode {
68         CALLBACK_SUCESS = 0,
69         CALLBACK_FAILED,
70         CALLBACK_CANCEL,
71         CALLBACK_REMOVE_TIME_OUT,
72         CALLBACK_FAILED_INVALID_PARAM,
73     };
74 };
75 } // namespace AbilityRuntime
76 } // namespace OHOS
77 #endif // OHOS_ABILITY_RUNTIME_JS_AUTO_FILL_EXTENSION_UTIL_H
78