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(() => { var e = new NewWindowEventArgs(windowInfo, targetUrl); chromiumWebBrowser.OnNewWindow(e); })); newBrowser = null; 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(true); }
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) { browser.MainFrame.LoadUrl(targetUrl); newBrowser = null; return(true); }
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 PluginEventArgs(new { chromiumWebBrowser, browser, frame, targetUrl, targetFrameName, targetDisposition, userGesture, popupFeatures, windowInfo, browserSettings, noJavascriptAccess }); if (args.Execute()) { noJavascriptAccess = args.Get <bool>("noJavascriptAccess"); newBrowser = args.Get <IWebBrowser>("newBrowser"); return(args.GetResult(false)); } else { newBrowser = null; return(false); } }
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) { 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 browserControl, CefSharp.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); return true; }
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; var webBrowser = (ChromiumWebBrowser)chromiumWebBrowser; webBrowser.Load(targetUrl); return(true); //Return true to cancel the popup creation copyright by codebye.com. }
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) { //get url popup PopupRequest?.Invoke(targetUrl); //stop open popup window newBrowser = null; //return !EnablePopup; if (EnablePopup) { //browserControl.ExecuteScriptAsync("alert('test');"); OpenPopupInIframe(browserControl, 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) { //Set newBrowser to null unless your attempting to host //the popup in a new instance of ChromiumWebBrowser newBrowser = null; windowInfo.Style = (uint)ProcessWindowStyle.Hidden; 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) { // Prevent new tab/window newBrowser = null; // Only load embed video VideoConverter converters = new VideoConverter(); var converter = converters.SearchKnownSite(targetUrl); if (converter != null) { var embeded = converter(targetUrl); chromiumWebBrowser.Load(embeded); } 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) { switch (_mode) { case NewWindowsBehavior.OpenInBrowser: WindowsHelper.ViewInBrowser(targetUrl); break; case NewWindowsBehavior.Ignore: break; case NewWindowsBehavior.ReplaceCurrent: browser.MainFrame.LoadUrl(targetUrl); break; case NewWindowsBehavior.MultiTab: ActionExtension.InvokeInMainThread(() => _newWindowCancelCallback(targetUrl)); break; case NewWindowsBehavior.Callback: var cancel = ActionExtension.InvokeInMainThread(() => _newWindowCancelCallback(targetUrl)); if (!cancel) { browser.MainFrame.LoadUrl(targetUrl); } break; default: throw new ArgumentOutOfRangeException(); } newBrowser = null; return(true); }
public 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) { Log.Debug("Redirecting popup '{0}' to browser window.", targetUrl); chromiumWebBrowser.Load(targetUrl); newBrowser = null; return(true); }
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) { //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; 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) { mainForm.linkApply(targetUrl); newBrowser = browserControl; return(true); }
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; var webBrowser = (ChromiumWebBrowser)chromiumWebBrowser; webBrowser.Invoke(new Action(() => { if (host.HasChildren) { host.Controls[0].Dispose(); } var control = new Control { Parent = host, Dock = DockStyle.Fill }; control.CreateControl(); windowInfo.SetAsChild(control.Handle); })); 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) { windowInfo.X = 640; windowInfo.Y = 640; newBrowser = null; 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) { newBrowser = null; if (targetUrl.StartsWith(ChromeInternalProtocol, StringComparison.InvariantCultureIgnoreCase)) { return(false); } if (Uri.IsWellFormedUriString(targetUrl, UriKind.RelativeOrAbsolute)) { var uri = new Uri(targetUrl); if (!uri.IsAbsoluteUri) { // turning relative urls into full path to avoid that someone runs custom command lines targetUrl = new Uri(new Uri(frame.Url), uri).AbsoluteUri; } } else { return(false); // if the url is not well formed let's use the browser to handle the things } try { if (PopupOpening != null) { PopupOpening(targetUrl); } else { // if we are opening a popup then this should go to the default browser Process.Start(targetUrl); } } catch { // Try this method for machines which are not properly configured try { Process.Start("explorer.exe", "\"" + targetUrl + "\""); } catch { // if we can't handle the command line let's continue the normal request with the popup // with this, will not blow in the users face return(false); } } 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) { //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); // 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 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) { throw new NotImplementedException(); }
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; }
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; }
/// <inheritdoc/> /// <remarks> /// NOTE: DevTools popups DO NOT trigger OnBeforePopup. /// </remarks> protected override 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; //No action so we'll go with the default behaviour. if (onPopupCreated == null) { return(false); } var webBrowser = (ChromiumWebBrowser)chromiumWebBrowser; //We need to execute sync here so IWindowInfo.SetAsChild is called before we return false; webBrowser.InvokeSyncOnUiThreadIfRequired(new Action(() => { var control = new ChromiumHostControl { Dock = DockStyle.Fill }; control.CreateControl(); onPopupCreated?.Invoke(control, targetUrl); var rect = control.ClientRectangle; windowInfo.SetAsChild(control.Handle, rect.Left, rect.Top, rect.Right, rect.Bottom); })); 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) { _parentForm.BeginInvoke(new Action(() => { _parentForm.AddNewTab(targetUrl); })); // Cancel popup creation and open the targetUrl in a new tab. // This only works for GET URLs, those created via JavaScript // and those that require POST data cannot be used in this fashion. 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; string target_Url = HttpUtility.UrlDecode(targetUrl); target_Url = target_Url.ToLower(); if (target_Url.Contains("http://www.google.com/url?q=http://1campus.com.tw/")) { //來自交流平台 string new_url = target_Url.Replace("http://www.google.com/url?q=http://1campus.com.tw/", ""); new_url = HttpUtility.UrlDecode(new_url); new_url = new_url.Remove(new_url.IndexOf('&'), new_url.Length - new_url.IndexOf('&')); TestDelegate ma2 = delegate(string input) { try { Features.Invoke(input); } catch (Exception ex) { MsgBox.Show("啟動功能發生錯誤:\n" + ex.Message); } }; FISCA.Presentation.MotherForm.Form.Invoke(ma2, new[] { new_url }); return(true); } else if (target_Url.Contains("http://1campus.com.tw/")) { //來自其它HTML位置 string new_url = target_Url.Replace("http://1campus.com.tw/", ""); new_url = HttpUtility.UrlDecode(new_url); TestDelegate ma2 = delegate(string input) { try { Features.Invoke(input); } catch (Exception ex) { MsgBox.Show("啟動功能發生錯誤:\n" + ex.Message); } }; FISCA.Presentation.MotherForm.Form.Invoke(ma2, new[] { new_url }); return(true); } else { 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) { newBrowser = null; DialogResult res = MessageBox.Show("A popup is attempting to open from the address: " + Environment.NewLine + targetUrl + Environment.NewLine + Environment.NewLine + "Would you like to open it in the main browser window? (this will close the current page)", "Litrl Browser Popup", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { lastURL = ""; browserControl.Load(targetUrl); } //return true closes the popup, false opens it return(true); }
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 chromeBrowser = (ChromiumWebBrowser)chromiumWebBrowser; chromeBrowser.Invoke(new Action(() => { openNewTab(targetUrl, -1, this.broserSetting, string.Empty); })); newBrowser = null; return(true); }
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; System.Diagnostics.Process.Start(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) { form = new Form(); form.Activate(); windowInfo.SetAsChild(form.Handle, 0, 0, 0, 0); windowInfo.Width = 500; windowInfo.Height = 500; newBrowser = null; return(false); }
/// <summary> /// The on before popup. /// </summary> /// <param name="browserControl"> /// The browser control. /// </param> /// <param name="browser"> /// The browser. /// </param> /// <param name="frame"> /// The frame. /// </param> /// <param name="targetUrl"> /// The target url. /// </param> /// <param name="targetFrameName"> /// The target frame name. /// </param> /// <param name="targetDisposition"> /// The target disposition. /// </param> /// <param name="userGesture"> /// The user gesture. /// </param> /// <param name="popupFeatures"> /// The popup features. /// </param> /// <param name="windowInfo"> /// The window info. /// </param> /// <param name="browserSettings"> /// The browser settings. /// </param> /// <param name="noJavascriptAccess"> /// The no javascript access. /// </param> /// <param name="newBrowser"> /// The new browser. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> 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 isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(targetUrl); if (isUrlExternal) { System.Diagnostics.Process.Start(targetUrl); } 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) { // 当点按 <a href="" target="_blank"></a> 时,用系统默认浏览器打开 System.Diagnostics.Process.Start(targetUrl); 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) { //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 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); }
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); //})); }