Page 1 of 1

Close second browser and return control to first browser

PostPosted: Sat Jul 21, 2018 12:09 pm
by Artem
Hello

1. I create a first browser with OSR rendering and load page
2. Next I find a link on page and click it with CefBrowserHost->SendMouseClickEvent()
3. Link has a target=blank attribute and implement CefLifeSpanHandler for catching OnBeforePopup event and create second browser windowless too.
4. When second browser page loaded I register CefV8Handler and execute some JS code for finding buttons on page and click with CefBrowserHost->SendMouseClickEvent()
5. After that I call CefBrowserHost->CloseBrowser(true)

How to return control to first CefBrowser?

I try to implement CefRenderProcessHandler->OnBrowserCreated and OnBrowserDestroyed

OnBrowserCreated called twice, with browser identifier 1 and after creating second browser with identifier 2, but OnBrowserDestroyed not called.

CefFocusHandler how I understand used for page inputs and controls focus, not for browser tabs

Also I tried to save reference to first CefBrowser in global object, but in second browser I get null reference.

Re: Close second browser and return control to first browser

PostPosted: Sat Jul 21, 2018 1:59 pm
by magreenblatt
What do you mean by "return control to first CefBrowser"? Do you mean focus some control in the first browser?

Re: Close second browser and return control to first browser

PostPosted: Sat Jul 21, 2018 2:23 pm
by Artem
I want to execute JS in first browser, after closing second browser.

Re: Close second browser and return control to first browser

PostPosted: Sat Jul 21, 2018 7:27 pm
by magreenblatt
You can use the ExecuteJavaScript method. See https://bitbucket.org/chromiumembedded/ ... gration.md

Re: Close second browser and return control to first browser

PostPosted: Sun Jul 22, 2018 1:03 am
by Artem
I don't understand how I can use this method.

For example, in second browser
Code: Select all
internal class SecondBrowserCefClient : CefClient
{
        protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
        {
            if (message.Name == "CLOSE_BROWSER")
            {
                browser.GetHost().CloseBrowser(true);
            }

            return false;
        }
}


This code close second browser, where I can call ExecuteJavaScript for first browser?