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; //browserControl.Load(targetUrl); OpenInNewTab?.Invoke(this, new NewTabEventArgs(targetUrl)); //this breaks when there are multiple window.open calls from JS. return true; }
public bool OnBeforePopup(IWebBrowser rpBrowserControl, IBlinkBrowser rpBrowser, IFrame rpFrame, string rpTargetUrl, string rpTargetFrameName, WindowOpenDisposition rpTargetDisposition, bool rpUserGesture, IPopupFeatures rpPopupFeatures, IWindowInfo rpWindowInfo, IBrowserSettings rpBrowserSettings, ref bool rrpNoJavascriptAccess, out IWebBrowser ropNewBrowser) { rpBrowserControl.Load(rpTargetUrl); ropNewBrowser = rpBrowserControl; return true; }
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) { //Default behaviour newBrowser = null; return false; //Return true to cancel the popup creation //EXPERIMENTAL: Demonstrates using a new instance of ChromiumWebBrowser to host the popup. var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; ChromiumWebBrowser chromiumBrowser = null; var windowX = windowInfo.X; var windowY = windowInfo.Y; var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width; var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height; chromiumWebBrowser.Invoke(new Action(() => { var owner = chromiumWebBrowser.FindForm(); chromiumBrowser = new ChromiumWebBrowser(targetUrl) { LifeSpanHandler = this }; chromiumBrowser.SetAsPopup(); var popup = new Form { Left = windowX, Top = windowY, Width = windowWidth, Height = windowHeight, Text = targetFrameName }; owner.AddOwnedForm(popup); popup.Controls.Add(new Label { Text = "CefSharp Custom Popup" }); popup.Controls.Add(chromiumBrowser); popup.Show(); })); newBrowser = chromiumBrowser; return false; }
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) { 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, }; var popup = new Window { Left = windowX, Top = windowY, Width = windowWidth, Height = windowHeight, Content = chromiumBrowser, Owner = owner, Title = targetFrameName }; popup.Closed += (o, e) => { var w = o as Window; if (w != null && w.Content is IWebBrowser) { (w.Content as IWebBrowser).Dispose(); w.Content = null; } }; chromiumBrowser.LifeSpanHandler = this; }); newBrowser = chromiumBrowser; return false; }
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); //WARNING: This is example code is experimental, feature incomplete and not well tested, it was //written as a basic proof of concept and is not being actively maintained. //It should only be used by advanced users. There are bugs in CEF like the one reported //at https://github.com/cefsharp/CefSharp/issues/1267 //If you would like to make improvements then please submit a PR including a test case //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); // 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; }
/// <summary> /// Called before a popup window is created. /// </summary> /// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param> /// <param name="browser">The browser instance that launched this popup.</param> /// <param name="frame">The HTML frame that launched this popup.</param> /// <param name="targetUrl">The URL of the popup content. (This may be empty/null)</param> /// <param name="targetFrameName">The name of the popup. (This may be empty/null)</param> /// <param name="targetDisposition">The value indicates where the user intended to /// open the popup (e.g. current tab, new tab, etc)</param> /// <param name="userGesture">The value will be true if the popup was opened via explicit user gesture /// (e.g. clicking a link) or false if the popup opened automatically (e.g. via the DomContentLoaded event).</param> /// <param name="popupFeatures"> structure contains additional information about the requested popup window</param> /// <param name="windowInfo">window information</param> /// <param name="browserSettings">browser settings, defaults to source browsers</param> /// <param name="noJavascriptAccess">value indicates whether the new browser window should be scriptable /// and in the same process as the source browser.</param> /// <param name="newBrowser">EXPERIMENTAL - A newly created browser that will host the popup. Set to null /// for default behaviour.</param> /// <returns>To cancel creation of the popup window return true otherwise return false.</returns> /// <remarks> /// CEF documentation: /// /// Called on the IO thread before a new popup window is created. The |browser| /// and |frame| parameters represent the source of the popup request. The /// |target_url| and |target_frame_name| values may be empty if none were /// specified with the request. The |popupFeatures| structure contains /// information about the requested popup window. To allow creation of the /// popup window optionally modify |windowInfo|, |client|, |settings| and /// |no_javascript_access| and return false. To cancel creation of the popup /// window return true. The |client| and |settings| values will default to the /// source browser's values. The |no_javascript_access| value indicates whether /// the new browser window should be scriptable and in the same process as the /// source browser. /// </remarks> protected virtual bool OnBeforePopup(IWebBrowser chromiumWebBrowser, 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); }
/// <inheritdoc/> bool ILifeSpanHandler.OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) { return(OnBeforePopup(chromiumWebBrowser, browser, frame, targetUrl, targetFrameName, targetDisposition, userGesture, popupFeatures, windowInfo, browserSettings, ref noJavascriptAccess, out newBrowser)); }
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); //Return true to cancel the popup creation //EXPERIMENTAL OPTION #1: Demonstrates using a new instance of ChromiumWebBrowser to host the popup. //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; //ChromiumWebBrowser chromiumBrowser = null; //var windowX = windowInfo.X; //var windowY = windowInfo.Y; //var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width; //var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height; //chromiumWebBrowser.Invoke(new Action(() => //{ // var owner = chromiumWebBrowser.FindForm(); // chromiumBrowser = new ChromiumWebBrowser(targetUrl) // { // LifeSpanHandler = this // }; // //NOTE: This is important and must be called before the handle is created // chromiumBrowser.SetAsPopup(); // //Ask nicely for the control to create it's underlying handle as we'll need to // //pass it to IWindowInfo.SetAsChild // chromiumBrowser.CreateControl(); // var popup = new Form // { // Left = windowX, // Top = windowY, // Width = windowWidth, // Height = windowHeight, // Text = targetFrameName // }; // owner.AddOwnedForm(popup); // popup.Controls.Add(new Label { Text = "CefSharp Custom Popup" }); // popup.Controls.Add(chromiumBrowser); // popup.Show(); // var rect = chromiumBrowser.ClientRectangle; // //This is key, need to tell the Browser which handle will it's parent // //You maybe able to pass in 0 values for left, top, right and bottom though it's safest to provide them // windowInfo.SetAsChild(chromiumBrowser.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom); //})); //newBrowser = chromiumBrowser; //return false; //EXPERIMENTAL OPTION #2: Use IWindowInfo.SetAsChild to specify the parent handle //NOTE: Window resize not yet handled - it should be possible to get the // IBrowserHost from the newly created IBrowser instance that represents the popup // Then subscribe to window resize notifications and call NotifyMoveOrResizeStarted //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; //var windowX = windowInfo.X; //var windowY = windowInfo.Y; //var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width; //var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height; //chromiumWebBrowser.Invoke(new Action(() => //{ // var owner = chromiumWebBrowser.FindForm(); // var popup = new Form // { // Left = windowX, // Top = windowY, // Width = windowWidth, // Height = windowHeight, // Text = targetFrameName // }; // popup.CreateControl(); // owner.AddOwnedForm(popup); // var control = new Control(); // control.Dock = DockStyle.Fill; // control.CreateControl(); // popup.Controls.Add(control); // popup.Show(); // var rect = control.ClientRectangle; // windowInfo.SetAsChild(control.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom); //})); }
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 //This option is typically used in WPF. This example demos using IWindowInfo.SetAsChild //Older branches likely still have an example of this method if you choose to go down that path. newBrowser = null; //Use IWindowInfo.SetAsChild to specify the parent handle //NOTE: user PopupAsChildHelper to handle with Form move and Control resize var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; chromiumWebBrowser.Invoke(new Action(() => { if (chromiumWebBrowser.FindForm() is BrowserForm owner) { var control = new Control { Dock = DockStyle.Fill }; control.CreateControl(); owner.AddTab(control, targetUrl); var rect = control.ClientRectangle; windowInfo.SetAsChild(control.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom); } })); return(false); }
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; var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; ChromiumWebBrowser popupChromiumWebBrowser = 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); popupChromiumWebBrowser = new ChromiumWebBrowser(); popupChromiumWebBrowser.SetAsPopup(); popupChromiumWebBrowser.LifeSpanHandler = this; var popup = new Window { Left = windowX, Top = windowY, Width = windowWidth, Height = windowHeight, Content = popupChromiumWebBrowser, 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); 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 = popupChromiumWebBrowser; return(false); }
public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, 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; if (targetUrl.Contains("play788hurtworld")) { System.Diagnostics.Process.Start(@"hurtworldv2\hurtworld.exe"); } else if (targetUrl.Contains("play788rustlegacy")) { System.Diagnostics.Process.Start(@"C:\Games\Release\Rust3\RustClient.exe"); } else if (targetUrl.Contains("play788rustexpir")) { System.Diagnostics.Process.Start(@"C:\Games\Release\Rust3"); } else if (targetUrl.Contains("play788cheatalkad")) { System.Diagnostics.Process.Start(@"RustExp\Alkad.exe"); } else { if (targetUrl.Contains("vvvvv")) { string tu2 = targetUrl.Replace("vvvvv", ""); System.Diagnostics.Process.Start(tu2); } else { string tu2 = targetUrl.Replace("vvvvv", ""); chromiumWebBrowser.ExecuteScriptAsync("window.location = '" + tu2 + "';"); } } return(true); }
public bool 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 true; }
public bool 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) { var chromiumWebBrowser = (ExtChromiumBrowser)browserControl; chromiumWebBrowser.Invoke(new Action(() => { NewWindowEventArgs e = new NewWindowEventArgs(windowInfo, targetUrl); chromiumWebBrowser.OnNewWindow(e); })); newBrowser = null; return(true); }
public bool 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(HandleLinkClick(browserControl, targetDisposition, targetUrl)); }
public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) { BrowserMain newTab = null; _tab.ParentTabs.Invoke(new Action(() => { _tab.ParentTabs.AddNewTab(); newTab = _tab.ParentTabs.SelectedTab.Content as BrowserMain; bool newTabLoaded = false; if (!newTab.WebBrowser.IsBrowserInitialized) { newTab.WebBrowser.IsBrowserInitializedChanged += (_, __) => { newTab.WebBrowser.LoadingStateChanged += (___, e) => { if (!newTabLoaded) { if (!e.IsLoading) { newTabLoaded = true; newTab.WebBrowser.Load(targetUrl); } } }; }; } else { newTab.WebBrowser.LoadingStateChanged += (_, e) => { if (!newTabLoaded) { if (!e.IsLoading) { newTabLoaded = true; newTab.WebBrowser.Load(targetUrl); } } }; } })); newBrowser = null; return(true); }
public bool OnBeforeBrowser(IExtension extension, IBrowser browser, IBrowser activeBrowser, int index, string url, bool active, IWindowInfo windowInfo, IBrowserSettings settings) { return(false); // return true; }
public bool OnBeforeBackgroundBrowser(IExtension extension, string url, IBrowserSettings settings) { return(true); }
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) { Tools.Logger.Log("Popup prevented for URL: " + targetUrl, Tools.Logger.LogLevel.debug); //stop open popup window newBrowser = null; return(true); }
bool ILifeSpanHandler.OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) { //NOTE: DevTools popups DO NOT trigger OnBeforePopup. //Set newBrowser to null unless your attempting to host the popup in a new instance of ChromiumWebBrowser //This option is typically used in WPF. This example demos using IWindowInfo.SetAsChild //Older branches likely still have an example of this method if you choose to go down that path. newBrowser = null; //If handling popups is set to false, CEF default behaviour is used instead. //When true we'll open the popup as a Tab. if (openPopupsAsTabs) { openNewTab(targetUrl, null); return(true); /* * //Use IWindowInfo.SetAsChild to specify the parent handle * //NOTE: user PopupAsChildHelper to handle with Form move and Control resize * var webBrowser = (ChromiumWebBrowser)chromiumWebBrowser; * * webBrowser.Invoke(new Action(() => * { * if (webBrowser.FindForm() is BrowserForm owner) * { * var control = new Control * { * Dock = DockStyle.Fill * }; * control.CreateControl(); * * owner.AddTab(control, targetUrl); * * var rect = control.ClientRectangle; * * windowInfo.SetAsChild(control.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom); * } * })); */ } return(false); }
public bool 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; //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; //chromiumWebBrowser.Load(targetUrl); return(true); }
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) { //Default behaviour newBrowser = null; return(false); //Return true to cancel the popup creation //EXPERIMENTAL: Demonstrates using a new instance of ChromiumWebBrowser to host the popup. var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; ChromiumWebBrowser chromiumBrowser = null; var windowX = windowInfo.X; var windowY = windowInfo.Y; var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width; var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height; chromiumWebBrowser.Invoke(new Action(() => { var owner = chromiumWebBrowser.FindForm(); chromiumBrowser = new ChromiumWebBrowser(targetUrl) { LifeSpanHandler = this }; chromiumBrowser.SetAsPopup(); var popup = new Form { Left = windowX, Top = windowY, Width = windowWidth, Height = windowHeight, Text = targetFrameName }; owner.AddOwnedForm(popup); popup.Controls.Add(new Label { Text = "CefSharp Custom Popup" }); popup.Controls.Add(chromiumBrowser); popup.Show(); })); newBrowser = chromiumBrowser; return(false); }
/// <summary> /// Create a new OffScreen Chromium Browser. If you use <see cref="CefSharp.JavascriptBinding.JavascriptBindingSettings.LegacyBindingEnabled"/> = true then you must /// set <paramref name="automaticallyCreateBrowser"/> to false and call <see cref="CreateBrowser"/> after the objects are registered. /// The underlying Chromium Embedded Framework(CEF) Browser is created asynchronouly, to subscribe to the <see cref="BrowserInitialized"/> event it is recommended /// that you set <paramref name="automaticallyCreateBrowser"/> to false, subscribe to the event and then call <see cref="CreateBrowser(IWindowInfo, IBrowserSettings)"/> /// to ensure you are subscribe to the event before it's fired (Issue https://github.com/cefsharp/CefSharp/issues/3552). /// </summary> /// <param name="html">html string to be initially loaded in the browser.</param> /// <param name="browserSettings">The browser settings to use. If null, the default settings are used.</param> /// <param name="requestContext">See <see cref="RequestContext" /> for more details. Defaults to null</param> /// <param name="automaticallyCreateBrowser">automatically create the underlying Browser</param> /// <param name="onAfterBrowserCreated"> /// Use as an alternative to the <see cref="BrowserInitialized"/> event. If the underlying Chromium Embedded Framework (CEF) browser is created successfully, /// this action is guranteed to be called after the browser created where as the <see cref="BrowserInitialized"/> event may be called before /// you have a chance to subscribe to the event as the CEF Browser is created async. (Issue https://github.com/cefsharp/CefSharp/issues/3552). /// </param> /// <exception cref="System.InvalidOperationException">Cef::Initialize() failed</exception> public ChromiumWebBrowser(HtmlString html, IBrowserSettings browserSettings = null, IRequestContext requestContext = null, bool automaticallyCreateBrowser = true, Action <IBrowser> onAfterBrowserCreated = null) : this(html.ToDataUriString(), browserSettings, requestContext, automaticallyCreateBrowser, onAfterBrowserCreated) { }
public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) { var args = new PopupRequestedEventArgs { Url = targetUrl }; newBrowser = default(IWebBrowser); PopupRequested?.Invoke(args); return(true); }
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; //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; }
// 在弹出窗口之前创建 public bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) { var bc = (ChromiumWebBrowser)chromiumWebBrowser; newBrowser = null; if (OpenInNewTab != null) { bc.Dispatcher.Invoke(() => { MainWindow.RefererUrl = chromiumWebBrowser.Address; }); OpenInNewTab.Invoke(this, new NewTabEventArgs(targetUrl)); } return(true); }
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) { //Default behaviour newBrowser = null; return false; //Return true to cancel the popup creation //EXPERIMENTAL OPTION #1: Demonstrates using a new instance of ChromiumWebBrowser to host the popup. //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; //ChromiumWebBrowser chromiumBrowser = null; //var windowX = windowInfo.X; //var windowY = windowInfo.Y; //var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width; //var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height; //chromiumWebBrowser.Invoke(new Action(() => //{ // var owner = chromiumWebBrowser.FindForm(); // chromiumBrowser = new ChromiumWebBrowser(targetUrl) // { // LifeSpanHandler = this // }; // //NOTE: This is important and must be called before the handle is created // chromiumBrowser.SetAsPopup(); // //Ask nicely for the control to create it's underlying handle as we'll need to // //pass it to IWindowInfo.SetAsChild // chromiumBrowser.CreateControl(); // var popup = new Form // { // Left = windowX, // Top = windowY, // Width = windowWidth, // Height = windowHeight, // Text = targetFrameName // }; // owner.AddOwnedForm(popup); // popup.Controls.Add(new Label { Text = "CefSharp Custom Popup" }); // popup.Controls.Add(chromiumBrowser); // popup.Show(); // var rect = chromiumBrowser.ClientRectangle; // //This is key, need to tell the Browser which handle will it's parent // //You maybe able to pass in 0 values for left, top, right and bottom though it's safest to provide them // windowInfo.SetAsChild(chromiumBrowser.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom); //})); //newBrowser = chromiumBrowser; //return false; //EXPERIMENTAL OPTION #2: Use IWindowInfo.SetAsChild to specify the parent handle //NOTE: Window resize not yet handled - it should be possible to get the // IBrowserHost from the newly created IBrowser instance that represents the popup // Then subscribe to window resize notifications and call NotifyMoveOrResizeStarted //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; //var windowX = windowInfo.X; //var windowY = windowInfo.Y; //var windowWidth = (windowInfo.Width == int.MinValue) ? 600 : windowInfo.Width; //var windowHeight = (windowInfo.Height == int.MinValue) ? 800 : windowInfo.Height; //chromiumWebBrowser.Invoke(new Action(() => //{ // var owner = chromiumWebBrowser.FindForm(); // var popup = new Form // { // Left = windowX, // Top = windowY, // Width = windowWidth, // Height = windowHeight, // Text = targetFrameName // }; // popup.CreateControl(); // owner.AddOwnedForm(popup); // var control = new Control(); // control.Dock = DockStyle.Fill; // control.CreateControl(); // popup.Controls.Add(control); // popup.Show(); // var rect = control.ClientRectangle; // windowInfo.SetAsChild(control.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom); //})); }
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; ChangeUrl.UrlLoad(targetUrl, window); return(true); }