When navigating nasty web pages with a lot of tricks / bad behaviours to open advertisements i noticed sometimes OnBeforePopup was not called but the new view gets open so you do not have any chance to block it. Even, if you're working as OSR, the new view opens in a new native window without control over it.
Messing a bit on the source i found.
One:
The function bool CefBrowserInfoManager::CanCreateWindow on browser_info_manager.cc returns true if the new view is allowed false otherwise.
It sets the boolean variable "allow" to true, but next, if client.get() fails or handler.get() fails, allow is not set to false, making the code to allow the creation run even if the handler has not been called / parameters modified.
Two:
Also, negates the value returned by handler->OnBeforePopup, that could be right, but we gonna look in the called functions:
"CEF_CALLBACK life_span_handler_on_before_popup" on "life_span_handler_cpptoc.cc"
"CefLifeSpanHandlerCToCpp::OnBeforePopup " on "life_span_handler_ctocpp.cc"
The two functions make some extra checks... the point is in case of check fauilure, they return 0 / false, making the new view get opened also without call the handler / set parameters.
Solution:
I added sentences to set "allow=false" in case of error and reversed the returned values in case of fail for the two routines, compiled and checked again.
Now the result is adequate, if asked for a new view but the checks before call the user handler fails (frame gets invalid for example because was deleted while the view was opening), the view is canceled so, no new view will be created if no call to OnBeforePopup is made.
I checked it on 2623 but looking at sources i saw 2840 stills the same, so, the fix could apply i guess, until now.
browser_info_manager.cc
- Code: Select all
if (client.get()) {
CefRefPtr<CefLifeSpanHandler> handler = client->GetLifeSpanHandler();
if (handler.get()) {
CefRefPtr<CefFrame> frame =
browser->GetFrame(pending_popup->opener_frame_id);
CefPopupFeatures cef_features;
TranslatePopupFeatures(features, cef_features);
#if (defined(OS_WIN) || defined(OS_MACOSX))
// Default to the size from the popup features.
if (cef_features.xSet)
pending_popup->window_info.x = cef_features.x;
if (cef_features.ySet)
pending_popup->window_info.y = cef_features.y;
if (cef_features.widthSet)
pending_popup->window_info.width = cef_features.width;
if (cef_features.heightSet)
pending_popup->window_info.height = cef_features.height;
#endif
allow = !handler->OnBeforePopup(browser.get(),
frame,
pending_popup->target_url.spec(),
pending_popup->target_frame_name,
static_cast<cef_window_open_disposition_t>(disposition),
user_gesture,
cef_features,
pending_popup->window_info,
pending_popup->client,
pending_popup->settings,
no_javascript_access);
}
else{
allow = false;
}
}
else{
allow = false;
}
life_span_handler_cpptoc.cc
- Code: Select all
DCHECK(self);
if (!self)
return 1;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return 1;
// Verify param: frame; type: refptr_diff
DCHECK(frame);
if (!frame)
return 1;
// Verify param: popupFeatures; type: struct_byref_const
DCHECK(popupFeatures);
if (!popupFeatures)
return 1;
// Verify param: windowInfo; type: struct_byref
DCHECK(windowInfo);
if (!windowInfo)
return 1;
// Verify param: client; type: refptr_same_byref
DCHECK(client);
if (!client)
return 1;
// Verify param: settings; type: struct_byref
DCHECK(settings);
if (!settings)
return 1;
// Verify param: no_javascript_access; type: bool_byaddr
DCHECK(no_javascript_access);
if (!no_javascript_access)
return 1;
life_span_handler_ctocpp.cc
- Code: Select all
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return true;
// Verify param: frame; type: refptr_diff
DCHECK(frame.get());
if (!frame.get())
return true;
// Verify param: no_javascript_access; type: bool_byaddr
DCHECK(no_javascript_access);
if (!no_javascript_access)
return true;
// Unverified params: target_url, target_frame_name
Marshall, im just newbie to the forums, i dont know if there is a better place to report bugs / give fixes, feel free to instruct me because im working "a bit" with the source, just in case.
Cheers.