Passing creation/arbitrary context to newly created browser?

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

Passing creation/arbitrary context to newly created browser?

Postby mukunda » Fri May 17, 2019 10:43 am

I have a Browser object that holds a CefBrowser instance, and I'm wondering how to cleanly associate a created browser with it. Example and question:

Code: Select all
web_browser.cpp
//-----------------------------------------------------------------------------
Browser::Browser() {
   CefBrowserSettings browser_settings;
   CefWindowInfo window_info;
   window_info.SetAsWindowless( nullptr );
   window_info.shared_texture_enabled = true;
   
   CefBrowserHost::CreateBrowser( window_info, GetClient(),
                             "www.google.com", browser_settings, nullptr );
}

web_client.cpp
//-----------------------------------------------------------------------------
void Client::OnAfterCreated( CefRefPtr<CefBrowser> browser ) {
   // Assign this new CEF browser object to the Browser that created it.
   // >>> But how do I forward the reference to the original Browser to here? <<<
}


If I'm doing something not recommended with this design please let me know too. :)

My current solution in mind is to keep a queue of Browser objects in the Client that are waiting for their CEF browser to be created, but I'd like to avoid that as it seems more like a workaround rather than a proper solution, not to mention safety concerns from an additional cog in the multithreaded system.
mukunda
Newbie
 
Posts: 4
Joined: Thu May 16, 2019 12:20 pm

Re: Passing creation/arbitrary context to newly created brow

Postby magreenblatt » Fri May 17, 2019 11:07 am

If you use a different client for each browser the association will be clear.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Passing creation/arbitrary context to newly created brow

Postby mukunda » Fri May 17, 2019 11:28 am

Do you think it would be wasteful to have multiple clients just for that purpose? I imagine each browser like a separate tab. Would it be normal for each browser tab to have their own client?
mukunda
Newbie
 
Posts: 4
Joined: Thu May 16, 2019 12:20 pm

Re: Passing creation/arbitrary context to newly created brow

Postby magreenblatt » Fri May 17, 2019 11:34 am

You can use however many clients you like. It depends on what makes sense for your application.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Passing creation/arbitrary context to newly created brow

Postby mukunda » Fri May 17, 2019 12:08 pm

Thanks for the insight. :thumbsup:

It seemed to make sense before to share a client, but I think I'll rework things to have client and browser in the same object.
mukunda
Newbie
 
Posts: 4
Joined: Thu May 16, 2019 12:20 pm


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 33 guests