Problem when creating Custom Popup

691 views
Skip to first unread message

Wladimir Coka

unread,
Mar 4, 2013, 12:19:28 PM3/4/13
to cef...@googlegroups.com
I'm following the example from previous thread where there is an example of implementing a custom popup, but seams that some parts are broken with new version:

In the old example I saw that a method should be added to CefWindowInfo.cs

        public void SetAsChild(IntPtr parentHandle)
        {
            var self = (cef_window_info_t_windows*)_self;
            self->parent_window = parentHandle;
            self->style = (uint)(WindowStyles.WS_CHILD
            | WindowStyles.WS_CLIPCHILDREN
            | WindowStyles.WS_CLIPSIBLINGS
            | WindowStyles.WS_TABSTOP
            | WindowStyles.WS_VISIBLE)
            ;
        }

But now that class is a little different and there is also another methond that might me doing somehting alike (SetAsPopup)


This is the code I use:

protected override bool OnBeforePopup(CefBrowser parentBrowser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
{

customPopUp = new PopupForm2(parentBrowser, popupFeatures, targetUrl, ref client, settings);

//Option 1
//windowInfo.SetAsChild(customPopUp.GetWeBrowserControlHandle());
//Option 2
windowInfo.SetAsPopup(customPopUp.GetWeBrowserControlHandle(), null);

customPopUp.Show();
return false;

}

I tried using SetAsPopup() and also added the SetAsChild() method from the example (with some minor changes on the abstract class) but on both cases the customPopUp shows but stays "No responding", also tried sending the Form and Panel Handle but on both cases the result is the same.

How should I do this?


Wladimir Coka

unread,
Mar 4, 2013, 9:02:07 PM3/4/13
to cef...@googlegroups.com
Something new that I found out is that OnAfterCreated never got fired. But if I remove customPopUp.Show() form OnBeforePopup,;then that event does get fired but the form isnt shown.

This is the code of the event: 

        protected override void OnAfterCreated(CefBrowser browser)
        {
            base.OnAfterCreated(browser);

            if (browser.GetHost().GetOpenerWindowHandle() != IntPtr.Zero && customPopUp != null)
                customPopUp.AttachBrowser(browser); //_core.OnCreated(browser) is called in attachBrowser
            else
                _core.OnCreated(browser);

        }

Dmitry Azaraev

unread,
Mar 5, 2013, 4:23:31 AM3/5/13
to cef...@googlegroups.com
Hi. Once you create own form which will contain browser - you doesn't need use SetAsPopup. It is just set window styles. Check probably threading issues, i.e. in your case you probably create form from CEF UI thread, but mean Main UI (WinForm) thread. If multi-thread message loop enabled - this threads are completely differenet.
I can't say more without reproduction sample.


--
You received this message because you are subscribed to the Google Groups "CefGlue" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cefglue+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Best regards,
   Dmitry

Wladimir Coka

unread,
Mar 5, 2013, 9:53:16 AM3/5/13
to cef...@googlegroups.com, dmitry....@gmail.com
I just use last CefGlue source Winform example, added a folder called POPUP with popup files (used from the example I found other thread) and and the only other files modified were: WebLifeSpanHandler (implemented OnBeforePopup and OnAfterCreated), added method to SetAsChild to CefWindowInfo (not sure if needed because there were others very alike)

The problem is that popup stays idle / No responding

Thanks
Xilium.CefGlue.POPUP.zip

fddima

unread,
Mar 5, 2013, 10:37:20 AM3/5/13
to cef...@googlegroups.com, dmitry....@gmail.com
As i say before, it is threading issue (bug in your's code).

        protected override bool OnBeforePopup(CefBrowser parentBrowser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
        {
            // UI elements can be accessed ONLY from UI thread.
            // Main UI thread - it is WinForms's UI thread.
            // CEF UI thread - it is DIFFERENT thread, when MultiThreadedMessageLoop enabled (default for windows, on other platform inaccessible).
            // but now we at CEF IO thread!

            // TODO: do not reuse CefClient - provide new CefClient object which will notify your's new browser form (PopupForm2).
            // It can be constructed based on current CefClient, but better is provide CefClientFactory.
            // I.e. for easy using just assume that you always need ONE CefClient (and dependend CefLifeSpanHandler) instances PER BROWSER. If you want share CefClient - then CefClient impls must dispatch events by actual CefBrowser / etc

            // Also don't keep popupfeaturs, windowInfo and settings outside this method. Once this method returned -> this objects will be dispoed.

            IntPtr handle = IntPtr.Zero;
            DemoApp.MainSynchronizationContext.Send((s) =>
            {
                customPopUp = new PopupForm2(parentBrowser, popupFeatures, targetUrl, settings);
                handle = customPopUp.GetWeBrowserControlHandle();
                customPopUp.Show();
            }, null);

            Trace.Assert(handle != IntPtr.Zero);
            windowInfo.SetAsChild(handle);
            //windowInfo.SetAsChild(customPopUp.GetWeBrowserControlHandle(), new CefRectangle { X = 0, Y = 0, Width = customPopUp.Width, Height = customPopUp.Height });

            // TODO: about same can be implemented without sync, via later reparenting browser's window in target control (when it will be done).

            return false;
        }

I attach complete fixed modified sample (also added DemoApp.MainSynchronizationContext, which set from MainViewImpl).
CefGlue project now doesn't provide any internal infrastructure, so some things probably unclear, but all of them not so hard.
And read my comments carefully for code (in this post, in code not all present).
Xilium.CefGlue.Popup.1.7z

Wladimir Coka

unread,
Mar 5, 2013, 2:09:09 PM3/5/13
to cef...@googlegroups.com, dmitry....@gmail.com
Got it.

Confusion was that the same code worked on the example from previous thread without this SyncronizationContext, I guess this is now needed.

Thanks

fddima

unread,
Mar 6, 2013, 2:30:07 AM3/6/13
to cef...@googlegroups.com, dmitry....@gmail.com
Probably some new internal CEF / chromium implementation affects.
Also some kind of luck (unluck) within code from previous thread.
Reply all
Reply to author
Forward
0 new messages