/// <summary> /// Create a standard web browser window /// </summary> /// <param name="url">Url to be opened in the browser</param> /// <param name="browserId">Browser identificator</param> /// <param name="title">Title to be displayed in the browser header</param> /// <returns></returns> private ISmartBrowserWindow CreateWebBrowserWindow(Uri url, string browserId, string title) { if (string.IsNullOrEmpty(browserId)) { browserId = "Browser"; } var browserWindow = UIHelper.Instance.CreateNewSmartBrowserWindow(browserId); browserWindow.WindowStyle = new WindowStyle(); browserWindow.Title = title; browserWindow.NoClose = false; browserWindow.Width = 1350; browserWindow.Height = 750; browserWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner; browserWindow.Owner = UIHelper.Instance.GetOwnerWindow(UIHelper.Instance.CurrentTEControl.SmartTerminalWindow); var wb = browserWindow.Content as SmartBrowserControl; // CefSharpSettings.LegacyJavascriptBindingEnabled = true; // change this to new binding technique https://github.com/cefsharp/CefSharp/issues/2246 wb = new SmartBrowserControl(); // set background to white otherwise it will inherit SP background color like bluish. var converter = new System.Windows.Media.BrushConverter(); var brush = (Brush)converter.ConvertFromString("#FFFFFFFF"); wb.Background = brush; try { // legacy //wb.RegisterJsObject("spHelper", this); // new wb.WebBrowserControl.JavascriptObjectRepository.Register("spHelper", this, true); } catch (Exception ex) { } wb.NavigateTo(url); browserWindow.Content = wb; browserWindow.Closed += delegate { wb.Close(); }; string windowTitle = GetWindowTitle(); wb.WebBrowserControl.FrameLoadEnd += (sender, eventArgs) => { var host = eventArgs.Browser.GetHost(); host.ShowDevTools(); wb.WebBrowserControl.Dispatcher.BeginInvoke( DispatcherPriority.Normal, new Action(() => { browserWindow.Title = wb.WebBrowserControl.Title ?? windowTitle; })); }; return(browserWindow); }
/// <summary> /// Create a standard web browser window /// </summary> /// <param name="url">Url to be opened in the browser</param> /// <param name="browserId">Browser identificator</param> /// <param name="title">Title to be displayed in the browser header</param> /// <returns></returns> private ISmartBrowserWindow CreateWebBrowserWindow(Uri url, string browserId, string title) { if (string.IsNullOrEmpty(browserId)) { browserId = "Browser"; } var browserWindow = UIHelper.Instance.CreateNewSmartBrowserWindow(browserId); browserWindow.WindowStyle = new WindowStyle(); browserWindow.Title = title; browserWindow.NoClose = false; browserWindow.Width = 1350; browserWindow.Height = 750; browserWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner; browserWindow.Owner = UIHelper.Instance.GetOwnerWindow(UIHelper.Instance.CurrentTEControl.SmartTerminalWindow); var wb = browserWindow.Content as SmartBrowserControl; if (wb == null) { wb = new SmartBrowserControl(); try { wb.WebBrowserControl.RegisterJsObject("spHelper", this); } catch (Exception ex) { } wb.NavigateTo(url); browserWindow.Content = wb; browserWindow.Closed += delegate { wb.Close(); }; wb.WebBrowserControl.FrameLoadEnd += delegate { if (string.IsNullOrEmpty(title)) { wb.WebBrowserControl.Dispatcher.BeginInvoke( DispatcherPriority.Normal, new Action(() => { browserWindow.Title = wb.WebBrowserControl.Title; })); } }; } else { wb.NavigateTo(url); } return(browserWindow); }