Popup in custom window, e.WindowInfo.SetAsChild can't work

Having problems with building or using the CefGlue .NET/Mono binding? Ask your questions here.

Moderator: fddima

Popup in custom window, e.WindowInfo.SetAsChild can't work

Postby Wyman » Wed May 04, 2016 3:14 am

Hi,

My project based on Cef version 3.2526.1373 and Xilium revision 0bd98ba7dce1(3.2526.1366) .

I override OnBeforePopup:

Code: Select all
protected override void OnBeforePopup(BeforePopupEventArgs e)
{
   base.OnBeforePopup(e);

   e.Handled = false;
   CefWebBrowser clone = new CefWebBrowser();
   e.WindowInfo.SetAsChild(clone.Handle, new CefRectangle { X = 0, Y = 0, Width = Width, Height = Height });

   Window1 parent = new Window1();
   parent.Title = "TestPage";
   WindowsFormsHost a = parent.FindName("browserParent") as WindowsFormsHost;             
   a.Child = clone ;
   parent.Show();
}


Window1.xaml is :

Code: Select all
<Window x:Class="Test.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" Height="800" Width="1024">

    <Grid>
        <WindowsFormsHost x:Name="browserParent">

        </WindowsFormsHost>
    </Grid>
</Window>


By this ,parent not show the page.

if use Window1 as the e.WindowInfo.ParentHandle,will show the page,

Code: Select all
Window1 parent = new Window1();
parent.Show();
IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(parent).Handle;
e.WindowInfo.SetAsChild(hwnd, new CefRectangle { X = 0, Y = 0, Width = Width, Height = Height });


when set StartUrl of CefWebBrowser,works well:

Code: Select all
CefWebBrowser clone = new CefWebBrowser() { StartUrl = "http://google.com"};
Window1 parent = new Window1();
parent.Title = "TestPage";
WindowsFormsHost a = parent.FindName("browserParent") as WindowsFormsHost;             
a.Child = clone ;
parent.Show();



Could anyone help me ,thanks very much. :D
Last edited by Wyman on Wed May 04, 2016 8:04 am, edited 2 times in total.
Wyman
Newbie
 
Posts: 4
Joined: Wed Apr 13, 2016 10:34 pm

Re: Popup in custom window, e.WindowInfo.SetAsChild can't wo

Postby fddima » Wed May 04, 2016 7:23 am

You use WPF? I mean you use CefGlue.WinForms or CefGlue.WPF?

UPD: What is 'e'? What is CefWebBrowser?
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Popup in custom window, e.WindowInfo.SetAsChild can't wo

Postby Wyman » Wed May 04, 2016 7:56 am

fddima wrote:You use WPF? I mean you use CefGlue.WinForms or CefGlue.WPF?

UPD: What is 'e'? What is CefWebBrowser?



I use CefGlue.WindowsForms , but i want to includ it in WPF window

in CefGlue.WindowsForms project, the method OnBeforePopup in CefWebLifeSpanHandler.cs:

Code: Select all
protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
      {
         var e = new BeforePopupEventArgs(frame, targetUrl, targetFrameName, popupFeatures, windowInfo, client, settings, noJavascriptAccess);

         _core.InvokeIfRequired(() => _core.OnBeforePopup(e));

         client = e.Client;
         noJavascriptAccess = e.NoJavascriptAccess;

         return e.Handled;
      }


e is BeforePopupEventArgs,and CefWebBrowser is the browser control included in CefGlue.WindowsForms
Wyman
Newbie
 
Posts: 4
Joined: Wed Apr 13, 2016 10:34 pm

Re: Popup in custom window, e.WindowInfo.SetAsChild can't wo

Postby fddima » Wed May 04, 2016 8:13 am

Clear.

1. CefGlue.WindowsForms is part of sample application. I'm recommend aggregate it in own project, to easy modify it, because it is always needed.

2. Problem in OnBeforePopup:

Code: Select all
protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)


Code: Select all
   e.Handled = false;
   CefWebBrowser clone = new CefWebBrowser();
   e.WindowInfo.SetAsChild(clone.Handle, new CefRectangle { X = 0, Y = 0, Width = Width, Height = Height });


Read carefully OnBeforePopup documentation (one of easy way is press F12 on CefLifeSpanHandler class name, and metadata browser will be opened).
If you allow popup, you can provide (and should) new CefClient, modify settings, modify CefWindowInfo.

Next part actually prevent to do it, and also will not work completely for this purpose in case of multi threaded message loop is used (because windowinfo should not be accessed outside OnBeforePopup).
Code: Select all
var e = new BeforePopupEventArgs(frame, targetUrl, targetFrameName, popupFeatures, windowInfo, client, settings, noJavascriptAccess);
_core.InvokeIfRequired(() => _core.OnBeforePopup(e));


So to get popups work correctly you need allow to create CefWebBorwser, and then get CefClient and provide it for CEF.

CefGlue mainly aimed to allow almost raw access to CEF API, but if you have concrete patches to CefWebBrowser then okay.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Popup in custom window, e.WindowInfo.SetAsChild can't wo

Postby Wyman » Wed May 04, 2016 10:11 pm

fddima wrote:Clear.

1. CefGlue.WindowsForms is part of sample application. I'm recommend aggregate it in own project, to easy modify it, because it is always needed.

2. Problem in OnBeforePopup:

Code: Select all
protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)


Code: Select all
   e.Handled = false;
   CefWebBrowser clone = new CefWebBrowser();
   e.WindowInfo.SetAsChild(clone.Handle, new CefRectangle { X = 0, Y = 0, Width = Width, Height = Height });


Read carefully OnBeforePopup documentation (one of easy way is press F12 on CefLifeSpanHandler class name, and metadata browser will be opened).
If you allow popup, you can provide (and should) new CefClient, modify settings, modify CefWindowInfo.

Next part actually prevent to do it, and also will not work completely for this purpose in case of multi threaded message loop is used (because windowinfo should not be accessed outside OnBeforePopup).
Code: Select all
var e = new BeforePopupEventArgs(frame, targetUrl, targetFrameName, popupFeatures, windowInfo, client, settings, noJavascriptAccess);
_core.InvokeIfRequired(() => _core.OnBeforePopup(e));


So to get popups work correctly you need allow to create CefWebBorwser, and then get CefClient and provide it for CEF.

CefGlue mainly aimed to allow almost raw access to CEF API, but if you have concrete patches to CefWebBrowser then okay.


Thanks! I have solve the issue by your help . :D
Wyman
Newbie
 
Posts: 4
Joined: Wed Apr 13, 2016 10:34 pm


Return to CefGlue Forum

Who is online

Users browsing this forum: No registered users and 12 guests