Ok,
I tried this code to detect if the request comes from the iframe or the main frame, and redirect the request to the iframe
- Code: Select all
bool
WrapperClient::OnBeforeBrowse (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, bool isRedirect)
{
if ((request->GetResourceType() == RT_MAIN_FRAME) && (!frame->IsMain()))
{
// a request comes from iframe and redirected to main frame,
// cancels it, and load to iframe
frame->LoadURL(request->GetURL());
return true;
}
return false;
}
when the iframe contains <a href=... target="_self" />, GetResourceType() returns RT_SUB_FRAME and frame->IsMain() returns false => so i think that the request comes from the iframe
instead when the iframe contains <a href=... target="_top"/>, GetResourceType() returns RT_MAIN_FRAME and frame->IsMain() return true, assuming the request comes from the top level frame instead of the iframe; i was expeting that when the target=_top request comes from the iframe, the frame->IsMain() was false...
(I hope you understand the usecase
)
Is there any other method to detect if the url loaded by the iframe will be loaded into the toplevel frame?