alloy: Fix FrameHandlerTest failures with BackForwardCache enabled (see issue #2421)
To test: Run `ceftests --gtest_filter=FrameHandlerTest.OrderSub* --enable-features=BackForwardCache`
This commit is contained in:
parent
7a56371b84
commit
db807e804a
|
@ -365,6 +365,10 @@ void CefBrowserContentsDelegate::DidFinishNavigation(
|
|||
(error_code == net::OK ? navigation_handle->GetURL() : GURL());
|
||||
|
||||
auto browser_info = browser_info_;
|
||||
if (!browser_info->browser()) {
|
||||
// Ignore notifications when the browser is closing.
|
||||
return;
|
||||
}
|
||||
|
||||
// May return NULL when starting a new navigation if the previous navigation
|
||||
// caused the renderer process to crash during load.
|
||||
|
|
|
@ -798,6 +798,7 @@ void CefBrowserHostBase::OnBeforeClose() {
|
|||
handler->OnBeforeClose(this);
|
||||
}
|
||||
}
|
||||
browser_info_->SetClosing();
|
||||
}
|
||||
|
||||
void CefBrowserHostBase::OnBrowserDestroyed() {
|
||||
|
|
|
@ -41,7 +41,9 @@ CefBrowserInfo::~CefBrowserInfo() {
|
|||
|
||||
CefRefPtr<CefBrowserHostBase> CefBrowserInfo::browser() const {
|
||||
base::AutoLock lock_scope(lock_);
|
||||
if (!is_closing_)
|
||||
return browser_;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CefBrowserInfo::SetBrowser(CefRefPtr<CefBrowserHostBase> browser) {
|
||||
|
@ -71,6 +73,12 @@ void CefBrowserInfo::SetBrowser(CefRefPtr<CefBrowserHostBase> browser) {
|
|||
}
|
||||
}
|
||||
|
||||
void CefBrowserInfo::SetClosing() {
|
||||
base::AutoLock lock_scope(lock_);
|
||||
DCHECK(!is_closing_);
|
||||
is_closing_ = true;
|
||||
}
|
||||
|
||||
void CefBrowserInfo::MaybeCreateFrame(content::RenderFrameHost* host,
|
||||
bool is_guest_view) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
@ -228,7 +236,7 @@ void CefBrowserInfo::RemoveFrame(content::RenderFrameHost* host) {
|
|||
CefRefPtr<CefFrameHostImpl> CefBrowserInfo::GetMainFrame() {
|
||||
NotificationStateLock lock_scope(this);
|
||||
// Early exit if called post-destruction.
|
||||
if (!browser_)
|
||||
if (!browser_ || is_closing_)
|
||||
return nullptr;
|
||||
|
||||
CHECK(main_frame_);
|
||||
|
|
|
@ -52,6 +52,13 @@ class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {
|
|||
// (to set) and DestroyBrowser (to clear).
|
||||
void SetBrowser(CefRefPtr<CefBrowserHostBase> browser);
|
||||
|
||||
// Called after OnBeforeClose and before SetBrowser(nullptr). This will cause
|
||||
// browser() and GetMainFrame() to return nullptr as expected by
|
||||
// CefFrameHandler callbacks. Note that this differs from calling
|
||||
// SetBrowser(nullptr) because the WebContents has not yet been destroyed and
|
||||
// further frame-related callbacks are expected.
|
||||
void SetClosing();
|
||||
|
||||
// Ensure that a frame record exists for |host|. Called for the main frame
|
||||
// when the RenderView is created, or for a sub-frame when the associated
|
||||
// RenderFrame is created in the renderer process.
|
||||
|
@ -239,6 +246,9 @@ class CefBrowserInfo : public base::RefCountedThreadSafe<CefBrowserInfo> {
|
|||
// The current main frame.
|
||||
CefRefPtr<CefFrameHostImpl> main_frame_;
|
||||
|
||||
// True if the browser is currently closing.
|
||||
bool is_closing_ = false;
|
||||
|
||||
// Only accessed on the UI thread.
|
||||
std::vector<CefDraggableRegion> draggable_regions_;
|
||||
|
||||
|
|
Loading…
Reference in New Issue