• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_FORM_FWK_JS_FORM_PROVIDER_H
17 #define OHOS_FORM_FWK_JS_FORM_PROVIDER_H
18 
19 #include "ability.h"
20 #include "form_provider_info.h"
21 #include "napi_form_util.h"
22 #include "napi/native_api.h"
23 #include "napi/native_common.h"
24 #include "napi/native_node_api.h"
25 #include "nlohmann/json.hpp"
26 #include "want.h"
27 
28 namespace OHOS {
29 namespace AbilityRuntime {
30 struct RequestPublishFormCallbackInfo {
31     Want want {};
32     bool withFormBindingData = false;
33     std::unique_ptr<OHOS::AppExecFwk::FormProviderData> formProviderData = nullptr;
34 };
35 
36 struct AsyncIsRequestPublishFormSupportedCallbackInfo : AsyncCallbackInfoBase {
37     bool result = false;
38 
AsyncIsRequestPublishFormSupportedCallbackInfoAsyncIsRequestPublishFormSupportedCallbackInfo39     explicit AsyncIsRequestPublishFormSupportedCallbackInfo(napi_env env) : AsyncCallbackInfoBase(env) {};
40     ~AsyncIsRequestPublishFormSupportedCallbackInfo() override = default;
41 };
42 
43 napi_value NAPI_RequestPublishForm(napi_env env, napi_callback_info info);
44 
45 /**
46  * @brief Check if the request to publish a form to the form host is supported.
47  *
48  * @param[in] env The environment that the Node-API call is invoked under
49  * @param[in] info This is an opaque pointer that is used to represent a JavaScript value
50  *
51  * @return This is an opaque pointer that is used to represent a JavaScript value
52  *         which is true if the request of publishing form is supported and false otherwise
53  */
54 napi_value NAPI_IsRequestPublishFormSupported(napi_env env, napi_callback_info info);
55 
56 class JsFormProvider {
57 public:
58     JsFormProvider() = default;
59     ~JsFormProvider() = default;
60 
61     static void Finalizer(NativeEngine* engine, void* data, void* hint);
62     static NativeValue* GetFormsInfo(NativeEngine* engine, NativeCallbackInfo* info);
63     static NativeValue* SetFormNextRefreshTime(NativeEngine *engine, NativeCallbackInfo *info);
64     static NativeValue* UpdateForm(NativeEngine *engine, NativeCallbackInfo *info);
65     static NativeValue* IsRequestPublishFormSupported(NativeEngine *engine, NativeCallbackInfo *info);
66     static NativeValue* RequestPublishForm(NativeEngine *engine, NativeCallbackInfo *info);
67 private:
68     NativeValue* OnGetFormsInfo(NativeEngine &engine, NativeCallbackInfo &info);
69     NativeValue* OnSetFormNextRefreshTime(NativeEngine &engine, NativeCallbackInfo &info);
70     NativeValue* OnUpdateForm(NativeEngine &engine, NativeCallbackInfo &info);
71     NativeValue* OnIsRequestPublishFormSupported(NativeEngine &engine, const NativeCallbackInfo &info);
72     NativeValue* OnRequestPublishForm(NativeEngine &engine, NativeCallbackInfo &info);
73 };
74 }  // namespace AbilityRuntime
75 }  // namespace OHOS
76 #endif /* OHOS_FORM_FWK_JS_FORM_PROVIDER_H */
77