CefLifeSpanHandler, customized OnBeforePopup problem

Issue #1949 invalid
DonSleza4e created an issue

Hello

I'm using latest stable CefSharp 49.0.1, designed for CEF 3.2623.1401. I didn't tried with latest CEF version because CefSharp 51 for it isn't released yet (alpha version is not working at my app for some reason)

I stuck with issue reported at their issues tracker. Guys investigated it and redirected me here - it's a CEF issue, not theirs

Sorry, I'm not familiar with C++, and use C# syntax in examples (and my English is not perfect as well...)

I experience troubles with some specific webpages with <form target="_blank"></form>. Here's small demo page to test this issue:

<html>
<body>
    <form method='post' action='test.php' target="_blank">
        <input name="field_a" value='value 1'/>
        <input name="field_b" value='value 2'/>
        <input type='submit' value='submit'/>
    </form>
    <br/><br/>
    <?
        echo "post data #1: " . $_POST['field_a'];
        echo "<br/>";
        echo "post data #2: " . $_POST['field_b'];
    ?>
</body>
</html>

Life url for testing mibs.info/test.php . Everything good at Chrome. When I click "submit" button - browser opens new tab and shows posted data.

Problem is in CefLifeSpanHandler, OnBeforePopup method. Everything good if I return false in this method

      bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            newBrowser = null;
            return false;
        }

But I have a multitabbed interface and open all new urls in my own styled tabs So my code is something like

      bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            //
            // Here's code to create new tab at my application. I removed it, because it's not important
            //

            newBrowser = .......WebBrowser;    //assigning to browser at new tab
            return true;
        }

This code worked fine in all typical webpages.

But I experience troubles with specific webpage (I provided it before). CEF just opens fresh webpage when I click on "submit" page - so this is a problem. Expected behaviour is to send "post" data, but this is not happens

I tried to use sniffer: With default "return false;" at OnBeforePopup, cef sends expected "post" action.fine.png

With "return true" cef sends "get" action instead of "post" bad.png

Comments (4)

  1. Cristian Amarie

    Quote from OnBeforePopup documentation: "To cancel creation of the popup browser return true." I see you are returning true, and I think this means the popup passed to OnBeforePopup will do nothing more. I think you should modify the windowInfo to reparent the popup into a new tab (I guess this is what you want, I'm not sure), not return true from OnBeforePopup. If so, I'm doing something similar using

    ...
    windowInfo.SetAsChild( parentWindow, parentTabRectangle );
    // store browser somewhere in a collection of tabs 
    return false;
    

    I think this issue should be marked as invalid.

  2. Marshall Greenblatt

    @DonSleza4e: Your usage of OnBeforePopup is incorrect. It will not automatically open the request in an existing CefBrowser for you.

  3. amaitland

    The problem this issue was meant to highlight is as follows:

    Unless I'm mistaken when you wish to have the popup rendered using OSR the only option is to provide a custom CefClient instance in OnBeforePopup, this is what CefSharp does when you populate the newBrowser parameter. When doing so the POST data is no longer successfully passed to the popup.

    The actual code CefSharp uses is https://github.com/cefsharp/CefSharp/blob/423fc2a8065ef7497c9ade2b84f0747a7af0d401/CefSharp.Core/Internals/ClientAdapter.cpp#L101

    I've never found the time to modify cefclient to see if the problem reproduces, though I suspect that it would.

    There is a lot of information that's irreverent to CEF in this issue, is it better to create a new issue or reopen this one? thoughts?

  4. Log in to comment