1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_IMPL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_IMPL_H 18 19 #include <refbase.h> 20 21 #include "session/host/include/extension_session.h" 22 #include "want.h" 23 24 #include "base/geometry/ng/rect_t.h" 25 #include "base/memory/referenced.h" 26 #include "core/components_ng/pattern/ui_extension/session_wrapper.h" 27 #include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h" 28 29 namespace OHOS::Ace::NG { 30 class SessionWrapperImpl : public SessionWrapper { 31 DECLARE_ACE_TYPE(SessionWrapperImpl, SessionWrapper); 32 33 public: 34 SessionWrapperImpl(const WeakPtr<UIExtensionPattern>& hostPattern, int32_t instanceId, bool isTransferringCaller); 35 ~SessionWrapperImpl() override; 36 37 // About session 38 void CreateSession(const AAFwk::Want& want, bool isAsyncModalBinding = false) override; 39 void DestroySession() override; 40 bool IsSessionValid() override; 41 int32_t GetSessionId() override; 42 const std::shared_ptr<AAFwk::Want> GetWant() override; 43 44 // Synchronous interface for event notify 45 bool NotifyFocusEventSync(bool isFocus) override; 46 bool NotifyFocusStateSync(bool focusState) override; 47 bool NotifyBackPressedSync() override; 48 bool NotifyPointerEventSync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override; 49 bool NotifyKeyEventSync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) override; 50 bool NotifyAxisEventSync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override; 51 52 // Asynchronous interface for event notify 53 bool NotifyFocusEventAsync(bool isFocus) override; 54 bool NotifyFocusStateAsync(bool focusState) override; 55 bool NotifyBackPressedAsync() override; 56 bool NotifyPointerEventAsync(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override; 57 bool NotifyKeyEventAsync(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) override; 58 bool NotifyAxisEventAsync(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override; 59 60 // The lifecycle interface 61 void NotifyCreate() override; 62 void NotifyForeground() override; 63 void NotifyBackground() override; 64 void NotifyDestroy() override; 65 void NotifyConfigurationUpdate() override; 66 67 // The interface about the accessibility 68 bool TransferExecuteAction(int64_t elementId, const std::map<std::string, std::string>& actionArguments, 69 int32_t action, int64_t offset) override; 70 void SearchExtensionElementInfoByAccessibilityId(int64_t elementId, int32_t mode, int64_t baseParent, 71 std::list<Accessibility::AccessibilityElementInfo>& output) override; 72 void SearchElementInfosByText(int64_t elementId, const std::string& text, int64_t baseParent, 73 std::list<Accessibility::AccessibilityElementInfo>& output) override; 74 void FindFocusedElementInfo(int64_t elementId, int32_t focusType, int64_t baseParent, 75 Accessibility::AccessibilityElementInfo& output) override; 76 void FocusMoveSearch(int64_t elementId, int32_t direction, int64_t baseParent, 77 Accessibility::AccessibilityElementInfo& output) override; 78 79 // The interface to control the display area 80 std::shared_ptr<Rosen::RSSurfaceNode> GetSurfaceNode() const override; 81 void RefreshDisplayArea(const RectF& displayArea) override; 82 83 // The interface to send the data for ArkTS 84 void SendDataAsync(const AAFwk::WantParams& params) const override; 85 int32_t SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const override; 86 87 // The interface to control the avoid area 88 void NotifyOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) const override; 89 bool NotifyOccupiedAreaChangeInfo(sptr<Rosen::OccupiedAreaChangeInfo> info) const override; 90 91 private: 92 void InitAllCallback(); 93 sptr<Rosen::ExtensionSession> session_; 94 WeakPtr<UIExtensionPattern> hostPattern_; 95 RectF displayArea_; 96 bool isNotifyOccupiedAreaChange_ = false; 97 int32_t instanceId_; 98 bool isTransferringCaller_; 99 std::shared_ptr<Rosen::ILifecycleListener> lifecycleListener_; 100 std::function<void((OHOS::Rosen::WSError))> foregroundCallback_; 101 std::function<void((OHOS::Rosen::WSError))> backgroundCallback_; 102 std::function<void((OHOS::Rosen::WSError))> destructionCallback_; 103 }; 104 } // namespace OHOS::Ace::NG 105 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_IMPL_H 106