Skip to content

Commit

Permalink
Use direct member for CefBrowserHostBase::contents_delegate_
Browse files Browse the repository at this point in the history
There's no reason to use unique_ptr here as the lifespan of
|contents_delegate_| exactly matches CefBrowserHostBase.
  • Loading branch information
magreenblatt committed Jul 18, 2024
1 parent d470cf8 commit 3acdbac
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 37 deletions.
28 changes: 14 additions & 14 deletions libcef/browser/alloy/alloy_browser_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ void AlloyBrowserHostImpl::OnSetFocus(cef_focus_source_t source) {
return;
}

if (contents_delegate_->OnSetFocus(source)) {
if (contents_delegate_.OnSetFocus(source)) {
return;
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -877,7 +877,7 @@ content::WebContents* AlloyBrowserHostImpl::OpenURLFromTab(
const content::OpenURLParams& params,
base::OnceCallback<void(content::NavigationHandle&)>
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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand All @@ -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) {
Expand Down Expand Up @@ -1003,13 +1003,13 @@ void AlloyBrowserHostImpl::CanDownload(
const GURL& url,
const std::string& request_method,
base::OnceCallback<void(bool)> 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(
Expand All @@ -1020,7 +1020,7 @@ bool AlloyBrowserHostImpl::HandleKeyboardEvent(
return false;
}

if (contents_delegate_->HandleKeyboardEvent(source, event)) {
if (contents_delegate_.HandleKeyboardEvent(source, event)) {
return true;
}

Expand Down Expand Up @@ -1215,7 +1215,7 @@ content::PreloadingEligibility AlloyBrowserHostImpl::IsPrerender2Supported(
void AlloyBrowserHostImpl::DraggableRegionsChanged(
const std::vector<blink::mojom::DraggableRegionPtr>& regions,
content::WebContents* contents) {
contents_delegate_->DraggableRegionsChanged(regions, contents);
contents_delegate_.DraggableRegionsChanged(regions, contents);
}

// content::WebContentsObserver methods.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions libcef/browser/browser_contents_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ class CefWidgetHostInterceptor

CefBrowserContentsDelegate::CefBrowserContentsDelegate(
scoped_refptr<CefBrowserInfo> browser_info)
: browser_info_(browser_info) {
DCHECK(browser_info_->browser());
}
: browser_info_(browser_info) {}

void CefBrowserContentsDelegate::ObserveWebContents(
content::WebContents* new_contents) {
Expand Down
29 changes: 14 additions & 15 deletions libcef/browser/browser_host_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<CefBrowserContentsDelegate>(browser_info_);
contents_delegate_->AddObserver(this);
contents_delegate_.AddObserver(this);
}

void CefBrowserHostBase::InitializeBrowser() {
Expand Down Expand Up @@ -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_);
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions libcef/browser/browser_host_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -439,7 +439,7 @@ class CefBrowserHostBase : public CefBrowserHost,
const bool is_views_hosted_;

// Only accessed on the UI thread.
std::unique_ptr<CefBrowserContentsDelegate> contents_delegate_;
CefBrowserContentsDelegate contents_delegate_;
CefRefPtr<CefUnresponsiveProcessCallback> unresponsive_process_callback_;
raw_ptr<RenderViewContextMenuObserver> context_menu_observer_ = nullptr;

Expand Down
4 changes: 2 additions & 2 deletions libcef/browser/chrome/chrome_browser_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void ChromeBrowserHostImpl::OnSetFocus(cef_focus_source_t source) {
return;
}

if (contents_delegate_->OnSetFocus(source)) {
if (contents_delegate_.OnSetFocus(source)) {
return;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3acdbac

Please sign in to comment.