diff --git a/frameworks/core/components_ng/pattern/web/web_pattern.cpp b/frameworks/core/components_ng/pattern/web/web_pattern.cpp index 2d068eff7ffdfd627537f578e2835a01cc7bff89..e38e4d2f0dbe95c333485ce0383f59506d91cd5b 100644 --- a/frameworks/core/components_ng/pattern/web/web_pattern.cpp +++ b/frameworks/core/components_ng/pattern/web/web_pattern.cpp @@ -215,6 +215,8 @@ enum PictureInPictureState { PIP_STATE_HLS_EXIT, PIP_STATE_RESIZE, PIP_STATE_NONE, + PIP_STATE_UPDATE_SURFACE, + PIP_STATE_PAGE_CLOSE, }; struct PipData { @@ -8528,6 +8530,10 @@ bool WebPattern::Pip(int status, result = StopPip(delegateId, childId, frameRoutingId); break; } + case PIP_STATE_PAGE_CLOSE: { + result = PageClosePip(delegateId, childId, frameRoutingId); + break; + } case PIP_STATE_PLAY: { result = PlayPip(delegateId, childId, frameRoutingId); break; @@ -8695,6 +8701,23 @@ bool WebPattern::StopPip(int delegateId, int childId, int frameRoutingId) return false; } +bool WebPattern::PageClosePip(int delegateId, int childId, int frameRoutingId) +{ + std::lock_guard lock(pipCallbackMapMutex_); + for (auto &it : pipCallbackMap_) { + auto pip = it.second; + if (pip.delegateId == delegateId && pip.childId == childId && + pip.frameRoutingId == frameRoutingId) { + auto errCode = OH_PictureInPicture_StopPip(it.first); + if (errCode != 0) { + TAG_LOGE(AceLogTag::ACE_WEB, "OH_PictureInPicture_StopPip err: %{public}d", errCode); + } + return errCode == 0; + } + } + return false; +} + bool WebPattern::PlayPip(int delegateId, int childId, int frameRoutingId) { bool flag = false; diff --git a/frameworks/core/components_ng/pattern/web/web_pattern.h b/frameworks/core/components_ng/pattern/web/web_pattern.h index 4faedd4ce2a9848c0eb640e8552531f2e3e7583a..d14a752d955e593c1b9661c01baa647de66bca55 100644 --- a/frameworks/core/components_ng/pattern/web/web_pattern.h +++ b/frameworks/core/components_ng/pattern/web/web_pattern.h @@ -909,6 +909,7 @@ private: bool StopPip(int delegateId, int childId, int frameRoutingId); bool PlayPip(int delegateId, int childId, int frameRoutingId); bool PausePip(int delegateId, int childId, int frameRoutingId); + bool PageClosePip(int delegateId, int childId, int frameRoutingId); void GetPreviewImageOffsetAndSize(bool isImage, Offset& previewOffset, SizeF& previewSize); RefPtr CreatePreviewImageFrameNode(bool isImage); void ShowPreviewMenu(WebElementType type); diff --git a/test/unittest/core/pattern/web/web_pattern_test_ng.cpp b/test/unittest/core/pattern/web/web_pattern_test_ng.cpp index 28c29f3b54ca0c42128fac24a82f57cdaea147e0..c14c7a70f287e9978cf979def46be98918f20244 100755 --- a/test/unittest/core/pattern/web/web_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/web/web_pattern_test_ng.cpp @@ -48,6 +48,8 @@ enum PictureInPictureState { PIP_STATE_HLS_EXIT, PIP_STATE_RESIZE, PIP_STATE_NONE, + PIP_STATE_UPDATE_SURFACE, + PIP_STATE_PAGE_CLOSE, }; enum PictureInPictureCallback { @@ -4631,6 +4633,83 @@ HWTEST_F(WebPatternTestNg, StopPipPip_004, TestSize.Level1) #endif } +/** + * @tc.name: PageClosePip_001 + * @tc.desc: PageClosePip. + * @tc.type: FUNC + */ +HWTEST_F(WebPatternTestNg, PageClosePip_001, TestSize.Level1) +{ +#ifdef OHOS_STANDARD_SYSTEM + WebPattern webPattern; + webPattern.delegate_ = nullptr; + EXPECT_EQ(webPattern.delegate_, nullptr); + bool init = false; + uint32_t pipController = 0; + napi_env env = nullptr; + PipInfo info{1, 0, 0, 0, PIP_WIDTH, PIP_HEIGHT}; + bool ret = webPattern.PageClosePip(info.delegateId, info.childId, info.frameRoutingId); + ret = webPattern.CreatePip(PIP_STATE_ENTER, env, init, pipController, info); + ASSERT_EQ(ret, true); + ret = webPattern.RegisterPip(pipController); + ASSERT_EQ(ret, true); + ret = webPattern.StartPip(pipController); + ASSERT_EQ(ret, true); + webPattern.EnablePip(pipController); + ret = webPattern.PageClosePip(info.delegateId, info.childId, info.frameRoutingId); + ASSERT_EQ(ret, true); + ret = webPattern.PageClosePip(info.delegateId + 1, info.childId, info.frameRoutingId); + ASSERT_EQ(ret, false); + ret = webPattern.PageClosePip(info.delegateId, info.childId + 1, info.frameRoutingId); + ASSERT_EQ(ret, false); + ret = webPattern.PageClosePip(info.delegateId, info.childId, info.frameRoutingId + 1); + ASSERT_EQ(ret, false); +#endif +} + +/** + * @tc.name: PageClosePip_002 + * @tc.desc: PageClosePip. + * @tc.type: FUNC + */ +HWTEST_F(WebPatternTestNg, PageClosePip_002, TestSize.Level1) +{ +#ifdef OHOS_STANDARD_SYSTEM + WebPattern webPattern; + webPattern.delegate_ = nullptr; + EXPECT_EQ(webPattern.delegate_, nullptr); + bool init = false; + uint32_t pipController = PIP_ID_OK_2; + napi_env env = nullptr; + PipInfo info{1, 0, 0, 0, PIP_WIDTH, PIP_HEIGHT}; + bool ret = webPattern.CreatePip(PIP_STATE_ENTER, env, init, pipController, info); + ASSERT_EQ(ret, true); + ret = webPattern.PageClosePip(info.delegateId, info.childId, info.frameRoutingId); + ASSERT_EQ(ret, false); +#endif +} + +/** + * @tc.name: OnPipPip_007 + * @tc.desc: OnPipPip. + * @tc.type: FUNC + */ +HWTEST_F(WebPatternTestNg, OnPipPip_007, TestSize.Level1) +{ +#ifdef OHOS_STANDARD_SYSTEM + WebPattern webPattern; + webPattern.delegate_ = nullptr; + EXPECT_EQ(webPattern.delegate_, nullptr); + bool init = false; + uint32_t pipController = 0; + napi_env env = nullptr; + PipInfo pipInfo{0, 0, 0, 0, PIP_WIDTH, PIP_HEIGHT}; + bool ret = webPattern.CreatePip(PIP_STATE_ENTER, env, init, pipController, pipInfo); + ASSERT_EQ(ret, true); + webPattern.OnPip(PIP_STATE_PAGE_CLOSE, 0, 0, 0, 0, 0); +#endif +} + /** * @tc.name: CreateSnapshotImageFrameNode_001 * @tc.desc: CreateSnapshotImageFrameNode.