1 /* 2 * Copyright (c) 2021-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_FORM_FWK_NAPI_FORM_PROVIDER_H 17 #define OHOS_FORM_FWK_NAPI_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 AsyncRequestPublishFormCallbackInfo { 31 napi_env env = nullptr; 32 napi_async_work asyncWork = nullptr; 33 napi_deferred deferred = nullptr; 34 napi_ref callback = nullptr; 35 Want want {}; 36 bool withFormBindingData = false; 37 std::unique_ptr<OHOS::AppExecFwk::FormProviderData> formProviderData = nullptr; 38 int32_t result = OHOS::ERR_OK; 39 int64_t formId = 0; 40 }; 41 42 struct AsyncIsRequestPublishFormSupportedCallbackInfo : AsyncCallbackInfoBase { 43 bool result = false; 44 AsyncIsRequestPublishFormSupportedCallbackInfoAsyncIsRequestPublishFormSupportedCallbackInfo45 explicit AsyncIsRequestPublishFormSupportedCallbackInfo(napi_env env) : AsyncCallbackInfoBase(env) {}; 46 ~AsyncIsRequestPublishFormSupportedCallbackInfo() override = default; 47 }; 48 49 napi_value NAPI_RequestPublishForm(napi_env env, napi_callback_info info); 50 51 /** 52 * @brief Check if the request to publish a form to the form host is supported. 53 * 54 * @param[in] env The environment that the Node-API call is invoked under 55 * @param[in] info This is an opaque pointer that is used to represent a JavaScript value 56 * 57 * @return This is an opaque pointer that is used to represent a JavaScript value 58 * which is true if the request of publishing form is supported and false otherwise 59 */ 60 napi_value NAPI_IsRequestPublishFormSupported(napi_env env, napi_callback_info info); 61 62 class JsFormProvider { 63 public: 64 JsFormProvider() = default; 65 ~JsFormProvider() = default; 66 67 static void Finalizer(napi_env env, void* data, void* hint); 68 static napi_value GetFormsInfo(napi_env env, napi_callback_info info); 69 static napi_value SetFormNextRefreshTime(napi_env env, napi_callback_info info); 70 static napi_value UpdateForm(napi_env env, napi_callback_info info); 71 static napi_value IsRequestPublishFormSupported(napi_env env, napi_callback_info info); 72 private: 73 napi_value OnGetFormsInfo(napi_env env, size_t argc, napi_value* argv); 74 napi_value OnSetFormNextRefreshTime(napi_env env, size_t argc, napi_value* argv); 75 napi_value OnUpdateForm(napi_env env, size_t argc, napi_value* argv); 76 napi_value OnIsRequestPublishFormSupported(napi_env env, size_t argc, napi_value* argv); 77 }; 78 } // namespace AbilityRuntime 79 } // namespace OHOS 80 #endif /* OHOS_FORM_FWK_NAPI_FORM_PROVIDER_H */ 81