<commit_before>﻿// Copyright © 2010-2016 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System;
using System.Windows;
using System.Windows.Interop;

namespace CefSharp.Wpf.Example.Handlers
{
    public class LifespanHandler : ILifeSpanHandler
    {
        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)
        {
            //Set newBrowser to null unless your attempting to host the popup in a new instance of ChromiumWebBrowser
            newBrowser = null;

            return false;

            //NOTE: This is experimental
            //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //ChromiumWebBrowser chromiumBrowser = null;

            //var windowX = (windowInfo.X == int.MinValue) ? double.NaN : windowInfo.X;
            //var windowY = (windowInfo.Y == int.MinValue) ? double.NaN : windowInfo.Y;
            //var windowWidth = (windowInfo.Width == int.MinValue) ? double.NaN : windowInfo.Width;
            //var windowHeight = (windowInfo.Height == int.MinValue) ? double.NaN : windowInfo.Height;

            //chromiumWebBrowser.Dispatcher.Invoke(() =>
            //{
            //	var owner = Window.GetWindow(chromiumWebBrowser);
            //	chromiumBrowser = new ChromiumWebBrowser
            //	{
            //		Address = targetUrl,
            //	};

            //	chromiumBrowser.SetAsPopup();
            //	chromiumBrowser.LifeSpanHandler = this;

            //	var popup = new Window
            //	{
            //		Left = windowX,
            //		Top = windowY,
            //		Width = windowWidth,
            //		Height = windowHeight,
            //		Content = chromiumBrowser,
            //		Owner = owner,
            //		Title = targetFrameName
            //	};

            //	var windowInteropHelper = new WindowInteropHelper(popup);
            //	//Create the handle Window handle (In WPF there's only one handle per window, not per control)
            //	var handle = windowInteropHelper.EnsureHandle();

            //	//The parentHandle value will be used to identify monitor info and to act as the parent window for dialogs,
            //	//context menus, etc. If parentHandle is not provided then the main screen monitor will be used and some
            //	//functionality that requires a parent window may not function correctly.
            //	windowInfo.SetAsWindowless(handle, true);

            //	popup.Closed += (o, e) => 
            //	{
            //		var w = o as Window;
            //		if (w != null && w.Content is IWebBrowser)
            //		{
            //			(w.Content as IWebBrowser).Dispose();
            //			w.Content = null;
            //		}
            //	};
            //});

            //newBrowser = chromiumBrowser;

            //return false;
        }

        void ILifeSpanHandler.OnAfterCreated(IWebBrowser browserControl, IBrowser browser)
        {
            //NOTE: This is experimental
            //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //chromiumWebBrowser.Dispatcher.Invoke(() =>
            //{
            //	var owner = Window.GetWindow(chromiumWebBrowser);

            //	if (owner != null && owner.Content == browserControl)
            //	{
            //		owner.Show();
            //	}
            //});
        }

        bool ILifeSpanHandler.DoClose(IWebBrowser browserControl, IBrowser browser)
        {
            return false;
        }

        void ILifeSpanHandler.OnBeforeClose(IWebBrowser browserControl, IBrowser browser)
        {
            //NOTE: This is experimental
            //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //chromiumWebBrowser.Dispatcher.Invoke(() =>
            //{
            //	var owner = Window.GetWindow(chromiumWebBrowser);

            //	if (owner != null && owner.Content == browserControl)
            //	{
            //		owner.Close();
            //	}
            //});
        }
    }
}<commit_msg>WPF - Add browser.IsPopup checks to the example LifespanHandler when using EXPERIMENTAL newBrowser method Was hanging on exit before<commit_after>﻿// Copyright © 2010-2016 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System;
using System.Windows;
using System.Windows.Interop;

namespace CefSharp.Wpf.Example.Handlers
{
    public class LifespanHandler : ILifeSpanHandler
    {
        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)
        {
            //Set newBrowser to null unless your attempting to host the popup in a new instance of ChromiumWebBrowser
            newBrowser = null;

            return false;

            //NOTE: This is experimental
            //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //ChromiumWebBrowser chromiumBrowser = null;

            //var windowX = (windowInfo.X == int.MinValue) ? double.NaN : windowInfo.X;
            //var windowY = (windowInfo.Y == int.MinValue) ? double.NaN : windowInfo.Y;
            //var windowWidth = (windowInfo.Width == int.MinValue) ? double.NaN : windowInfo.Width;
            //var windowHeight = (windowInfo.Height == int.MinValue) ? double.NaN : windowInfo.Height;

            //chromiumWebBrowser.Dispatcher.Invoke(() =>
            //{
            //	var owner = Window.GetWindow(chromiumWebBrowser);
            //	chromiumBrowser = new ChromiumWebBrowser
            //	{
            //		Address = targetUrl,
            //	};

            //	chromiumBrowser.SetAsPopup();
            //	chromiumBrowser.LifeSpanHandler = this;

            //	var popup = new Window
            //	{
            //		Left = windowX,
            //		Top = windowY,
            //		Width = windowWidth,
            //		Height = windowHeight,
            //		Content = chromiumBrowser,
            //		Owner = owner,
            //		Title = targetFrameName
            //	};

            //	var windowInteropHelper = new WindowInteropHelper(popup);
            //	//Create the handle Window handle (In WPF there's only one handle per window, not per control)
            //	var handle = windowInteropHelper.EnsureHandle();

            //	//The parentHandle value will be used to identify monitor info and to act as the parent window for dialogs,
            //	//context menus, etc. If parentHandle is not provided then the main screen monitor will be used and some
            //	//functionality that requires a parent window may not function correctly.
            //	windowInfo.SetAsWindowless(handle, true);

            //	popup.Closed += (o, e) =>
            //	{
            //		var w = o as Window;
            //		if (w != null && w.Content is IWebBrowser)
            //		{
            //			(w.Content as IWebBrowser).Dispose();
            //			w.Content = null;
            //		}
            //	};
            //});

            //newBrowser = chromiumBrowser;

            //return false;
        }

        void ILifeSpanHandler.OnAfterCreated(IWebBrowser browserControl, IBrowser browser)
        {
            //NOTE: This is experimental
            //if(browser.IsPopup)
            //{ 
            //	var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //	chromiumWebBrowser.Dispatcher.Invoke(() =>
            //	{
            //		var owner = Window.GetWindow(chromiumWebBrowser);

            //		if (owner != null && owner.Content == browserControl)
            //		{
            //			owner.Show();
            //		}
            //	});
            //}
        }

        bool ILifeSpanHandler.DoClose(IWebBrowser browserControl, IBrowser browser)
        {
            return false;
        }

        void ILifeSpanHandler.OnBeforeClose(IWebBrowser browserControl, IBrowser browser)
        {
            //NOTE: This is experimental
            //if(!browser.IsDisposed && browser.IsPopup)
            //{ 
            //	var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            //	chromiumWebBrowser.Dispatcher.Invoke(() =>
            //	{
            //		var owner = Window.GetWindow(chromiumWebBrowser);

            //		if (owner != null && owner.Content == browserControl)
            //		{
            //			owner.Close();
            //		}
            //	});
            //}
        }
    }
}
{'fraction_non_alphanumeric': 0.10007749363445145, 'fraction_numerical': 0.001771283073176132, 'mean_word_length': 1.7023631468740652, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6263986', 'n_tokens_mistral': 2441, 'n_tokens_neox': 2318, 'n_words': 618}