ILifeSpanHandler + Popups into new "tabs"

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.

ILifeSpanHandler + Popups into new "tabs"

Postby jeremyke » Thu Apr 21, 2016 2:42 pm

Hi all,

I'm new to CEFsharp so please bear with me as my understanding of how it works is quite limited. I'm currently writing a Browser using CEFSharp (3.2526.1362)/ Winforms (47.0.3), and I'm having issues with implementing the ILifeSpanHandler OnBeforePopup.

I'm trying to intercept popups from our website by putting them into a new ChromiumWebBrowser and then loading them into a TabControl via a Tab Page.

Code: Select all
bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IWindowInfo windowInfo, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
    {
        var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;   
        ChromiumWebBrowser newChromiumBrowser = new ChromiumWebBrowser(targetUrl);
        chromiumWebBrowser.Invoke(new Action(() =>
                                             {                                           
                                      newChromiumBrowser = mainForm.AddTab(targetUrl);
                                             }));
        newBrowser = newChromiumBrowser;
   return false;
    }



what mainForm.addTab() calls:
Code: Select all
public ChromiumWebBrowser AddTab(string url="")
{
   ChromiumWebBrowser browser = null;
   Invoke(new Action(() =>
                 {
                  browser.DownloadHandler = new DownloadHandler();
                  browser.LifeSpanHandler = new LifeSpanHandler(this);
                  
                  CreateBrowserTab(browser);

                  browser.Dock = DockStyle.Fill;
                  browser.Name = "browser";
                  browser.AllowDrop = true;
                  browser.BackColor = Color.DarkGray;
                  browser.TabIndex = 0;
                 }));
   currentBrowser=browser;
   
   return browser;
}

public ReportTabPage CreateBrowserTab(ChromiumWebBrowser browser)
{
   ReportTabPage tabPage= new ReportTabPage();
   Invoke(new Action(() =>
                 {                     
                  tabPage.Dock = DockStyle.Fill;
                  tabPage.AddBrowser(browser); //just a reference
                  
                  tabPanel.TabPages.Add(tabPage);
                  
                  tabPage.Show();
                  tabPanel.SelectedTab = tabPage;
                  tabPage.Controls.Add(browser);
                 }));
   return tabPage;
}


It works in the sense that I can intercept popups and put them as tab panels into my Tab Control. However, when trying to open a new popup using Javascript's window.open():
Code: Select all
var report = window.open("popup.html", 'Popup');


it seems that Javascript can/will not retain reference of that window (i.e. it's set to null), unless I let CEFSharp handle the popup by default, or create a separate form and load the popup there (see here: https://github.com/cefsharp/CefSharp/bl ... Handler.cs).

Is there something I'm missing that needs to be set in the popup handler so I can still reference the Javascript report variable if I add the new browser as a new tab?

Thanks in advance!
jeremyke
Newbie
 
Posts: 3
Joined: Thu Apr 21, 2016 2:39 pm

Re: ILifeSpanHandler + Popups into new "tabs"

Postby amaitland » Thu Apr 21, 2016 6:34 pm

Unfortunately that feature is Experimental, there are quite a few aspects that don't work. Unfortunately the problems will likely need to be fixed in CEF.

https://github.com/cefsharp/CefSharp/bl ... ler.cs#L24

In general this forum isn't the place to be asking CefSharp questions.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am


Return to Support Forum

Who is online

Users browsing this forum: civilogic and 106 guests