Refactor the code of UIExtensionComponent.

Signed-off-by: ZhangYu <zhangyu578@huawei.com>
Change-Id: I0cc8470f84c1f978f5aad2f2b525590074833128
This commit is contained in:
ZhangYu 2023-12-08 11:25:39 +00:00
parent 85486e53da
commit d25dd43643
18 changed files with 1126 additions and 752 deletions

View File

@ -117,18 +117,17 @@ void JSUIExtensionProxy::SendSync(const JSCallbackInfo& info)
auto wantParams = WantParamsWrap::CreateWantWrap(reinterpret_cast<napi_env>(nativeEngine), nativeValue);
if (proxy_) {
AAFwk::WantParams reWantParams;
Rosen::WSErrorCode sendCode = proxy_->SendDataSync(wantParams, reWantParams);
if (sendCode != Rosen::WSErrorCode::WS_OK) {
const int32_t reErrorCode = static_cast<int32_t>(sendCode);
int32_t sendCode = proxy_->SendDataSync(wantParams, reWantParams);
if (sendCode != 0) {
std::string errMsg;
if (reErrorCode == ERROR_CODE_UIEXTENSION_NOT_REGISTER_SYNC_CALLBACK) {
if (sendCode == ERROR_CODE_UIEXTENSION_NOT_REGISTER_SYNC_CALLBACK) {
errMsg = "No callback has been registered to process synchronous data transferring.";
} else if (reErrorCode == ERROR_CODE_UIEXTENSION_TRANSFER_DATA_FAILED) {
} else if (sendCode == ERROR_CODE_UIEXTENSION_TRANSFER_DATA_FAILED) {
errMsg = "Transferring data failed.";
} else {
errMsg = "Unknown error.";
}
JSException::Throw(reErrorCode, errMsg.c_str());
JSException::Throw(sendCode, errMsg.c_str());
return;
}
auto execCtx = info.GetExecutionContext();
@ -283,9 +282,9 @@ void JSUIExtensionProxy::On(const JSCallbackInfo& info)
CHECK_NULL_VOID(pattern);
auto onFuncList = GetOnFuncList(registerType);
if (registerType == RegisterType::SYNC) {
pattern->SetOnSyncOnCallbackList(std::move(onFuncList));
pattern->SetSyncCallbacks(std::move(onFuncList));
} else if (registerType == RegisterType::ASYNC) {
pattern->SetOnAsyncOnCallbackList(std::move(onFuncList));
pattern->SetAsyncCallbacks(std::move(onFuncList));
}
}
@ -319,9 +318,9 @@ void JSUIExtensionProxy::Off(const JSCallbackInfo& info)
CHECK_NULL_VOID(pattern);
auto onFuncList = GetOnFuncList(registerType);
if (registerType == RegisterType::SYNC) {
pattern->SetOnSyncOffCallbackList(std::move(onFuncList));
pattern->SetSyncCallbacks(std::move(onFuncList));
} else if (registerType == RegisterType::ASYNC) {
pattern->SetOnAsyncOffCallbackList(std::move(onFuncList));
pattern->SetAsyncCallbacks(std::move(onFuncList));
}
}

View File

@ -21,6 +21,8 @@ config("ui_extension_config") {
build_component_ng("ui_extension_pattern_ng") {
sources = [
"modal_ui_extension_proxy_impl.cpp",
"session_wrapper_factory.cpp",
"session_wrapper_impl.cpp",
"ui_extension_manager.cpp",
"ui_extension_model_ng.cpp",
"ui_extension_pattern.cpp",

View File

@ -15,17 +15,16 @@
#include "core/components_ng/pattern/ui_extension/modal_ui_extension_proxy_impl.h"
#include "session/host/include/extension_session.h"
#include "frameworks/base/utils/utils.h"
namespace OHOS::Ace::NG {
ModalUIExtensionProxyImpl::ModalUIExtensionProxyImpl(const sptr<Rosen::Session>& session) : session_(session) {}
ModalUIExtensionProxyImpl::ModalUIExtensionProxyImpl(const RefPtr<SessionWrapper>& sessionWrapper)
: sessionWrapper_(sessionWrapper)
{}
void ModalUIExtensionProxyImpl::SendData(const AAFwk::WantParams& params)
{
auto session = session_.promote();
if (session) {
sptr<Rosen::ExtensionSession> extensionSession(static_cast<Rosen::ExtensionSession*>(session.GetRefPtr()));
extensionSession->TransferComponentData(params);
}
CHECK_NULL_VOID(sessionWrapper_);
sessionWrapper_->SendDataAsync(params);
}
} // namespace OHOS::Ace::NG

View File

@ -16,23 +16,19 @@
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_MODAL_UI_EXTENSION_PROXY_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_MODAL_UI_EXTENSION_PROXY_H
#include <refbase.h>
#include "interfaces/inner_api/ace/modal_ui_extension_proxy.h"
namespace OHOS::Rosen {
class Session;
} // namespace OHOS::Rosen
#include "core/components_ng/pattern/ui_extension/session_wrapper.h"
namespace OHOS::Ace::NG {
class ModalUIExtensionProxyImpl : public ModalUIExtensionProxy {
public:
explicit ModalUIExtensionProxyImpl(const sptr<Rosen::Session>& session);
explicit ModalUIExtensionProxyImpl(const RefPtr<SessionWrapper>& sessionWrapper);
~ModalUIExtensionProxyImpl() override = default;
void SendData(const AAFwk::WantParams& params) override;
private:
wptr<Rosen::Session> session_;
RefPtr<SessionWrapper> sessionWrapper_;
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_MODAL_UI_EXTENSION_PROXY_H

View File

@ -0,0 +1,108 @@
/*
* Copyright (c) 2023 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_H
#include <cstdint>
#include <list>
#include <map>
#include <memory>
#include "base/memory/ace_type.h"
namespace OHOS {
namespace MMI {
class PointerEvent;
class KeyEvent;
class AxisEvent;
} // namespace MMI
namespace Rosen {
class RSSurfaceNode;
} // namespace Rosen
namespace AAFwk {
class Want;
class WantParams;
} // namespace AAFwk
namespace Accessibility {
class AccessibilityElementInfo;
class AccessibilityEventInfo;
} // namespace Accessibility
} // namespace OHOS
namespace OHOS::Ace::NG {
class SessionWrapper : public AceType {
DECLARE_ACE_TYPE(SessionWrapper, AceType);
public:
virtual ~SessionWrapper() = default;
// About session
virtual void CreateSession(const AAFwk::Want& want) = 0;
virtual void DestroySession() = 0;
virtual bool IsSessionValid() = 0;
virtual int32_t GetSessionId() = 0;
virtual const std::shared_ptr<AAFwk::Want> GetWant() = 0;
// Synchronous interface for event notify
virtual bool NotifyFocusEventSync(bool isFocus) = 0;
virtual bool NotifyFocusStateSync(bool focusState) = 0;
virtual bool NotifyBackPressedSync() = 0;
virtual bool NotifyPointerEventSync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) = 0;
virtual bool NotifyKeyEventSync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) = 0;
virtual bool NotifyAxisEventSync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) = 0;
// Asynchronous interface for event notify
virtual bool NotifyFocusEventAsync(bool isFocus) = 0;
virtual bool NotifyFocusStateAsync(bool focusState) = 0;
virtual bool NotifyBackPressedAsync() = 0;
virtual bool NotifyPointerEventAsync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) = 0;
virtual bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) = 0;
virtual bool NotifyAxisEventAsync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) = 0;
// The lifecycle interface
virtual void NotifyCreate() = 0;
virtual void NotifyForeground() = 0;
virtual void NotifyBackground() = 0;
virtual void NotifyDestroy() = 0;
virtual void NotifyConfigurationUpdate() = 0;
// The interface about the accessibility
virtual bool TransferExecuteAction(int32_t elementId, const std::map<std::string, std::string>& actionArguments,
int32_t action, int32_t offset) = 0;
virtual void SearchExtensionElementInfoByAccessibilityId(int32_t elementId, int32_t mode, int32_t baseParent,
std::list<Accessibility::AccessibilityElementInfo>& output) = 0;
virtual void SearchElementInfosByText(int32_t elementId, const std::string& text, int32_t baseParent,
std::list<Accessibility::AccessibilityElementInfo>& output) = 0;
virtual void FindFocusedElementInfo(
int32_t elementId, int32_t focusType, int32_t baseParent, Accessibility::AccessibilityElementInfo& output) = 0;
virtual void FocusMoveSearch(
int32_t elementId, int32_t direction, int32_t baseParent, Accessibility::AccessibilityElementInfo& output) = 0;
// The interface to control the display area
virtual std::shared_ptr<Rosen::RSSurfaceNode> GetSurfaceNode() const = 0;
virtual void RefreshDisplayArea(float left, float top, float width, float height) = 0;
// The interface to send the data for ArkTS
virtual void SendDataAsync(const AAFwk::WantParams& params) const = 0;
virtual int32_t SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const = 0;
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_H

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2023 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 "core/components_ng/pattern/ui_extension/session_wrapper_factory.h"
#include "base/memory/referenced.h"
#include "core/components_ng/pattern/ui_extension/session_wrapper_impl.h"
#include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h"
namespace OHOS::Ace::NG {
RefPtr<SessionWrapper> SessionWrapperFactory::CreateSessionWrapper(SessionTye sessionType,
const WeakPtr<UIExtensionPattern>& hostPattern, int32_t instanceId, bool isTransferringCaller)
{
if (sessionType == SessionTye::UI_EXTENSION_ABILITY) {
return AceType::MakeRefPtr<SessionWrapperImpl>(hostPattern, instanceId, isTransferringCaller);
}
return nullptr;
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_FACTORY_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_FACTORY_H
#include "base/memory/referenced.h"
#include "core/components_ng/pattern/ui_extension/session_wrapper.h"
#include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h"
namespace OHOS::Ace::NG {
enum class SessionTye { UI_EXTENSION_ABILITY, UNKNOWN };
class SessionWrapperFactory {
public:
static RefPtr<SessionWrapper> CreateSessionWrapper(SessionTye sessionType,
const WeakPtr<UIExtensionPattern>& hostPattern, int32_t instanceId, bool isTransferringCaller);
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_FACTORY_H

View File

@ -0,0 +1,447 @@
/*
* Copyright (c) 2023 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 "core/components_ng/pattern/ui_extension/session_wrapper_impl.h"
#include <memory>
#include "accessibility_event_info.h"
#include "session_manager/include/extension_session_manager.h"
#include "ui/rs_surface_node.h"
#include "adapter/ohos/entrance/ace_container.h"
#include "adapter/ohos/osal/want_wrap_ohos.h"
#include "base/utils/utils.h"
namespace OHOS::Ace::NG {
class UIExtensionLifecycleListener : public Rosen::ILifecycleListener {
public:
UIExtensionLifecycleListener(int32_t instanceId, const WeakPtr<UIExtensionPattern>& hostPattern)
: instanceId_(instanceId), hostPattern_(hostPattern)
{}
virtual ~UIExtensionLifecycleListener() = default;
void OnActivation() override {}
void OnForeground() override {}
void OnBackground() override {}
void OnConnect() override
{
ContainerScope scope(instanceId_);
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto taskExecutor = pipeline->GetTaskExecutor();
CHECK_NULL_VOID(taskExecutor);
taskExecutor->PostTask(
[weak = hostPattern_]() {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
pattern->OnConnect();
},
TaskExecutor::TaskType::UI);
}
void OnDisconnect() override
{
ContainerScope scope(instanceId_);
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto taskExecutor = pipeline->GetTaskExecutor();
CHECK_NULL_VOID(taskExecutor);
taskExecutor->PostTask(
[weak = hostPattern_]() {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
pattern->OnDisconnect();
},
TaskExecutor::TaskType::UI);
}
void OnExtensionDied() override
{
ContainerScope scope(instanceId_);
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto taskExecutor = pipeline->GetTaskExecutor();
CHECK_NULL_VOID(taskExecutor);
taskExecutor->PostTask(
[weak = hostPattern_]() {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
pattern->OnExtensionDied();
},
TaskExecutor::TaskType::UI);
}
void OnAccessibilityEvent(
const Accessibility::AccessibilityEventInfo& info, const std::vector<int32_t>& uiExtensionIdLevelList) override
{
ContainerScope scope(instanceId_);
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto taskExecutor = pipeline->GetTaskExecutor();
CHECK_NULL_VOID(taskExecutor);
taskExecutor->PostTask(
[weak = hostPattern_, info, uiExtensionIdLevelList]() {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
pattern->OnAccessibilityEvent(info, uiExtensionIdLevelList);
},
TaskExecutor::TaskType::UI);
}
private:
int32_t instanceId_;
WeakPtr<UIExtensionPattern> hostPattern_;
};
/************************************************ Begin: Initialization ***********************************************/
SessionWrapperImpl::SessionWrapperImpl(
const WeakPtr<UIExtensionPattern>& hostPattern, int32_t instanceId, bool isTransferringCaller)
: hostPattern_(hostPattern), instanceId_(instanceId), isTransferringCaller_(isTransferringCaller)
{}
SessionWrapperImpl::~SessionWrapperImpl() {}
void SessionWrapperImpl::InitAllCallback()
{
CHECK_NULL_VOID(session_);
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto taskExecutor = pipeline->GetTaskExecutor();
CHECK_NULL_VOID(taskExecutor);
auto sessionCallbacks = session_->GetExtensionSessionEventCallback();
foregroundCallback_ = [weak = hostPattern_, taskExecutor](OHOS::Rosen::WSError errcode) {
if (errcode != OHOS::Rosen::WSError::WS_OK) {
taskExecutor->PostTask(
[weak, errcode] {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
std::string name = "start_ability_fail";
std::string message =
"Start ui extension ability failed, please check the want of UIextensionAbility.";
pattern->FireOnErrorCallback(static_cast<int32_t>(errcode), name, message);
},
TaskExecutor::TaskType::UI);
}
};
backgroundCallback_ = [weak = hostPattern_, taskExecutor](OHOS::Rosen::WSError errcode) {
if (errcode != OHOS::Rosen::WSError::WS_OK) {
taskExecutor->PostTask(
[weak, errcode] {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
std::string name = "background_fail";
std::string message = "background ui extension ability failed, please check AMS log.";
pattern->FireOnErrorCallback(static_cast<int32_t>(errcode), name, message);
},
TaskExecutor::TaskType::UI);
}
};
destructionCallback_ = [weak = hostPattern_, taskExecutor](OHOS::Rosen::WSError errcode) {
if (errcode != OHOS::Rosen::WSError::WS_OK) {
taskExecutor->PostTask(
[weak, errcode] {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
std::string name = "terminate_fail";
std::string message = "terminate ui extension ability failed, please check AMS log.";
pattern->FireOnErrorCallback(static_cast<int32_t>(errcode), name, message);
},
TaskExecutor::TaskType::UI);
}
};
sessionCallbacks->transferAbilityResultFunc_ = [weak = hostPattern_, taskExecutor](
int32_t code, const AAFwk::Want& want) {
taskExecutor->PostTask(
[weak, code, want]() {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
pattern->FireOnResultCallback(code, want);
},
TaskExecutor::TaskType::UI);
};
sessionCallbacks->transferExtensionDataFunc_ = [weak = hostPattern_, taskExecutor](
const AAFwk::WantParams& params) {
taskExecutor->PostTask(
[weak, params]() {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
pattern->FireOnReceiveCallback(params);
},
TaskExecutor::TaskType::UI);
};
sessionCallbacks->notifyRemoteReadyFunc_ = [weak = hostPattern_, taskExecutor]() {
taskExecutor->PostTask(
[weak]() {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
pattern->FireOnRemoteReadyCallback();
},
TaskExecutor::TaskType::UI);
};
sessionCallbacks->notifySyncOnFunc_ = [weak = hostPattern_, taskExecutor]() {
taskExecutor->PostTask(
[weak]() {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
pattern->FireSyncCallbacks();
},
TaskExecutor::TaskType::UI);
};
sessionCallbacks->notifyAsyncOnFunc_ = [weak = hostPattern_, taskExecutor]() {
taskExecutor->PostTask(
[weak]() {
auto pattern = weak.Upgrade();
CHECK_NULL_VOID(pattern);
pattern->FireAsyncCallbacks();
},
TaskExecutor::TaskType::UI);
};
}
/************************************************ End: Initialization *************************************************/
/************************************************ Begin: About session ************************************************/
void SessionWrapperImpl::CreateSession(const AAFwk::Want& want)
{
TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Create session: %{private}s", want.ToString().c_str());
auto container = AceType::DynamicCast<Platform::AceContainer>(Container::Current());
CHECK_NULL_VOID(container);
auto callerToken = container->GetToken();
auto parentToken = container->GetParentToken();
Rosen::SessionInfo extensionSessionInfo = {
.bundleName_ = want.GetElement().GetBundleName(),
.abilityName_ = want.GetElement().GetAbilityName(),
.callerToken_ = callerToken,
.rootToken_ = (isTransferringCaller_ && parentToken) ? parentToken : callerToken,
.want = std::make_shared<Want>(want),
};
session_ = Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSession(extensionSessionInfo);
CHECK_NULL_VOID(session_);
lifecycleListener_ = std::make_shared<UIExtensionLifecycleListener>(instanceId_, hostPattern_);
session_->RegisterLifecycleListener(lifecycleListener_);
InitAllCallback();
}
void SessionWrapperImpl::DestroySession()
{
CHECK_NULL_VOID(session_);
session_->UnregisterLifecycleListener(lifecycleListener_);
session_ = nullptr;
}
bool SessionWrapperImpl::IsSessionValid()
{
return session_ != nullptr;
}
int32_t SessionWrapperImpl::GetSessionId()
{
return session_ ? session_->GetPersistentId() : 0;
}
const std::shared_ptr<AAFwk::Want> SessionWrapperImpl::GetWant()
{
return session_ ? session_->GetSessionInfo().want : nullptr;
}
/************************************************ End: About session **************************************************/
/************************************************ Begin: Synchronous interface for event notify ***********************/
bool SessionWrapperImpl::NotifyFocusEventSync(bool isFocus)
{
return false;
}
bool SessionWrapperImpl::NotifyFocusStateSync(bool focusState)
{
return false;
}
bool SessionWrapperImpl::NotifyBackPressedSync()
{
CHECK_NULL_RETURN(session_, false);
bool isConsumed = false;
session_->TransferBackPressedEventForConsumed(isConsumed);
return isConsumed;
}
bool SessionWrapperImpl::NotifyPointerEventSync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent)
{
return false;
}
bool SessionWrapperImpl::NotifyKeyEventSync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent)
{
CHECK_NULL_RETURN(session_, false);
bool isConsumed = false;
session_->TransferKeyEventForConsumed(keyEvent, isConsumed);
return isConsumed;
}
bool SessionWrapperImpl::NotifyAxisEventSync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent)
{
return false;
}
/************************************************ End: Synchronous interface for event notify *************************/
/************************************************ Begin: Asynchronous interface for event notify **********************/
bool SessionWrapperImpl::NotifyFocusEventAsync(bool isFocus)
{
CHECK_NULL_RETURN(session_, false);
session_->TransferFocusActiveEvent(isFocus);
return true;
}
bool SessionWrapperImpl::NotifyFocusStateAsync(bool focusState)
{
CHECK_NULL_RETURN(session_, false);
session_->TransferFocusStateEvent(focusState);
return true;
}
bool SessionWrapperImpl::NotifyBackPressedAsync()
{
return false;
}
bool SessionWrapperImpl::NotifyPointerEventAsync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent)
{
if (session_ && pointerEvent) {
session_->TransferPointerEvent(pointerEvent);
}
return false;
}
bool SessionWrapperImpl::NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent)
{
if (session_ && keyEvent) {
session_->TransferKeyEvent(keyEvent);
}
return false;
}
bool SessionWrapperImpl::NotifyAxisEventAsync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent)
{
return false;
}
/************************************************ End: Asynchronous interface for event notify ************************/
/************************************************ Begin: The lifecycle interface **************************************/
void SessionWrapperImpl::NotifyCreate() {}
void SessionWrapperImpl::NotifyForeground()
{
TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Foreground: session = %{public}s", session_ ? "non-null" : "null");
CHECK_NULL_VOID(session_);
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto hostWindowId = pipeline->GetFocusWindowId();
Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSessionActivation(
session_, hostWindowId, std::move(foregroundCallback_));
}
void SessionWrapperImpl::NotifyBackground()
{
TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Background: session = %{public}s", session_ ? "non-null" : "null");
CHECK_NULL_VOID(session_);
Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSessionBackground(
session_, std::move(backgroundCallback_));
}
void SessionWrapperImpl::NotifyDestroy()
{
TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Destroy: session = %{public}s", session_ ? "non-null" : "null");
CHECK_NULL_VOID(session_);
Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSessionDestruction(
session_, std::move(destructionCallback_));
}
void SessionWrapperImpl::NotifyConfigurationUpdate()
{
CHECK_NULL_VOID(session_);
session_->UpdateConfiguration();
}
/************************************************ End: The lifecycle interface ****************************************/
/************************************************ Begin: The interface about the accessibility ************************/
bool SessionWrapperImpl::TransferExecuteAction(
int32_t elementId, const std::map<std::string, std::string>& actionArguments, int32_t action, int32_t offset)
{
CHECK_NULL_RETURN(session_, false);
return OHOS::Rosen::WSError::WS_OK == session_->TransferExecuteAction(elementId, actionArguments, action, offset);
}
void SessionWrapperImpl::SearchExtensionElementInfoByAccessibilityId(
int32_t elementId, int32_t mode, int32_t baseParent, std::list<Accessibility::AccessibilityElementInfo>& output)
{
CHECK_NULL_VOID(session_);
session_->TransferSearchElementInfo(elementId, mode, baseParent, output);
}
void SessionWrapperImpl::SearchElementInfosByText(int32_t elementId, const std::string& text, int32_t baseParent,
std::list<Accessibility::AccessibilityElementInfo>& output)
{
CHECK_NULL_VOID(session_);
session_->TransferSearchElementInfosByText(elementId, text, baseParent, output);
}
void SessionWrapperImpl::FindFocusedElementInfo(
int32_t elementId, int32_t focusType, int32_t baseParent, Accessibility::AccessibilityElementInfo& output)
{
CHECK_NULL_VOID(session_);
session_->TransferFindFocusedElementInfo(elementId, focusType, baseParent, output);
}
void SessionWrapperImpl::FocusMoveSearch(
int32_t elementId, int32_t direction, int32_t baseParent, Accessibility::AccessibilityElementInfo& output)
{
CHECK_NULL_VOID(session_);
session_->TransferFocusMoveSearch(elementId, direction, baseParent, output);
}
/************************************************ Begin: The interface about the accessibility ************************/
/************************************************ Begin: The interface to control the display area ********************/
std::shared_ptr<Rosen::RSSurfaceNode> SessionWrapperImpl::GetSurfaceNode() const
{
return session_ ? session_->GetSurfaceNode() : nullptr;
}
void SessionWrapperImpl::RefreshDisplayArea(float left, float top, float width, float height)
{
CHECK_NULL_VOID(session_);
Rosen::WSRect windowRect {
.posX_ = std::round(left), .posY_ = std::round(top), .width_ = std::round(width), .height_ = std::round(height)
};
session_->UpdateRect(windowRect, Rosen::SizeChangeReason::UNDEFINED);
}
/************************************************ End: The interface to control the display area **********************/
/************************************************ Begin: The interface to send the data for ArkTS *********************/
void SessionWrapperImpl::SendDataAsync(const AAFwk::WantParams& params) const
{
TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Sync: session = %{public}s", session_ ? "non-null" : "null");
CHECK_NULL_VOID(session_);
session_->TransferComponentData(params);
}
int32_t SessionWrapperImpl::SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const
{
TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Async: session = %{public}s", session_ ? "non-null" : "null");
Rosen::WSErrorCode transferCode = Rosen::WSErrorCode::WS_ERROR_TRANSFER_DATA_FAILED;
if (session_) {
transferCode = session_->TransferComponentDataSync(wantParams, reWantParams);
}
return static_cast<int32_t>(transferCode);
}
/************************************************ End: The interface to send the data for ArkTS ***********************/
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,98 @@
/*
* Copyright (c) 2023 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_IMPL_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_IMPL_H
#include <refbase.h>
#include "session/host/include/extension_session.h"
#include "want.h"
#include "base/memory/referenced.h"
#include "core/components_ng/pattern/ui_extension/session_wrapper.h"
#include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h"
namespace OHOS::Ace::NG {
class SessionWrapperImpl : public SessionWrapper {
DECLARE_ACE_TYPE(SessionWrapperImpl, SessionWrapper);
public:
SessionWrapperImpl(const WeakPtr<UIExtensionPattern>& hostPattern, int32_t instanceId, bool isTransferringCaller);
~SessionWrapperImpl() override;
// About session
void CreateSession(const AAFwk::Want& want) override;
void DestroySession() override;
bool IsSessionValid() override;
int32_t GetSessionId() override;
const std::shared_ptr<AAFwk::Want> GetWant() override;
// Synchronous interface for event notify
bool NotifyFocusEventSync(bool isFocus) override;
bool NotifyFocusStateSync(bool focusState) override;
bool NotifyBackPressedSync() override;
bool NotifyPointerEventSync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override;
bool NotifyKeyEventSync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) override;
bool NotifyAxisEventSync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override;
// Asynchronous interface for event notify
bool NotifyFocusEventAsync(bool isFocus) override;
bool NotifyFocusStateAsync(bool focusState) override;
bool NotifyBackPressedAsync() override;
bool NotifyPointerEventAsync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override;
bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) override;
bool NotifyAxisEventAsync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override;
// The lifecycle interface
void NotifyCreate() override;
void NotifyForeground() override;
void NotifyBackground() override;
void NotifyDestroy() override;
void NotifyConfigurationUpdate() override;
// The interface about the accessibility
bool TransferExecuteAction(int32_t elementId, const std::map<std::string, std::string>& actionArguments,
int32_t action, int32_t offset) override;
void SearchExtensionElementInfoByAccessibilityId(int32_t elementId, int32_t mode, int32_t baseParent,
std::list<Accessibility::AccessibilityElementInfo>& output) override;
void SearchElementInfosByText(int32_t elementId, const std::string& text, int32_t baseParent,
std::list<Accessibility::AccessibilityElementInfo>& output) override;
void FindFocusedElementInfo(int32_t elementId, int32_t focusType, int32_t baseParent,
Accessibility::AccessibilityElementInfo& output) override;
void FocusMoveSearch(int32_t elementId, int32_t direction, int32_t baseParent,
Accessibility::AccessibilityElementInfo& output) override;
// The interface to control the display area
std::shared_ptr<Rosen::RSSurfaceNode> GetSurfaceNode() const override;
void RefreshDisplayArea(float left, float top, float width, float height) override;
// The interface to send the data for ArkTS
void SendDataAsync(const AAFwk::WantParams& params) const override;
int32_t SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const override;
private:
void InitAllCallback();
sptr<Rosen::ExtensionSession> session_;
WeakPtr<UIExtensionPattern> hostPattern_;
int32_t instanceId_;
bool isTransferringCaller_;
std::shared_ptr<Rosen::ILifecycleListener> lifecycleListener_;
std::function<void((OHOS::Rosen::WSError))> foregroundCallback_;
std::function<void((OHOS::Rosen::WSError))> backgroundCallback_;
std::function<void((OHOS::Rosen::WSError))> destructionCallback_;
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_IMPL_H

View File

@ -14,8 +14,9 @@
*/
#include "core/components_ng/pattern/ui_extension/ui_extension_manager.h"
#include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h"
#include "adapter/ohos/entrance/ace_container.h"
#include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h"
namespace OHOS::Ace::NG {
std::bitset<UI_EXTENSION_ID_FIRST_MAX> UIExtensionManager::UIExtensionIdUtility::idPool_;
@ -76,8 +77,7 @@ bool UIExtensionManager::SendAccessibilityEventInfo(const Accessibility::Accessi
return ret == OHOS::Rosen::WMError::WM_OK;
}
std::pair<int32_t, int32_t> UIExtensionManager::UnWrapExtensionAbilityId(
int32_t extensionOffset, int32_t elementId)
std::pair<int32_t, int32_t> UIExtensionManager::UnWrapExtensionAbilityId(int32_t extensionOffset, int32_t elementId)
{
if (extensionOffset == 0) {
return std::pair<int32_t, int32_t>(0, 0);

View File

@ -39,11 +39,12 @@ constexpr int32_t UI_EXTENSION_OFFSET_MIN = 100000;
constexpr int32_t UI_EXTENSION_ID_FACTOR = 10;
constexpr int32_t UI_EXTENSION_LEVEL_MAX = 3;
constexpr int32_t UI_EXTENSION_ROOT_ID = -1;
};
}; // namespace
class UIExtensionPattern;
class UIExtensionManager : public AceType {
DECLARE_ACE_TYPE(UIExtensionManager, AceType);
public:
UIExtensionManager() = default;
~UIExtensionManager() override = default;
@ -60,13 +61,12 @@ public:
void RecycleExtensionId(int32_t id);
private:
class UIExtensionIdUtility {
public:
UIExtensionIdUtility() = default;
~UIExtensionIdUtility() = default;
UIExtensionIdUtility(const UIExtensionIdUtility&) = delete;
UIExtensionIdUtility &operator=(const UIExtensionIdUtility&) = delete;
UIExtensionIdUtility& operator=(const UIExtensionIdUtility&) = delete;
int32_t ApplyExtensionId();
void RecycleExtensionId(int32_t id);
@ -79,5 +79,5 @@ private:
WeakPtr<UIExtensionPattern> uiExtensionFocused_;
std::unique_ptr<UIExtensionIdUtility> extensionIdUtility_ = std::make_unique<UIExtensionIdUtility>();
};
} // namespace OHOS::Ace
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_MANAGER_H

View File

@ -26,7 +26,7 @@
namespace OHOS::AAFwk {
class Want;
class WantParams;
}
} // namespace OHOS::AAFwk
namespace OHOS::Ace {
namespace NG {
@ -44,6 +44,7 @@ public:
virtual void SetOnReceive(std::function<void(const AAFwk::WantParams&)>&& onReceive);
virtual void SetOnError(
std::function<void(int32_t code, const std::string& name, const std::string& message)>&& onError);
private:
static std::unique_ptr<UIExtensionModel> instance_;
static std::mutex mutex_;

View File

@ -15,9 +15,8 @@
#include "core/components_ng/pattern/ui_extension/ui_extension_model_ng.h"
#include "want.h"
#include "interfaces/inner_api/ace/modal_ui_extension_config.h"
#include "want.h"
#include "core/components/common/layout/constants.h"
#include "core/components_ng/base/view_stack_processor.h"
@ -34,8 +33,8 @@ RefPtr<FrameNode> UIExtensionModelNG::Create(const std::string& bundleName, cons
ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::UI_EXTENSION_COMPONENT_ETS_TAG, nodeId);
auto wantWrap = WantWrap::CreateWantWrap(bundleName, abilityName);
wantWrap->SetWantParam(params);
auto frameNode = FrameNode::GetOrCreateFrameNode(V2::UI_EXTENSION_COMPONENT_ETS_TAG, nodeId,
[]() { return AceType::MakeRefPtr<UIExtensionPattern>(); });
auto frameNode = FrameNode::GetOrCreateFrameNode(
V2::UI_EXTENSION_COMPONENT_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<UIExtensionPattern>(); });
auto pattern = frameNode->GetPattern<UIExtensionPattern>();
CHECK_NULL_RETURN(pattern, frameNode);
pattern->UpdateWant(wantWrap);
@ -47,11 +46,10 @@ RefPtr<FrameNode> UIExtensionModelNG::Create(const std::string& bundleName, cons
RefPtr<FrameNode> UIExtensionModelNG::Create(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks)
{
auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
auto frameNode = FrameNode::GetOrCreateFrameNode(
V2::UI_EXTENSION_COMPONENT_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<UIExtensionPattern>(); });
auto frameNode = FrameNode::GetOrCreateFrameNode(V2::UI_EXTENSION_COMPONENT_ETS_TAG, nodeId,
[]() { return AceType::MakeRefPtr<UIExtensionPattern>(false, true); });
auto pattern = frameNode->GetPattern<UIExtensionPattern>();
CHECK_NULL_RETURN(pattern, frameNode);
pattern->SetModalFlag(true);
pattern->UpdateWant(want);
auto pipeline = PipelineContext::GetCurrentContext();
CHECK_NULL_RETURN(pipeline, frameNode);
@ -70,10 +68,9 @@ void UIExtensionModelNG::Create(const RefPtr<OHOS::Ace::WantWrap>& wantWrap, boo
auto* stack = ViewStackProcessor::GetInstance();
auto nodeId = stack->ClaimNodeId();
auto frameNode = FrameNode::GetOrCreateFrameNode(V2::UI_EXTENSION_COMPONENT_ETS_TAG, nodeId,
[]() { return AceType::MakeRefPtr<UIExtensionPattern>(); });
[transferringCaller]() { return AceType::MakeRefPtr<UIExtensionPattern>(transferringCaller); });
auto pattern = frameNode->GetPattern<UIExtensionPattern>();
CHECK_NULL_VOID(pattern);
pattern->SetTransferringCaller(transferringCaller);
pattern->UpdateWant(wantWrap);
stack->Push(frameNode);
auto pipeline = PipelineContext::GetCurrentContext();

View File

@ -18,9 +18,9 @@
#include <cstdint>
#include <functional>
#include <list>
#include <memory>
#include <refbase.h>
#include <list>
#include <vector>
#include "base/memory/referenced.h"
@ -28,15 +28,10 @@
#include "core/common/container.h"
#include "core/components_ng/event/gesture_event_hub.h"
#include "core/components_ng/pattern/pattern.h"
#include "core/components_ng/pattern/ui_extension/session_wrapper.h"
#include "core/event/mouse_event.h"
#include "core/event/touch_event.h"
namespace OHOS::Rosen {
class Session;
class ILifecycleListener;
enum class WSError;
} // namespace OHOS::Rosen
namespace OHOS::Accessibility {
class AccessibilityElementInfo;
class AccessibilityEventInfo;
@ -57,84 +52,72 @@ class UIExtensionPattern : public Pattern {
DECLARE_ACE_TYPE(UIExtensionPattern, Pattern);
public:
UIExtensionPattern();
explicit UIExtensionPattern(bool isTransferringCaller = false, bool isModal = false);
~UIExtensionPattern() override;
RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override;
FocusPattern GetFocusPattern() const override;
void UpdateWant(const RefPtr<OHOS::Ace::WantWrap>& wantWrap);
void UpdateWant(const AAFwk::Want& want);
void DestorySession();
void OnWindowShow() override;
void OnWindowHide() override;
RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override;
FocusPattern GetFocusPattern() const override;
void OnVisibleChange(bool visible) override;
bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
void SetModalOnDestroy(const std::function<void()>&& callback);
void SetModalOnRemoteReadyCallback(
const std::function<void(const std::shared_ptr<ModalUIExtensionProxy>&)>&& callback);
void SetOnRemoteReadyCallback(const std::function<void(const RefPtr<UIExtensionProxy>&)>&& callback);
void SetOnSyncOnCallbackList(
const std::list<std::function<void(const RefPtr<UIExtensionProxy>&)>>&& callbackList);
void SetOnAsyncOnCallbackList(
const std::list<std::function<void(const RefPtr<UIExtensionProxy>&)>>&& callbackList);
void SetOnSyncOffCallbackList(
const std::list<std::function<void(const RefPtr<UIExtensionProxy>&)>>&& callbackList);
void SetOnAsyncOffCallbackList(
const std::list<std::function<void(const RefPtr<UIExtensionProxy>&)>>&& callbackList);
void SetOnReleaseCallback(const std::function<void(int32_t)>&& callback);
void SetOnResultCallback(const std::function<void(int32_t, const AAFwk::Want&)>&& callback);
void SetOnReceiveCallback(const std::function<void(const AAFwk::WantParams&)>&& callback);
void SetOnErrorCallback(
const std::function<void(int32_t code, const std::string& name, const std::string& message)>&& callback);
void SetTransferringCaller(bool value);
void RegisterLifecycleListener();
void UnregisterLifecycleListener();
void OnConnect();
void OnDisconnect();
void OnExtensionDied();
bool OnBackPressed();
void HandleDragEvent(const PointerEvent& info) override;
void RequestExtensionSessionActivation();
void RequestExtensionSessionBackground();
void RequestExtensionSessionDestruction();
virtual void SearchExtensionElementInfoByAccessibilityId(int32_t elementId, int32_t mode,
int32_t baseParent, std::list<Accessibility::AccessibilityElementInfo>& output) override;
virtual void SearchElementInfosByText(int32_t elementId, const std::string& text,
int32_t baseParent, std::list<Accessibility::AccessibilityElementInfo>& output) override;
virtual void FindFocusedElementInfo(int32_t elementId, int32_t focusType,
int32_t baseParent, Accessibility::AccessibilityElementInfo& output) override;
virtual void FocusMoveSearch(int32_t elementId, int32_t direction,
int32_t baseParent, Accessibility::AccessibilityElementInfo& output) override;
virtual bool TransferExecuteAction(int32_t elementId, const std::map<std::string, std::string>& actionArguments,
int32_t action, int32_t offset) override;
void SetModalOnDestroy(const std::function<void()>&& callback);
void FireModalOnDestroy();
void SetModalOnRemoteReadyCallback(
const std::function<void(const std::shared_ptr<ModalUIExtensionProxy>&)>&& callback);
void SetOnRemoteReadyCallback(const std::function<void(const RefPtr<UIExtensionProxy>&)>&& callback);
void FireOnRemoteReadyCallback();
void SetOnReleaseCallback(const std::function<void(int32_t)>&& callback);
void FireOnReleaseCallback(int32_t releaseCode);
void SetOnResultCallback(const std::function<void(int32_t, const AAFwk::Want&)>&& callback);
void FireOnResultCallback(int32_t code, const AAFwk::Want& want);
void SetOnReceiveCallback(const std::function<void(const AAFwk::WantParams&)>&& callback);
void FireOnReceiveCallback(const AAFwk::WantParams& params);
void SetOnErrorCallback(
const std::function<void(int32_t code, const std::string& name, const std::string& message)>&& callback);
void FireOnErrorCallback(int32_t code, const std::string& name, const std::string& message);
void SetSyncCallbacks(const std::list<std::function<void(const RefPtr<UIExtensionProxy>&)>>&& callbackList);
void FireSyncCallbacks();
void SetAsyncCallbacks(const std::list<std::function<void(const RefPtr<UIExtensionProxy>&)>>&& callbackList);
void FireAsyncCallbacks();
void NotifyForeground();
void NotifyBackground();
void NotifyDestroy();
int32_t GetSessionId();
void SetModalFlag(bool isModal)
{
isModal_ = isModal;
}
int32_t GetUiExtensionId() override;
int32_t WrapExtensionAbilityId(int32_t extensionOffset, int32_t abilityId) override;
virtual void SearchExtensionElementInfoByAccessibilityId(int32_t elementId, int32_t mode, int32_t baseParent,
std::list<Accessibility::AccessibilityElementInfo>& output) override;
virtual void SearchElementInfosByText(int32_t elementId, const std::string& text, int32_t baseParent,
std::list<Accessibility::AccessibilityElementInfo>& output) override;
virtual void FindFocusedElementInfo(int32_t elementId, int32_t focusType, int32_t baseParent,
Accessibility::AccessibilityElementInfo& output) override;
virtual void FocusMoveSearch(int32_t elementId, int32_t direction, int32_t baseParent,
Accessibility::AccessibilityElementInfo& output) override;
virtual bool TransferExecuteAction(int32_t elementId, const std::map<std::string, std::string>& actionArguments,
int32_t action, int32_t offset) override;
void OnAccessibilityEvent(
const Accessibility::AccessibilityEventInfo& info, const std::vector<int32_t>& uiExtensionIdLevelList);
void HandleDragEvent(const PointerEvent& info) override;
private:
enum ReleaseCode {
enum class ReleaseCode {
DESTROY_NORMAL = 0,
CONNECT_BROKEN,
};
enum AbilityState {
enum class AbilityState {
NONE = 0,
FOREGROUND,
BACKGROUND,
@ -147,42 +130,31 @@ private:
std::string message;
};
void OnModifyDone() override;
void OnDetachFromFrameNode(FrameNode* frameNode) override;
void OnLanguageConfigurationUpdate() override;
void OnColorConfigurationUpdate() override;
void OnModifyDone() override;
void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub);
bool OnKeyEvent(const KeyEvent& event);
void HandleFocusEvent();
void HandleBlurEvent();
bool KeyEventConsumed(const KeyEvent& event);
void InitKeyEvent(const RefPtr<FocusHub>& focusHub);
void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub);
void InitMouseEvent(const RefPtr<InputEventHub>& inputHub);
void InitHoverEvent(const RefPtr<InputEventHub>& inputHub);
bool HandleKeyEvent(const KeyEvent& event);
void HandleFocusEvent();
void HandleBlurEvent();
void HandleTouchEvent(const TouchEventInfo& info);
void HandleMouseEvent(const MouseInfo& info);
void HandleHoverEvent(bool isHover);
void UnregisterAbilityResultListener();
void DispatchPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
void DispatchKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
void DispatchBackpressedEventForConsumed(bool& isConsumed);
void DispatchKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed);
void DisPatchFocusActiveEvent(bool isFocusActive);
void TransferFocusState(bool focusState);
bool DispatchKeyEventSync(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
void DispatchFocusActiveEvent(bool isFocusActive);
void DispatchFocusState(bool focusState);
void DispatchPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
void RegisterVisibleAreaChange();
void UpdateTextFieldManager(const Offset& offset, float height);
bool IsCurrentFocus() const;
void ProcessUIExtensionSessionActivationResult(OHOS::Rosen::WSError errcode);
void ProcessUIExtensionSessionBackgroundResult(OHOS::Rosen::WSError errcode);
void ProcessUIExtensionSessionDestructionResult(OHOS::Rosen::WSError errcode);
void onConfigurationUpdate();
void OnLanguageConfigurationUpdate() override;
void OnColorConfigurationUpdate() override;
RefPtr<TouchEventImpl> touchEvent_;
RefPtr<InputEvent> mouseEvent_;
RefPtr<InputEvent> hoverEvent_;
@ -191,27 +163,23 @@ private:
std::function<void()> onModalDestroy_;
std::function<void(const std::shared_ptr<ModalUIExtensionProxy>&)> onModalRemoteReadyCallback_;
std::function<void(const RefPtr<UIExtensionProxy>&)> onRemoteReadyCallback_;
std::list<std::function<void(const RefPtr<UIExtensionProxy>&)>> onSyncOnCallbackList_;
std::list<std::function<void(const RefPtr<UIExtensionProxy>&)>> onAsyncOnCallbackList_;
std::function<void(int32_t)> onReleaseCallback_;
std::function<void(int32_t, const AAFwk::Want&)> onResultCallback_;
std::function<void(const AAFwk::WantParams&)> onReceiveCallback_;
std::function<void(int32_t code, const std::string& name, const std::string& message)> onErrorCallback_;
std::list<std::function<void(const RefPtr<UIExtensionProxy>&)>> onSyncOnCallbackList_;
std::list<std::function<void(const RefPtr<UIExtensionProxy>&)>> onAsyncOnCallbackList_;
std::shared_ptr<Rosen::ILifecycleListener> lifecycleListener_;
sptr<Rosen::Session> session_;
RefPtr<FrameNode> contentNode_;
RefPtr<SessionWrapper> sessionWrapper_;
ErrorMsg lastError_;
int32_t instanceId_ = Container::CurrentId();
AbilityState state_ = AbilityState::NONE;
ACE_DISALLOW_COPY_AND_MOVE(UIExtensionPattern);
bool transferringCaller_ = false;
bool isTransferringCaller_ = false;
bool isVisible_ = true;
bool isModal_ = false;
int32_t uiExtensionId_ = 0;
ACE_DISALLOW_COPY_AND_MOVE(UIExtensionPattern);
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_PATTERN_H

View File

@ -15,35 +15,27 @@
#include "core/components_ng/pattern/ui_extension/ui_extension_proxy.h"
#include "session/host/include/extension_session.h"
#include "adapter/ohos/osal/want_wrap_ohos.h"
#include "base/utils/utils.h"
#include "core/components_ng/pattern/ui_extension/session_wrapper.h"
namespace OHOS::Ace::NG {
UIExtensionProxy::UIExtensionProxy(const sptr<Rosen::Session>& session,
const RefPtr<UIExtensionPattern>& pattern): session_(session), pattern_(pattern) {}
UIExtensionProxy::UIExtensionProxy(
const RefPtr<SessionWrapper>& sessionWrapper, const RefPtr<UIExtensionPattern>& pattern)
: sessionWrapper_(sessionWrapper), pattern_(pattern)
{}
void UIExtensionProxy::SendData(const RefPtr<WantParamsWrap>& wantParams)
{
auto session = session_.promote();
if (session) {
sptr<Rosen::ExtensionSession> extensionSession(static_cast<Rosen::ExtensionSession*>(session.GetRefPtr()));
auto params = DynamicCast<WantParamsWrapOhos>(wantParams)->GetWantParams();
extensionSession->TransferComponentData(params);
}
CHECK_NULL_VOID(sessionWrapper_);
auto params = DynamicCast<WantParamsWrapOhos>(wantParams)->GetWantParams();
sessionWrapper_->SendDataAsync(params);
}
OHOS::Rosen::WSErrorCode UIExtensionProxy::SendDataSync(const RefPtr<WantParamsWrap>& wantParams,
AAFwk::WantParams& reWantParams)
int32_t UIExtensionProxy::SendDataSync(const RefPtr<WantParamsWrap>& wantParams, AAFwk::WantParams& reWantParams)
{
Rosen::WSErrorCode transferCode = Rosen::WSErrorCode::WS_ERROR_TRANSFER_DATA_FAILED;
auto session = session_.promote();
if (session) {
sptr<Rosen::ExtensionSession> extensionSession(static_cast<Rosen::ExtensionSession*>(session.GetRefPtr()));
auto params = DynamicCast<WantParamsWrapOhos>(wantParams)->GetWantParams();
transferCode = extensionSession->TransferComponentDataSync(params, reWantParams);
}
return transferCode;
auto params = DynamicCast<WantParamsWrapOhos>(wantParams)->GetWantParams();
return sessionWrapper_ ? sessionWrapper_->SendDataSync(params, reWantParams) : 0;
}
RefPtr<UIExtensionPattern> UIExtensionProxy::GetPattern() const

View File

@ -16,30 +16,23 @@
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_PROXY_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_PROXY_H
#include <refbase.h>
#include "base/memory/ace_type.h"
#include "base/memory/referenced.h"
#include "base/want/want_wrap.h"
#include "ui_extension_pattern.h"
namespace OHOS::Rosen {
class Session;
enum class WSErrorCode : int32_t;
} // namespace OHOS::Rosen
#include "core/components_ng/pattern/ui_extension/session_wrapper.h"
#include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h"
namespace OHOS::Ace::NG {
class UIExtensionProxy : public AceType {
DECLARE_ACE_TYPE(UIExtensionProxy, AceType);
public:
UIExtensionProxy(const sptr<Rosen::Session>& session, const RefPtr<UIExtensionPattern>& pattern);
UIExtensionProxy(const RefPtr<SessionWrapper>& sessionWrapper, const RefPtr<UIExtensionPattern>& pattern);
void SendData(const RefPtr<WantParamsWrap>& params);
OHOS::Rosen::WSErrorCode SendDataSync(const RefPtr<WantParamsWrap>& wantParams,
AAFwk::WantParams& reWantParams);
int32_t SendDataSync(const RefPtr<WantParamsWrap>& wantParams, AAFwk::WantParams& reWantParams);
RefPtr<UIExtensionPattern> GetPattern() const;
private:
wptr<Rosen::Session> session_;
RefPtr<SessionWrapper> sessionWrapper_;
WeakPtr<UIExtensionPattern> pattern_;
};
} // namespace OHOS::Ace::NG

View File

@ -16,6 +16,7 @@
#ifndef FOUNDATION_ACE_INTERFACE_INNERKITS_UI_EXTENSION_PROXY_H
#define FOUNDATION_ACE_INTERFACE_INNERKITS_UI_EXTENSION_PROXY_H
#include <cstdint>
#include "macros.h"
namespace OHOS::AAFwk {