mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Fix draggable region update with BackForwardCache enabled (see issue #2421)
When BackForwardCache is enabled and the user navigates the main frame back/forward a new RFH may be created for an existing main frame GlobalId value and CefFrameHostImpl (e.g. an object that was previously Detach()ed after main frame navigation called SetMainFrame, but for which RenderFrameDeleted was not subsequently called due to insertion in the BackForwardCache). In this case we can re-attach the new RFH to the existing main frame CefFrameHostImpl in RenderFrameHostStateChanged and resume processing of messages. Swapping back/forward to an existing (already loaded) renderer does not trigger new notifications for draggable regions (e.g. RenderFrameObserver:: DraggableRegionsChanged is not called by default). We therefore explicitly request an update of draggable regions by sending the DidStopLoading message to the renderer. A new |reattached| parameter is added to CefFrameHandler::OnFrameAttached to support identification of BackForwardCache usage by the client. To test with unit tests: Run `ceftests --gtest_filter=DraggableRegionsTest.DraggableRegionsCrossOrigin --enable-features=BackForwardCache` To test manually: 1. Run `cefclient --enable-features=BackForwardCache --use-views --url=http://tests/draggable`, note that draggable regions work. 2. Load https://www.google.com via the address bar, note that draggable regions are removed. 3. Go back to http://tests/draggable, note that draggable regions work. 4. Go forward to https://www.google.com, note that draggable regions are removed.
This commit is contained in:
@@ -460,6 +460,36 @@ bool CefFrameHostImpl::Detach() {
|
||||
return first_detach;
|
||||
}
|
||||
|
||||
void CefFrameHostImpl::MaybeReAttach(
|
||||
scoped_refptr<CefBrowserInfo> browser_info,
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
CEF_REQUIRE_UIT();
|
||||
if (is_attached_ && render_frame_host_ == render_frame_host) {
|
||||
// Nothing to do here.
|
||||
return;
|
||||
}
|
||||
|
||||
// We expect that Detach() was called previously.
|
||||
CHECK(!is_temporary());
|
||||
CHECK(!is_attached_);
|
||||
CHECK(!render_frame_host_);
|
||||
|
||||
// The RFH may change but the GlobalId should remain the same.
|
||||
CHECK_EQ(frame_id_,
|
||||
frame_util::MakeFrameId(render_frame_host->GetGlobalId()));
|
||||
|
||||
{
|
||||
base::AutoLock lock_scope(state_lock_);
|
||||
browser_info_ = browser_info;
|
||||
}
|
||||
|
||||
render_frame_host_ = render_frame_host;
|
||||
RefreshAttributes();
|
||||
|
||||
// Restore the RenderFrame connection.
|
||||
FrameAttachedInternal(/*reattached=*/true);
|
||||
}
|
||||
|
||||
// kMainFrameId must be -1 to align with renderer expectations.
|
||||
const int64_t CefFrameHostImpl::kMainFrameId = -1;
|
||||
const int64_t CefFrameHostImpl::kFocusedFrameId = -2;
|
||||
@@ -552,6 +582,10 @@ void CefFrameHostImpl::SendMessage(const std::string& name,
|
||||
}
|
||||
|
||||
void CefFrameHostImpl::FrameAttached() {
|
||||
FrameAttachedInternal(/*reattached=*/false);
|
||||
}
|
||||
|
||||
void CefFrameHostImpl::FrameAttachedInternal(bool reattached) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
auto browser_info = GetBrowserInfo();
|
||||
@@ -573,13 +607,13 @@ void CefFrameHostImpl::FrameAttached() {
|
||||
}
|
||||
|
||||
browser_info->MaybeExecuteFrameNotification(base::BindOnce(
|
||||
[](CefRefPtr<CefFrameHostImpl> self,
|
||||
[](CefRefPtr<CefFrameHostImpl> self, bool reattached,
|
||||
CefRefPtr<CefFrameHandler> handler) {
|
||||
if (auto browser = self->GetBrowserHostBase()) {
|
||||
handler->OnFrameAttached(browser, self);
|
||||
handler->OnFrameAttached(browser, self, reattached);
|
||||
}
|
||||
},
|
||||
CefRefPtr<CefFrameHostImpl>(this)));
|
||||
CefRefPtr<CefFrameHostImpl>(this), reattached));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,13 +630,6 @@ void CefFrameHostImpl::UpdateDraggableRegions(
|
||||
if (!browser)
|
||||
return;
|
||||
|
||||
CefRefPtr<CefDragHandler> handler;
|
||||
auto client = browser->GetClient();
|
||||
if (client)
|
||||
handler = client->GetDragHandler();
|
||||
if (!handler)
|
||||
return;
|
||||
|
||||
std::vector<CefDraggableRegion> draggable_regions;
|
||||
if (regions) {
|
||||
draggable_regions.reserve(regions->size());
|
||||
@@ -615,7 +642,10 @@ void CefFrameHostImpl::UpdateDraggableRegions(
|
||||
}
|
||||
}
|
||||
|
||||
handler->OnDraggableRegionsChanged(browser.get(), this, draggable_regions);
|
||||
// Delegate to BrowserInfo so that current state is maintained with
|
||||
// cross-origin navigation.
|
||||
browser_info_->MaybeNotifyDraggableRegionsChanged(
|
||||
browser, this, std::move(draggable_regions));
|
||||
}
|
||||
|
||||
void CefExecuteJavaScriptWithUserGestureForTests(CefRefPtr<CefFrame> frame,
|
||||
|
Reference in New Issue
Block a user