chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.35k stars 467 forks source link

CefLifeSpanHandler, customized OnBeforePopup problem #1949

Closed magreenblatt closed 8 years ago

magreenblatt commented 8 years ago

Original report by DonSleza4e (Bitbucket: DonSleza4e, GitHub: DonSleza4e).


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

. Here's small demo page to test this issue:

#!php

<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

#!c#

      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

#!c#

      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

magreenblatt commented 8 years ago

Original comment by DonSleza4e (Bitbucket: DonSleza4e, GitHub: DonSleza4e).


Problem still exists at CEF 3.2704.1432 (released with CefSharp 51.0.0.0)

magreenblatt commented 8 years ago

Original comment by Cristian Amarie (Bitbucket: ndesktop, GitHub: ndesktop).


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

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

I think this issue should be marked as invalid.

magreenblatt commented 8 years ago

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

magreenblatt commented 7 years ago

Original comment by amaitland (Bitbucket: amaitland, GitHub: 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?

magreenblatt commented 8 years ago