1 /* 2 * Copyright (c) 2022-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_JS_FORM_PROVIDER_H 17 #define OHOS_FORM_FWK_JS_FORM_PROVIDER_H 18 19 #include "ability.h" 20 #include "form_info_filter.h" 21 #include "form_provider_info.h" 22 #include "napi_form_util.h" 23 #include "napi/native_api.h" 24 #include "napi/native_common.h" 25 #include "napi/native_node_api.h" 26 #include "nlohmann/json.hpp" 27 #include "want.h" 28 #include <vector> 29 30 namespace OHOS { 31 namespace AbilityRuntime { 32 struct RequestPublishFormCallbackInfo { 33 Want want {}; 34 bool withFormBindingData = false; 35 std::unique_ptr<OHOS::AppExecFwk::FormProviderData> formProviderData = nullptr; 36 std::vector<AppExecFwk::FormDataProxy> formDataProxies; 37 }; 38 39 struct AsyncIsRequestPublishFormSupportedCallbackInfo : AsyncCallbackInfoBase { 40 bool result = false; 41 AsyncIsRequestPublishFormSupportedCallbackInfoAsyncIsRequestPublishFormSupportedCallbackInfo42 explicit AsyncIsRequestPublishFormSupportedCallbackInfo(napi_env env) : AsyncCallbackInfoBase(env) {}; 43 ~AsyncIsRequestPublishFormSupportedCallbackInfo() override = default; 44 }; 45 46 napi_value NAPI_RequestPublishForm(napi_env env, napi_callback_info info); 47 48 /** 49 * @brief Check if the request to publish a form to the form host is supported. 50 * 51 * @param[in] env The environment that the Node-API call is invoked under 52 * @param[in] info This is an opaque pointer that is used to represent a JavaScript value 53 * 54 * @return This is an opaque pointer that is used to represent a JavaScript value 55 * which is true if the request of publishing form is supported and false otherwise 56 */ 57 napi_value NAPI_IsRequestPublishFormSupported(napi_env env, napi_callback_info info); 58 59 class JsFormProvider { 60 public: 61 JsFormProvider() = default; 62 ~JsFormProvider() = default; 63 64 static void Finalizer(napi_env env, void* data, void* hint); 65 static napi_value GetFormsInfo(napi_env env, napi_callback_info info); 66 static napi_value SetFormNextRefreshTime(napi_env env, napi_callback_info info); 67 static napi_value UpdateForm(napi_env env, napi_callback_info info); 68 static napi_value IsRequestPublishFormSupported(napi_env env, napi_callback_info info); 69 static napi_value RequestPublishForm(napi_env env, napi_callback_info info); 70 static napi_value GetPublishedFormInfoById(napi_env env, napi_callback_info info); 71 static napi_value GetPublishedFormInfos(napi_env env, napi_callback_info info); 72 static napi_value OpenFormManager(napi_env env, napi_callback_info info); 73 static napi_value OpenFormEditAbility(napi_env env, napi_callback_info info); 74 private: 75 napi_value OnGetFormsInfo(napi_env env, size_t argc, napi_value* argv); 76 napi_value OnGetPublishedFormInfoById(napi_env env, size_t argc, napi_value* argv); 77 napi_value OnGetPublishedFormInfos(napi_env env, size_t argc, napi_value* argv); 78 napi_value OnOpenFormManager(napi_env env, size_t argc, napi_value* argv); 79 napi_value OnSetFormNextRefreshTime(napi_env env, size_t argc, napi_value* argv); 80 napi_value OnUpdateForm(napi_env env, size_t argc, napi_value* argv); 81 napi_value OnIsRequestPublishFormSupported(napi_env env, size_t argc, napi_value* argv); 82 napi_value OnRequestPublishForm(napi_env env, size_t argc, napi_value* argv); 83 bool ConvertFromDataProxies(napi_env env, napi_value jsValue, 84 std::vector<AppExecFwk::FormDataProxy> &formDataProxies); 85 bool ConvertFormDataProxy(napi_env env, napi_value jsValue, AppExecFwk::FormDataProxy &formDataProxy); 86 87 bool OnGetFormsInfoParseParam(NapiParamPackage &napiParam, 88 size_t &convertArgc, bool &isPromise, AppExecFwk::FormInfoFilter &formInfoFilter); 89 napi_value OnUpdateFormParseParam(napi_env env, size_t argc, napi_value* argv, int64_t &formId); 90 napi_value OnOpenFormEditAbility(napi_env env, size_t argc, napi_value* argv); 91 }; 92 } // namespace AbilityRuntime 93 } // namespace OHOS 94 #endif /* OHOS_FORM_FWK_JS_FORM_PROVIDER_H */ 95