From 4a97d99781d20fd81e05878eb89bce77b94f6827 Mon Sep 17 00:00:00 2001 From: wangle Date: Tue, 19 Aug 2025 15:55:36 +0800 Subject: [PATCH 01/11] SyncYellowToBlue Signed-off-by: wangle --- .../innerkits/wm/web_picture_in_picture_controller_interface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/innerkits/wm/web_picture_in_picture_controller_interface.h b/interfaces/innerkits/wm/web_picture_in_picture_controller_interface.h index 9d1052a321..fa7b1e4583 100644 --- a/interfaces/innerkits/wm/web_picture_in_picture_controller_interface.h +++ b/interfaces/innerkits/wm/web_picture_in_picture_controller_interface.h @@ -57,7 +57,7 @@ private: SIZE_CHANGE_CB, PIP_START_CB, }; - WMError CheckRegisterParam(const sptr& listener); + WMError CheckRegisterParam(ListenerType type, const sptr& listener); WMError RegisterListenerWithType(ListenerType type, const sptr& listener); WMError UnregisterListenerWithType(ListenerType type, const sptr& listener); WMError ProcessStateChangeRegister(const sptr& listener); -- Gitee From c45769fbea841aebe8ded2df18e0c841670d969e Mon Sep 17 00:00:00 2001 From: wangle Date: Tue, 19 Aug 2025 17:13:28 +0800 Subject: [PATCH 02/11] SyncYellowToBlue Signed-off-by: wangle --- .../inner/js_pip_manager.cpp | 168 +++--------------- 1 file changed, 27 insertions(+), 141 deletions(-) diff --git a/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp b/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp index 5302374df5..e6b6d9c204 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp +++ b/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp @@ -27,8 +27,7 @@ namespace { constexpr int32_t NUMBER_ONE = 1; constexpr int32_t NUMBER_TWO = 2; constexpr int32_t NUMBER_FOUR = 4; - const std::string STATE_CHANGE_CB = "stateChange"; - const std::string UPDATE_TYPE_CB = "nodeUpdate"; + const std::unordered_set PIP_CONTENT_CALLBACK {"stateChange", "nodeUpdate"}; } napi_valuetype GetType(napi_env env, napi_value value) @@ -81,10 +80,6 @@ napi_value GetSurfaceIdFromJs(napi_env env, napi_value surfaceIdNapiValue, JsPipManager::JsPipManager() { - listenerCodeMap_ = { - { STATE_CHANGE_CB, ListenerType::STATE_CHANGE_CB }, - { UPDATE_TYPE_CB, ListenerType::UPDATE_TYPE_CB }, - }; } JsPipManager::~JsPipManager() @@ -323,93 +318,38 @@ napi_value JsPipManager::OnRegisterCallback(napi_env env, napi_callback_info inf TLOGE(WmsLogTag::WMS_PIP, "Failed to convert param to cbType"); return NapiThrowInvalidParam(env); } + if (PIP_CONTENT_CALLBACK.count(cbType) == 0) { + TLOGE(WmsLogTag::WMS_PIP, "cbType is not in PIP_CONTENT_CALLBACK"); + return NapiThrowInvalidParam(env); + } napi_value value = argv[1]; if (value == nullptr || !NapiIsCallable(env, value)) { TLOGE(WmsLogTag::WMS_PIP, "Callback is null or not callable"); return NapiThrowInvalidParam(env); } - WmErrorCode errCode = RegisterListenerWithType(env, cbType, value); - if (errCode != WmErrorCode::WM_OK) { - TLOGE(WmsLogTag::WMS_PIP, "Failed to registerCallback"); - return NapiGetUndefined(env); - } - TLOGI(WmsLogTag::WMS_PIP, "Register type %{public}s success!", cbType.c_str()); - return NapiGetUndefined(env); -} - -WmErrorCode JsPipManager::RegisterListenerWithType(napi_env env, const std::string& type, napi_value value) -{ - if (IfCallbackRegistered(env, type, value)) { - TLOGE(WmsLogTag::WMS_PIP, "Callback already registered!"); - return WmErrorCode::WM_ERROR_INVALID_CALLING; - } std::shared_ptr callbackRef; napi_ref result = nullptr; napi_create_reference(env, value, 1, &result); callbackRef.reset(reinterpret_cast(result)); - auto pipWindowListener = sptr::MakeSptr(env, callbackRef); - if (pipWindowListener == nullptr) { - TLOGE(WmsLogTag::WMS_PIP, "New JsPiPWindowListener failed"); - return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; - } - WmErrorCode ret = RegisterListener(type, pipWindowListener); - if (ret != WmErrorCode::WM_OK) { - TLOGE(WmsLogTag::WMS_PIP, "Register type %{public}s failed", type.c_str()); - return ret; - } - TLOGI(WmsLogTag::WMS_PIP, "Register type %{public}s success! callback map size: %{public}zu", - type.c_str(), jsCbMap_[type].size()); - return WmErrorCode::WM_OK; -} - -WmErrorCode JsPipManager::RegisterListener(const std::string& type, - const sptr& pipWindowListener) -{ sptr pipWindow = Window::Find(PIP_WINDOW_NAME); if (pipWindow == nullptr) { TLOGE(WmsLogTag::WMS_PIP, "Failed to find pip window"); - return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; + return NapiGetUndefined(env); } int32_t windowId = static_cast(pipWindow->GetWindowId()); sptr pipController = PictureInPictureManager::GetPipControllerInfo(windowId); if (pipController == nullptr) { TLOGE(WmsLogTag::WMS_PIP, "Failed to get pictureInPictureController"); - return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; - } - jsCbMap_[type].insert(pipWindowListener); - switch (listenerCodeMap_[type]) { - case ListenerType::STATE_CHANGE_CB: { - sptr lifeCycleListener(pipWindowListener); - pipController->RegisterPiPLifecycle(lifeCycleListener); - break; - } - case ListenerType::UPDATE_TYPE_CB: { - sptr typeNodeChangeObserver(pipWindowListener); - pipController->RegisterPiPTypeNodeChange(typeNodeChangeObserver); - break; - } - default: - TLOGE(WmsLogTag::WMS_PIP, "Failed to match ListenerType"); - return WmErrorCode::WM_ERROR_INVALID_PARAM; + return NapiGetUndefined(env); } - return WmErrorCode::WM_OK; -} - -bool JsPipManager::IfCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject) -{ - if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { - TLOGI(WmsLogTag::WMS_PIP, "methodName %{public}s not registered!", type.c_str()); - return false; - } - for (auto& listener : jsCbMap_[type]) { - bool isEquals = false; - napi_strict_equals(env, jsListenerObject, listener->GetCallbackRef()->GetNapiValue(), &isEquals); - if (isEquals) { - TLOGE(WmsLogTag::WMS_PIP, "Callback already registered!"); - return true; - } + TLOGI(WmsLogTag::WMS_PIP, "OnRegisterCallback to window:%{public}d", windowId); + WMError errCode = pipController->RegisterPipContentListenerWithType(cbType, callbackRef); + if (errCode != WMError::WM_OK) { + TLOGE(WmsLogTag::WMS_PIP, "Failed to registerCallback"); + return NapiGetUndefined(env); } - return false; + TLOGI(WmsLogTag::WMS_PIP, "Register type %{public}s success!", cbType.c_str()); + return NapiGetUndefined(env); } napi_value JsPipManager::UnregisterCallback(napi_env env, napi_callback_info info) @@ -424,7 +364,7 @@ napi_value JsPipManager::OnUnregisterCallback(napi_env env, napi_callback_info i size_t argc = NUMBER_FOUR; napi_value argv[NUMBER_FOUR] = {nullptr}; napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - if (argc != NUMBER_TWO) { + if (argc != NUMBER_ONE) { TLOGE(WmsLogTag::WMS_PIP, "Params count not match:%{public}zu", argc); return NapiThrowInvalidParam(env); } @@ -433,84 +373,30 @@ napi_value JsPipManager::OnUnregisterCallback(napi_env env, napi_callback_info i TLOGE(WmsLogTag::WMS_PIP, "Failed to convert param to cbType"); return NapiThrowInvalidParam(env); } - napi_value value = argv[NUMBER_ONE]; - if (value == nullptr || !NapiIsCallable(env, value)) { - TLOGE(WmsLogTag::WMS_PIP, "Callback is null or not callable"); + if (PIP_CONTENT_CALLBACK.count(cbType) == 0) { + TLOGE(WmsLogTag::WMS_PIP, "cbType is not in PIP_CONTENT_CALLBACK"); return NapiThrowInvalidParam(env); } - WmErrorCode errCode = UnRegisterListenerWithType(env, cbType, value); - if (errCode != WmErrorCode::WM_OK) { - TLOGE(WmsLogTag::WMS_PIP, "Failed to set UnRegisterPipContentListenerWithType"); - return NapiGetUndefined(env); - } - TLOGI(WmsLogTag::WMS_PIP, "unregister type:%{public}s success!", cbType.c_str()); - return NapiGetUndefined(env); -} - -WmErrorCode JsPipManager::UnRegisterListenerWithType(napi_env env, const std::string& type, napi_value value) -{ - if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { - TLOGI(WmsLogTag::WMS_PIP, "methodName %{public}s not registered!", type.c_str()); - return WmErrorCode::WM_ERROR_INVALID_CALLING; - } - bool foundCallbackValue = false; - for (auto& listener : jsCbMap_[type]) { - bool isEquals = false; - napi_strict_equals(env, value, listener->GetCallbackRef()->GetNapiValue(), &isEquals); - if (!isEquals) { - continue; - } - foundCallbackValue = true; - WmErrorCode ret = UnRegisterListener(type, listener); - if (ret != WmErrorCode::WM_OK) { - TLOGE(WmsLogTag::WMS_PIP, "Unregister type %{public}s failed", type.c_str()); - return ret; - } - jsCbMap_[type].erase(listener); - break; - } - if (!foundCallbackValue) { - TLOGE(WmsLogTag::WMS_PIP, "Unregister type %{public}s failed because not found callback!", type.c_str()); - return WmErrorCode::WM_OK; - } - if (jsCbMap_[type].empty()) { - jsCbMap_.erase(type); - } - TLOGI(WmsLogTag::WMS_PIP, "Unregister type %{public}s success!", type.c_str()); - return WmErrorCode::WM_OK; -} - -WmErrorCode JsPipManager::UnRegisterListener(const std::string& type, - const sptr& pipWindowListener) -{ sptr pipWindow = Window::Find(PIP_WINDOW_NAME); if (pipWindow == nullptr) { TLOGE(WmsLogTag::WMS_PIP, "Failed to find pip window"); - return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; + return NapiGetUndefined(env); } int32_t windowId = static_cast(pipWindow->GetWindowId()); sptr pipController = PictureInPictureManager::GetPipControllerInfo(windowId); if (pipController == nullptr) { TLOGE(WmsLogTag::WMS_PIP, "Failed to get pictureInPictureController"); - return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; + return NapiGetUndefined(env); } - switch (listenerCodeMap_[type]) { - case ListenerType::STATE_CHANGE_CB: { - sptr lifeCycleListener(pipWindowListener); - pipController->UnregisterPiPLifecycle(lifeCycleListener); - break; - } - case ListenerType::UPDATE_TYPE_CB: { - sptr typeNodeChangeObserver(pipWindowListener); - pipController->UnRegisterPiPTypeNodeChange(typeNodeChangeObserver); - break; - } - default: - TLOGE(WmsLogTag::WMS_PIP, "Failed to match ListenerType"); - return WmErrorCode::WM_ERROR_INVALID_PARAM; + TLOGI(WmsLogTag::WMS_PIP, "UnRegisterPipContentListenerWithType to window:%{public}d", windowId); + WMError errCode = pipController->UnRegisterPipContentListenerWithType(cbType); + if (errCode != WMError::WM_OK) { + TLOGE(WmsLogTag::WMS_PIP, "Failed to set UnRegisterPipContentListenerWithType"); + return NapiGetUndefined(env); + } + TLOGI(WmsLogTag::WMS_PIP, "unregister type:%{public}s success!", cbType.c_str()); + return NapiGetUndefined(env); } - return WmErrorCode::WM_OK; -} napi_value JsPipManagerInit(napi_env env, napi_value exportObj) { -- Gitee From 93a5c3a417077773aefcee64a8dfda6627387796 Mon Sep 17 00:00:00 2001 From: wangle Date: Tue, 19 Aug 2025 17:29:37 +0800 Subject: [PATCH 03/11] SyncYellowToBlue Signed-off-by: wangle --- .../inner/js_pip_manager.h | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.h b/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.h index c1b886d813..dcbdd78571 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.h +++ b/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.h @@ -16,11 +16,7 @@ #ifndef OHOS_JS_PIP_MANAGER_H #define OHOS_JS_PIP_MANAGER_H -#include - -#include "js_pip_window_listener.h" #include "js_runtime_utils.h" -#include "wm_common.h" namespace OHOS { namespace Rosen { @@ -38,16 +34,7 @@ public: static napi_value UnregisterCallback(napi_env env, napi_callback_info info); static napi_value SetTypeNodeEnabled(napi_env env, napi_callback_info info); static napi_value SetPipNodeType(napi_env env, napi_callback_info info); - bool IfCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject); - WmErrorCode RegisterListener(const std::string &type, const sptr &pipWindowListener); - WmErrorCode RegisterListenerWithType(napi_env env, const std::string& type, napi_value value); - WmErrorCode UnRegisterListener(const std::string &type, const sptr &pipWindowListener); - WmErrorCode UnRegisterListenerWithType(napi_env env, const std::string& type, napi_value value); private: - enum class ListenerType : uint32_t { - STATE_CHANGE_CB, - UPDATE_TYPE_CB, - }; napi_value OnInitXComponentController(napi_env env, napi_callback_info info); napi_value OnInitWebXComponentController(napi_env env, napi_callback_info info); napi_value OnGetCustomUIController(napi_env env, napi_callback_info info); @@ -56,8 +43,6 @@ private: napi_value OnUnregisterCallback(napi_env env, napi_callback_info info); napi_value OnSetTypeNodeEnabled(napi_env env, napi_callback_info info); napi_value OnSetPipNodeType(napi_env env, napi_callback_info info); - std::map listenerCodeMap_; - std::unordered_map>> jsCbMap_; }; } // namespace Rosen } // namespace OHOS -- Gitee From 28a9baab6e431593666da3dfd2ff1867c6eff646 Mon Sep 17 00:00:00 2001 From: wangle Date: Tue, 19 Aug 2025 17:39:05 +0800 Subject: [PATCH 04/11] SyncYellowToBlue Signed-off-by: wangle --- .../js_pip_window_listener.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_listener.cpp b/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_listener.cpp index 0f58d7e320..14b848efb0 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_listener.cpp +++ b/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_listener.cpp @@ -164,24 +164,5 @@ void JsPiPWindowListener::OnPipSizeChange(const PiPWindowSize& size) } } -void JsPiPWindowListener::OnPipTypeNodeChange(const napi_ref nodeRef) -{ - TLOGI(WmsLogTag::WMS_PIP, "called"); - auto napiTask = [jsCallback = jsCallBack_, nodeRef, env = env_]() { - napi_value typeNode = nullptr; - napi_get_reference_value(env, nodeRef, &typeNode); - napi_value argv[] = {typeNode}; - CallJsFunction(env, jsCallback->GetNapiValue(), argv, 1); - }; - if (env_ != nullptr) { - napi_status ret = napi_send_event(env_, napiTask, napi_eprio_immediate, "OnPipTypeNodeChange"); - if (ret != napi_status::napi_ok) { - TLOGE(WmsLogTag::WMS_PIP, "Failed to SendEvent"); - } - } else { - TLOGE(WmsLogTag::WMS_PIP, "env is nullptr"); - } -} - } // namespace Rosen } // namespace OHOS \ No newline at end of file -- Gitee From 142adff4697cd60bf7c3f2c88229c4a5008260dc Mon Sep 17 00:00:00 2001 From: wangle Date: Tue, 19 Aug 2025 17:45:59 +0800 Subject: [PATCH 05/11] SyncYellowToBlue Signed-off-by: wangle --- .../napi/picture_in_picture_napi/js_pip_window_listener.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_listener.h b/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_listener.h index bce797eaaf..1911bc7185 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_listener.h +++ b/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_listener.h @@ -25,8 +25,7 @@ namespace Rosen { class JsPiPWindowListener : public IPiPLifeCycle, public IPiPActionObserver, public IPiPControlObserver, - public IPiPWindowSize, - public IPiPTypeNodeObserver { + public IPiPWindowSize{ public: JsPiPWindowListener(napi_env env, const std::shared_ptr& callback) : env_(env), jsCallBack_(callback) {} @@ -41,7 +40,6 @@ public: void OnActionEvent(const std::string& actionEvent, int32_t statusCode) override; void OnControlEvent(PiPControlType controlType, PiPControlStatus statusCode) override; void OnPipSizeChange(const PiPWindowSize& size) override; - void OnPipTypeNodeChange(const napi_ref nodeRef) override; private: void OnPipListenerCallback(PiPState state, int32_t errorCode); -- Gitee From 097fe8a0b269efd7bab1266db2010b1bbd87a223 Mon Sep 17 00:00:00 2001 From: wangle Date: Tue, 19 Aug 2025 20:36:37 +0800 Subject: [PATCH 06/11] SyncYellowToBlue Signed-off-by: wangle --- .../js_pip_window_manager.cpp | 2 +- wm/include/picture_in_picture_controller.h | 8 +++++++- wm/include/picture_in_picture_controller_base.h | 10 ++++++---- wm/include/picture_in_picture_interface.h | 12 +----------- wm/include/picture_in_picture_option.h | 5 +++++ wm/src/oh_window_pip.cpp | 4 ---- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_manager.cpp b/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_manager.cpp index 2e0cfe24ae..ad548abe54 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_manager.cpp +++ b/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_manager.cpp @@ -285,7 +285,7 @@ napi_value JsPipWindowManager::NapiSendTask(napi_env env, PipOption& pipOption) pipOption.GetPiPTemplateInfo(pipTemplateInfo); mainWindow->UpdatePiPTemplateInfo(pipTemplateInfo); }; - if (napi_send_event(env, asyncTask, napi_eprio_immediate, "NapiSendTask") != napi_status::napi_ok) { + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { pipOption.ClearNapiRefs(env); napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WMError::WM_ERROR_PIP_INTERNAL_ERROR), "Send event failed")); diff --git a/wm/include/picture_in_picture_controller.h b/wm/include/picture_in_picture_controller.h index 6ba4c8c962..c04e5b5b27 100644 --- a/wm/include/picture_in_picture_controller.h +++ b/wm/include/picture_in_picture_controller.h @@ -33,7 +33,10 @@ public: void UpdateContentNodeRef(napi_ref nodeRef) override; void PrepareSource() override; void RestorePictureInPictureWindow() override; - void NotifyNodeUpdate(napi_ref nodeRef) override; + WMError RegisterPipContentListenerWithType(const std::string&, + std::shared_ptr updateNodeCallbackRef) override; + WMError UnRegisterPipContentListenerWithType(const std::string&) override; + std::shared_ptr GetPipContentCallbackRef(const std::string&) override; WMError SetXComponentController(std::shared_ptr xComponentController) override; napi_ref GetCustomNodeController() override; napi_ref GetTypeNode() const override; @@ -47,6 +50,9 @@ protected: void UpdatePiPSourceRect() const override; void SetUIContent() const override; void ResetExtController() override; + void NotifyNodeUpdate(napi_ref nodeRef) override; + void NotifyStateChangeInner(napi_env env, PiPState state) override; + wptr weakRef_ = nullptr; std::shared_ptr mainWindowXComponentController_ = nullptr; int32_t firstHandleId_ = -1; diff --git a/wm/include/picture_in_picture_controller_base.h b/wm/include/picture_in_picture_controller_base.h index 13ffbde0be..21fc5020f4 100644 --- a/wm/include/picture_in_picture_controller_base.h +++ b/wm/include/picture_in_picture_controller_base.h @@ -58,6 +58,7 @@ public: PictureInPictureControllerBase() { weakRef_ = this; } PictureInPictureControllerBase(sptr pipOption, sptr mainWindow, uint32_t windowId, napi_env env); virtual ~PictureInPictureControllerBase(); + static napi_value CallJsFunction(napi_env env, napi_value method, napi_value const * argv, size_t argc); WMError StopPictureInPicture(bool destroyWindow, StopPipType stopPipType, bool withAnim = true); WMError StopPictureInPictureFromClient(); WMError DestroyPictureInPictureWindow(); @@ -78,13 +79,11 @@ public: WMError RegisterPiPActionObserver(const sptr& listener); WMError RegisterPiPControlObserver(const sptr& listener); WMError RegisterPiPWindowSize(const sptr& listener); - WMError RegisterPiPTypeNodeChange(const sptr& listener); WMError RegisterPiPStart(const sptr& listener); WMError UnregisterPiPLifecycle(const sptr& listener); WMError UnregisterPiPActionObserver(const sptr& listener); WMError UnregisterPiPControlObserver(const sptr& listener); WMError UnregisterPiPWindowSize(const sptr& listener); - WMError UnRegisterPiPTypeNodeChange(const sptr& listener); WMError UnregisterPiPStart(const sptr& listener); void UnregisterAllPiPLifecycle(); void UnregisterAllPiPControlObserver(); @@ -115,6 +114,10 @@ public: virtual void IsAutoStartEnabled(bool& enable) const {}; virtual void UpdateContentNodeRef(napi_ref nodeRef) {}; virtual void PrepareSource() {}; + virtual WMError RegisterPipContentListenerWithType(const std::string&, + std::shared_ptr updateNodeCallbackRef) { return WMError::WM_OK; }; + virtual WMError UnRegisterPipContentListenerWithType(const std::string&) { return WMError::WM_OK; }; + virtual std::shared_ptr GetPipContentCallbackRef(const std::string&) { return nullptr; }; virtual napi_ref GetCustomNodeController() { return nullptr; }; virtual napi_ref GetTypeNode() const { return nullptr; }; virtual bool IsTypeNodeEnabled() const { return false; }; @@ -144,7 +147,6 @@ protected: std::vector> pipActionObservers_; std::vector> pipControlObservers_; std::vector> pipWindowSizeListeners_; - std::vector> pipTypeNodeObserver_; std::vector> pipStartListeners_; sptr window_ = nullptr; sptr mainWindow_ = nullptr; @@ -168,7 +170,7 @@ protected: // normal virtual void ResetExtController() {}; virtual void NotifyNodeUpdate(napi_ref nodeRef) {}; - + virtual void NotifyStateChangeInner(napi_env env, PiPState state) {}; private: wptr weakRef_ = nullptr; }; diff --git a/wm/include/picture_in_picture_interface.h b/wm/include/picture_in_picture_interface.h index 3e80f58d33..8313bf11e1 100644 --- a/wm/include/picture_in_picture_interface.h +++ b/wm/include/picture_in_picture_interface.h @@ -16,7 +16,6 @@ #ifndef OHOS_PICTURE_IN_PICTURE_INTERFACE_H #define OHOS_PICTURE_IN_PICTURE_INTERFACE_H -#include "napi/native_api.h" #include "wm_common.h" namespace OHOS { @@ -80,21 +79,12 @@ public: virtual void OnPipSizeChange(uint32_t controllerId, const PiPWindowSize& size) {} }; -/** - * @class IPiPTypeNodeObserver - * - * @brief Pip typeNode observer. - */ -class IPiPTypeNodeObserver : virtual public RefBase { -public: - virtual void OnPipTypeNodeChange(const napi_ref nodeRef) {} -}; - class IPiPStartObserver : virtual public RefBase { public: // native callback virtual void OnPipStart(uint32_t controllerId, uint8_t requestId, uint64_t surfaceId) {} }; + } // namespace Rosen } // namespace OHOS #endif //OHOS_PICTURE_IN_PICTURE_INTERFACE_H diff --git a/wm/include/picture_in_picture_option.h b/wm/include/picture_in_picture_option.h index 952bfb68e2..16f3f8b382 100644 --- a/wm/include/picture_in_picture_option.h +++ b/wm/include/picture_in_picture_option.h @@ -17,6 +17,7 @@ #define OHOS_PIP_OPTION_H #include #include +#include "js_runtime_utils.h" #include "napi/native_api.h" #include "wm_common.h" #include "xcomponent_controller.h" @@ -37,6 +38,8 @@ public: void SetPiPControlStatus(PiPControlType controlType, PiPControlStatus status); void SetPiPControlEnabled(PiPControlType controlType, PiPControlStatus enabled); void SetXComponentController(std::shared_ptr xComponentController); + void RegisterPipContentListenerWithType(const std::string&, std::shared_ptr updateNodeCallbackRef); + void UnRegisterPipContentListenerWithType(const std::string&); void SetControlGroup(std::vector controlGroup); void* GetContext() const; std::string GetNavigationId() const; @@ -47,6 +50,7 @@ public: std::vector GetControlEnable(); void GetContentSize(uint32_t& width, uint32_t& height); std::shared_ptr GetXComponentController(); + std::shared_ptr GetPipContentCallbackRef(const std::string&); void SetNodeControllerRef(napi_ref ref); napi_ref GetNodeControllerRef() const; void SetTypeNodeRef(napi_ref ref); @@ -68,6 +72,7 @@ private: std::vector pipControlEnableInfoList_; std::vector controlGroup_; std::shared_ptr xComponentController_ = nullptr; + std::map> pipContentlistenerMap_; napi_ref customNodeController_ = nullptr; napi_ref typeNode_ = nullptr; bool useTypeNode_ = false; diff --git a/wm/src/oh_window_pip.cpp b/wm/src/oh_window_pip.cpp index e7dcc3401a..d8d37619e4 100644 --- a/wm/src/oh_window_pip.cpp +++ b/wm/src/oh_window_pip.cpp @@ -107,10 +107,6 @@ int32_t OH_PictureInPicture_DestroyPipConfig(PictureInPicture_PipConfig* pipConf return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM; } auto config = reinterpret_cast(*pipConfig); - if (config == nullptr) { - TLOGE(WmsLogTag::WMS_PIP, "config is nullptr"); - return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM; - } delete config; *pipConfig = nullptr; TLOGI(WmsLogTag::WMS_PIP, "pipConfig destroyed"); -- Gitee From 7601560865c917584e4314292ee098118fdd48cf Mon Sep 17 00:00:00 2001 From: wangle Date: Tue, 19 Aug 2025 21:21:48 +0800 Subject: [PATCH 07/11] SyncYellowToBlue Signed-off-by: wangle --- .../kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp | 2 +- .../kits/napi/picture_in_picture_napi/js_pip_window_listener.h | 2 +- wm/include/picture_in_picture_controller_base.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp b/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp index e6b6d9c204..fe74b9373b 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp +++ b/interfaces/kits/napi/picture_in_picture_napi/inner/js_pip_manager.cpp @@ -396,7 +396,7 @@ napi_value JsPipManager::OnUnregisterCallback(napi_env env, napi_callback_info i } TLOGI(WmsLogTag::WMS_PIP, "unregister type:%{public}s success!", cbType.c_str()); return NapiGetUndefined(env); - } +} napi_value JsPipManagerInit(napi_env env, napi_value exportObj) { diff --git a/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_listener.h b/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_listener.h index 1911bc7185..19df60d5e1 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_listener.h +++ b/interfaces/kits/napi/picture_in_picture_napi/js_pip_window_listener.h @@ -25,7 +25,7 @@ namespace Rosen { class JsPiPWindowListener : public IPiPLifeCycle, public IPiPActionObserver, public IPiPControlObserver, - public IPiPWindowSize{ + public IPiPWindowSize { public: JsPiPWindowListener(napi_env env, const std::shared_ptr& callback) : env_(env), jsCallBack_(callback) {} diff --git a/wm/include/picture_in_picture_controller_base.h b/wm/include/picture_in_picture_controller_base.h index 21fc5020f4..92da316e40 100644 --- a/wm/include/picture_in_picture_controller_base.h +++ b/wm/include/picture_in_picture_controller_base.h @@ -171,6 +171,7 @@ protected: virtual void ResetExtController() {}; virtual void NotifyNodeUpdate(napi_ref nodeRef) {}; virtual void NotifyStateChangeInner(napi_env env, PiPState state) {}; + private: wptr weakRef_ = nullptr; }; -- Gitee From 87401dccda3015e21dc45ba84e22c16421158a51 Mon Sep 17 00:00:00 2001 From: wangle Date: Wed, 20 Aug 2025 15:14:04 +0800 Subject: [PATCH 08/11] SyncYellowToBlue Signed-off-by: wangle --- .../picture_in_picture_napi/inner/BUILD.gn | 6 +-- wm/include/picture_in_picture_controller.h | 2 +- .../picture_in_picture_controller_base.h | 4 +- wm/src/picture_in_picture_controller.cpp | 53 ++++++++++++++++++- wm/src/picture_in_picture_controller_base.cpp | 32 +++++++---- wm/src/picture_in_picture_option.cpp | 20 +++++++ ...icture_in_picture_controller_interface.cpp | 46 ++++++++++++---- 7 files changed, 134 insertions(+), 29 deletions(-) diff --git a/interfaces/kits/napi/picture_in_picture_napi/inner/BUILD.gn b/interfaces/kits/napi/picture_in_picture_napi/inner/BUILD.gn index d974ea2b67..fa1db04764 100644 --- a/interfaces/kits/napi/picture_in_picture_napi/inner/BUILD.gn +++ b/interfaces/kits/napi/picture_in_picture_napi/inner/BUILD.gn @@ -16,10 +16,7 @@ import("../../../../../windowmanager_aafwk.gni") config("pip_manager_config") { visibility = [ ":*" ] - include_dirs = [ - "../", - "../../../../../wm/include", - ] + include_dirs = [ "../../../../../wm/include" ] } ohos_shared_library("pip_napi") { @@ -31,7 +28,6 @@ ohos_shared_library("pip_napi") { debug = false } sources = [ - "../js_pip_window_listener.cpp", "js_pip_manager.cpp", "js_pip_module.cpp", ] diff --git a/wm/include/picture_in_picture_controller.h b/wm/include/picture_in_picture_controller.h index c04e5b5b27..4726b58afd 100644 --- a/wm/include/picture_in_picture_controller.h +++ b/wm/include/picture_in_picture_controller.h @@ -34,7 +34,7 @@ public: void PrepareSource() override; void RestorePictureInPictureWindow() override; WMError RegisterPipContentListenerWithType(const std::string&, - std::shared_ptr updateNodeCallbackRef) override; + std::shared_ptr updateNodeCallbackRef) override; WMError UnRegisterPipContentListenerWithType(const std::string&) override; std::shared_ptr GetPipContentCallbackRef(const std::string&) override; WMError SetXComponentController(std::shared_ptr xComponentController) override; diff --git a/wm/include/picture_in_picture_controller_base.h b/wm/include/picture_in_picture_controller_base.h index 92da316e40..1be7b3dcf5 100644 --- a/wm/include/picture_in_picture_controller_base.h +++ b/wm/include/picture_in_picture_controller_base.h @@ -115,7 +115,7 @@ public: virtual void UpdateContentNodeRef(napi_ref nodeRef) {}; virtual void PrepareSource() {}; virtual WMError RegisterPipContentListenerWithType(const std::string&, - std::shared_ptr updateNodeCallbackRef) { return WMError::WM_OK; }; + std::shared_ptr updateNodeCallbackRef) { return WMError::WM_OK; }; virtual WMError UnRegisterPipContentListenerWithType(const std::string&) { return WMError::WM_OK; }; virtual std::shared_ptr GetPipContentCallbackRef(const std::string&) { return nullptr; }; virtual napi_ref GetCustomNodeController() { return nullptr; }; @@ -171,7 +171,7 @@ protected: virtual void ResetExtController() {}; virtual void NotifyNodeUpdate(napi_ref nodeRef) {}; virtual void NotifyStateChangeInner(napi_env env, PiPState state) {}; - + private: wptr weakRef_ = nullptr; }; diff --git a/wm/src/picture_in_picture_controller.cpp b/wm/src/picture_in_picture_controller.cpp index b6dda2eaa7..61699c365c 100644 --- a/wm/src/picture_in_picture_controller.cpp +++ b/wm/src/picture_in_picture_controller.cpp @@ -23,6 +23,9 @@ namespace Rosen { namespace { const std::string PIP_CONTENT_PATH = "/system/etc/window/resources/pip_content.abc"; const std::string DESTROY_TIMEOUT_TASK = "PipDestroyTimeout"; + const std::string STATE_CHANGE = "stateChange"; + const std::string UPDATE_NODE = "nodeUpdate"; + } PictureInPictureController::PictureInPictureController(sptr pipOption, sptr mainWindow, @@ -282,9 +285,17 @@ void PictureInPictureController::NotifyNodeUpdate(napi_ref nodeRef) return; } if (PictureInPictureManager::IsActiveController(weakRef_)) { - for (auto& listener : pipTypeNodeObserver_) { - listener->OnPipTypeNodeChange(nodeRef); + std::shared_ptr updateNodeCallbackRef = GetPipContentCallbackRef(UPDATE_NODE); + if (updateNodeCallbackRef == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "updateNodeCallbackRef is null"); + SingletonContainer::Get().ReportPiPUpdateContent(static_cast(IsTypeNodeEnabled()), + pipOption_->GetPipTemplate(), PipConst::FAILED, "updateNodeCallbackRef is null"); + return; } + napi_value typeNode = nullptr; + napi_get_reference_value(env_, nodeRef, &typeNode); + napi_value value[] = { typeNode }; + CallJsFunction(env_, updateNodeCallbackRef->GetNapiValue(), value, 1); SingletonContainer::Get().ReportPiPUpdateContent(static_cast(IsTypeNodeEnabled()), pipOption_->GetPipTemplate(), PipConst::PIP_SUCCESS, "updateNode success"); } @@ -429,6 +440,44 @@ WMError PictureInPictureController::SetXComponentController(std::shared_ptrRegisterPipContentListenerWithType(type, callbackRef); + return WMError::WM_OK; +} + +WMError PictureInPictureController::UnRegisterPipContentListenerWithType(const std::string& type) +{ + TLOGI(WmsLogTag::WMS_PIP, "Unregister type:%{public}s", type.c_str()); + if (pipOption_ == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "Get PictureInPicture option failed"); + return WMError::WM_ERROR_PIP_STATE_ABNORMALLY; + } + pipOption_->UnRegisterPipContentListenerWithType(type); + return WMError::WM_OK; +} + +std::shared_ptr PictureInPictureController::GetPipContentCallbackRef(const std::string& type) +{ + return pipOption_ == nullptr ? nullptr : pipOption_->GetPipContentCallbackRef(type); +} + +void PictureInPictureController::NotifyStateChangeInner(napi_env env, PiPState state) +{ + std::shared_ptr innerCallbackRef = GetPipContentCallbackRef(STATE_CHANGE); + if (innerCallbackRef == nullptr) { + return; + } + napi_value value[] = {AbilityRuntime::CreateJsValue(env, static_cast(state))}; + CallJsFunction(env, innerCallbackRef->GetNapiValue(), value, 1); +} + bool PictureInPictureController::IsTypeNodeEnabled() const { return pipOption_ != nullptr ? pipOption_->IsTypeNodeEnabled() : false; diff --git a/wm/src/picture_in_picture_controller_base.cpp b/wm/src/picture_in_picture_controller_base.cpp index 174364ebc5..16e121908a 100644 --- a/wm/src/picture_in_picture_controller_base.cpp +++ b/wm/src/picture_in_picture_controller_base.cpp @@ -70,6 +70,22 @@ void PictureInPictureControllerBase::NotifyOpretationError(WMError errCode, Star pipOption_->GetPipTemplate(), PipConst::FAILED, "window show failed"); } +napi_value PictureInPictureControllerBase::CallJsFunction(napi_env env, napi_value method, + napi_value const * argv, size_t argc) +{ + TLOGD(WmsLogTag::WMS_PIP, "called."); + if (env == nullptr || method == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "env nullptr or method is nullptr"); + return nullptr; + } + napi_value result = nullptr; + napi_value callResult = nullptr; + napi_get_undefined(env, &result); + napi_get_undefined(env, &callResult); + napi_call_function(env, result, method, argc, argv, &callResult); + return callResult; +} + void PictureInPictureControllerBase::SetControllerId(uint32_t controllerId) { controllerId_ = controllerId; @@ -93,6 +109,7 @@ WMError PictureInPictureControllerBase::ShowPictureInPictureWindow(StartPipType pipOption_->GetPipTemplate(), PipConst::FAILED, "window is nullptr"); return WMError::WM_ERROR_PIP_STATE_ABNORMALLY; } + NotifyStateChangeInner(env_, PiPState::ABOUT_TO_START); for (auto& listener : pipLifeCycleListeners_) { if (listener == nullptr) { TLOGE(WmsLogTag::WMS_PIP, "one lifecycle listener is nullptr"); @@ -198,6 +215,7 @@ WMError PictureInPictureControllerBase::StopPictureInPicture(bool destroyWindow, return WMError::WM_ERROR_PIP_STATE_ABNORMALLY; } curState_ = PiPWindowState::STATE_STOPPING; + NotifyStateChangeInner(env_, PiPState::ABOUT_TO_STOP); for (auto& listener : pipLifeCycleListeners_) { if (listener == nullptr) { TLOGE(WmsLogTag::WMS_PIP, "one lifecycle listener is nullptr"); @@ -209,6 +227,7 @@ WMError PictureInPictureControllerBase::StopPictureInPicture(bool destroyWindow, if (!destroyWindow) { ResetExtController(); curState_ = PiPWindowState::STATE_STOPPED; + NotifyStateChangeInner(env_, PiPState::STOPPED); for (auto& listener : pipLifeCycleListeners_) { if (listener == nullptr) { TLOGE(WmsLogTag::WMS_PIP, "one lifecycle listener is nullptr"); @@ -294,6 +313,7 @@ WMError PictureInPictureControllerBase::DestroyPictureInPictureWindow() mainWindowLifeCycleListener_ = nullptr; PictureInPictureManager::RemovePipControllerInfo(window_->GetWindowId()); window_ = nullptr; + NotifyStateChangeInner(env_, PiPState::STOPPED); PictureInPictureManager::RemoveActiveController(this); return WMError::WM_OK; } @@ -385,6 +405,7 @@ void PictureInPictureControllerBase::PreRestorePictureInPicture() { TLOGI(WmsLogTag::WMS_PIP, "called"); curState_ = PiPWindowState::STATE_RESTORING; + NotifyStateChangeInner(env_, PiPState::ABOUT_TO_RESTORE); for (auto& listener : pipLifeCycleListeners_) { if (listener == nullptr) { TLOGE(WmsLogTag::WMS_PIP, "one lifecycle listener is nullptr"); @@ -436,6 +457,7 @@ uint64_t PictureInPictureControllerBase::GetSurfaceId() const void PictureInPictureControllerBase::OnPictureInPictureStart() { + NotifyStateChangeInner(env_, PiPState::STARTED); for (auto& listener : pipLifeCycleListeners_) { if (listener == nullptr) { TLOGE(WmsLogTag::WMS_PIP, "one lifecycle listener is nullptr"); @@ -466,11 +488,6 @@ WMError PictureInPictureControllerBase::RegisterPiPWindowSize(const sptr& listener) -{ - return RegisterListener(pipTypeNodeObserver_, listener); -} - WMError PictureInPictureControllerBase::RegisterPiPStart(const sptr& listener) { return RegisterListener(pipStartListeners_, listener); @@ -496,11 +513,6 @@ WMError PictureInPictureControllerBase::UnregisterPiPWindowSize(const sptr& listener) -{ - return UnregisterListener(pipTypeNodeObserver_, listener); -} - WMError PictureInPictureControllerBase::UnregisterPiPStart(const sptr& listener) { return UnregisterListener(pipStartListeners_, listener); diff --git a/wm/src/picture_in_picture_option.cpp b/wm/src/picture_in_picture_option.cpp index 49614ca274..dacfe44b43 100644 --- a/wm/src/picture_in_picture_option.cpp +++ b/wm/src/picture_in_picture_option.cpp @@ -127,6 +127,26 @@ napi_ref PipOption::GetTypeNodeRef() const return typeNode_; } +void PipOption::RegisterPipContentListenerWithType(const std::string& type, + std::shared_ptr updateNodeCallbackRef) +{ + pipContentlistenerMap_[type] = updateNodeCallbackRef; +} + +void PipOption::UnRegisterPipContentListenerWithType(const std::string& type) +{ + pipContentlistenerMap_.erase(type); +} + +std::shared_ptr PipOption::GetPipContentCallbackRef(const std::string& type) +{ + auto iter = pipContentlistenerMap_.find(type); + if (iter == pipContentlistenerMap_.end()) { + return nullptr; + } + return iter->second; +} + void* PipOption::GetContext() const { return contextPtr_; diff --git a/wm/src/web_picture_in_picture_controller_interface.cpp b/wm/src/web_picture_in_picture_controller_interface.cpp index 624ff6bae3..716231657f 100644 --- a/wm/src/web_picture_in_picture_controller_interface.cpp +++ b/wm/src/web_picture_in_picture_controller_interface.cpp @@ -334,7 +334,8 @@ WMError WebPictureInPictureControllerInterface::UnregisterResizeListener(NativeP return UnregisterListenerWithType(ListenerType::SIZE_CHANGE_CB, listener); } -WMError WebPictureInPictureControllerInterface::CheckRegisterParam(const sptr& listener) +WMError WebPictureInPictureControllerInterface::CheckRegisterParam(ListenerType type, + const sptr& listener) { if (sptrWebPipController_ == nullptr) { TLOGE(WmsLogTag::WMS_PIP, "WebPipController is nullptr"); @@ -351,7 +352,7 @@ WMError WebPictureInPictureControllerInterface::RegisterListenerWithType(Listene const sptr& listener) { WMError ret = WMError::WM_OK; - if ((ret = CheckRegisterParam(listener)) != WMError::WM_OK) { + if ((ret = CheckRegisterParam(type, listener)) != WMError::WM_OK) { return ret; } if (IsRegistered(type, listener)) { @@ -379,8 +380,7 @@ WMError WebPictureInPictureControllerInterface::RegisterListenerWithType(Listene cbMapSize = startPipCallbackSet_.size(); break; default: - TLOGE(WmsLogTag::WMS_PIP, "Listener type not found"); - return WMError::WM_ERROR_INVALID_PARAM; + break; } } if (ret != WMError::WM_OK) { @@ -395,7 +395,7 @@ WMError WebPictureInPictureControllerInterface::UnregisterListenerWithType(Liste const sptr& listener) { WMError ret = WMError::WM_OK; - if ((ret = CheckRegisterParam(listener)) != WMError::WM_OK) { + if ((ret = CheckRegisterParam(type, listener)) != WMError::WM_OK) { return ret; } if (!IsRegistered(type, listener)) { @@ -423,8 +423,7 @@ WMError WebPictureInPictureControllerInterface::UnregisterListenerWithType(Liste cbMapSize = startPipCallbackSet_.size(); break; default: - TLOGE(WmsLogTag::WMS_PIP, "Listener type not found"); - return WMError::WM_ERROR_INVALID_PARAM; + break; } } if (ret != WMError::WM_OK) { @@ -481,8 +480,7 @@ WMError WebPictureInPictureControllerInterface::UnregisterAll(ListenerType type) pipController->UnregisterAllPiPStart(); break; default: - TLOGE(WmsLogTag::WMS_PIP, "Listener type not found"); - return WMError::WM_ERROR_INVALID_PARAM; + break; } return WMError::WM_OK; } else { @@ -498,6 +496,9 @@ bool WebPictureInPictureControllerInterface::IsRegistered(ListenerType type, switch (type) { case ListenerType::STATE_CHANGE_CB: for (const auto& it : lifeCycleCallbackSet_) { + if (it == nullptr) { + continue; + } if (it->GetLifeCycleCallbackRef() == listener->GetLifeCycleCallbackRef()) { return true; } @@ -505,6 +506,9 @@ bool WebPictureInPictureControllerInterface::IsRegistered(ListenerType type, break; case ListenerType::CONTROL_EVENT_CB: for (const auto& it : controlEventCallbackSet_) { + if (it == nullptr) { + continue; + } if (it->GetControlEventCallbackRef() == listener->GetControlEventCallbackRef()) { return true; } @@ -512,6 +516,9 @@ bool WebPictureInPictureControllerInterface::IsRegistered(ListenerType type, break; case ListenerType::SIZE_CHANGE_CB: for (const auto& it : resizeCallbackSet_) { + if (it == nullptr) { + continue; + } if (it->GetResizeCallbackRef() == listener->GetResizeCallbackRef()) { return true; } @@ -519,6 +526,9 @@ bool WebPictureInPictureControllerInterface::IsRegistered(ListenerType type, break; case ListenerType::PIP_START_CB: for (const auto& it : startPipCallbackSet_) { + if (it == nullptr) { + continue; + } if (it->GetStartPipCallbackRef() == listener->GetStartPipCallbackRef()) { return true; } @@ -547,6 +557,10 @@ WMError WebPictureInPictureControllerInterface::ProcessStateChangeUnregister( const sptr& listener) { for (const auto& it : lifeCycleCallbackSet_) { + if (it == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "one of lifeCycleCallbacks is nullptr"); + return WMError::WM_ERROR_PIP_INTERNAL_ERROR; + } if (it->GetLifeCycleCallbackRef() != listener->GetLifeCycleCallbackRef()) { continue; } @@ -580,6 +594,10 @@ WMError WebPictureInPictureControllerInterface::ProcessControlEventUnregister( const sptr& listener) { for (const auto& it : controlEventCallbackSet_) { + if (it == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "one of controlEventCallbacks is nullptr"); + return WMError::WM_ERROR_PIP_INTERNAL_ERROR; + } if (it->GetControlEventCallbackRef() != listener->GetControlEventCallbackRef()) { continue; } @@ -613,6 +631,10 @@ WMError WebPictureInPictureControllerInterface::ProcessSizeChangeUnregister( const sptr& listener) { for (const auto& it : resizeCallbackSet_) { + if (it == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "one of resizeCallbacks is nullptr"); + return WMError::WM_ERROR_PIP_INTERNAL_ERROR; + } if (it->GetResizeCallbackRef() != listener->GetResizeCallbackRef()) { continue; } @@ -623,6 +645,7 @@ WMError WebPictureInPictureControllerInterface::ProcessSizeChangeUnregister( return ret; } resizeCallbackSet_.erase(it); + TLOGI(WmsLogTag::WMS_PIP, "resize listener deleted"); return ret; } TLOGE(WmsLogTag::WMS_PIP, "resize callback not found"); @@ -646,6 +669,10 @@ WMError WebPictureInPictureControllerInterface::ProcessPipStartUnregister( const sptr& listener) { for (const auto& it : startPipCallbackSet_) { + if (it == nullptr) { + TLOGE(WmsLogTag::WMS_PIP, "one of startPipCallbacks is nullptr"); + return WMError::WM_ERROR_PIP_INTERNAL_ERROR; + } if (it->GetStartPipCallbackRef() != listener->GetStartPipCallbackRef()) { continue; } @@ -656,6 +683,7 @@ WMError WebPictureInPictureControllerInterface::ProcessPipStartUnregister( return ret; } startPipCallbackSet_.erase(it); + TLOGI(WmsLogTag::WMS_PIP, "startPip listener deleted"); return ret; } TLOGE(WmsLogTag::WMS_PIP, "startPip callback not found"); -- Gitee From efd951f2c01258f60c78993281bf9e77d7a72444 Mon Sep 17 00:00:00 2001 From: wangle Date: Wed, 20 Aug 2025 15:52:59 +0800 Subject: [PATCH 09/11] SyncYellowToBlue Signed-off-by: wangle --- wm/src/picture_in_picture_controller.cpp | 6 +++--- wm/src/picture_in_picture_option.cpp | 4 ++-- wm/src/web_picture_in_picture_controller_interface.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wm/src/picture_in_picture_controller.cpp b/wm/src/picture_in_picture_controller.cpp index 61699c365c..840276882e 100644 --- a/wm/src/picture_in_picture_controller.cpp +++ b/wm/src/picture_in_picture_controller.cpp @@ -441,7 +441,7 @@ WMError PictureInPictureController::SetXComponentController(std::shared_ptr callbackRef) { TLOGI(WmsLogTag::WMS_PIP, "Register type:%{public}s", type.c_str()); if (pipOption_ == nullptr) { @@ -463,14 +463,14 @@ WMError PictureInPictureController::UnRegisterPipContentListenerWithType(const s return WMError::WM_OK; } -std::shared_ptr PictureInPictureController::GetPipContentCallbackRef(const std::string& type) +std::shared_ptr PictureInPictureController::GetPipContentCallbackRef(const std::string& type) { return pipOption_ == nullptr ? nullptr : pipOption_->GetPipContentCallbackRef(type); } void PictureInPictureController::NotifyStateChangeInner(napi_env env, PiPState state) { - std::shared_ptr innerCallbackRef = GetPipContentCallbackRef(STATE_CHANGE); + std::shared_ptr innerCallbackRef = GetPipContentCallbackRef(STATE_CHANGE); if (innerCallbackRef == nullptr) { return; } diff --git a/wm/src/picture_in_picture_option.cpp b/wm/src/picture_in_picture_option.cpp index dacfe44b43..e3eb564e08 100644 --- a/wm/src/picture_in_picture_option.cpp +++ b/wm/src/picture_in_picture_option.cpp @@ -128,7 +128,7 @@ napi_ref PipOption::GetTypeNodeRef() const } void PipOption::RegisterPipContentListenerWithType(const std::string& type, - std::shared_ptr updateNodeCallbackRef) + std::shared_ptr updateNodeCallbackRef) { pipContentlistenerMap_[type] = updateNodeCallbackRef; } @@ -138,7 +138,7 @@ void PipOption::UnRegisterPipContentListenerWithType(const std::string& type) pipContentlistenerMap_.erase(type); } -std::shared_ptr PipOption::GetPipContentCallbackRef(const std::string& type) +std::shared_ptr PipOption::GetPipContentCallbackRef(const std::string& type) { auto iter = pipContentlistenerMap_.find(type); if (iter == pipContentlistenerMap_.end()) { diff --git a/wm/src/web_picture_in_picture_controller_interface.cpp b/wm/src/web_picture_in_picture_controller_interface.cpp index 716231657f..e3f02d7ffa 100644 --- a/wm/src/web_picture_in_picture_controller_interface.cpp +++ b/wm/src/web_picture_in_picture_controller_interface.cpp @@ -335,7 +335,7 @@ WMError WebPictureInPictureControllerInterface::UnregisterResizeListener(NativeP } WMError WebPictureInPictureControllerInterface::CheckRegisterParam(ListenerType type, - const sptr& listener) + const sptr& listener) { if (sptrWebPipController_ == nullptr) { TLOGE(WmsLogTag::WMS_PIP, "WebPipController is nullptr"); -- Gitee From bd4e14a1a58aeb11bfe5bda411e3de746c045bde Mon Sep 17 00:00:00 2001 From: wangle Date: Thu, 21 Aug 2025 15:13:13 +0800 Subject: [PATCH 10/11] SyncYellowToBlue Signed-off-by: wangle --- wm/BUILD.gn | 1 + .../picture_in_picture_controller_test.cpp | 112 ++++++++++++------ 2 files changed, 78 insertions(+), 35 deletions(-) diff --git a/wm/BUILD.gn b/wm/BUILD.gn index e32469eec9..1bca54d11f 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -128,6 +128,7 @@ ohos_static_library("libwm_static") { "ability_runtime:ability_context_native", "ability_runtime:ability_manager", "ability_runtime:app_manager", + "ability_runtime:runtime", "accessibility:accessibility_common", "ace_engine:ace_uicontent", "ace_engine:ace_xcomponent_controller", diff --git a/wm/test/unittest/picture_in_picture_controller_test.cpp b/wm/test/unittest/picture_in_picture_controller_test.cpp index 21b919fa59..53fe8c94c0 100644 --- a/wm/test/unittest/picture_in_picture_controller_test.cpp +++ b/wm/test/unittest/picture_in_picture_controller_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * 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 @@ -50,9 +50,9 @@ public: MOCK_METHOD2(GetGlobalPosition, XComponentControllerErrorCode(float& offsetX, float& offsetY)); MOCK_METHOD2(GetSize, XComponentControllerErrorCode(float& width, float& height)); MOCK_METHOD1(SetExtController, - XComponentControllerErrorCode(std::shared_ptr xComponentController)); + XComponentControllerErrorCode(std::shared_ptr xComponentController)); MOCK_METHOD1(ResetExtController, - XComponentControllerErrorCode(std::shared_ptr xComponentController)); + XComponentControllerErrorCode(std::shared_ptr xComponentController)); }; class PictureInPictureControllerTest : public testing::Test { @@ -65,7 +65,9 @@ private: static constexpr uint32_t WAIT_SYNC_IN_NS = 200000; }; -void PictureInPictureControllerTest::SetUpTestCase() {} +void PictureInPictureControllerTest::SetUpTestCase() +{ +} void PictureInPictureControllerTest::TearDownTestCase() { @@ -74,9 +76,13 @@ void PictureInPictureControllerTest::TearDownTestCase() #endif } -void PictureInPictureControllerTest::SetUp() {} +void PictureInPictureControllerTest::SetUp() +{ +} -void PictureInPictureControllerTest::TearDown() {} +void PictureInPictureControllerTest::TearDown() +{ +} namespace { /** @@ -515,7 +521,7 @@ HWTEST_F(PictureInPictureControllerTest, UpdateContentSize02, TestSize.Level1) pipControl->mainWindowXComponentController_ = xComponentController; pipControl->UpdateContentSize(width, height); pipControl->pipOption_->SetTypeNodeEnabled(false); - pipControl->windowRect_ = { 0, 0, 0, 0 }; + pipControl->windowRect_ = {0, 0, 0, 0}; pipControl->IsContentSizeChanged(0, 0, 0, 0); pipControl->UpdateContentSize(width, height); pipControl->IsContentSizeChanged(10, 10, 10, 10); @@ -562,7 +568,7 @@ HWTEST_F(PictureInPictureControllerTest, IsContentSizeChanged, TestSize.Level1) ASSERT_NE(nullptr, option); sptr pipControl = new (std::nothrow) PictureInPictureController(option, mw, 100, nullptr); - pipControl->windowRect_ = { 0, 0, 0, 0 }; + pipControl->windowRect_ = {0, 0, 0, 0}; ASSERT_EQ(true, pipControl->IsContentSizeChanged(10.5, 0, 0, 0)); ASSERT_EQ(true, pipControl->IsContentSizeChanged(0, 10.5, 0, 0)); ASSERT_EQ(true, pipControl->IsContentSizeChanged(0, 0, 10.5, 0)); @@ -629,6 +635,27 @@ HWTEST_F(PictureInPictureControllerTest, DoControlEvent, TestSize.Level1) ASSERT_EQ(1, pipControl->pipOption_->GetControlStatus().size()); } +/** + * @tc.name: PipSizeChange + * @tc.desc: PipSizeChange + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureControllerTest, PipSizeChange, Function | SmallTest | Level2) +{ +auto mw = sptr::MakeSptr(); +ASSERT_NE(nullptr, mw); +auto option = sptr::MakeSptr(); +ASSERT_NE(nullptr, option); +auto pipControl = sptr::MakeSptr(option, mw, 100, nullptr); +sptr listener = nullptr; + +pipControl->pipOption_ = option; +pipControl->PipSizeChange(1, 2, 0.5); +pipControl->RegisterPiPControlObserver(listener); +pipControl->PipSizeChange(1, 2, 0.5); +ASSERT_EQ(0, pipControl->pipOption_->GetControlStatus().size()); +} + /** * @tc.name: PreRestorePictureInPicture * @tc.desc: PreRestorePictureInPicture @@ -836,12 +863,10 @@ HWTEST_F(PictureInPictureControllerTest, ResetExtController, TestSize.Level1) pipControl->mainWindowXComponentController_ = xComponentController1; pipControl->ResetExtController(); pipControl->pipXComponentController_ = xComponentController; - EXPECT_CALL(*(xComponentController1), ResetExtController(_)) - .Times(1) + EXPECT_CALL(*(xComponentController1), ResetExtController(_)).Times(1) .WillOnce(Return(XComponentControllerErrorCode::XCOMPONENT_CONTROLLER_TYPE_ERROR)); pipControl->ResetExtController(); - EXPECT_CALL(*(xComponentController1), ResetExtController(_)) - .Times(1) + EXPECT_CALL(*(xComponentController1), ResetExtController(_)).Times(1) .WillOnce(Return(XComponentControllerErrorCode::XCOMPONENT_CONTROLLER_NO_ERROR)); pipControl->ResetExtController(); } @@ -928,46 +953,63 @@ HWTEST_F(PictureInPictureControllerTest, SetXComponentController, TestSize.Level pipControl->pipXComponentController_ = xComponentController; ASSERT_EQ(WMError::WM_ERROR_PIP_STATE_ABNORMALLY, pipControl->SetXComponentController(xComponentController)); pipControl->mainWindowXComponentController_ = xComponentController1; - EXPECT_CALL(*(xComponentController1), SetExtController(_)) - .Times(1) + EXPECT_CALL(*(xComponentController1), SetExtController(_)).Times(1) .WillOnce(Return(XComponentControllerErrorCode::XCOMPONENT_CONTROLLER_TYPE_ERROR)); ASSERT_EQ(WMError::WM_ERROR_PIP_INTERNAL_ERROR, pipControl->SetXComponentController(xComponentController)); - EXPECT_CALL(*(xComponentController1), SetExtController(_)) - .Times(1) + EXPECT_CALL(*(xComponentController1), SetExtController(_)).Times(1) .WillOnce(Return(XComponentControllerErrorCode::XCOMPONENT_CONTROLLER_NO_ERROR)); ASSERT_EQ(WMError::WM_OK, pipControl->SetXComponentController(xComponentController)); } /** - * @tc.name: RegisterPiPTypeNodeChange - * @tc.desc: RegisterPiPTypeNodeChange + * @tc.name: RegisterPipContentListenerWithType + * @tc.desc: RegisterPipContentListenerWithType * @tc.type: FUNC */ -HWTEST_F(PictureInPictureControllerTest, RegisterPiPTypeNodeChange, Function | SmallTest | Level2) +HWTEST_F(PictureInPictureControllerTest, RegisterPipContentListenerWithType, TestSize.Level1) { sptr mw = new MockWindow(); sptr option = new PipOption(); sptr pipControl = new PictureInPictureController(option, mw, 100, nullptr); - auto listener = sptr::MakeSptr(); - ASSERT_NE(nullptr, listener); - ASSERT_EQ(WMError::WM_ERROR_NULLPTR, pipControl->RegisterPiPTypeNodeChange(nullptr)); - ASSERT_EQ(WMError::WM_OK, pipControl->RegisterPiPTypeNodeChange(listener)); + pipControl->pipOption_ = nullptr; + ASSERT_EQ(WMError::WM_ERROR_PIP_STATE_ABNORMALLY, + pipControl->RegisterPipContentListenerWithType("nodeUpdate", nullptr)); + pipControl->pipOption_ = option; + ASSERT_EQ(WMError::WM_OK, pipControl->RegisterPipContentListenerWithType("nodeUpdate", nullptr)); } /** - * @tc.name: UnRegisterPiPTypeNodeChange - * @tc.desc: UnRegisterPiPTypeNodeChange + * @tc.name: UnRegisterPipContentListenerWithType + * @tc.desc: UnRegisterPipContentListenerWithType * @tc.type: FUNC */ -HWTEST_F(PictureInPictureControllerTest, UnRegisterPiPTypeNodeChange, Function | SmallTest | Level2) +HWTEST_F(PictureInPictureControllerTest, UnRegisterPipContentListenerWithType, TestSize.Level1) { sptr mw = new MockWindow(); sptr option = new PipOption(); sptr pipControl = new PictureInPictureController(option, mw, 100, nullptr); - auto listener = sptr::MakeSptr(); - ASSERT_NE(nullptr, listener); - ASSERT_EQ(WMError::WM_ERROR_NULLPTR, pipControl->UnRegisterPiPTypeNodeChange(nullptr)); - ASSERT_EQ(WMError::WM_OK, pipControl->UnRegisterPiPTypeNodeChange(listener)); + pipControl->pipOption_ = nullptr; + ASSERT_EQ(WMError::WM_ERROR_PIP_STATE_ABNORMALLY, pipControl->UnRegisterPipContentListenerWithType("nodeUpdate")); + pipControl->pipOption_ = option; + ASSERT_EQ(WMError::WM_OK, pipControl->UnRegisterPipContentListenerWithType("nodeUpdate")); +} + +/** + * @tc.name: GetPipContentCallbackRef + * @tc.desc: GetPipContentCallbackRef + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureControllerTest, GetPipContentCallbackRef, TestSize.Level1) +{ +sptr mw = new MockWindow(); +sptr option = new PipOption(); +sptr pipControl = new PictureInPictureController(option, mw, 100, nullptr); +pipControl->pipOption_ = nullptr; +pipControl->RegisterPipContentListenerWithType("nodeUpdate", nullptr); +ASSERT_EQ(nullptr, pipControl->GetPipContentCallbackRef("nodeUpdate")); +pipControl->pipOption_ = option; +pipControl->RegisterPipContentListenerWithType("nodeUpdate", nullptr); +ASSERT_EQ(nullptr, pipControl->GetPipContentCallbackRef("nodeUpdate")); } /** @@ -1044,7 +1086,8 @@ HWTEST_F(PictureInPictureControllerTest, DestroyPictureInPictureWindow, TestSize ASSERT_NE(nullptr, mw); sptr option = new (std::nothrow) PipOption(); ASSERT_NE(nullptr, option); - sptr pipControl = sptr::MakeSptr(option, mw, 100, nullptr); + sptr pipControl = + sptr::MakeSptr(option, mw, 100, nullptr); pipControl->window_ = nullptr; ASSERT_EQ(WMError::WM_ERROR_PIP_INTERNAL_ERROR, pipControl->DestroyPictureInPictureWindow()); @@ -1138,10 +1181,10 @@ HWTEST_F(PictureInPictureControllerTest, StopPictureInPictureInner, TestSize.Lev pipControl->pipOption_ = option; pipControl->window_ = nullptr; ASSERT_EQ(WMError::WM_ERROR_PIP_INTERNAL_ERROR, - pipControl->StopPictureInPictureInner(StopPipType::NULL_STOP, true)); + pipControl->StopPictureInPictureInner(StopPipType::NULL_STOP, true)); pipControl->mainWindow_ = mw; ASSERT_EQ(WMError::WM_ERROR_PIP_INTERNAL_ERROR, - pipControl->StopPictureInPictureInner(StopPipType::NULL_STOP, true)); + pipControl->StopPictureInPictureInner(StopPipType::NULL_STOP, true)); auto window = sptr::MakeSptr(); pipControl->window_ = window; ASSERT_EQ(WMError::WM_OK, pipControl->StopPictureInPictureInner(StopPipType::NULL_STOP, true)); @@ -1162,8 +1205,7 @@ HWTEST_F(PictureInPictureControllerTest, GetPipPossible, TestSize.Level1) auto pipControl = sptr::MakeSptr(option, mw, 100, nullptr); const std::string multiWindowUIType = system::GetParameter("const.window.multiWindowUIType", ""); - bool isDeviceSupported = multiWindowUIType == "HandsetSmartWindow" || multiWindowUIType == "FreeFormMultiWindow" || - multiWindowUIType == "TabletSmartWindow"; + bool isDeviceSupported = multiWindowUIType == "HandsetSmartWindow" || multiWindowUIType == "TabletSmartWindow"; bool pipSupported = false; pipControl->pipOption_ = option; -- Gitee From 45dfa5dbfb236882e86657b5ed0be920a75c15ff Mon Sep 17 00:00:00 2001 From: wangle Date: Thu, 21 Aug 2025 16:24:04 +0800 Subject: [PATCH 11/11] SyncYellowToBlue Signed-off-by: wangle --- wm/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/wm/BUILD.gn b/wm/BUILD.gn index 1bca54d11f..1595a2b7aa 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -129,6 +129,7 @@ ohos_static_library("libwm_static") { "ability_runtime:ability_manager", "ability_runtime:app_manager", "ability_runtime:runtime", + "ability_runtime:abilitykit_native", "accessibility:accessibility_common", "ace_engine:ace_uicontent", "ace_engine:ace_xcomponent_controller", -- Gitee