Improve timing of frame attach/detach (see #3664)

- Move frame attachment from RenderFrameCreated to
  DidCommitProvisionalLoad. This has a number of advantages:
  - Significantly reduces the frequency of disconnects by avoiding
    the GetInterface/DidCommitNavigation race condition.
  - Stops connecting temporary frames (created during cross-origin
    navigation), making callback behavior more consistent.
- Split frame detach and destruction notifications into separate
  callbacks. OnFrameDetached now reflects a potentially recoverable
  state. Add a new OnFrameDestroyed callback for the unrecoverable
  destruction state.
This commit is contained in:
Marshall Greenblatt
2024-11-27 17:08:42 -05:00
parent 7f253f83a2
commit 35fc888c72
16 changed files with 484 additions and 220 deletions

View File

@@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=4a3d33abbaa00a373ea515338ed67d96708dbb9c$
// $hash=51da21d569dd41e38cb2dc6e0f2dea0bd88dbdce$
//
#include "libcef_dll/cpptoc/frame_handler_cpptoc.h"
@@ -50,6 +50,34 @@ frame_handler_on_frame_created(struct _cef_frame_handler_t* self,
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame));
}
void CEF_CALLBACK
frame_handler_on_frame_destroyed(struct _cef_frame_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self) {
return;
}
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser) {
return;
}
// Verify param: frame; type: refptr_diff
DCHECK(frame);
if (!frame) {
return;
}
// Execute
CefFrameHandlerCppToC::Get(self)->OnFrameDestroyed(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame));
}
void CEF_CALLBACK
frame_handler_on_frame_attached(struct _cef_frame_handler_t* self,
cef_browser_t* browser,
@@ -140,6 +168,7 @@ frame_handler_on_main_frame_changed(struct _cef_frame_handler_t* self,
CefFrameHandlerCppToC::CefFrameHandlerCppToC() {
GetStruct()->on_frame_created = frame_handler_on_frame_created;
GetStruct()->on_frame_destroyed = frame_handler_on_frame_destroyed;
GetStruct()->on_frame_attached = frame_handler_on_frame_attached;
GetStruct()->on_frame_detached = frame_handler_on_frame_detached;
GetStruct()->on_main_frame_changed = frame_handler_on_main_frame_changed;

View File

@@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=0074492ed580ccc06962a05b6c72bdabae182a51$
// $hash=14e4a39489488582d7965ae71ed1ef174a4f3b08$
//
#include "libcef_dll/ctocpp/frame_handler_ctocpp.h"
@@ -48,6 +48,34 @@ void CefFrameHandlerCToCpp::OnFrameCreated(CefRefPtr<CefBrowser> browser,
CefFrameCppToC::Wrap(frame));
}
NO_SANITIZE("cfi-icall")
void CefFrameHandlerCToCpp::OnFrameDestroyed(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame) {
shutdown_checker::AssertNotShutdown();
cef_frame_handler_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, on_frame_destroyed)) {
return;
}
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get()) {
return;
}
// Verify param: frame; type: refptr_diff
DCHECK(frame.get());
if (!frame.get()) {
return;
}
// Execute
_struct->on_frame_destroyed(_struct, CefBrowserCppToC::Wrap(browser),
CefFrameCppToC::Wrap(frame));
}
NO_SANITIZE("cfi-icall")
void CefFrameHandlerCToCpp::OnFrameAttached(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,

View File

@@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=a571fa8b3c173d78cfb67eb3e44c8f2c3fb2e089$
// $hash=f33fedc6d7e0d692b03fe7f35319e93c5f31b9b1$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_FRAME_HANDLER_CTOCPP_H_
@@ -36,6 +36,8 @@ class CefFrameHandlerCToCpp : public CefCToCppRefCounted<CefFrameHandlerCToCpp,
// CefFrameHandler methods.
void OnFrameCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame) override;
void OnFrameDestroyed(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame) override;
void OnFrameAttached(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
bool reattached) override;