custom support for window.open in CefSharp 1

469 views
Skip to first unread message

Zeze Lazo

unread,
Jun 10, 2014, 11:36:40 PM6/10/14
to cefs...@googlegroups.com
Im using CefSharp1 and implementing support for window.open in JS, so i implmentent ILifeSpanHandler in my class like this:

  #region Implementation of ILifeSpanHandler
 
        public bool OnBeforePopup(IWebBrowser browser, string url, ref int x, ref int y, ref int width, ref int height)
        {
         	if (url.StartsWith("chrome")) return false;
                Messenger.Default.Send(new ApplicationMessage { Action = ApplicationActions.ShowExtendedView, 
                                                                ActionParameter = url,Tag=browser});
		return true;
        }
 
        public void OnBeforeClose(IWebBrowser browser)
        {
            throw new NotImplementedException();
        }
 
        #endregion

Then with the application message i handle it in another class with

var myNewForm = new Form();
myNewForm.Load += (s, e) =>
			{
			   var view = browser as WebView;
			   myNewForm.Controls.Add(view);
			   view.Dock = DockStyle.Fill;
			};
myNewForm.Show();

But it render the original view (i mean the parent view).

Im doing something wrong, i Know CefSharp 1 support it because if i dont use the handler it renders a new window with the new view. but i want to render the new window in my own form. Is that possible??

Michal Tsadok

unread,
Sep 1, 2014, 5:09:33 AM9/1/14
to cefs...@googlegroups.com
Hi Zeze,

I'm curiouse if you had some progress with that...
Actually your question helped me
I'll list down my findings:

  • OnBeforePopup has reference to the existing browser and not to the one that is about to open...
  • OnBeforePopup: return false when you want the original javascript behavior, return true when you want to handle it yourself
  • I understood that if I want to have some control over the window.open browser, I should create it myself (new WebView... and return true to OnBeforePopup)
  • This how, I could open a popup window and open DevTools to it (couldn't find a way to do it when the javascript was responsible to open the new browser window...)
  • If I need to interact between the opener and the child window, I can do it through the code behind
  • I might have more findings as I'm just in the middle of my development
It seems that there is no much activity in this group - maybe we can help each other
Please share your thoughts

Michal
Reply all
Reply to author
Forward
0 new messages