diff --git a/bundle.json b/bundle.json index 03b356b56800bf3cfcd32538d69dd3a3bb6ccd8e..14d247fdf9bf8927eb9210e2999720e5a41ba92f 100644 --- a/bundle.json +++ b/bundle.json @@ -418,6 +418,15 @@ }, "name": "//foundation/ability/ability_runtime/frameworks/native/ability/native:ui_extension" }, + { + "header": { + "header_base": "//foundation/ability/ability_runtime/interfaces/kits/native/ability/native/auto_fill_extension_ability", + "header_files": [ + "auto_fill_extension_context.h" + ] + }, + "name": "//foundation/ability/ability_runtime/frameworks/native/ability/native:auto_fill_extension" + }, { "header": { "header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/extension_manager/include", diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 4395d496011d2e940afb005b896735d46b1f6669..9fd7d615fcad375887088c235502e3fc2a31f331 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -400,6 +400,7 @@ ohos_shared_library("extensionkit_native") { "${ability_runtime_native_path}/ability/native/extension_module_loader.cpp", "${ability_runtime_native_path}/ability/native/js_extension_common.cpp", "${ability_runtime_native_path}/appkit/ability_runtime/extension_context.cpp", + "${ability_runtime_native_path}/appkit/ability_runtime/ui_holder_extension_context.cpp", "${ability_runtime_services_path}/abilitymgr/src/launch_param.cpp", ] @@ -411,6 +412,7 @@ ohos_shared_library("extensionkit_native") { "${ability_runtime_innerkits_path}/runtime:runtime", "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${ability_runtime_native_path}/ability:ability_context_native", + "${ability_runtime_native_path}/appkit:app_context", ] external_deps = [ @@ -1747,13 +1749,14 @@ ohos_shared_library("embedded_ui_extension_module") { config("auto_fill_extension_config") { visibility = [ ":*" ] include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime", "${ability_runtime_path}/interfaces/kits/native/ability/native/auto_fill_extension_ability", "${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability", ] } ohos_shared_library("auto_fill_extension") { - configs = [ ":auto_fill_extension_config" ] + public_configs = [ ":auto_fill_extension_config" ] sources = [ "${ability_runtime_native_path}/ability/native/auto_fill_extension_ability/auto_fill_extension.cpp", diff --git a/frameworks/native/ability/native/auto_fill_extension_ability/auto_fill_extension_context.cpp b/frameworks/native/ability/native/auto_fill_extension_ability/auto_fill_extension_context.cpp index fde3d01d891dfcf4c853af89ca99cd8dc038a51b..5f72253da5ca29ead04ad08111546d4cc58b082d 100644 --- a/frameworks/native/ability/native/auto_fill_extension_ability/auto_fill_extension_context.cpp +++ b/frameworks/native/ability/native/auto_fill_extension_ability/auto_fill_extension_context.cpp @@ -16,9 +16,12 @@ #include "auto_fill_extension_context.h" #include "hilog_tag_wrapper.h" +#include "js_auto_fill_extension_util.h" namespace OHOS { namespace AbilityRuntime { +const size_t AutoFillExtensionContext::CONTEXT_TYPE_ID(std::hash {} ("AutoFillExtensionContext")); + void AutoFillExtensionContext::SetAutoFillExtensionCallback( const std::weak_ptr &autoFillExtensionCallback) { @@ -44,5 +47,10 @@ int32_t AutoFillExtensionContext::ReloadInModal(const CustomData &customData) } return autoFillExtensionCallback->OnReloadInModal(sessionInfo_, customData); } + +bool AutoFillExtensionContext::IsContext(size_t contextTypeId) +{ + return contextTypeId == CONTEXT_TYPE_ID || UIExtensionContext::IsContext(contextTypeId); +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp b/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp index 2bbc95dc48b16f23766a5e3734d25b9ca2fe372c..9f71a35c8af839b00ae01a76dcf3e558332470c3 100644 --- a/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp +++ b/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp @@ -509,6 +509,9 @@ bool JsAutoFillExtension::HandleAutoFillCreate(const AAFwk::Want &want, const sp CallJsOnRequest(want, sessionInfo, uiWindow); uiWindowMap_[obj] = uiWindow; context->SetSessionInfo(sessionInfo); +#ifdef SUPPORT_GRAPHICS + context->SetWindow(uiWindow); +#endif // SUPPORT_GRAPHICS } return true; } diff --git a/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension_context.cpp b/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension_context.cpp index d175d5be22b0f6017507da9bca4d214fc6f0c11f..1d56c824d2595cd91c6770745ab345f39048f857 100755 --- a/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension_context.cpp +++ b/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension_context.cpp @@ -16,6 +16,7 @@ #include "js_auto_fill_extension_context.h" #include "hilog_tag_wrapper.h" +#include "js_auto_fill_extension_util.h" #include "js_error_utils.h" #include "js_extension_context.h" #include "napi/native_api.h" diff --git a/frameworks/native/appkit/ability_runtime/ui_holder_extension_context.cpp b/frameworks/native/appkit/ability_runtime/ui_holder_extension_context.cpp new file mode 100644 index 0000000000000000000000000000000000000000..160047f6b0a791c51396f836f9c84516b53b0415 --- /dev/null +++ b/frameworks/native/appkit/ability_runtime/ui_holder_extension_context.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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 "ui_holder_extension_context.h" + +namespace OHOS { +namespace AbilityRuntime { +const size_t UIHolderExtensionContext::CONTEXT_TYPE_ID(std::hash {} ("UIHolderExtensionContext")); + +bool UIHolderExtensionContext::IsContext(size_t contextTypeId) +{ + return contextTypeId == CONTEXT_TYPE_ID || ExtensionContext::IsContext(contextTypeId); +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/interfaces/kits/native/ability/native/auto_fill_extension_ability/auto_fill_extension_context.h b/interfaces/kits/native/ability/native/auto_fill_extension_ability/auto_fill_extension_context.h index c6b1709aa2969782e1915985df73d09b3bf7928a..c8b0087c708168b8bae5098f36ec2c29c74a98aa 100755 --- a/interfaces/kits/native/ability/native/auto_fill_extension_ability/auto_fill_extension_context.h +++ b/interfaces/kits/native/ability/native/auto_fill_extension_ability/auto_fill_extension_context.h @@ -16,18 +16,18 @@ #ifndef OHOS_ABILITY_RUNTIME_AUTO_FILL_EXTENSION_CONTEXT_H #define OHOS_ABILITY_RUNTIME_AUTO_FILL_EXTENSION_CONTEXT_H -#include "extension_context.h" -#include "js_auto_fill_extension_util.h" +#include "ui_extension_context.h" #include "session_info.h" namespace OHOS { namespace AbilityRuntime { +struct CustomData; class IAutoFillExtensionCallback { public: virtual int32_t OnReloadInModal(const sptr &sessionInfo, const CustomData &customData) = 0; }; -class AutoFillExtensionContext : public ExtensionContext { +class AutoFillExtensionContext : public UIExtensionContext { public: AutoFillExtensionContext() = default; virtual ~AutoFillExtensionContext() = default; @@ -36,6 +36,10 @@ public: void SetSessionInfo(const sptr &sessionInfo); int32_t ReloadInModal(const CustomData &customData); + using SelfType = AutoFillExtensionContext; + static const size_t CONTEXT_TYPE_ID; +protected: + bool IsContext(size_t contextTypeId) override; private: std::weak_ptr autoFillExtensionCallback_; sptr sessionInfo_; diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_context.h b/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_context.h index cf4261016e822fe02cfc45b26a324d5b0399dbb4..444c30a68eda47d6ed586db9318eb5ec3d403b6c 100755 --- a/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_context.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/ui_extension_context.h @@ -22,22 +22,20 @@ #include "extension_context.h" #include "free_install_observer_interface.h" #include "start_options.h" +#include "ui_holder_extension_context.h" #include "want.h" #ifdef SUPPORT_SCREEN #include "window.h" #endif // SUPPORT_SCREEN namespace OHOS { -namespace Ace { -class UIContent; -} namespace AbilityRuntime { using RuntimeTask = std::function; /** * @brief context supply for UIExtension * */ -class UIExtensionContext : public ExtensionContext { +class UIExtensionContext : public UIHolderExtensionContext { public: UIExtensionContext() = default; virtual ~UIExtensionContext() = default; @@ -143,8 +141,9 @@ public: void SetWindow(sptr window); sptr GetWindow(); + + Ace::UIContent* GetUIContent() override; #endif // SUPPORT_SCREEN - Ace::UIContent* GetUIContent(); ErrCode OpenLink(const AAFwk::Want& want, int reuqestCode); @@ -163,17 +162,16 @@ public: protected: bool IsContext(size_t contextTypeId) override { - return contextTypeId == CONTEXT_TYPE_ID || ExtensionContext::IsContext(contextTypeId); + return contextTypeId == CONTEXT_TYPE_ID || UIHolderExtensionContext::IsContext(contextTypeId); } + + sptr window_ = nullptr; #endif // SUPPORT_SCREEN private: static int ILLEGAL_REQUEST_CODE; std::map resultCallbacks_; static int32_t curRequestCode_; static std::mutex requestCodeMutex_; -#ifdef SUPPORT_SCREEN - sptr window_ = nullptr; -#endif // SUPPORT_SCREEN std::mutex mutexlock_; /** * @brief Get Current Ability Type diff --git a/interfaces/kits/native/appkit/ability_runtime/ui_holder_extension_context.h b/interfaces/kits/native/appkit/ability_runtime/ui_holder_extension_context.h new file mode 100644 index 0000000000000000000000000000000000000000..3bd925d27cea3d6f6201cff7671ac3dc39e15ef1 --- /dev/null +++ b/interfaces/kits/native/appkit/ability_runtime/ui_holder_extension_context.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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_UI_HOLDER_EXTENSION_CONTEXT_H +#define OHOS_ABILITY_RUNTIME_UI_HOLDER_EXTENSION_CONTEXT_H + +#include "extension_context.h" + +namespace OHOS { +namespace Ace { +class UIContent; +} +namespace AbilityRuntime { +class UIHolderExtensionContext : public ExtensionContext { +public: + UIHolderExtensionContext() = default; + virtual ~UIHolderExtensionContext() = default; + + virtual Ace::UIContent* GetUIContent() + { + return nullptr; + } + + using SelfType = UIHolderExtensionContext; + static const size_t CONTEXT_TYPE_ID; +protected: + bool IsContext(size_t contextTypeId) override; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_UI_HOLDER_EXTENSION_CONTEXT_H diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 61c3af2ea71b446c57bb07b9f404cb7439e43731..79c05229a151085a4c236d7823ef1fb7ae6841b7 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -415,6 +415,7 @@ group("unittest") { "atomic_service_status_callback_proxy_test:unittest", "atomic_service_status_callback_stub_test:unittest", "authorization_result_test:unittest", + "auto_fill_extension_context_test:unittest", "auto_fill_manager_test:unittest", "auto_fill_manager_util_test:unittest", "auto_startup_callback_proxy_test:unittest", diff --git a/test/unittest/auto_fill_extension_context_test/BUILD.gn b/test/unittest/auto_fill_extension_context_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6032315184e38ab0e7a24f3e6ef75d203cc55d38 --- /dev/null +++ b/test/unittest/auto_fill_extension_context_test/BUILD.gn @@ -0,0 +1,58 @@ +# Copyright (c) 2022 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("//build/ohos.gni") +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_unittest("auto_fill_extension_context_test") { + module_out_path = "ability_runtime/extension" + + sources = [ "auto_fill_extension_context_test.cpp" ] + + include_dirs = [ + "./", + "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", + "${ability_runtime_test_path}/mock/services_appmgr_test/include", + "${ability_runtime_path}/interfaces/kits/native/ability/native/auto_fill_extension_ability", + ] + + cflags = [] + + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:auto_fill_extension", + "${ability_runtime_native_path}/ability/native:ui_extension", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_native", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "napi:ace_napi", + ] +} + +group("unittest") { + testonly = true + deps = [ ":auto_fill_extension_context_test" ] +} diff --git a/test/unittest/auto_fill_extension_context_test/auto_fill_extension_context_test.cpp b/test/unittest/auto_fill_extension_context_test/auto_fill_extension_context_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ea6cb1218361d762b58b5f6b8132bcc22cb72736 --- /dev/null +++ b/test/unittest/auto_fill_extension_context_test/auto_fill_extension_context_test.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2024 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 + +#define private public +#define protected public +#include "auto_fill_extension_context.h" +#undef private +#undef protected + +#include "hilog_tag_wrapper.h" +#include "mock_window.h" + +using namespace testing::ext; +using namespace OHOS::Rosen; + +namespace OHOS { +namespace AbilityRuntime { +class AutoFillExtensionContextTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void AutoFillExtensionContextTest::SetUpTestCase(void) +{} + +void AutoFillExtensionContextTest::TearDownTestCase(void) +{} + +void AutoFillExtensionContextTest::SetUp() +{} + +void AutoFillExtensionContextTest::TearDown() +{} + +class AutoFillMockWindow : public MockWindow { +public: + AutoFillMockWindow() = default; + ~AutoFillMockWindow() = default; + + virtual Ace::UIContent* GetUIContent() const override + { + return (Ace::UIContent*)0x12345678; + } +}; + +/** + * @tc.number: GetWidow_0100 + * @tc.name: GetWidow + * @tc.desc: GetWidow. + */ +HWTEST_F(AutoFillExtensionContextTest, GetWidow_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "GetWidow_0100 start"); + + auto context = std::make_shared(); + sptr window(new (std::nothrow) AutoFillMockWindow()); + context->SetWindow(window); + EXPECT_TRUE(context->GetWindow() != nullptr); + TAG_LOGI(AAFwkTag::TEST, "GetWidow_0100 end"); +} + +/** + * @tc.number: GetUIContent_0100 + * @tc.name: GetUIContent + * @tc.desc: GetUIContent. + */ +HWTEST_F(AutoFillExtensionContextTest, GetUIContent_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "GetUIContent_0100 start"); + + auto context = std::make_shared(); + sptr window(new (std::nothrow) AutoFillMockWindow()); + context->SetWindow(window); + Ace::UIContent* content = context->GetUIContent(); + EXPECT_TRUE(content == (Ace::UIContent*)0x12345678); + TAG_LOGI(AAFwkTag::TEST, "GetUIContent_0100 end"); +} + +/** + * @tc.number: IsContext_0100 + * @tc.name: IsContext + * @tc.desc: IsContext. + */ +HWTEST_F(AutoFillExtensionContextTest, IsContext_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "IsContext_0100 start"); + auto context = std::make_shared(); + auto ret = context->IsContext(AutoFillExtensionContext::CONTEXT_TYPE_ID); + EXPECT_TRUE(ret); + ret = context->IsContext(UIExtensionContext::CONTEXT_TYPE_ID); + EXPECT_TRUE(ret); + TAG_LOGI(AAFwkTag::TEST, "IsContext_0100 end"); +} + +/** + * @tc.number: ConvertTo_0100 + * @tc.name: ConvertTo + * @tc.desc: ConvertTo. + */ +HWTEST_F(AutoFillExtensionContextTest, ConvertTo_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "ConvertTo_0100 start"); + std::shared_ptr context = std::make_shared(); + auto uiHolderExtensionContext = Context::ConvertTo(context); + EXPECT_NE(uiHolderExtensionContext, nullptr); + auto uiExtensionContext = Context::ConvertTo(context); + EXPECT_NE(uiExtensionContext, nullptr); + auto autoFillExtensionContext = Context::ConvertTo(context); + EXPECT_NE(autoFillExtensionContext, nullptr); + TAG_LOGI(AAFwkTag::TEST, "ConvertTo_0100 end"); +} + +/** + * @tc.number: ConvertTo_0200 + * @tc.name: ConvertTo + * @tc.desc: ConvertTo. + */ +HWTEST_F(AutoFillExtensionContextTest, ConvertTo_0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "ConvertTo_0200 start"); + std::shared_ptr context = std::make_shared(); + auto autoFillExtensionContext = Context::ConvertTo(context); + EXPECT_EQ(autoFillExtensionContext, nullptr); + TAG_LOGI(AAFwkTag::TEST, "ConvertTo_0200 end"); +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/test/unittest/js_auto_fill_extension_test/BUILD.gn b/test/unittest/js_auto_fill_extension_test/BUILD.gn index 6a919c7e81ab224f7e7ae8dd3aa12244c1abdb5f..9bf5d49016b908752a16cad5ec07c3bfd6c229b0 100644 --- a/test/unittest/js_auto_fill_extension_test/BUILD.gn +++ b/test/unittest/js_auto_fill_extension_test/BUILD.gn @@ -36,6 +36,7 @@ ohos_unittest("js_auto_fill_extension_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:auto_fill_extension", + "${ability_runtime_native_path}/ability/native:ui_extension", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", "//third_party/icu/icu4c:shared_icuuc", diff --git a/test/unittest/ui_extension_context_test/ui_extension_context_test.cpp b/test/unittest/ui_extension_context_test/ui_extension_context_test.cpp index b2ebcc185211fd58a166a8cc5c2816859da71701..a8e53f36d54c9828328a7449cd66d93cdb16487f 100644 --- a/test/unittest/ui_extension_context_test/ui_extension_context_test.cpp +++ b/test/unittest/ui_extension_context_test/ui_extension_context_test.cpp @@ -432,5 +432,21 @@ HWTEST_F(UIExtensionContextTest, StartUIServiceExtension_0100, TestSize.Level1) EXPECT_TRUE(ans != ERR_OK); TAG_LOGI(AAFwkTag::TEST, "StartUIServiceExtension_0100 end"); } + +/** + * @tc.number: ConvertTo_0100 + * @tc.name: ConvertTo + * @tc.desc: ConvertTo. + */ +HWTEST_F(UIExtensionContextTest, ConvertTo_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "ConvertTo_0100 start"); + std::shared_ptr context = std::make_shared(); + auto uiHolderExtensionContext = Context::ConvertTo(context); + EXPECT_NE(uiHolderExtensionContext, nullptr); + auto uiExtensionContext = Context::ConvertTo(context); + EXPECT_NE(uiExtensionContext, nullptr); + TAG_LOGI(AAFwkTag::TEST, "ConvertTo_0100 end"); +} } // namespace AbilityRuntime } // namespace OHOS