From dad9eba825cab6472b38b3ae1e4d343a3be5c9f5 Mon Sep 17 00:00:00 2001 From: liuxiao_310 Date: Tue, 24 Dec 2024 21:42:09 +0800 Subject: [PATCH] add onActivateContent by window.open Signed-off-by: liuxiao_310 --- include/cef_client.h | 6 ++++++ include/cef_focus_handler.h | 8 ++++++++ libcef/browser/alloy/alloy_browser_host_impl.cc | 5 ++++- libcef/browser/browser_contents_delegate.cc | 11 +++++++++++ libcef/browser/browser_contents_delegate.h | 3 +++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/cef_client.h b/include/cef_client.h index ccef36a46..413492cdf 100644 --- a/include/cef_client.h +++ b/include/cef_client.h @@ -321,6 +321,12 @@ class CefClient : public virtual CefBaseRefCounted { /// /*--cef()--*/ virtual void OnPullToRefreshPull(float offset_x, float offset_y) {} + + /// + /// Notify the web activated by window.open. + /// + /*--cef()--*/ + virtual void OnActivateContent() {} #endif #if defined(OHOS_CUSTOM_VIDEO_PLAYER) diff --git a/include/cef_focus_handler.h b/include/cef_focus_handler.h index 5f05e5049..ab6d3377c 100644 --- a/include/cef_focus_handler.h +++ b/include/cef_focus_handler.h @@ -76,6 +76,14 @@ class CefFocusHandler : public virtual CefBaseRefCounted { /// /*--cef()--*/ virtual void OnGotFocus(CefRefPtr browser) {} + +#if defined(OHOS_MULTI_WINDOW) + /// + /// Notify the web activated by window.open. + /// + /*--cef()--*/ + virtual void OnActivateContent() {} +#endif }; #endif // CEF_INCLUDE_CEF_FOCUS_HANDLER_H_ diff --git a/libcef/browser/alloy/alloy_browser_host_impl.cc b/libcef/browser/alloy/alloy_browser_host_impl.cc index c1ebc140c..c7e60ff4f 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.cc +++ b/libcef/browser/alloy/alloy_browser_host_impl.cc @@ -1964,10 +1964,13 @@ content::PreloadingEligibility AlloyBrowserHostImpl::IsPrerender2Supported( #endif } -#ifdef OHOS_FOCUS +#if defined(OHOS_MULTI_WINDOW) void AlloyBrowserHostImpl::ActivateContents(content::WebContents* contents) { LOG(INFO) << "AlloyBrowserHostImpl::ActivateContents"; OnSetFocus(FOCUS_SOURCE_SYSTEM); + if (contents_delegate_) { + contents_delegate_->OnActivateContent(); + } } #endif diff --git a/libcef/browser/browser_contents_delegate.cc b/libcef/browser/browser_contents_delegate.cc index fb9e3c8bf..ab258b209 100644 --- a/libcef/browser/browser_contents_delegate.cc +++ b/libcef/browser/browser_contents_delegate.cc @@ -1044,6 +1044,17 @@ bool CefBrowserContentsDelegate::OnSetFocus(cef_focus_source_t source) { return false; } +#if defined(OHOS_MULTI_WINDOW) +void CefBrowserContentsDelegate::OnActivateContent() { + LOG(INFO) << "CefBrowserContentsDelegate::ActivateContent"; + if (auto c = client()) { + if (auto handler = c->GetFocusHandler()) { + handler->OnActivateContent(); + } + } +} +#endif + CefRefPtr CefBrowserContentsDelegate::client() const { if (auto b = browser()) { return b->GetHost()->GetClient(); diff --git a/libcef/browser/browser_contents_delegate.h b/libcef/browser/browser_contents_delegate.h index a1f06bf07..85af25528 100644 --- a/libcef/browser/browser_contents_delegate.h +++ b/libcef/browser/browser_contents_delegate.h @@ -124,6 +124,9 @@ class CefBrowserContentsDelegate : public content::WebContentsDelegate, void ShowRepostFormWarningDialog(content::WebContents* source) override; #endif +#if defined(OHOS_MULTI_WINDOW) +void OnActivateContent() override; +#endif // WebContentsObserver methods: void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; void RenderFrameHostChanged(content::RenderFrameHost* old_host, -- Gitee