in libcef/renderer/render_manager.cc [267:348]
CefRefPtr<CefBrowserImpl> CefRenderManager::MaybeCreateBrowser(
content::RenderView* render_view,
content::RenderFrame* render_frame,
bool* browser_created,
absl::optional<bool>* is_windowless) {
if (browser_created)
*browser_created = false;
if (!render_view || !render_frame)
return nullptr;
// Don't create another browser or guest view object if one already exists for
// the view.
auto browser = GetBrowserForView(render_view);
if (browser) {
if (is_windowless) {
*is_windowless = browser->is_windowless();
}
return browser;
}
auto guest_view = GetGuestViewForView(render_view);
if (guest_view) {
if (is_windowless) {
*is_windowless = guest_view->is_windowless();
}
return nullptr;
}
const int render_frame_routing_id = render_frame->GetRoutingID();
// Retrieve the browser information synchronously. This will also register
// the routing ids with the browser info object in the browser process.
auto params = cef::mojom::NewBrowserInfo::New();
GetBrowserManager()->GetNewBrowserInfo(render_frame_routing_id, ¶ms);
if (is_windowless) {
*is_windowless = params->is_windowless;
}
if (params->browser_id == 0) {
// The popup may have been canceled during creation.
return nullptr;
}
if (params->is_guest_view || params->browser_id < 0) {
// Don't create a CefBrowser for guest views, or if the new browser info
// response has timed out.
guest_views_.insert(std::make_pair(
render_view, std::make_unique<CefGuestView>(this, render_view,
params->is_windowless)));
return nullptr;
}
browser = new CefBrowserImpl(render_view, params->browser_id,
params->is_popup, params->is_windowless);
browsers_.insert(std::make_pair(render_view, browser));
// Notify the render process handler.
CefRefPtr<CefApp> application = CefAppManager::Get()->GetApplication();
if (application.get()) {
CefRefPtr<CefRenderProcessHandler> handler =
application->GetRenderProcessHandler();
if (handler.get()) {
CefRefPtr<CefDictionaryValueImpl> dictValuePtr;
if (params->extra_info) {
auto& dict_value = base::Value::AsDictionaryValue(*params->extra_info);
dictValuePtr = new CefDictionaryValueImpl(
const_cast<base::DictionaryValue*>(&dict_value),
/*will_delete=*/false, /*read_only=*/true);
}
handler->OnBrowserCreated(browser.get(), dictValuePtr.get());
if (dictValuePtr)
ignore_result(dictValuePtr->Detach(nullptr));
}
}
if (browser_created)
*browser_created = true;
return browser;
}