/// <summary> /// Create a new OffScreen Chromium Browser /// </summary> /// <param name="address">Initial address (url) to load</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> /// <exception cref="System.InvalidOperationException">Cef::Initialize() failed</exception> public ChromiumWebBrowser(string address = "", BrowserSettings browserSettings = null, RequestContext requestContext = null, bool automaticallyCreateBrowser = true) { if (!Cef.IsInitialized && !Cef.Initialize()) { throw new InvalidOperationException("Cef::Initialize() failed"); } BitmapFactory = new BitmapFactory(BitmapLock); ResourceHandlerFactory = new DefaultResourceHandlerFactory(); BrowserSettings = browserSettings ?? new BrowserSettings(); RequestContext = requestContext; Cef.AddDisposable(this); Address = address; managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true); if (automaticallyCreateBrowser) { CreateBrowser(IntPtr.Zero); } popupPosition = new Point(); popupSize = new Size(); }
private void InitializeFieldsAndCefIfRequired() { if (!initialized) { if (!Cef.IsInitialized && !Cef.Initialize(new CefSettings())) { throw new InvalidOperationException("Cef::Initialize() failed"); } Cef.AddDisposable(this); if (FocusHandler == null) { //If the WinForms UI thread and the CEF UI thread are one in the same //then we don't need the FocusHandler, it's only required when using //MultiThreadedMessageLoop (the default) if (!Cef.CurrentlyOnThread(CefThreadIds.TID_UI)) { FocusHandler = new DefaultFocusHandler(); } } if (browserSettings == null) { browserSettings = new BrowserSettings(frameworkCreated: true); } managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, false); initialized = true; } }
/// <summary> /// Required for designer support - this method cannot be inlined as the designer /// will attempt to load libcef.dll and will subsiquently throw an exception. /// TODO: Still not happy with this method name, need something better /// </summary> private void InitializeFieldsAndCefIfRequired() { if (!_initialized) { if (!Cef.IsInitialized && !Cef.Initialize(_settings)) { throw new InvalidOperationException("Cef::Initialize() failed"); } Cef.AddDisposable(this); if (ResourceRequestHandlerFactory == null) { ResourceRequestHandlerFactory = new ResourceRequestHandlerFactory(); } if (_browserSettings == null) { _browserSettings = new BrowserSettings(); } _managedCefBrowserAdapter = ManagedCefBrowserAdapter.Create(this, false); _initialized = true; } }
/// <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="address">Initial address (url) to load</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(string address = "", IBrowserSettings browserSettings = null, IRequestContext requestContext = null, bool automaticallyCreateBrowser = true, Action <IBrowser> onAfterBrowserCreated = null) { if (!Cef.IsInitialized) { var settings = new CefSettings(); if (!Cef.Initialize(settings)) { throw new InvalidOperationException(CefInitializeFailedErrorMessage); } } RequestContext = requestContext; Cef.AddDisposable(this); Address = address; onAfterBrowserCreatedDelegate = onAfterBrowserCreated; managedCefBrowserAdapter = ManagedCefBrowserAdapter.Create(this, true); if (automaticallyCreateBrowser) { CreateBrowser(null, browserSettings); } RenderHandler = new DefaultRenderHandler(this); }
/// <summary> /// Create a new OffScreen Chromium Browser. If you use <see cref="CefSharpSettings.LegacyJavascriptBindingEnabled"/> = true then you must /// set <paramref name="automaticallyCreateBrowser"/> to false and call <see cref="CreateBrowser"/> after the objects are registered. /// </summary> /// <param name="address">Initial address (url) to load</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> /// <exception cref="System.InvalidOperationException">Cef::Initialize() failed</exception> public ChromiumWebBrowser(string address = "", BrowserSettings browserSettings = null, RequestContext requestContext = null, bool automaticallyCreateBrowser = true) { if (!Cef.IsInitialized) { var settings = new CefSettings(); if (!Cef.Initialize(settings)) { throw new InvalidOperationException("Cef::Initialize() failed"); } } ResourceHandlerFactory = new DefaultResourceHandlerFactory(); RequestContext = requestContext; Cef.AddDisposable(this); Address = address; managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true); if (automaticallyCreateBrowser) { CreateBrowser(null, browserSettings); } RenderHandler = new DefaultRenderHandler(this); }
protected virtual void Dispose(bool isdisposing) { // No longer reference event listeners: ConsoleMessage = null; FrameLoadStart = null; FrameLoadEnd = null; LoadError = null; LoadingStateChanged = null; Rendering = null; // No longer reference handlers: this.SetHandlersToNull(); if (isdisposing) { if (BrowserSettings != null) { BrowserSettings.Dispose(); BrowserSettings = null; } PresentationSource.RemoveSourceChangedHandler(this, PresentationSourceChangedHandler); // Release internal event listeners: Loaded -= OnLoaded; GotKeyboardFocus -= OnGotKeyboardFocus; LostKeyboardFocus -= OnLostKeyboardFocus; // Release internal event listeners for Drag Drop events: DragEnter -= OnDragEnter; DragOver -= OnDragOver; DragLeave -= OnDragLeave; Drop -= OnDrop; IsVisibleChanged -= OnIsVisibleChanged; if (tooltipTimer != null) { tooltipTimer.Tick -= OnTooltipTimerTick; } if (CleanupElement != null) { CleanupElement.Unloaded -= OnCleanupElementUnloaded; } foreach (var disposable in disposables) { disposable.Dispose(); } disposables.Clear(); UiThreadRunAsync(() => WebBrowser = null); } Cef.RemoveDisposable(this); RemoveSourceHook(); managedCefBrowserAdapter = null; }
protected virtual void Dispose(bool isdisposing) { ResourceHandler = null; Loaded -= OnLoaded; Unloaded -= OnUnloaded; GotKeyboardFocus -= OnGotKeyboardFocus; LostKeyboardFocus -= OnLostKeyboardFocus; IsVisibleChanged -= OnIsVisibleChanged; Cef.RemoveDisposable(this); RemoveSourceHook(); foreach (var disposable in disposables) { disposable.Dispose(); } disposables.Clear(); UiThreadRunAsync(() => WebBrowser = null); managedCefBrowserAdapter = null; ConsoleMessage = null; FrameLoadStart = null; FrameLoadEnd = null; LoadError = null; }
/// <summary> /// Create a new offscreen Chromium with the initial URL of "about:blank". /// </summary> /// <param name="browserSettings">The browser settings to use. If null, the default settings are used.</param> public ChromiumWebBrowser(BrowserSettings browserSettings = null) { Cef.AddDisposable(this); managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this); managedCefBrowserAdapter.CreateOffscreenBrowser(browserSettings ?? new BrowserSettings()); }
private void InitializeFieldsAndCefIfRequired() { if (!initialized) { if (!Cef.IsInitialized && !Cef.Initialize()) { throw new InvalidOperationException("Cef::Initialize() failed"); } Cef.AddDisposable(this); if (FocusHandler == null) { FocusHandler = new DefaultFocusHandler(this); } if (ResourceHandlerFactory == null) { ResourceHandlerFactory = new DefaultResourceHandlerFactory(); } if (BrowserSettings == null) { BrowserSettings = new BrowserSettings(); } managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, false); initialized = true; } }
/// <summary> /// Create a new OffScreen Chromium Browser /// </summary> /// <param name="address">Initial address (url) to load</param> /// <param name="browserSettings">The browser settings to use. If null, the default settings are used.</param> public ChromiumWebBrowser(string address, BrowserSettings browserSettings = null) { ResourceHandler = new DefaultResourceHandler(); Cef.AddDisposable(this); Address = address; managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true); managedCefBrowserAdapter.CreateOffscreenBrowser(IntPtr.Zero, browserSettings ?? new BrowserSettings(), address); }
public ChromiumWebBrowser() { if (!Cef.IsInitialized && !Cef.Initialize()) { throw new InvalidOperationException("Cef::Initialize() failed"); } Cef.AddDisposable(this); Focusable = true; FocusVisualStyle = null; IsTabStop = true; Dispatcher.BeginInvoke((Action)(() => WebBrowser = this)); Loaded += OnLoaded; GotKeyboardFocus += OnGotKeyboardFocus; LostKeyboardFocus += OnLostKeyboardFocus; IsVisibleChanged += OnIsVisibleChanged; ToolTip = toolTip = new ToolTip(); toolTip.StaysOpen = true; toolTip.Visibility = Visibility.Collapsed; toolTip.Closed += OnTooltipClosed; BackCommand = new DelegateCommand(Back, () => CanGoBack); ForwardCommand = new DelegateCommand(Forward, () => CanGoForward); ReloadCommand = new DelegateCommand(Reload, () => CanReload); PrintCommand = new DelegateCommand(Print); ZoomInCommand = new DelegateCommand(ZoomIn); ZoomOutCommand = new DelegateCommand(ZoomOut); ZoomResetCommand = new DelegateCommand(ZoomReset); ViewSourceCommand = new DelegateCommand(ViewSource); CleanupCommand = new DelegateCommand(Dispose); StopCommand = new DelegateCommand(Stop); CutCommand = new DelegateCommand(Cut); CopyCommand = new DelegateCommand(Copy); PasteCommand = new DelegateCommand(Paste); SelectAllCommand = new DelegateCommand(SelectAll); UndoCommand = new DelegateCommand(Undo); RedoCommand = new DelegateCommand(Redo); managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true); disposables.Add(managedCefBrowserAdapter); disposables.Add(new DisposableEventWrapper(this, ActualHeightProperty, OnActualSizeChanged)); disposables.Add(new DisposableEventWrapper(this, ActualWidthProperty, OnActualSizeChanged)); ResourceHandler = new DefaultResourceHandler(); BrowserSettings = new BrowserSettings(); PresentationSource.AddSourceChangedHandler(this, PresentationSourceChangedHandler); }
protected void Initialize() { Application.ApplicationExit += OnApplicationExit; Cef.AddDisposable(this); // Dock = DockStyle.Fill; FocusHandler = new DefaultFocusHandler(this); ResourceHandler = new DefaultResourceHandler(); managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this); }
protected override void Dispose(bool disposing) { if (disposing) { if (managedCefBrowserAdapter != null) { managedCefBrowserAdapter.Close(); managedCefBrowserAdapter.Dispose(); managedCefBrowserAdapter = null; } } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { Cef.RemoveDisposable(this); if (disposing) { if (managedCefBrowserAdapter != null) { managedCefBrowserAdapter.Dispose(); managedCefBrowserAdapter = null; } } base.Dispose(disposing); }
/// <summary> /// Create a new OffScreen Chromium Browser /// </summary> /// <param name="address">Initial address (url) to load</param> /// <param name="browserSettings">The browser settings to use. If null, the default settings are used.</param> public ChromiumWebBrowser(string address, BrowserSettings browserSettings = null) { if (!Cef.IsInitialized && !Cef.Initialize()) { throw new InvalidOperationException("Cef::Initialize() failed"); } ResourceHandler = new DefaultResourceHandler(); Cef.AddDisposable(this); Address = address; managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true); managedCefBrowserAdapter.CreateOffscreenBrowser(IntPtr.Zero, browserSettings ?? new BrowserSettings(), address); }
private void FreeUnmanagedResources() { browser = null; if (BrowserSettings != null) { BrowserSettings.Dispose(); BrowserSettings = null; } if (managedCefBrowserAdapter != null) { managedCefBrowserAdapter.Dispose(); managedCefBrowserAdapter = null; } }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { // Don't reference event listeners any longer: LoadError = null; FrameLoadStart = null; FrameLoadEnd = null; ConsoleMessage = null; BrowserInitialized = null; StatusMessage = null; LoadingStateChanged = null; AddressChanged = null; Cef.RemoveDisposable(this); if (disposing) { browser = null; IsBrowserInitialized = false; if (Bitmap != null) { Bitmap.Dispose(); Bitmap = null; } if (BrowserSettings != null) { BrowserSettings.Dispose(); BrowserSettings = null; } if (managedCefBrowserAdapter != null) { if (!managedCefBrowserAdapter.IsDisposed) { managedCefBrowserAdapter.Dispose(); } managedCefBrowserAdapter = null; } } // Release reference to handlers, make sure this is done after we dispose managedCefBrowserAdapter // otherwise the ILifeSpanHandler.DoClose will not be invoked. (More important in the WinForms version, // we do it here for consistency) this.SetHandlersToNull(); }
/// <summary> /// Initializes a new instance of the <see cref="ChromiumWebBrowser"/> class. /// </summary> /// <param name="address">The address.</param> /// <exception cref="System.InvalidOperationException">Cef::Initialize() failed</exception> public ChromiumWebBrowser(string address) { if (!Cef.IsInitialized && !Cef.Initialize()) { throw new InvalidOperationException("Cef::Initialize() failed"); } Cef.AddDisposable(this); Address = address; Dock = DockStyle.Fill; FocusHandler = new DefaultFocusHandler(this); ResourceHandlerFactory = new DefaultResourceHandlerFactory(); BrowserSettings = new BrowserSettings(); managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, false); }
/// <summary> /// Create a new OffScreen Chromium Browser. /// </summary> /// <param name="height">Height of browser</param> /// <param name="address">Initial address (url) to load</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="width">Width of browser</param> public ChromiumWebBrowserController(int width = 1366, int height = 768, string address = "", RequestContext requestcontext = null, BrowserSettings browserSettings = null) { if (!Cef.IsInitialized && !Cef.Initialize()) { throw new InvalidOperationException("Cef::Initialize() failed"); } size = new Size(width, height); ResourceHandlerFactory = new DefaultResourceHandlerFactory(); BrowserSettings = browserSettings ?? new BrowserSettings(); RequestContext = requestcontext; Cef.AddDisposable(this); Address = address; managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true); managedCefBrowserAdapter.CreateOffscreenBrowser(IntPtr.Zero, BrowserSettings, RequestContext, address); }
protected override void Dispose(bool disposing) { FocusHandler = null; ResourceHandler = null; BrowserSettings.Dispose(); BrowserSettings = null; Cef.RemoveDisposable(this); if (disposing) { if (managedCefBrowserAdapter != null) { managedCefBrowserAdapter.Dispose(); managedCefBrowserAdapter = null; } } base.Dispose(disposing); }
/// <summary> /// Releases the unmanaged resources used by the <see cref="T:System.Windows.Forms.Control" /> and its child controls and optionally releases the managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { // Don't utilize any of the handlers anymore: this.SetHandlersToNull(); Cef.RemoveDisposable(this); if (disposing) { browser = null; IsBrowserInitialized = false; if (BrowserSettings != null) { BrowserSettings.Dispose(); BrowserSettings = null; } if (parentFormMessageInterceptor != null) { parentFormMessageInterceptor.Dispose(); parentFormMessageInterceptor = null; } if (managedCefBrowserAdapter != null) { managedCefBrowserAdapter.Dispose(); managedCefBrowserAdapter = null; } // Don't maintain a reference to event listeners anylonger: LoadError = null; FrameLoadStart = null; FrameLoadEnd = null; LoadingStateChanged = null; ConsoleMessage = null; StatusMessage = null; AddressChanged = null; TitleChanged = null; IsBrowserInitializedChanged = null; } base.Dispose(disposing); }
protected virtual void Dispose(bool isdisposing) { Cef.RemoveDisposable(this); foreach (var disposable in disposables) { disposable.Dispose(); } disposables.Clear(); RemoveSourceHook(); DoInUi(() => WebBrowser = null); managedCefBrowserAdapter = null; ConsoleMessage = null; FrameLoadStart = null; FrameLoadEnd = null; LoadError = null; }
/// <summary> /// Create a new OffScreen Chromium Browser /// </summary> /// <param name="address">Initial address (url) to load</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> public ChromiumWebBrowser(string address = "", BrowserSettings browserSettings = null, RequestContext requestcontext = null) { if (!Cef.IsInitialized && !Cef.Initialize()) { throw new InvalidOperationException("Cef::Initialize() failed"); } BitmapFactory = new BitmapFactory(BitmapLock); ResourceHandlerFactory = new DefaultResourceHandlerFactory(); BrowserSettings = browserSettings ?? new BrowserSettings(); RequestContext = requestcontext; Cef.AddDisposable(this); Address = address; managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true); managedCefBrowserAdapter.CreateOffscreenBrowser(IntPtr.Zero, BrowserSettings, RequestContext, address); }
/// <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. /// </summary> /// <param name="address">Initial address (url) to load</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> /// <exception cref="System.InvalidOperationException">Cef::Initialize() failed</exception> public ChromiumWebBrowser(string address, IBrowserSettings browserSettings, IRequestContext requestContext, bool automaticallyCreateBrowser, IRenderTarget renderer) { if (!Cef.IsInitialized) { throw new InvalidOperationException("Cef IS NOT INITIALIZED"); } RequestContext = requestContext; _renderTarget = renderer; Cef.AddDisposable(this); Address = address; managedCefBrowserAdapter = ManagedCefBrowserAdapter.Create(this, true); if (automaticallyCreateBrowser) { CreateBrowser(null, browserSettings); } }
protected override void Dispose(bool disposing) { // Don't utilize any of the handlers anymore: DialogHandler = null; JsDialogHandler = null; KeyboardHandler = null; RequestHandler = null; DownloadHandler = null; LifeSpanHandler = null; MenuHandler = null; DragHandler = null; GeolocationHandler = null; FocusHandler = null; ResourceHandlerFactory = null; Cef.RemoveDisposable(this); if (disposing) { IsBrowserInitialized = false; if (BrowserSettings != null) { BrowserSettings.Dispose(); BrowserSettings = null; } if (parentFormMessageInterceptor != null) { parentFormMessageInterceptor.Dispose(); parentFormMessageInterceptor = null; } if (managedCefBrowserAdapter != null) { managedCefBrowserAdapter.Dispose(); managedCefBrowserAdapter = null; } // Don't maintain a reference to event listeners anylonger: LoadError = null; FrameLoadStart = null; FrameLoadEnd = null; NavStateChanged = null; ConsoleMessage = null; StatusMessage = null; AddressChanged = null; TitleChanged = null; IsBrowserInitializedChanged = null; IsLoadingChanged = null; } base.Dispose(disposing); }
private void OnApplicationExit(object sender, EventArgs e) { if (managedCefBrowserAdapter == null) { return; } managedCefBrowserAdapter.Close(); managedCefBrowserAdapter.Dispose(); managedCefBrowserAdapter = null; Cef.Shutdown(); }
protected virtual void Dispose(bool isdisposing) { // No longer reference event listeners: ConsoleMessage = null; FrameLoadStart = null; FrameLoadEnd = null; LoadError = null; NavStateChanged = null; // No longer reference handlers: ResourceHandler = null; DialogHandler = null; JsDialogHandler = null; KeyboardHandler = null; RequestHandler = null; DownloadHandler = null; LifeSpanHandler = null; MenuHandler = null; FocusHandler = null; DragHandler = null; GeolocationHandler = null; Rendering = null; if (isdisposing) { if (BrowserSettings != null) { BrowserSettings.Dispose(); BrowserSettings = null; } PresentationSource.RemoveSourceChangedHandler(this, PresentationSourceChangedHandler); // Release internal event listeners: Loaded -= OnLoaded; GotKeyboardFocus -= OnGotKeyboardFocus; LostKeyboardFocus -= OnLostKeyboardFocus; // Release internal event listeners for Drag Drop events: DragEnter -= OnDragEnter; DragOver -= OnDragOver; DragLeave -= OnDragLeave; Drop -= OnDrop; IsVisibleChanged -= OnIsVisibleChanged; foreach (var disposable in disposables) { disposable.Dispose(); } disposables.Clear(); UiThreadRunAsync(() => WebBrowser = null); } Cef.RemoveDisposable(this); managedCefBrowserAdapter = null; }
/// <summary> /// Releases the unmanaged resources used by the <see cref="T:System.Windows.Forms.Control" /> and its child controls and optionally releases the managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { Cef.RemoveDisposable(this); if (disposing) { browser = null; IsBrowserInitialized = false; if (BrowserSettings != null) { BrowserSettings.Dispose(); BrowserSettings = null; } if (parentFormMessageInterceptor != null) { parentFormMessageInterceptor.Dispose(); parentFormMessageInterceptor = null; } if (managedCefBrowserAdapter != null) { managedCefBrowserAdapter.Dispose(); managedCefBrowserAdapter = null; } // Don't maintain a reference to event listeners anylonger: LoadError = null; FrameLoadStart = null; FrameLoadEnd = null; LoadingStateChanged = null; ConsoleMessage = null; StatusMessage = null; AddressChanged = null; TitleChanged = null; IsBrowserInitializedChanged = null; } // Release reference to handlers, make sure this is done after we dispose managedCefBrowserAdapter // otherwise the ILifeSpanHandler.DoClose will not be invoked. this.SetHandlersToNull(); base.Dispose(disposing); }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="isDisposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool isDisposing) { //Check if already disposed if (Interlocked.Increment(ref disposeCount) == 1) { // No longer reference event listeners: ConsoleMessage = null; FrameLoadStart = null; FrameLoadEnd = null; LoadError = null; LoadingStateChanged = null; Rendering = null; if (isDisposing) { browser = null; if (BrowserSettings != null) { BrowserSettings.Dispose(); BrowserSettings = null; } PresentationSource.RemoveSourceChangedHandler(this, PresentationSourceChangedHandler); // Release internal event listeners: Loaded -= OnLoaded; SizeChanged -= OnActualSizeChanged; GotKeyboardFocus -= OnGotKeyboardFocus; LostKeyboardFocus -= OnLostKeyboardFocus; // Release internal event listeners for Drag Drop events: DragEnter -= OnDragEnter; DragOver -= OnDragOver; DragLeave -= OnDragLeave; Drop -= OnDrop; IsVisibleChanged -= OnIsVisibleChanged; if (tooltipTimer != null) { tooltipTimer.Tick -= OnTooltipTimerTick; } if (CleanupElement != null) { CleanupElement.Unloaded -= OnCleanupElementUnloaded; } if(managedCefBrowserAdapter != null) { managedCefBrowserAdapter.Dispose(); managedCefBrowserAdapter = null; } browserInitialized = false; UiThreadRunAsync(() => { SetCurrentValue(IsBrowserInitializedProperty, false); WebBrowser = null; }); } // Release reference to handlers, make sure this is done after we dispose managedCefBrowserAdapter // otherwise the ILifeSpanHandler.DoClose will not be invoked. (More important in the WinForms version, // we do it here for consistency) this.SetHandlersToNull(); Cef.RemoveDisposable(this); RemoveSourceHook(); } }
public WebView() { Focusable = true; FocusVisualStyle = null; IsTabStop = true; Dispatcher.BeginInvoke((Action)(() => WebBrowser = this)); Loaded += OnLoaded; Unloaded += OnUnloaded; this.IsVisibleChanged += OnIsVisibleChanged; ToolTip = toolTip = new ToolTip(); toolTip.StaysOpen = true; toolTip.Visibility = Visibility.Collapsed; toolTip.Closed += OnTooltipClosed; BackCommand = new DelegateCommand(Back, CanGoBack); ForwardCommand = new DelegateCommand(Forward, CanGoForward); ReloadCommand = new DelegateCommand(Reload, CanReload); browserCore = new BrowserCore("about:blank"); browserCore.PropertyChanged += OnBrowserCorePropertyChanged; managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this); managedCefBrowserAdapter.CreateOffscreenBrowser(BrowserSettings ?? new BrowserSettings()); disposables.Add(managedCefBrowserAdapter); disposables.Add(new DisposableEventWrapper(this, ActualHeightProperty, OnActualSizeChanged)); disposables.Add(new DisposableEventWrapper(this, ActualWidthProperty, OnActualSizeChanged)); }
protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this); managedCefBrowserAdapter.CreateBrowser(BrowserSettings ?? new BrowserSettings(), Handle, Address); }
/// <summary> /// Create a new OffScreen Chromium Browser /// </summary> /// <param name="address">Initial address (url) to load</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="blendPopup">Should the popup be blended in the background in the rendering</param> /// <exception cref="System.InvalidOperationException">Cef::Initialize() failed</exception> public ChromiumWebBrowser(string address = "", BrowserSettings browserSettings = null, RequestContext requestContext = null, bool automaticallyCreateBrowser = true) { if (!Cef.IsInitialized && !Cef.Initialize()) { throw new InvalidOperationException("Cef::Initialize() failed"); } BitmapFactory = new BitmapFactory(BitmapLock); ResourceHandlerFactory = new DefaultResourceHandlerFactory(); BrowserSettings = browserSettings ?? new BrowserSettings(); RequestContext = requestContext; Cef.AddDisposable(this); Address = address; managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true); if (automaticallyCreateBrowser) { CreateBrowser(IntPtr.Zero); } popupPosition = new Point(); popupSize = new Size(); }
protected override void Dispose(bool disposing) { // Don't utilize any of the handlers anymore: this.SetHandlersToNull(); Cef.RemoveDisposable(this); if (disposing) { IsBrowserInitialized = false; if (BrowserSettings != null) { BrowserSettings.Dispose(); BrowserSettings = null; } if (parentFormMessageInterceptor != null) { parentFormMessageInterceptor.Dispose(); parentFormMessageInterceptor = null; } if (managedCefBrowserAdapter != null) { managedCefBrowserAdapter.Dispose(); managedCefBrowserAdapter = null; } // Don't maintain a reference to event listeners anylonger: LoadError = null; FrameLoadStart = null; FrameLoadEnd = null; LoadingStateChanged = null; ConsoleMessage = null; StatusMessage = null; AddressChanged = null; TitleChanged = null; IsBrowserInitializedChanged = null; } base.Dispose(disposing); }
protected virtual void Dispose(bool isdisposing) { Cef.RemoveDisposable(this); foreach (var disposable in disposables) { disposable.Dispose(); } disposables.Clear(); RemoveSourceHook(); WebBrowser = null; managedCefBrowserAdapter = null; ConsoleMessage = null; FrameLoadStart = null; FrameLoadEnd = null; LoadError = null; }
protected virtual void Dispose(bool isdisposing) { Loaded -= OnLoaded; Unloaded -= OnUnloaded; GotKeyboardFocus -= OnGotKeyboardFocus; LostKeyboardFocus -= OnLostKeyboardFocus; IsVisibleChanged -= OnIsVisibleChanged; Cef.RemoveDisposable(this); RemoveSourceHook(); foreach (var disposable in disposables) { disposable.Dispose(); } disposables.Clear(); UiThreadRunAsync(() => WebBrowser = null); managedCefBrowserAdapter = null; ConsoleMessage = null; FrameLoadStart = null; FrameLoadEnd = null; LoadError = null; }
public ChromiumWebBrowser() { Cef.AddDisposable(this); Focusable = true; FocusVisualStyle = null; IsTabStop = true; Dispatcher.BeginInvoke((Action)(() => WebBrowser = this)); Loaded += OnLoaded; Unloaded += OnUnloaded; GotKeyboardFocus += OnGotKeyboardFocus; LostKeyboardFocus += OnLostKeyboardFocus; IsVisibleChanged += OnIsVisibleChanged; ToolTip = toolTip = new ToolTip(); toolTip.StaysOpen = true; toolTip.Visibility = Visibility.Collapsed; toolTip.Closed += OnTooltipClosed; BackCommand = new DelegateCommand(Back, () => CanGoBack); ForwardCommand = new DelegateCommand(Forward, () => CanGoForward); ReloadCommand = new DelegateCommand(Reload, () => CanReload); PrintCommand = new DelegateCommand(Print); ZoomInCommand = new DelegateCommand(ZoomIn); ZoomOutCommand = new DelegateCommand(ZoomOut); ZoomResetCommand = new DelegateCommand(ZoomReset); ViewSourceCommand = new DelegateCommand(ViewSource); CleanupCommand = new DelegateCommand(Dispose); StopCommand = new DelegateCommand(Stop); managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this); managedCefBrowserAdapter.CreateOffscreenBrowser(BrowserSettings ?? new BrowserSettings()); disposables.Add(managedCefBrowserAdapter); disposables.Add(new DisposableEventWrapper(this, ActualHeightProperty, OnActualSizeChanged)); disposables.Add(new DisposableEventWrapper(this, ActualWidthProperty, OnActualSizeChanged)); }
public ChromiumWebBrowser() { if (!Cef.IsInitialized && !Cef.Initialize()) { throw new InvalidOperationException("Cef::Initialize() failed"); } BitmapFactory = new BitmapFactory(); Cef.AddDisposable(this); Focusable = true; FocusVisualStyle = null; IsTabStop = true; Dispatcher.BeginInvoke((Action)(() => WebBrowser = this)); Loaded += OnLoaded; GotKeyboardFocus += OnGotKeyboardFocus; LostKeyboardFocus += OnLostKeyboardFocus; // Drag Drop events DragEnter += OnDragEnter; DragOver += OnDragOver; DragLeave += OnDragLeave; Drop += OnDrop; IsVisibleChanged += OnIsVisibleChanged; ToolTip = toolTip = new ToolTip(); toolTip.StaysOpen = true; toolTip.Visibility = Visibility.Collapsed; toolTip.Closed += OnTooltipClosed; BackCommand = new DelegateCommand(this.Back, () => CanGoBack); ForwardCommand = new DelegateCommand(this.Forward, () => CanGoForward); ReloadCommand = new DelegateCommand(this.Reload, () => !IsLoading); PrintCommand = new DelegateCommand(this.Print); ZoomInCommand = new DelegateCommand(ZoomIn); ZoomOutCommand = new DelegateCommand(ZoomOut); ZoomResetCommand = new DelegateCommand(ZoomReset); ViewSourceCommand = new DelegateCommand(this.ViewSource); CleanupCommand = new DelegateCommand(Dispose); StopCommand = new DelegateCommand(this.Stop); CutCommand = new DelegateCommand(this.Cut); CopyCommand = new DelegateCommand(this.Copy); PasteCommand = new DelegateCommand(this.Paste); SelectAllCommand = new DelegateCommand(this.SelectAll); UndoCommand = new DelegateCommand(this.Undo); RedoCommand = new DelegateCommand(this.Redo); managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true); disposables.Add(managedCefBrowserAdapter); disposables.Add(new DisposableEventWrapper(this, ActualHeightProperty, OnActualSizeChanged)); disposables.Add(new DisposableEventWrapper(this, ActualWidthProperty, OnActualSizeChanged)); ResourceHandlerFactory = new DefaultResourceHandlerFactory(); BrowserSettings = new BrowserSettings(); PresentationSource.AddSourceChangedHandler(this, PresentationSourceChangedHandler); }
protected virtual void Dispose(bool disposing) { // Don't reference handlers any longer: this.SetHandlersToNull(); // Don't reference event listeners any longer: LoadError = null; FrameLoadStart = null; FrameLoadEnd = null; ConsoleMessage = null; BrowserInitialized = null; StatusMessage = null; LoadingStateChanged = null; AddressChanged = null; Cef.RemoveDisposable(this); if (disposing) { IsBrowserInitialized = false; if (bitmap != null) { bitmap.Dispose(); bitmap = null; } if (BrowserSettings != null) { BrowserSettings.Dispose(); BrowserSettings = null; } if (managedCefBrowserAdapter != null) { if (!managedCefBrowserAdapter.IsDisposed) { managedCefBrowserAdapter.Dispose(); } managedCefBrowserAdapter = null; } } }
protected virtual void Dispose(bool disposing) { // Don't reference handlers any longer: ResourceHandler = null; JsDialogHandler = null; DialogHandler = null; DownloadHandler = null; KeyboardHandler = null; LifeSpanHandler = null; MenuHandler = null; FocusHandler = null; RequestHandler = null; DragHandler = null; GeolocationHandler = null; // Don't reference event listeners any longer: LoadError = null; FrameLoadStart = null; FrameLoadEnd = null; ConsoleMessage = null; BrowserInitialized = null; StatusMessage = null; NavStateChanged = null; Cef.RemoveDisposable(this); if (disposing) { if (bitmap != null) { bitmap.Dispose(); bitmap = null; } if (managedCefBrowserAdapter != null) { if (!managedCefBrowserAdapter.IsDisposed) { managedCefBrowserAdapter.Dispose(); } managedCefBrowserAdapter = null; } } }