From 3acdbac061a685a171e99af73a2dc4e935acdf8e Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 18 Jul 2024 13:50:37 -0400 Subject: [PATCH] Use direct member for CefBrowserHostBase::contents_delegate_ There's no reason to use unique_ptr here as the lifespan of |contents_delegate_| exactly matches CefBrowserHostBase. --- .../browser/alloy/alloy_browser_host_impl.cc | 28 +++++++++--------- libcef/browser/browser_contents_delegate.cc | 4 +-- libcef/browser/browser_host_base.cc | 29 +++++++++---------- libcef/browser/browser_host_base.h | 6 ++-- .../chrome/chrome_browser_host_impl.cc | 4 +-- 5 files changed, 34 insertions(+), 37 deletions(-) diff --git a/libcef/browser/alloy/alloy_browser_host_impl.cc b/libcef/browser/alloy/alloy_browser_host_impl.cc index 4284730c3..e47906432 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.cc +++ b/libcef/browser/alloy/alloy_browser_host_impl.cc @@ -587,7 +587,7 @@ void AlloyBrowserHostImpl::OnSetFocus(cef_focus_source_t source) { return; } - if (contents_delegate_->OnSetFocus(source)) { + if (contents_delegate_.OnSetFocus(source)) { return; } @@ -599,13 +599,13 @@ void AlloyBrowserHostImpl::OnSetFocus(cef_focus_source_t source) { void AlloyBrowserHostImpl::EnterFullscreenModeForTab( content::RenderFrameHost* requesting_frame, const blink::mojom::FullscreenOptions& options) { - contents_delegate_->EnterFullscreenModeForTab(requesting_frame, options); + contents_delegate_.EnterFullscreenModeForTab(requesting_frame, options); WasResized(); } void AlloyBrowserHostImpl::ExitFullscreenModeForTab( content::WebContents* web_contents) { - contents_delegate_->ExitFullscreenModeForTab(web_contents); + contents_delegate_.ExitFullscreenModeForTab(web_contents); WasResized(); } @@ -877,7 +877,7 @@ content::WebContents* AlloyBrowserHostImpl::OpenURLFromTab( const content::OpenURLParams& params, base::OnceCallback navigation_handle_callback) { - auto target_contents = contents_delegate_->OpenURLFromTabEx( + auto target_contents = contents_delegate_.OpenURLFromTabEx( source, params, navigation_handle_callback); if (target_contents) { // Start a navigation in the current browser that will result in the @@ -905,7 +905,7 @@ void AlloyBrowserHostImpl::AddNewContents( void AlloyBrowserHostImpl::LoadingStateChanged(content::WebContents* source, bool should_show_loading_ui) { - contents_delegate_->LoadingStateChanged(source, should_show_loading_ui); + contents_delegate_.LoadingStateChanged(source, should_show_loading_ui); } void AlloyBrowserHostImpl::CloseContents(content::WebContents* source) { @@ -958,7 +958,7 @@ void AlloyBrowserHostImpl::CloseContents(content::WebContents* source) { void AlloyBrowserHostImpl::UpdateTargetURL(content::WebContents* source, const GURL& url) { - contents_delegate_->UpdateTargetURL(source, url); + contents_delegate_.UpdateTargetURL(source, url); } bool AlloyBrowserHostImpl::DidAddMessageToConsole( @@ -967,8 +967,8 @@ bool AlloyBrowserHostImpl::DidAddMessageToConsole( const std::u16string& message, int32_t line_no, const std::u16string& source_id) { - return contents_delegate_->DidAddMessageToConsole(source, level, message, - line_no, source_id); + return contents_delegate_.DidAddMessageToConsole(source, level, message, + line_no, source_id); } void AlloyBrowserHostImpl::ContentsZoomChange(bool zoom_in) { @@ -1003,13 +1003,13 @@ void AlloyBrowserHostImpl::CanDownload( const GURL& url, const std::string& request_method, base::OnceCallback callback) { - contents_delegate_->CanDownload(url, request_method, std::move(callback)); + contents_delegate_.CanDownload(url, request_method, std::move(callback)); } KeyboardEventProcessingResult AlloyBrowserHostImpl::PreHandleKeyboardEvent( content::WebContents* source, const input::NativeWebKeyboardEvent& event) { - return contents_delegate_->PreHandleKeyboardEvent(source, event); + return contents_delegate_.PreHandleKeyboardEvent(source, event); } bool AlloyBrowserHostImpl::HandleKeyboardEvent( @@ -1020,7 +1020,7 @@ bool AlloyBrowserHostImpl::HandleKeyboardEvent( return false; } - if (contents_delegate_->HandleKeyboardEvent(source, event)) { + if (contents_delegate_.HandleKeyboardEvent(source, event)) { return true; } @@ -1215,7 +1215,7 @@ content::PreloadingEligibility AlloyBrowserHostImpl::IsPrerender2Supported( void AlloyBrowserHostImpl::DraggableRegionsChanged( const std::vector& regions, content::WebContents* contents) { - contents_delegate_->DraggableRegionsChanged(regions, contents); + contents_delegate_.DraggableRegionsChanged(regions, contents); } // content::WebContentsObserver methods. @@ -1289,7 +1289,7 @@ void AlloyBrowserHostImpl::WebContentsDestroyed() { // In case we're notified before the CefBrowserContentsDelegate, // reset it first for consistent state in DestroyWebContents. if (GetWebContents()) { - contents_delegate_->WebContentsDestroyed(); + contents_delegate_.WebContentsDestroyed(); } auto wc = web_contents(); @@ -1347,7 +1347,7 @@ AlloyBrowserHostImpl::AlloyBrowserHostImpl( content::WebContentsObserver(web_contents), opener_(kNullWindowHandle), is_windowless_(platform_delegate_->IsWindowless()) { - contents_delegate_->ObserveWebContents(web_contents); + contents_delegate_.ObserveWebContents(web_contents); if (opener.get() && !is_views_hosted_) { // GetOpenerWindowHandle() only returns a value for non-views-hosted diff --git a/libcef/browser/browser_contents_delegate.cc b/libcef/browser/browser_contents_delegate.cc index cabb389c5..2b8d04db2 100644 --- a/libcef/browser/browser_contents_delegate.cc +++ b/libcef/browser/browser_contents_delegate.cc @@ -82,9 +82,7 @@ class CefWidgetHostInterceptor CefBrowserContentsDelegate::CefBrowserContentsDelegate( scoped_refptr browser_info) - : browser_info_(browser_info) { - DCHECK(browser_info_->browser()); -} + : browser_info_(browser_info) {} void CefBrowserContentsDelegate::ObserveWebContents( content::WebContents* new_contents) { diff --git a/libcef/browser/browser_host_base.cc b/libcef/browser/browser_host_base.cc index e49444d1b..fc3c4a7fc 100644 --- a/libcef/browser/browser_host_base.cc +++ b/libcef/browser/browser_host_base.cc @@ -244,14 +244,13 @@ CefBrowserHostBase::CefBrowserHostBase( platform_delegate_(std::move(platform_delegate)), browser_info_(browser_info), request_context_(request_context), - is_views_hosted_(platform_delegate_->IsViewsHosted()) { + is_views_hosted_(platform_delegate_->IsViewsHosted()), + contents_delegate_(browser_info_) { CEF_REQUIRE_UIT(); DCHECK(!browser_info_->browser().get()); browser_info_->SetBrowser(this); - contents_delegate_ = - std::make_unique(browser_info_); - contents_delegate_->AddObserver(this); + contents_delegate_.AddObserver(this); } void CefBrowserHostBase::InitializeBrowser() { @@ -300,13 +299,13 @@ void CefBrowserHostBase::DestroyBrowser() { CEF_REQUIRE_UIT(); // The WebContents should no longer be observed. - DCHECK(!contents_delegate_->web_contents()); + DCHECK(!contents_delegate_.web_contents()); media_stream_registrar_.reset(); platform_delegate_.reset(); - contents_delegate_->RemoveObserver(this); + contents_delegate_.RemoveObserver(this); if (unresponsive_process_callback_) { hang_monitor::Detach(unresponsive_process_callback_); @@ -1131,21 +1130,21 @@ void CefBrowserHostBase::OnStateChanged(CefBrowserContentsState state_changed) { base::AutoLock lock_scope(state_lock_); if ((state_changed & CefBrowserContentsState::kNavigation) == CefBrowserContentsState::kNavigation) { - is_loading_ = contents_delegate_->is_loading(); - can_go_back_ = contents_delegate_->can_go_back(); - can_go_forward_ = contents_delegate_->can_go_forward(); + is_loading_ = contents_delegate_.is_loading(); + can_go_back_ = contents_delegate_.can_go_back(); + can_go_forward_ = contents_delegate_.can_go_forward(); } if ((state_changed & CefBrowserContentsState::kDocument) == CefBrowserContentsState::kDocument) { - has_document_ = contents_delegate_->has_document(); + has_document_ = contents_delegate_.has_document(); } if ((state_changed & CefBrowserContentsState::kFullscreen) == CefBrowserContentsState::kFullscreen) { - is_fullscreen_ = contents_delegate_->is_fullscreen(); + is_fullscreen_ = contents_delegate_.is_fullscreen(); } if ((state_changed & CefBrowserContentsState::kFocusedFrame) == CefBrowserContentsState::kFocusedFrame) { - focused_frame_ = contents_delegate_->focused_frame(); + focused_frame_ = contents_delegate_.focused_frame(); } } @@ -1338,7 +1337,7 @@ SkColor CefBrowserHostBase::GetBackgroundColor() const { content::WebContents* CefBrowserHostBase::GetWebContents() const { CEF_REQUIRE_UIT(); - return contents_delegate_->web_contents(); + return contents_delegate_.web_contents(); } content::BrowserContext* CefBrowserHostBase::GetBrowserContext() const { @@ -1418,7 +1417,7 @@ bool CefBrowserHostBase::IsVisible() const { bool CefBrowserHostBase::EnsureDevToolsProtocolManager() { CEF_REQUIRE_UIT(); - if (!contents_delegate_->web_contents()) { + if (!contents_delegate_.web_contents()) { return false; } @@ -1448,7 +1447,7 @@ void CefBrowserHostBase::InitializeDevToolsRegistrationOnUIThread( bool CefBrowserHostBase::EnsureFileDialogManager() { CEF_REQUIRE_UIT(); - if (!contents_delegate_->web_contents()) { + if (!contents_delegate_.web_contents()) { return false; } diff --git a/libcef/browser/browser_host_base.h b/libcef/browser/browser_host_base.h index ef0a8bd2f..cbc058582 100644 --- a/libcef/browser/browser_host_base.h +++ b/libcef/browser/browser_host_base.h @@ -369,8 +369,8 @@ class CefBrowserHostBase : public CefBrowserHost, CefBrowserPlatformDelegate* platform_delegate() const { return platform_delegate_.get(); } - CefBrowserContentsDelegate* contents_delegate() const { - return contents_delegate_.get(); + CefBrowserContentsDelegate* contents_delegate() { + return &contents_delegate_; } CefMediaStreamRegistrar* GetMediaStreamRegistrar(); CefDevToolsWindowRunner* GetDevToolsWindowRunner(); @@ -439,7 +439,7 @@ class CefBrowserHostBase : public CefBrowserHost, const bool is_views_hosted_; // Only accessed on the UI thread. - std::unique_ptr contents_delegate_; + CefBrowserContentsDelegate contents_delegate_; CefRefPtr unresponsive_process_callback_; raw_ptr context_menu_observer_ = nullptr; diff --git a/libcef/browser/chrome/chrome_browser_host_impl.cc b/libcef/browser/chrome/chrome_browser_host_impl.cc index 3c17bec31..a36a875ef 100644 --- a/libcef/browser/chrome/chrome_browser_host_impl.cc +++ b/libcef/browser/chrome/chrome_browser_host_impl.cc @@ -148,7 +148,7 @@ void ChromeBrowserHostImpl::OnSetFocus(cef_focus_source_t source) { return; } - if (contents_delegate_->OnSetFocus(source)) { + if (contents_delegate_.OnSetFocus(source)) { return; } @@ -470,7 +470,7 @@ void ChromeBrowserHostImpl::Attach(content::WebContents* web_contents, platform_delegate_->WebContentsCreated(web_contents, /*own_web_contents=*/false); - contents_delegate_->ObserveWebContents(web_contents); + contents_delegate_.ObserveWebContents(web_contents); // Associate the platform delegate with this browser. platform_delegate_->BrowserCreated(this);