Add notification for aborted popups (fixes #3776)

Pass a new |popup_id| parameter to OnBeforePopup and call a new
OnBeforePopupAborted callback if the popup is aborted before
OnAfterCreated is called for the popup browser. Add new
CefBrowserHost::GetBrowserByIdentifier and GetOpenerIdentifier
methods to assist with retrieval of associated browsers.

In cefclient, clean up state when a popup is aborted and close
any associated popup browsers when the opener browser is closed.
This also works when running with `--use-default-popup`.
This commit is contained in:
Marshall Greenblatt
2024-11-08 19:05:04 -05:00
parent b660522983
commit e513077eac
45 changed files with 773 additions and 109 deletions

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=8a2a8a4853c3869876ffad3e6c175945ac1c5021$
// $hash=c7458f64a0d7c8537dbdbcf34d11e62bf781428c$
//
#include "libcef_dll/cpptoc/browser_host_cpptoc.h"
@ -136,6 +136,20 @@ CEF_EXPORT cef_browser_t* cef_browser_host_create_browser_sync(
return CefBrowserCppToC::Wrap(_retval);
}
CEF_EXPORT cef_browser_t* cef_browser_host_get_browser_by_identifier(
int browser_id) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
CefRefPtr<CefBrowser> _retval =
CefBrowserHost::GetBrowserByIdentifier(browser_id);
// Return type: refptr_same
return CefBrowserCppToC::Wrap(_retval);
}
namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
@ -262,6 +276,24 @@ browser_host_get_opener_window_handle(struct _cef_browser_host_t* self) {
return _retval;
}
int CEF_CALLBACK
browser_host_get_opener_identifier(struct _cef_browser_host_t* self) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self) {
return 0;
}
// Execute
int _retval = CefBrowserHostCppToC::Get(self)->GetOpenerIdentifier();
// Return type: simple
return _retval;
}
int CEF_CALLBACK browser_host_has_view(struct _cef_browser_host_t* self) {
shutdown_checker::AssertNotShutdown();
@ -1536,6 +1568,7 @@ CefBrowserHostCppToC::CefBrowserHostCppToC() {
GetStruct()->set_focus = browser_host_set_focus;
GetStruct()->get_window_handle = browser_host_get_window_handle;
GetStruct()->get_opener_window_handle = browser_host_get_opener_window_handle;
GetStruct()->get_opener_identifier = browser_host_get_opener_identifier;
GetStruct()->has_view = browser_host_has_view;
GetStruct()->get_client = browser_host_get_client;
GetStruct()->get_request_context = browser_host_get_request_context;

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=3883fd2aca10df181da30759fcce351fed62d43d$
// $hash=b3844320e2d708a582a4bc2e3d5f2f143de8f514$
//
#include "libcef_dll/cpptoc/life_span_handler_cpptoc.h"
@ -29,6 +29,7 @@ int CEF_CALLBACK life_span_handler_on_before_popup(
struct _cef_life_span_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
int popup_id,
const cef_string_t* target_url,
const cef_string_t* target_frame_name,
cef_window_open_disposition_t target_disposition,
@ -128,7 +129,7 @@ int CEF_CALLBACK life_span_handler_on_before_popup(
// Execute
bool _retval = CefLifeSpanHandlerCppToC::Get(self)->OnBeforePopup(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), popup_id,
CefString(target_url), CefString(target_frame_name), target_disposition,
user_gesture ? true : false, popupFeaturesVal, windowInfoObj, clientPtr,
settingsObj, extra_infoPtr, &no_javascript_accessBool);
@ -170,6 +171,29 @@ int CEF_CALLBACK life_span_handler_on_before_popup(
return _retval;
}
void CEF_CALLBACK
life_span_handler_on_before_popup_aborted(struct _cef_life_span_handler_t* self,
cef_browser_t* browser,
int popup_id) {
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;
}
// Execute
CefLifeSpanHandlerCppToC::Get(self)->OnBeforePopupAborted(
CefBrowserCToCpp::Wrap(browser), popup_id);
}
void CEF_CALLBACK life_span_handler_on_before_dev_tools_popup(
struct _cef_life_span_handler_t* self,
cef_browser_t* browser,
@ -365,6 +389,8 @@ life_span_handler_on_before_close(struct _cef_life_span_handler_t* self,
CefLifeSpanHandlerCppToC::CefLifeSpanHandlerCppToC() {
GetStruct()->on_before_popup = life_span_handler_on_before_popup;
GetStruct()->on_before_popup_aborted =
life_span_handler_on_before_popup_aborted;
GetStruct()->on_before_dev_tools_popup =
life_span_handler_on_before_dev_tools_popup;
GetStruct()->on_after_created = life_span_handler_on_after_created;