diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web.cpp b/frameworks/bridge/declarative_frontend/jsview/js_web.cpp index cbfc5963d666f305897350ddbd022ae3945dabe7..16342e203b91b751212277cf0086136258e76d9e 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_web.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_web.cpp @@ -4206,6 +4206,7 @@ JSRef RefreshAccessedHistoryEventToJSValue(const RefreshAccessedHistoryEv JSRef obj = JSRef::New(); obj->SetProperty("url", eventInfo.GetVisitedUrl()); obj->SetProperty("isRefreshed", eventInfo.IsRefreshed()); + obj->SetProperty("isMainFrame", eventInfo.IsMainFrame()); return JSRef::Cast(obj); } diff --git a/frameworks/core/components/web/resource/web_client_impl.cpp b/frameworks/core/components/web/resource/web_client_impl.cpp index 2f5789692a97c507040bd2b44e919dc67cafec56..6d534e5fb371916b73ed3a2334c374eb3061494a 100644 --- a/frameworks/core/components/web/resource/web_client_impl.cpp +++ b/frameworks/core/components/web/resource/web_client_impl.cpp @@ -1527,4 +1527,14 @@ void WebClientImpl::OnPdfLoadEvent(int32_t result, const std::string& url) ContainerScope scope(delegate->GetInstanceId()); delegate->OnPdfLoadEvent(result, url); } + +void WebClientImpl::OnRefreshAccessedHistoryV2(const std::string& url, bool isReload, bool isMainFrame) +{ + auto delegate = webDelegate_.Upgrade(); + if (!delegate) { + return; + } + ContainerScope scope(delegate->GetInstanceId()); + delegate->OnRefreshAccessedHistory(url, isReload, isMainFrame); +} } // namespace OHOS::Ace diff --git a/frameworks/core/components/web/resource/web_client_impl.h b/frameworks/core/components/web/resource/web_client_impl.h index f20685154041f5e6d317077e6423a41f2a6b7d24..5586f16a336bb88e5baadfc23607c944b661ce4d 100644 --- a/frameworks/core/components/web/resource/web_client_impl.h +++ b/frameworks/core/components/web/resource/web_client_impl.h @@ -331,6 +331,8 @@ public: void OnPdfScrollAtBottom(const std::string& url) override; void OnPdfLoadEvent(int32_t result, const std::string& url) override; + + void OnRefreshAccessedHistoryV2(const std::string& url, bool isReload, bool isMainFrame) override; private: std::weak_ptr webviewWeak_; WeakPtr webDelegate_; diff --git a/frameworks/core/components/web/resource/web_delegate.cpp b/frameworks/core/components/web/resource/web_delegate.cpp index 02b562999013dbf222e3dc7f8a8a60f1475f3103..20a4a66adfcb2a6129e4c7c40e44cfa9e0bd4ff5 100644 --- a/frameworks/core/components/web/resource/web_delegate.cpp +++ b/frameworks/core/components/web/resource/web_delegate.cpp @@ -5881,16 +5881,17 @@ void WebDelegate::OnRenderExited(OHOS::NWeb::RenderExitReason reason) TaskExecutor::TaskType::JS, "ArkUIWebRenderExited"); } -void WebDelegate::OnRefreshAccessedHistory(const std::string& url, bool isRefreshed) +void WebDelegate::OnRefreshAccessedHistory(const std::string& url, bool isRefreshed, bool isMainFrame) { CHECK_NULL_VOID(taskExecutor_); taskExecutor_->PostTask( - [weak = WeakClaim(this), url, isRefreshed]() { + [weak = WeakClaim(this), url, isRefreshed, isMainFrame]() { auto delegate = weak.Upgrade(); CHECK_NULL_VOID(delegate); auto onRefreshAccessedHistoryV2 = delegate->onRefreshAccessedHistoryV2_; if (onRefreshAccessedHistoryV2) { - onRefreshAccessedHistoryV2(std::make_shared(url, isRefreshed)); + onRefreshAccessedHistoryV2(std::make_shared( + url, isRefreshed, isMainFrame)); } }, TaskExecutor::TaskType::JS, "ArkUIWebRefreshAccessedHistory"); diff --git a/frameworks/core/components/web/resource/web_delegate.h b/frameworks/core/components/web/resource/web_delegate.h index c2b497394dc3fd7b80ae76f68199fd8d54b026f6..e3780e4eac3bdffc470a3335ea784fcc7566994a 100644 --- a/frameworks/core/components/web/resource/web_delegate.h +++ b/frameworks/core/components/web/resource/web_delegate.h @@ -1031,7 +1031,7 @@ public: bool OnConsoleLog(std::shared_ptr message); void OnRouterPush(const std::string& param); void OnRenderExited(OHOS::NWeb::RenderExitReason reason); - void OnRefreshAccessedHistory(const std::string& url, bool isRefreshed); + void OnRefreshAccessedHistory(const std::string& url, bool isRefreshed, bool isMainFrame = false); bool OnFileSelectorShow(const std::shared_ptr& info); bool OnContextMenuShow(const std::shared_ptr& info); void OnContextMenuHide(const std::string& info); diff --git a/frameworks/core/components/web/web_event.h b/frameworks/core/components/web/web_event.h index 72c6e11c829be4e859387a70e2ec13fde9b4e942..b194bd10fdea82f8354205583e485bd2237cd59d 100644 --- a/frameworks/core/components/web/web_event.h +++ b/frameworks/core/components/web/web_event.h @@ -1370,8 +1370,9 @@ class ACE_EXPORT RefreshAccessedHistoryEvent : public BaseEventInfo { DECLARE_RELATIONSHIP_OF_CLASSES(RefreshAccessedHistoryEvent, BaseEventInfo); public: - RefreshAccessedHistoryEvent(const std::string& url, bool isRefreshed) - : BaseEventInfo("RefreshAccessedHistoryEvent"), url_(url), isRefreshed_(isRefreshed) + RefreshAccessedHistoryEvent(const std::string& url, bool isRefreshed, bool isMainFrame) + : BaseEventInfo("RefreshAccessedHistoryEvent"), + url_(url), isRefreshed_(isRefreshed), isMainFrame_(isMainFrame) {} ~RefreshAccessedHistoryEvent() = default; @@ -1386,9 +1387,15 @@ public: return isRefreshed_; } + bool IsMainFrame() const + { + return isMainFrame_; + } + private: std::string url_; bool isRefreshed_; + bool isMainFrame_; }; class ACE_EXPORT FileSelectorEvent : public BaseEventInfo { diff --git a/test/unittest/core/pattern/web/mock_web_delegate.cpp b/test/unittest/core/pattern/web/mock_web_delegate.cpp index 64477740b4abec35f23c13e550ef86facae685e0..020759deff5cddeb4ff9b2d0769dc58b5382782d 100644 --- a/test/unittest/core/pattern/web/mock_web_delegate.cpp +++ b/test/unittest/core/pattern/web/mock_web_delegate.cpp @@ -845,7 +845,7 @@ std::string WebDelegate::OnOverrideErrorPage( void WebDelegate::OnTooltip(const std::string& tooltip) {} void WebDelegate::OnRequestFocus() {} void WebDelegate::OnRenderExited(OHOS::NWeb::RenderExitReason reason) {} -void WebDelegate::OnRefreshAccessedHistory(const std::string& url, bool isRefreshed) {} +void WebDelegate::OnRefreshAccessedHistory(const std::string& url, bool isRefreshed, bool isMainFrame) {} void WebDelegate::OnPageError(const std::string& param) {} void WebDelegate::OnMessage(const std::string& param) {} void WebDelegate::OnRouterPush(const std::string& param) {}