[LINUX] Create multiple cef browsers in process

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

[LINUX] Create multiple cef browsers in process

Postby linuxcef9 » Tue Nov 06, 2018 3:26 pm

Hello,

I am writing a shared library on linux which will launch different CEF browsers IN PROCESS whenever it receives say 'Launch' command with a url. Here's a rough example of how I expect it to work :
1) If I receive 'LAUNCH 123 google.com' command, I want to launch cef with url google.com and associate that cef instance with id 123
2) If I receive 'LAUNCH 334 spotify.com' command, I want to launch cef with url spotify.com and associate that cef instance with id 334
3) If I receive 'DELETE 123' command, I want to stop the cef browser that was associated with id 123 but the 334 instance should keep running

I'd be launching them in offscreen rendering mode and use my own graphical toolkit to render the buffer on-screen.

I was trying out different approaches for a simple case of having 2 cef browsers and below is my observation :

1. Creating two threads. Each thread calls CefInitialize and CefRunMessageLoop. Each thread has its own SimpleApp object and OnContextInitialized creates its own SimpleHandler. In this method, I see that only 1 thread executes which calls OnContextInitialized and SimpleHandler's OnPaint. Second thread exits because CefRunMessageLoop returns immediately.

2. Creating two threads but this time I implemented my own message loop. So similar to #1, each thread calls CefInitialize and calls Run on my message loop
a. When settings.multi_threaded_message_loop = false (default)
Only 1 thread gets callback to OnContextInitialized but none of the threads get call to SimpleHandler constructor. Both the threads keep running the message
loop but no CefTasks are found in the queue.

b. When settings.multi_threaded_message_loop = true
Both threads successfully call CefInitialize and run the message loop. A separate thread gets created that gets a callback to OnContextInitialized and on this
thread, browser gets created successfully and SimpleHandler's OnPaint gets called.

3. Call CefInitialize once on the main thread. Create two threads that only call CefRunMessageLoop
Both threads call CefRunMessageLoop and CefRunMessageLoop returns immediately. Both threads exit.

4. Call CefInitialize once on the main thread. Create two threads that only call my message loop.
a. When settings.multi_threaded_message_loop = false (default)
None of the threads get OnContextInitialized callback. Both message loops run but no tasks found.

b. When settings.multi_threaded_message_loop = true
A separate thread is created that gets OnContextInitialized callback and Browser object gets created. SimpleHandler callbacks come on that thread. The
two threads that I created are running message loops but no tasks are found.

So based on above observation, what do you think would be the right way to make sure I can get my test app working?
Is there a way where I can have each cef player live in its own thread so that it's easy to do the bookkeeping?

Would appreciate your insight.
linuxcef9
Expert
 
Posts: 143
Joined: Tue Nov 06, 2018 3:08 pm

Re: [LINUX] Create multiple cef browsers in process

Postby magreenblatt » Tue Nov 06, 2018 5:15 pm

magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: [LINUX] Create multiple cef browsers in process

Postby linuxcef9 » Mon Nov 19, 2018 2:23 pm

Thanks marshall. I was finally able to fix the problem.

I had one more question - how do I build 32 bit version of cef on ubuntu host? I need 3538 branch. I could successfully build 64 bit version but I could hardly find any documentation to build 32 bit version except for https://bitbucket.org/chromiumembedded/ ... pile-build . Also, I mainly need cefsimple application only. I am okay if there's no cefclient application.

Thanks.
linuxcef9
Expert
 
Posts: 143
Joined: Tue Nov 06, 2018 3:08 pm

Re: [LINUX] Create multiple cef browsers in process

Postby magreenblatt » Mon Nov 19, 2018 3:27 pm

Instructions to build 32-bit CEF on a 64-bit Linux host system are available here: https://bitbucket.org/chromiumembedded/ ... figuration
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: [LINUX] Create multiple cef browsers in process

Postby linuxcef9 » Mon Nov 19, 2018 5:47 pm

Thanks for the link marshall.

For that, can I invoke automate-git.py with no-distrib and no-build options similar to 64 bit cef build (as per https://bitbucket.org/chromiumembedded/ ... inux-setup) and then manually
run create.sh (which runs gn command to generate ninja files) and then ninja command (to actually build cef)?

i noticed there's debian_sid_i386-sysroot folder under ~/code/chromium_git/chromium/src/build/linux folder. Which step generates that? I had used same configuration as mentioned in https://bitbucket.org/chromiumembedded/ ... inux-setup but still that sysroot folder was created.

Another question - while building on my local ubuntu machine, all the steps mentioned in https://bitbucket.org/chromiumembedded/ ... inux-setup worked fine. But when I did the same build on ubuntu 16.04 running in docker on a centOS host, I got errors about missing fonts in chromium/src/third_party/test_fonts/test_fonts. So I had to copy them manually and then it worked fine. Any idea how those fonts are found/fetched in normal install?

EDIT : I believe the fonts are downloaded via install-chromeos-fonts.py script which is invoked from install-deps.sh. However, we pass --no-chrome-os flag to install-deps.sh so I am still wondering how were the fonts fetched and which ninja rule requires them and if I can bypass it.
linuxcef9
Expert
 
Posts: 143
Joined: Tue Nov 06, 2018 3:08 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 58 guests