From c586e636932073ffa229cbb977847c256fbf55c5 Mon Sep 17 00:00:00 2001 From: wangle Date: Mon, 25 Aug 2025 10:11:42 +0800 Subject: [PATCH] SyncFirst Signed-off-by: wangle --- ..._picture_in_picture_controller_interface.h | 2 +- .../picture_in_picture_controller_base.h | 9 ++-- wm/src/oh_window_pip.cpp | 4 -- wm/src/picture_in_picture_controller_base.cpp | 32 +++++++++---- ...icture_in_picture_controller_interface.cpp | 46 +++++++++++++++---- 5 files changed, 66 insertions(+), 27 deletions(-) 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); diff --git a/wm/include/picture_in_picture_controller_base.h b/wm/include/picture_in_picture_controller_base.h index 13ffbde0be..1be7b3dcf5 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,6 +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/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"); 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/web_picture_in_picture_controller_interface.cpp b/wm/src/web_picture_in_picture_controller_interface.cpp index 624ff6bae3..e3f02d7ffa 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