diff --git a/frameworks/ets/ets/BUILD.gn b/frameworks/ets/ets/BUILD.gn index ae9a2fc41a8f842691e9361c2f8754eadd4a9fb2..0877316ed3486b47999ffb37cd64a4d81bb88bf0 100644 --- a/frameworks/ets/ets/BUILD.gn +++ b/frameworks/ets/ets/BUILD.gn @@ -128,6 +128,22 @@ ohos_prebuilt_etc("ability_runtime_context_abc_etc") { deps = [ ":ability_runtime_context_abc" ] } +generate_static_abc("ability_runtime_custom_data_abc") { + base_url = "./" + files = [ "./application/CustomData.ets" ] + + is_boot_abc = "True" + device_dst_file = "/system/framework/ability_runtime_custom_data_abc.abc" +} + +ohos_prebuilt_etc("ability_runtime_custom_data_abc_etc") { + source = "$target_out_dir/ability_runtime_custom_data_abc.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":ability_runtime_custom_data_abc" ] +} + generate_static_abc("ability_runtime_base_context_abc") { base_url = "./" files = [ "./application/BaseContext.ets" ] @@ -498,6 +514,22 @@ ohos_prebuilt_etc("ability_runtime_app_state_data_abc_etc") { deps = [ ":ability_runtime_app_state_data_abc" ] } +generate_static_abc("ability_runtime_auto_fill_extension_context_abc") { + base_url = "./" + files = [ "./application/AutoFillExtensionContext.ets" ] + + is_boot_abc = "True" + device_dst_file = "/system/framework/ability_runtime_auto_fill_extension_context_abc.abc" +} + +ohos_prebuilt_etc("ability_runtime_auto_fill_extension_context_abc_etc") { + source = "$target_out_dir/ability_runtime_auto_fill_extension_context_abc.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":ability_runtime_auto_fill_extension_context_abc" ] +} + generate_static_abc("ability_runtime_process_data_abc") { base_url = "./" files = [ "./application/ProcessData.ets" ] @@ -821,11 +853,13 @@ group("ets_packages") { ":ability_runtime_ability_utils_abc_etc", ":ability_runtime_app_manager_abc_etc", ":ability_runtime_app_state_data_abc_etc", + ":ability_runtime_auto_fill_extension_context_abc_etc", ":ability_runtime_application_context_abc_etc", ":ability_runtime_base_context_abc_etc", ":ability_runtime_configuration_abc_etc", ":ability_runtime_configuration_constant_abc_etc", ":ability_runtime_context_abc_etc", + ":ability_runtime_custom_data_abc_etc", ":ability_runtime_environment_callback_abc_etc", ":ability_runtime_event_hub_abc_etc", ":ability_runtime_extension_context_abc_etc", diff --git a/frameworks/ets/ets/application/AutoFillExtensionContext.ets b/frameworks/ets/ets/application/AutoFillExtensionContext.ets new file mode 100644 index 0000000000000000000000000000000000000000..930325f8e3a06063edca4a0440ce021eec82e7ce --- /dev/null +++ b/frameworks/ets/ets/application/AutoFillExtensionContext.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"), + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ExtensionContext from 'application.ExtensionContext'; +import type CustomData from 'application.CustomData'; +import AsyncCallbackWrapper from '../utils/AbilityUtils'; +import { BusinessError } from '@ohos.base'; + +export default class AutoFillExtensionContext extends ExtensionContext { + native nativeReloadInModal(customData: CustomData, callback: AsyncCallbackWrapper): void; + reloadInModal(customData: CustomData): Promise { + let p = new Promise((resolve: (data: undefined) => void, reject:(err: BusinessError) => void): void => { + let myCall = new AsyncCallbackWrapper((err: BusinessError) => { + if (err.code == 0) { + resolve(undefined); + } else { + reject(err); + } + }); + taskpool.execute((): void => { + this.nativeReloadInModal(customData, myCall); + }); + }); + return p; + } +} \ No newline at end of file diff --git a/frameworks/ets/ets/application/CustomData.ets b/frameworks/ets/ets/application/CustomData.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d4c0a061114a560a3f2466dd1e9e056381dc912 --- /dev/null +++ b/frameworks/ets/ets/application/CustomData.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"), + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default interface CustomData { + data: Record; +} + +class CustomDataImpl implements CustomData { + public data: Record = {}; +} \ No newline at end of file diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index cb53b53e80448a824c756cc3b0b0b72068aca6ca..52d67e19fae3525e673112e198f2c826cdeafe53 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -2322,6 +2322,7 @@ ohos_shared_library("auto_fill_extension") { "${ability_runtime_native_path}/ability:ability_context_native", "${ability_runtime_native_path}/ability/native:ability_business_error", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_path}/frameworks/ets/ani/ani_common:ani_common", ] external_deps = [ @@ -2345,6 +2346,8 @@ ohos_shared_library("auto_fill_extension") { "${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/auto_fill_extension_context.cpp", "${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp", "${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/js_auto_fill_extension_context.cpp", + "${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_context.cpp", + "${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_util.cpp", "${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/js_auto_fill_extension_util.cpp", "${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/js_fill_request_callback.cpp", "${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/js_save_request_callback.cpp", diff --git a/frameworks/native/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_context.cpp b/frameworks/native/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_context.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f8a6fe874565184dc905394ee483cd3ed52ab71d --- /dev/null +++ b/frameworks/native/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_context.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ets_auto_fill_extension_context.h" + +#include "ani_common_util.h" +#include "ani_common_want.h" +#include "ets_extension_context.h" +#include "hilog_tag_wrapper.h" +#include "sts_error_utils.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr const char* AUTO_FILL_EXTENSION_CONTEXT_CLASS_NAME = + "Lapplication/AutoFillExtensionContext/AutoFillExtensionContext;"; +constexpr const char* CUSTOMDATA_DATA = "data"; +} + +std::unique_ptr EtsAutoFillExtensionContext::etsContext_ = nullptr; + +void EtsAutoFillExtensionContext::ReloadInModal(ani_env *env, ani_object object, ani_object callback) +{ + etsContext_->OnReloadInModal(env, object, callback); +} + +void EtsAutoFillExtensionContext::OnReloadInModal(ani_env *env, ani_object object, ani_object callback) +{ + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "called"); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "null env"); + return; + } + ani_object etsCustomData = AppExecFwk::GetPropertyValueByName(env, object, CUSTOMDATA_DATA); + CustomData customData; + if (etsCustomData == nullptr || !AppExecFwk::UnwrapWantParams(env, etsCustomData, customData.data)) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "Parse custom data failed"); + ThrowStsError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return; + } + auto context = context_.lock(); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "null context"); + ThrowStsError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT); + return; + } + auto ret = context->ReloadInModal(customData); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "error is %{public}d", ret); + return; + } + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::CreateStsErrorByNativeErr(env, static_cast(ret)), nullptr); +} + +ani_object EtsAutoFillExtensionContext::CreateEtsAutoFillExtensionContext(ani_env *env, + const std::shared_ptr &context) +{ + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "called"); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "null env"); + return nullptr; + } + if (context == nullptr) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "null context"); + return nullptr; + } + etsContext_ = std::make_unique(context); + if (etsContext_ == nullptr) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "null etsContext_"); + return nullptr; + } + ani_class cls = nullptr; + ani_status status = ANI_ERROR; + ani_method method = nullptr; + ani_object contextObj = nullptr; + if ((status = env->FindClass(AUTO_FILL_EXTENSION_CONTEXT_CLASS_NAME, &cls)) != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "find class status: %{public}d", status); + return nullptr; + } + std::array functions = { + ani_native_function { "nativeReloadInModal", + "Lapplication/CustomData/CustomData;Lutils/AbilityUtils/AsyncCallbackWrapper;:V", + reinterpret_cast(EtsAutoFillExtensionContext::ReloadInModal) }, + }; + if ((status = env->Class_BindNativeMethods(cls, functions.data(), functions.size())) != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "bind method status : %{public}d", status); + return nullptr; + } + if ((status = env->Class_FindMethod(cls, "", ":V", &method)) != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "find method status: %{public}d", status); + return nullptr; + } + if ((status = env->Object_New(cls, method, &contextObj)) != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "new object status: %{public}d", status); + return nullptr; + } + OHOS::AbilityRuntime::CreatEtsExtensionContext(env, cls, contextObj, context, context->GetAbilityInfo()); + return contextObj; +} +} +} \ No newline at end of file diff --git a/frameworks/native/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_util.cpp b/frameworks/native/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_util.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a7906f000873740073705c93257a512fc7a826dc --- /dev/null +++ b/frameworks/native/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_util.cpp @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ets_auto_fill_extension_util.h" + +#include "ani_common_util.h" +#include "ani_common_want.h" +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr const char *VIEW_DATA_BUNDLE_NAME = "bundleName"; +constexpr const char *VIEW_DATA_MODULE_NAME = "moduleName"; +constexpr const char *VIEW_DATA_ABILITY_NAME = "abilityName"; +constexpr const char *VIEW_DATA_PAGEURL = "pageUrl"; +constexpr const char *VIEW_DATA_USER_SELECTED = "isUserSelected"; +constexpr const char *VIEW_DATA_OTHER_ACCOUNT = "isOtherAccount"; +constexpr const char *VIEW_DATA_PAGE_NODE_INFOS = "pageNodeInfos"; +constexpr const char *VIEW_DATA_VIEW_DATA = "viewData"; +constexpr const char *VIEW_DATA_PAGE_RECT = "pageRect"; +constexpr const char *PAGE_INFO_ID = "id"; +constexpr const char *PAGE_INFO_DEPTH = "depth"; +constexpr const char *PAGE_INFO_AUTOFILLTYPE = "autoFillType"; +constexpr const char *PAGE_INFO_TAG = "tag"; +constexpr const char *PAGE_INFO_VALUE = "value"; +constexpr const char *PAGE_INFO_PLACEHOLDER = "placeholder"; +constexpr const char *PAGE_INFO_META_DATA = "metadata"; +constexpr const char *PAGE_INFO_PASSWORDRULES = "passwordRules"; +constexpr const char *PAGE_INFO_ENABLEAUTOFILL = "enableAutoFill"; +constexpr const char *PAGE_INFO_IS_FOCUS = "isFocus"; +constexpr const char *PAGE_INFO_PAGE_NODE_RECT = "rect"; +constexpr const char *RECT_POSITION_LEFT = "left"; +constexpr const char *RECT_POSITION_TOP = "top"; +constexpr const char *RECT_WIDTH = "width"; +constexpr const char *RECT_HEIGHT = "height"; +constexpr uint32_t PAGE_NODE_COUNT_MAX = 100; +} // namespace + +void EtsAutoFillExtensionUtil::UnwrapViewData(ani_env *env, const ani_object object, AbilityBase::ViewData &viewData) +{ + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "called"); + ani_object etsViewData = AppExecFwk::GetPropertyValueByName(env, object, VIEW_DATA_VIEW_DATA); + if (etsViewData == nullptr) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "null etsViewData"); + return; + } + UnwrapViewDataString(env, etsViewData, viewData); + ani_boolean isUserSelected = false; + if (AppExecFwk::IsExistsProperty(env, etsViewData, VIEW_DATA_USER_SELECTED)) { + isUserSelected = AppExecFwk::GetBoolOrUndefined(env, etsViewData, VIEW_DATA_USER_SELECTED); + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "isUserSelected:%{public}hhu", isUserSelected); + viewData.isUserSelected = isUserSelected; + } + ani_boolean isOtherAccount = false; + if (AppExecFwk::IsExistsProperty(env, etsViewData, VIEW_DATA_OTHER_ACCOUNT)) { + isOtherAccount = AppExecFwk::GetBoolOrUndefined(env, etsViewData, VIEW_DATA_OTHER_ACCOUNT); + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "isOtherAccount:%{public}hhu", isOtherAccount); + viewData.isOtherAccount = isOtherAccount; + } + ani_object etsPageNodeInfos = AppExecFwk::GetPropertyValueByName(env, etsViewData, VIEW_DATA_PAGE_NODE_INFOS); + if (etsPageNodeInfos != nullptr) { + ani_double etsProCount = 0.0; + if (!AppExecFwk::GetDoublePropertyValue(env, etsViewData, VIEW_DATA_PAGE_NODE_INFOS, etsProCount)) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "get length fail"); + return; + } + for (uint32_t index = 0; index < static_cast(etsProCount) && index < PAGE_NODE_COUNT_MAX; index++) { + ani_ref etsNode = nullptr; + if (ANI_OK != (env->Object_CallMethodByName_Ref(etsViewData, "$_get", "I:Lstd/core/Object;", &etsNode, + (ani_int)index))) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "Object_CallMethodByName_Ref _get Failed"); + return; + } + AbilityBase::PageNodeInfo node; + UnwrapPageNodeInfo(env, static_cast(etsNode), node); + viewData.nodes.emplace_back(node); + } + } + ani_object etsPageRect = AppExecFwk::GetPropertyValueByName(env, etsViewData, VIEW_DATA_PAGE_RECT); + if (etsPageRect != nullptr) { + UnwrapRectData(env, etsPageRect, viewData.pageRect); + } +} + +void EtsAutoFillExtensionUtil::UnwrapPageNodeInfo(ani_env *env, const ani_object object, + AbilityBase::PageNodeInfo &node) +{ + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "called"); + ani_double id = 0.0; + if (AppExecFwk::GetDoubleOrUndefined(env, object, PAGE_INFO_ID, id)) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "id:%{public}f", id); + node.id = id; + } + ani_double depth = 0.0; + if (AppExecFwk::GetDoubleOrUndefined(env, object, PAGE_INFO_DEPTH, depth)) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "depth:%{public}f", depth); + node.depth = depth; + } + ani_double autoFillType = 0.0; + if (AppExecFwk::GetDoubleOrUndefined(env, object, PAGE_INFO_AUTOFILLTYPE, autoFillType)) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "autoFillType:%{public}f", autoFillType); + node.autoFillType = static_cast(autoFillType); + } + UnwrapPageNodeInfoString(env, object, node); + ani_boolean enableAutoFill = false; + if (AppExecFwk::IsExistsProperty(env, object, PAGE_INFO_ENABLEAUTOFILL)) { + enableAutoFill = AppExecFwk::GetBoolOrUndefined(env, object, PAGE_INFO_ENABLEAUTOFILL); + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "enableAutoFill:%{public}hhu", enableAutoFill); + node.enableAutoFill = enableAutoFill; + } + ani_object etsRect = AppExecFwk::GetPropertyValueByName(env, object, PAGE_INFO_PAGE_NODE_RECT); + if (etsRect != nullptr) { + UnwrapRectData(env, etsRect, node.rect); + } + ani_boolean isFocus = false; + if (AppExecFwk::IsExistsProperty(env, object, PAGE_INFO_IS_FOCUS)) { + isFocus = AppExecFwk::GetBoolOrUndefined(env, object, PAGE_INFO_IS_FOCUS); + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "isFocus:%{public}hhu", isFocus); + node.isFocus = isFocus; + } +} + +void EtsAutoFillExtensionUtil::UnwrapRectData(ani_env *env, const ani_object object, AbilityBase::Rect &rect) +{ + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "called"); + ani_double position = 0.0; + if (AppExecFwk::GetDoubleOrUndefined(env, object, RECT_POSITION_LEFT, position)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "left:%{public}f", position); + rect.left = position; + } + if (AppExecFwk::GetDoubleOrUndefined(env, object, RECT_POSITION_TOP, position)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "top:%{public}f", position); + rect.top = position; + } + if (AppExecFwk::GetDoubleOrUndefined(env, object, RECT_WIDTH, position)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "width:%{public}f", position); + rect.width = position; + } + if (AppExecFwk::GetDoubleOrUndefined(env, object, RECT_HEIGHT, position)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "height:%{public}f", position); + rect.height = position; + } +} + +void EtsAutoFillExtensionUtil::UnwrapFillResponse(ani_env *env, const ani_object object, FillResponse &response) +{ + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "called"); + UnwrapViewData(env, object, response.viewData); +} + +void EtsAutoFillExtensionUtil::UnwrapPopupSize(ani_env *env, const ani_object object, PopupSize &popupSize) +{ + ani_double width = 0.0; + if (AppExecFwk::GetDoubleOrUndefined(env, object, RECT_WIDTH, width)) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "width:%{public}f", width); + popupSize.width = width; + } + ani_double height = 0.0; + if (AppExecFwk::GetDoubleOrUndefined(env, object, RECT_HEIGHT, height)) { + TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "height:%{public}f", height); + popupSize.height = height; + } +} + +void EtsAutoFillExtensionUtil::UnwrapViewDataString(ani_env *env, const ani_object object, + AbilityBase::ViewData &viewData) +{ + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "called"); + std::string bundleName = ""; + if (AppExecFwk::GetStringOrUndefined(env, object, VIEW_DATA_BUNDLE_NAME, bundleName)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "The parsed bundleName part %{public}s", bundleName.c_str()); + viewData.bundleName = bundleName; + } + std::string moduleName = ""; + if (AppExecFwk::GetStringOrUndefined(env, object, VIEW_DATA_MODULE_NAME, moduleName)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "The parsed moduleName part %{public}s", moduleName.c_str()); + viewData.moduleName = moduleName; + } + std::string abilityName = ""; + if (AppExecFwk::GetStringOrUndefined(env, object, VIEW_DATA_ABILITY_NAME, abilityName)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "The parsed abilityName part %{public}s", abilityName.c_str()); + viewData.abilityName = abilityName; + } + std::string pageUrl = ""; + if (AppExecFwk::GetStringOrUndefined(env, object, VIEW_DATA_PAGEURL, pageUrl)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "The parsed pageUrl part %{public}s", pageUrl.c_str()); + viewData.pageUrl = pageUrl; + } +} + +void EtsAutoFillExtensionUtil::UnwrapPageNodeInfoString(ani_env *env, const ani_object object, + AbilityBase::PageNodeInfo &node) +{ + std::string tag = ""; + if (AppExecFwk::GetStringOrUndefined(env, object, PAGE_INFO_TAG, tag)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "The parsed tag part %{public}s", tag.c_str()); + node.tag = tag; + } + std::string value = ""; + if (AppExecFwk::GetStringOrUndefined(env, object, PAGE_INFO_VALUE, value)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "The parsed value part %{public}s", value.c_str()); + node.value = value; + } + std::string passwordRules = ""; + if (AppExecFwk::GetStringOrUndefined(env, object, PAGE_INFO_PASSWORDRULES, passwordRules)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "The parsed passwordRules part %{public}s", passwordRules.c_str()); + node.passwordRules = passwordRules; + } + std::string placeholder = ""; + if (AppExecFwk::GetStringOrUndefined(env, object, PAGE_INFO_PLACEHOLDER, placeholder)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "The parsed placeholder part %{public}s", placeholder.c_str()); + node.placeholder = placeholder; + } + std::string metadata = ""; + if (AppExecFwk::GetStringOrUndefined(env, object, PAGE_INFO_META_DATA, metadata)) { + TAG_LOGD(AAFwkTag::AUTOFILL_EXT, "The parsed metadata part %{public}s", metadata.c_str()); + node.metadata = metadata; + } +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/native/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_context.h b/interfaces/kits/native/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_context.h new file mode 100644 index 0000000000000000000000000000000000000000..e4b9c78976798d78c63a4d8c625b3bf5e436bcdb --- /dev/null +++ b/interfaces/kits/native/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_context.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_ETS_AUTO_FILL_EXTENSION_CONTEXT_H +#define OHOS_ABILITY_RUNTIME_ETS_AUTO_FILL_EXTENSION_CONTEXT_H + +#include "auto_fill_extension_context.h" +#include "ets_auto_fill_extension_util.h" +#include "sts_runtime.h" + +namespace OHOS { +namespace AbilityRuntime { +class EtsAutoFillExtensionContext final { +public: + explicit EtsAutoFillExtensionContext(const std::shared_ptr &context) + : context_(context) {} + virtual ~EtsAutoFillExtensionContext() = default; + + static void ReloadInModal(ani_env *env, ani_object object, ani_object callback); + static ani_object CreateEtsAutoFillExtensionContext(ani_env *env, + const std::shared_ptr &context); + std::shared_ptr GetAutoFillExtensionContext() + { + return context_.lock(); + } + +private: + void OnReloadInModal(ani_env *env, ani_object object, ani_object callback); + std::weak_ptr context_; + static std::unique_ptr etsContext_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ETS_AUTO_FILL_EXTENSION_CONTEXT_H \ No newline at end of file diff --git a/interfaces/kits/native/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_util.h b/interfaces/kits/native/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_util.h new file mode 100644 index 0000000000000000000000000000000000000000..2b61b83bd629eea763e397bf00bd3ef0d0d9c356 --- /dev/null +++ b/interfaces/kits/native/ability/native/auto_fill_extension_ability/ets_auto_fill_extension_util.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_ETS_AUTO_FILL_EXTENSION_UTIL_H +#define OHOS_ABILITY_RUNTIME_ETS_AUTO_FILL_EXTENSION_UTIL_H + +#include "session_info.h" +#include "sts_runtime.h" +#include "view_data.h" + +namespace OHOS { +namespace AbilityRuntime { +struct FillResponse { + AbilityBase::ViewData viewData; +}; + +struct PopupSize { + int32_t width = 0; + int32_t height = 0; +}; + +enum AutoFillCommand { + NONE, + FILL, + SAVE, + UPDATE, + RESIZE, + INPUT, + RELOAD_IN_MODAL +}; + +struct CustomData { + AAFwk::WantParams data; +}; + +class EtsAutoFillExtensionUtil { +public: + explicit EtsAutoFillExtensionUtil(const std::unique_ptr &runtime); + virtual ~EtsAutoFillExtensionUtil(); + static void UnwrapViewData(ani_env *env, const ani_object object, AbilityBase::ViewData &viewData); + static void UnwrapPageNodeInfo(ani_env *env, const ani_object object, AbilityBase::PageNodeInfo &node); + static void UnwrapRectData(ani_env *env, const ani_object object, AbilityBase::Rect &rect); + static void UnwrapFillResponse(ani_env *env, const ani_object object, FillResponse &response); + static void UnwrapPopupSize(ani_env *env, const ani_object object, PopupSize &popupSize); + + enum AutoFillResultCode { + CALLBACK_SUCESS = 0, + CALLBACK_FAILED, + CALLBACK_CANCEL, + CALLBACK_REMOVE_TIME_OUT, + CALLBACK_FAILED_INVALID_PARAM, + }; + +private: + static void UnwrapViewDataString(ani_env *env, const ani_object object, AbilityBase::ViewData &viewData); + static void UnwrapPageNodeInfoString(ani_env *env, const ani_object object, AbilityBase::PageNodeInfo &node); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ETS_AUTO_FILL_EXTENSION_UTIL_H \ No newline at end of file