diff --git a/CefSharp.Example/Handlers/BrowserProcessHandler.cs b/CefSharp.Example/Handlers/BrowserProcessHandler.cs
index c4d1342ef..1c966d0ca 100644
--- a/CefSharp.Example/Handlers/BrowserProcessHandler.cs
+++ b/CefSharp.Example/Handlers/BrowserProcessHandler.cs
@@ -9,7 +9,7 @@ using CefSharp.SchemeHandler;
namespace CefSharp.Example.Handlers
{
- public class BrowserProcessHandler : IBrowserProcessHandler
+ public class BrowserProcessHandler : CefSharp.Handler.BrowserProcessHandler
{
///
/// The interval between calls to Cef.DoMessageLoopWork
@@ -20,7 +20,7 @@ namespace CefSharp.Example.Handlers
///
protected const int ThirtyTimesPerSecond = 1000 / 30; //30fps
- void IBrowserProcessHandler.OnContextInitialized()
+ protected override void OnContextInitialized()
{
//The Global CookieManager has been initialized, you can now set cookies
var cookieManager = Cef.GetGlobalCookieManager();
@@ -106,26 +106,5 @@ namespace CefSharp.Example.Handlers
context.RegisterSchemeHandlerFactory("https", "cefsharp.example", folderSchemeHandlerExample);
}
}
-
- void IBrowserProcessHandler.OnScheduleMessagePumpWork(long delay)
- {
- //If the delay is greater than the Maximum then use ThirtyTimesPerSecond
- //instead - we do this to achieve a minimum number of FPS
- if (delay > ThirtyTimesPerSecond)
- {
- delay = ThirtyTimesPerSecond;
- }
- OnScheduleMessagePumpWork((int)delay);
- }
-
- protected virtual void OnScheduleMessagePumpWork(int delay)
- {
- //TODO: Schedule work on the UI thread - call Cef.DoMessageLoopWork
- }
-
- public virtual void Dispose()
- {
-
- }
}
}
diff --git a/CefSharp.WinForms.Example/Handlers/ScheduleMessagePumpBrowserProcessHandler.cs b/CefSharp.WinForms.Example/Handlers/ScheduleMessagePumpBrowserProcessHandler.cs
index 058667b92..a401629c6 100644
--- a/CefSharp.WinForms.Example/Handlers/ScheduleMessagePumpBrowserProcessHandler.cs
+++ b/CefSharp.WinForms.Example/Handlers/ScheduleMessagePumpBrowserProcessHandler.cs
@@ -39,8 +39,15 @@ namespace CefSharp.WinForms.Example.Handlers
factory.StartNew(() => Cef.DoMessageLoopWork());
}
- protected override void OnScheduleMessagePumpWork(int delay)
+ protected override void OnScheduleMessagePumpWork(long delay)
{
+ //If the delay is greater than the Maximum then use ThirtyTimesPerSecond
+ //instead - we do this to achieve a minimum number of FPS
+ if (delay > ThirtyTimesPerSecond)
+ {
+ delay = ThirtyTimesPerSecond;
+ }
+
//when delay <= 0 queue the Task up for execution on the UI thread.
if (delay <= 0)
{
@@ -49,14 +56,19 @@ namespace CefSharp.WinForms.Example.Handlers
}
}
- public override void Dispose()
+ protected override void Dispose(bool disposing)
{
- if (timer != null)
+ if(disposing)
{
- timer.Stop();
- timer.Dispose();
- timer = null;
+ if (timer != null)
+ {
+ timer.Stop();
+ timer.Dispose();
+ timer = null;
+ }
}
+
+ base.Dispose(disposing);
}
}
}
diff --git a/CefSharp.WinForms.Example/Handlers/WinFormsBrowserProcessHandler.cs b/CefSharp.WinForms.Example/Handlers/WinFormsBrowserProcessHandler.cs
index 50747f605..e34f4acf4 100644
--- a/CefSharp.WinForms.Example/Handlers/WinFormsBrowserProcessHandler.cs
+++ b/CefSharp.WinForms.Example/Handlers/WinFormsBrowserProcessHandler.cs
@@ -33,19 +33,24 @@ namespace CefSharp.WinForms.Example.Handlers
Cef.DoMessageLoopWork();
}
- protected override void OnScheduleMessagePumpWork(int delay)
+ protected override void OnScheduleMessagePumpWork(long delay)
{
//NOOP - Only enabled when CefSettings.ExternalMessagePump
}
- public override void Dispose()
+ protected override void Dispose(bool disposing)
{
- if (timer != null)
+ if(disposing)
{
- timer.Stop();
- timer.Dispose();
- timer = null;
+ if (timer != null)
+ {
+ timer.Stop();
+ timer.Dispose();
+ timer = null;
+ }
}
+
+ base.Dispose(disposing);
}
}
}
diff --git a/CefSharp.Wpf.Example/Handlers/WpfBrowserProcessHandler.cs b/CefSharp.Wpf.Example/Handlers/WpfBrowserProcessHandler.cs
index c3115c6d5..95eb6a080 100644
--- a/CefSharp.Wpf.Example/Handlers/WpfBrowserProcessHandler.cs
+++ b/CefSharp.Wpf.Example/Handlers/WpfBrowserProcessHandler.cs
@@ -44,8 +44,15 @@ namespace CefSharp.Wpf.Example.Handlers
dispatcher.BeginInvoke((Action)(() => Cef.DoMessageLoopWork()), DispatcherPriority.Render);
}
- protected override void OnScheduleMessagePumpWork(int delay)
+ protected override void OnScheduleMessagePumpWork(long delay)
{
+ //If the delay is greater than the Maximum then use ThirtyTimesPerSecond
+ //instead - we do this to achieve a minimum number of FPS
+ if (delay > ThirtyTimesPerSecond)
+ {
+ delay = ThirtyTimesPerSecond;
+ }
+
//When delay <= 0 we'll execute Cef.DoMessageLoopWork immediately
// if it's greater than we'll just let the Timer which fires 30 times per second
// care of the call
@@ -55,20 +62,25 @@ namespace CefSharp.Wpf.Example.Handlers
}
}
- public override void Dispose()
+ protected override void Dispose(bool disposing)
{
- if (dispatcher != null)
+ if(disposing)
{
- dispatcher.ShutdownStarted -= DispatcherShutdownStarted;
- dispatcher = null;
+ if (dispatcher != null)
+ {
+ dispatcher.ShutdownStarted -= DispatcherShutdownStarted;
+ dispatcher = null;
+ }
+
+ if (timer != null)
+ {
+ timer.Stop();
+ timer.Dispose();
+ timer = null;
+ }
}
- if (timer != null)
- {
- timer.Stop();
- timer.Dispose();
- timer = null;
- }
+ base.Dispose(disposing);
}
}
}
diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj
index 11835dd4b..ea0213781 100644
--- a/CefSharp/CefSharp.csproj
+++ b/CefSharp/CefSharp.csproj
@@ -104,6 +104,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CefSharp/DefaultApp.cs b/CefSharp/DefaultApp.cs
index ebfa0d195..368150f34 100644
--- a/CefSharp/DefaultApp.cs
+++ b/CefSharp/DefaultApp.cs
@@ -2,6 +2,7 @@
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+using System;
using System.Collections.Generic;
namespace CefSharp
@@ -10,8 +11,10 @@ namespace CefSharp
/// Default implementation of which represents the CefApp class.
///
///
- public class DefaultApp : IApp
+ public class DefaultApp : IApp, IDisposable
{
+ private bool isDisposed;
+
///
/// Return the handler for functionality specific to the browser process. This method is called on multiple threads.
///
@@ -88,5 +91,31 @@ namespace CefSharp
}
}
}
+
+ ///
+ /// Releases unmanaged and managed resources
+ ///
+ /// to release both managed and unmanaged resources; to release only unmanaged resources.
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!isDisposed)
+ {
+ if (disposing)
+ {
+ BrowserProcessHandler?.Dispose();
+ BrowserProcessHandler = null;
+ }
+
+ isDisposed = true;
+ }
+ }
+
+ ///
+ void IDisposable.Dispose()
+ {
+ // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
+ }
}
}
diff --git a/CefSharp/Handler/AccessibilityHandler.cs b/CefSharp/Handler/AccessibilityHandler.cs
new file mode 100644
index 000000000..608ce7e73
--- /dev/null
+++ b/CefSharp/Handler/AccessibilityHandler.cs
@@ -0,0 +1,44 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Inherit from this class to receive accessibility notification when accessibility events have been registered.
+ /// It's important to note that the methods of this interface are called on a CEF UI thread,
+ /// which by default is not the same as your application UI thread.
+ ///
+ public class AccessibilityHandler : IAccessibilityHandler
+ {
+ ///
+ void IAccessibilityHandler.OnAccessibilityLocationChange(IValue value)
+ {
+ OnAccessibilityLocationChange(value);
+ }
+
+ ///
+ /// Called after renderer process sends accessibility location changes to the browser process.
+ ///
+ /// Updated location info.
+ protected virtual void OnAccessibilityLocationChange(IValue value)
+ {
+
+ }
+
+ ///
+ void IAccessibilityHandler.OnAccessibilityTreeChange(IValue value)
+ {
+ OnAccessibilityTreeChange(value);
+ }
+
+ ///
+ /// Called after renderer process sends accessibility tree changes to the browser process.
+ ///
+ /// Updated tree info.
+ protected virtual void OnAccessibilityTreeChange(IValue value)
+ {
+
+ }
+ }
+}
diff --git a/CefSharp/Handler/AudioHandler.cs b/CefSharp/Handler/AudioHandler.cs
new file mode 100644
index 000000000..06be75e4f
--- /dev/null
+++ b/CefSharp/Handler/AudioHandler.cs
@@ -0,0 +1,121 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+using System;
+using CefSharp.Structs;
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Inherit from this class to handle audio events
+ /// All methods will be called on the CEF UI thread
+ ///
+ public class AudioHandler : IAudioHandler
+ {
+ ///
+ bool IAudioHandler.GetAudioParameters(IWebBrowser chromiumWebBrowser, IBrowser browser, ref AudioParameters parameters)
+ {
+ return GetAudioParameters(chromiumWebBrowser, browser, ref parameters);
+ }
+
+ ///
+ /// Called on the CEF UI thread to allow configuration of audio stream parameters.
+ /// Audio stream paramaters can optionally be configured by modifying
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// audio stream parameters can optionally be configured here, they are
+ /// pre-filled with some sensible defaults.
+ /// Return true to proceed with audio stream capture, or false to cancel it
+ protected virtual bool GetAudioParameters(IWebBrowser chromiumWebBrowser, IBrowser browser, ref AudioParameters parameters)
+ {
+ return false;
+ }
+
+ ///
+ void IAudioHandler.OnAudioStreamStarted(IWebBrowser chromiumWebBrowser,
+ IBrowser browser,
+ AudioParameters parameters,
+ int channels)
+ {
+ OnAudioStreamStarted(chromiumWebBrowser, browser, parameters, channels);
+ }
+
+ ///
+ /// Called on a browser audio capture thread when the browser starts streaming audio.
+ /// OnAudioSteamStopped will always be called after OnAudioStreamStarted; both methods may be called multiple
+ /// times for the same browser.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// contains the audio parameters like sample rate and channel layout.
+ /// Changing the param values will have no effect here.
+ /// is the number of channels
+ protected virtual void OnAudioStreamStarted(IWebBrowser chromiumWebBrowser,
+ IBrowser browser,
+ AudioParameters parameters,
+ int channels)
+ {
+
+ }
+
+ ///
+ void IAudioHandler.OnAudioStreamPacket(IWebBrowser chromiumWebBrowser, IBrowser browser, IntPtr data, int noOfFrames, long pts)
+ {
+ OnAudioStreamPacket(chromiumWebBrowser, browser, data, noOfFrames, pts);
+ }
+
+ ///
+ /// Called on the audio stream thread when a PCM packet is received for the stream.
+ /// Based on and the value passed to
+ /// you can calculate the size of the array in bytes.
+ ///
+ ///
+ /// is an array representing the raw PCM data as a floating point type, i.e. 4-byte value(s).
+ /// is the number of frames in the PCM packet
+ /// is the presentation timestamp (in milliseconds since the Unix Epoch)
+ /// and represents the time at which the decompressed packet should be presented to the user
+ protected virtual void OnAudioStreamPacket(IWebBrowser chromiumWebBrowser, IBrowser browser, IntPtr data, int noOfFrames, long pts)
+ {
+
+ }
+
+ ///
+ void IAudioHandler.OnAudioStreamStopped(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+ OnAudioStreamStopped(chromiumWebBrowser, browser);
+ }
+
+ ///
+ /// Called on the CEF UI thread when the stream has stopped. OnAudioSteamStopped will always be called after ;
+ /// both methods may be called multiple times for the same stream.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ protected virtual void OnAudioStreamStopped(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+
+ }
+
+ ///
+ void IAudioHandler.OnAudioStreamError(IWebBrowser chromiumWebBrowser, IBrowser browser, string errorMessage)
+ {
+ OnAudioStreamError(chromiumWebBrowser, browser, errorMessage);
+ }
+
+ ///
+ /// Called on the CEF UI thread or audio stream thread when an error occurred. During the
+ /// stream creation phase this callback will be called on the UI thread while
+ /// in the capturing phase it will be called on the audio stream thread. The
+ /// stream will be stopped immediately.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// error message
+ protected virtual void OnAudioStreamError(IWebBrowser chromiumWebBrowser, IBrowser browser, string errorMessage)
+ {
+
+ }
+ }
+}
diff --git a/CefSharp/Handler/BrowserProcessHandler.cs b/CefSharp/Handler/BrowserProcessHandler.cs
new file mode 100644
index 000000000..18ac65ad7
--- /dev/null
+++ b/CefSharp/Handler/BrowserProcessHandler.cs
@@ -0,0 +1,78 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+using System;
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Inherit from this class to handle events related to browser process callbacks.
+ /// The methods of this class will be called on the CEF UI thread unless otherwise indicated. .
+ ///
+ public class BrowserProcessHandler : IBrowserProcessHandler
+ {
+ private bool isDisposed;
+
+ ///
+ void IBrowserProcessHandler.OnContextInitialized()
+ {
+ OnContextInitialized();
+ }
+
+ ///
+ /// Called on the CEF UI thread immediately after the CEF context has been initialized.
+ /// You can now access the Global RequestContext through Cef.GetGlobalRequestContext() - this is the
+ /// first place you can set Preferences (e.g. proxy settings, spell check dictionaries).
+ ///
+ protected virtual void OnContextInitialized()
+ {
+
+ }
+
+ ///
+ void IBrowserProcessHandler.OnScheduleMessagePumpWork(long delay)
+ {
+ OnScheduleMessagePumpWork(delay);
+ }
+
+ ///
+ /// Called from any thread when work has been scheduled for the browser process
+ /// main (UI) thread. This callback is used in combination with CefSettings.
+ /// ExternalMessagePump and Cef.DoMessageLoopWork() in cases where the CEF
+ /// message loop must be integrated into an existing application message loop
+ /// (see additional comments and warnings on Cef.DoMessageLoopWork). This
+ /// callback should schedule a Cef.DoMessageLoopWork() call to happen on the
+ /// main (UI) thread.
+ ///
+ /// is the requested delay in milliseconds. If
+ /// delay is less than or equal to 0 then the call should happen reasonably soon. If
+ /// delay is greater than 0 then the call should be scheduled to happen after the
+ /// specified delay and any currently pending scheduled call should be
+ /// cancelled.
+ protected virtual void OnScheduleMessagePumpWork(long delay)
+ {
+
+ }
+
+ ///
+ /// IsDisposed
+ ///
+ public bool IsDisposed
+ {
+ get { return isDisposed; }
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ isDisposed = true;
+ }
+
+ ///
+ void IDisposable.Dispose()
+ {
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
+ }
+ }
+}
diff --git a/CefSharp/Handler/ContextMenuHandler.cs b/CefSharp/Handler/ContextMenuHandler.cs
new file mode 100644
index 000000000..2b18324fa
--- /dev/null
+++ b/CefSharp/Handler/ContextMenuHandler.cs
@@ -0,0 +1,100 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+namespace CefSharp.Handler
+{
+ /// Inherit from this class to handle context menu events.
+ ///
+ public class ContextMenuHandler : IContextMenuHandler
+ {
+ ///
+ void IContextMenuHandler.OnBeforeContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters,
+ IMenuModel model)
+ {
+ OnBeforeContextMenu(chromiumWebBrowser, browser, frame, parameters, model);
+ }
+
+ ///
+ /// Called before a context menu is displayed. The model can be cleared to show no context menu or
+ /// modified to show a custom menu.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// The frame the request is coming from
+ /// provides information about the context menu state
+ /// initially contains the default context menu
+ protected virtual void OnBeforeContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters,
+ IMenuModel model)
+ {
+
+ }
+
+ ///
+ bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters,
+ CefMenuCommand commandId, CefEventFlags eventFlags)
+ {
+ return OnContextMenuCommand(chromiumWebBrowser, browser, frame, parameters, commandId, eventFlags);
+ }
+
+ ///
+ /// Called to execute a command selected from the context menu. See
+ /// cef_menu_id_t for the command ids that have default implementations. All
+ /// user-defined command ids should be between MENU_ID_USER_FIRST and
+ /// MENU_ID_USER_LAST.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// The frame the request is coming from
+ /// will have the same values as what was passed to
+ /// menu command id
+ /// event flags
+ /// Return true if the command was handled or false for the default implementation.
+ protected virtual bool OnContextMenuCommand(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters,
+ CefMenuCommand commandId, CefEventFlags eventFlags)
+ {
+ return false;
+ }
+
+ ///
+ void IContextMenuHandler.OnContextMenuDismissed(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
+ {
+ OnContextMenuDismissed(chromiumWebBrowser, browser, frame);
+ }
+
+ ///
+ /// Called when the context menu is dismissed irregardless of whether the menu
+ /// was empty or a command was selected.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// The frame the request is coming from
+ protected virtual void OnContextMenuDismissed(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame)
+ {
+
+ }
+
+ ///
+ bool IContextMenuHandler.RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
+ {
+ return RunContextMenu(chromiumWebBrowser, browser, frame, parameters, model, callback);
+ }
+
+ ///
+ /// Called to allow custom display of the context menu.
+ /// For custom display return true and execute callback either synchronously or asynchronously with the selected command Id.
+ /// For default display return false. Do not keep references to parameters or model outside of this callback.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// The frame the request is coming from
+ /// provides information about the context menu state
+ /// contains the context menu model resulting from OnBeforeContextMenu
+ /// the callback to execute for custom display
+ /// For custom display return true and execute callback either synchronously or asynchronously with the selected command ID.
+ protected virtual bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
+ {
+ return false;
+ }
+ }
+}
diff --git a/CefSharp/Handler/CookieAccessFilter.cs b/CefSharp/Handler/CookieAccessFilter.cs
new file mode 100644
index 000000000..0023ca21d
--- /dev/null
+++ b/CefSharp/Handler/CookieAccessFilter.cs
@@ -0,0 +1,55 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Inherit from this class to filter cookies that may be sent or received from
+ /// resource requests. The methods of this class will be called on the CEF IO thread
+ /// unless otherwise indicated.
+ ///
+ public class CookieAccessFilter : ICookieAccessFilter
+ {
+ ///
+ bool ICookieAccessFilter.CanSendCookie(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, Cookie cookie)
+ {
+ return CanSendCookie(chromiumWebBrowser, browser, frame, request, cookie);
+ }
+
+ ///
+ /// Called on the CEF IO thread before a resource request is sent.
+ ///
+ /// The ChromiumWebBrowser control
+ /// the browser object - may be null if originating from ServiceWorker or CefURLRequest
+ /// the frame object - may be null if originating from ServiceWorker or CefURLRequest
+ /// the request object - cannot be modified in this callback
+ /// the cookie object
+ /// Return true if the specified cookie can be sent with the request or false otherwise.
+ protected virtual bool CanSendCookie(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, Cookie cookie)
+ {
+ return false;
+ }
+
+ ///
+ bool ICookieAccessFilter.CanSaveCookie(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response, Cookie cookie)
+ {
+ return CanSaveCookie(chromiumWebBrowser, browser, frame, request, response, cookie);
+ }
+
+ ///
+ /// Called on the CEF IO thread after a resource response is received.
+ ///
+ /// The ChromiumWebBrowser control
+ /// the browser object - may be null if originating from ServiceWorker or CefURLRequest
+ /// the frame object - may be null if originating from ServiceWorker or CefURLRequest
+ /// the request object - cannot be modified in this callback
+ /// the response object - cannot be modified in this callback
+ /// the cookie object
+ /// Return true if the specified cookie returned with the response can be saved or false otherwise.
+ protected virtual bool CanSaveCookie(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response, Cookie cookie)
+ {
+ return false;
+ }
+ }
+}
diff --git a/CefSharp/Handler/DialogHandler.cs b/CefSharp/Handler/DialogHandler.cs
new file mode 100644
index 000000000..98a01c2f3
--- /dev/null
+++ b/CefSharp/Handler/DialogHandler.cs
@@ -0,0 +1,69 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+using System.Collections.Generic;
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Implement this interface to handle dialog events. The methods of this class will be called on the CEF UI thread.
+ ///
+ public class DialogHandler : IDialogHandler
+ {
+ ///
+ bool IDialogHandler.OnFileDialog(
+ IWebBrowser chromiumWebBrowser,
+ IBrowser browser,
+ CefFileDialogMode mode,
+ CefFileDialogFlags flags,
+ string title,
+ string defaultFilePath,
+ List acceptFilters,
+ int selectedAcceptFilter,
+ IFileDialogCallback callback)
+ {
+ return OnFileDialog(chromiumWebBrowser, browser, mode, flags, title, defaultFilePath, acceptFilters, selectedAcceptFilter, callback);
+ }
+
+ ///
+ /// Runs a file chooser dialog.
+ ///
+ ///
+ /// To test assign something like TempFileDialogHandler (from CefSharp.Example) to DialogHandler e.g.
+ ///
+ /// browser.DialogHandler = new TempFileDialogHandler();
+ ///
+ /// Example URL to use for file browsing http://www.cs.tut.fi/~jkorpela/forms/file.html#example
+ /// Simply click browse, the space next to the browse button should be populated with a randomly generated filename.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// represents the type of dialog to display
+ /// further specifies behavior dialog should exhibit
+ /// the title to be used for the dialog. It may be empty to show the default title ("Open" or "Save"
+ /// depending on the mode).
+ /// is the path with optional directory and/or file name component that
+ /// should be initially selected in the dialog.
+ /// are used to restrict the selectable file types and may any combination of
+ /// (a) valid lower-cased MIME types (e.g. "text/*" or "image/*"),
+ /// (b) individual file extensions (e.g. ".txt" or ".png"),
+ /// (c) combined description and file extension delimited using "|" and ";" (e.g. "Image Types|.png;.gif;.jpg").
+ /// is the 0-based index of the filter that should be selected by default.
+ /// Callback interface for asynchronous continuation of file dialog requests.
+ /// To display a custom dialog return true. To display the default dialog return false.
+ protected virtual bool OnFileDialog(
+ IWebBrowser chromiumWebBrowser,
+ IBrowser browser,
+ CefFileDialogMode mode,
+ CefFileDialogFlags flags,
+ string title,
+ string defaultFilePath,
+ List acceptFilters,
+ int selectedAcceptFilter,
+ IFileDialogCallback callback)
+ {
+ return false;
+ }
+ }
+}
diff --git a/CefSharp/Handler/DisplayHandler.cs b/CefSharp/Handler/DisplayHandler.cs
new file mode 100644
index 000000000..eaa549abc
--- /dev/null
+++ b/CefSharp/Handler/DisplayHandler.cs
@@ -0,0 +1,198 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+using CefSharp.Enums;
+using CefSharp.Structs;
+using System;
+using System.Collections.Generic;
+
+using Size = CefSharp.Structs.Size;
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Handle events related to browser display state.
+ ///
+ public class DisplayHandler : IDisplayHandler
+ {
+ ///
+ void IDisplayHandler.OnAddressChanged(IWebBrowser chromiumWebBrowser, AddressChangedEventArgs addressChangedArgs)
+ {
+ OnAddressChanged(chromiumWebBrowser, addressChangedArgs);
+ }
+
+ ///
+ /// Called when a frame's address has changed.
+ ///
+ /// the ChromiumWebBrowser control
+ /// args
+ protected virtual void OnAddressChanged(IWebBrowser chromiumWebBrowser, AddressChangedEventArgs addressChangedArgs)
+ {
+
+ }
+
+ ///
+ bool IDisplayHandler.OnAutoResize(IWebBrowser chromiumWebBrowser, IBrowser browser, Size newSize)
+ {
+ return OnAutoResize(chromiumWebBrowser, browser, newSize);
+ }
+
+ ///
+ /// Called when auto-resize is enabled via IBrowserHost.SetAutoResizeEnabled and the contents have auto-resized.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// will be the desired size in view coordinates
+ /// Return true if the resize was handled or false for default handling.
+ protected virtual bool OnAutoResize(IWebBrowser chromiumWebBrowser, IBrowser browser, Size newSize)
+ {
+ return false;
+ }
+
+ ///
+ bool IDisplayHandler.OnCursorChange(IWebBrowser chromiumWebBrowser, IBrowser browser, IntPtr cursor, CursorType type, CursorInfo customCursorInfo)
+ {
+ return OnCursorChange(chromiumWebBrowser, browser, cursor, type, customCursorInfo);
+ }
+
+ ///
+ /// Called when the browser's cursor has changed.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// If type is Custom then customCursorInfo will be populated with the custom cursor information
+ /// cursor type
+ /// custom cursor Information
+ /// Return true if the cursor change was handled or false for default handling.
+ protected virtual bool OnCursorChange(IWebBrowser chromiumWebBrowser, IBrowser browser, IntPtr cursor, CursorType type, CursorInfo customCursorInfo)
+ {
+ return false;
+ }
+
+ ///
+ void IDisplayHandler.OnTitleChanged(IWebBrowser chromiumWebBrowser, TitleChangedEventArgs titleChangedArgs)
+ {
+ OnTitleChanged(chromiumWebBrowser, titleChangedArgs);
+ }
+
+ ///
+ /// Called when the page title changes.
+ ///
+ /// the ChromiumWebBrowser control
+ /// args
+ protected virtual void OnTitleChanged(IWebBrowser chromiumWebBrowser, TitleChangedEventArgs titleChangedArgs)
+ {
+
+ }
+
+ ///
+ void IDisplayHandler.OnFaviconUrlChange(IWebBrowser chromiumWebBrowser, IBrowser browser, IList urls)
+ {
+ OnFaviconUrlChange(chromiumWebBrowser, browser, urls);
+ }
+
+ ///
+ /// Called when the page icon changes.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// list of urls where the favicons can be downloaded
+ protected virtual void OnFaviconUrlChange(IWebBrowser chromiumWebBrowser, IBrowser browser, IList urls)
+ {
+
+ }
+
+ ///
+ void IDisplayHandler.OnFullscreenModeChange(IWebBrowser chromiumWebBrowser, IBrowser browser, bool fullscreen)
+ {
+ OnFullscreenModeChange(chromiumWebBrowser, browser, fullscreen);
+ }
+
+ ///
+ /// Called when web content in the page has toggled fullscreen mode. The client is
+ /// responsible for resizing the browser if desired.
+ ///
+ /// The ChromiumWebBrowser control
+ /// the browser object
+ /// If true the content will automatically be sized to fill the browser content area.
+ /// If false the content will automatically return to its original size and position.
+ protected virtual void OnFullscreenModeChange(IWebBrowser chromiumWebBrowser, IBrowser browser, bool fullscreen)
+ {
+
+ }
+
+ ///
+ void IDisplayHandler.OnLoadingProgressChange(IWebBrowser chromiumWebBrowser, IBrowser browser, double progress)
+ {
+ OnLoadingProgressChange(chromiumWebBrowser, browser, progress);
+ }
+
+ ///
+ /// Called when the overall page loading progress has changed
+ ///
+ /// The ChromiumWebBrowser control
+ /// the browser object
+ /// ranges from 0.0 to 1.0.
+ protected virtual void OnLoadingProgressChange(IWebBrowser chromiumWebBrowser, IBrowser browser, double progress)
+ {
+
+ }
+
+ ///
+ bool IDisplayHandler.OnTooltipChanged(IWebBrowser chromiumWebBrowser, ref string text)
+ {
+ return OnTooltipChanged(chromiumWebBrowser, ref text);
+ }
+
+ ///
+ /// Called when the browser is about to display a tooltip. text contains the
+ /// text that will be displayed in the tooltip. You can optionally modify text
+ /// and then return false to allow the browser to display the tooltip.
+ /// When window rendering is disabled the application is responsible for
+ /// drawing tooltips and the return value is ignored.
+ ///
+ /// The ChromiumWebBrowser control
+ /// the text that will be displayed in the tooltip
+ /// To handle the display of the tooltip yourself return true otherwise return false
+ /// to allow the browser to display the tooltip.
+ /// Only called when using Off-screen rendering (WPF and OffScreen)
+ protected virtual bool OnTooltipChanged(IWebBrowser chromiumWebBrowser, ref string text)
+ {
+ return false;
+ }
+
+ ///
+ void IDisplayHandler.OnStatusMessage(IWebBrowser chromiumWebBrowser, StatusMessageEventArgs statusMessageArgs)
+ {
+
+ }
+
+ ///
+ /// Called when the browser receives a status message.
+ ///
+ /// The control this popup is related to.
+ /// args
+ protected virtual void OnStatusMessage(IWebBrowser chromiumWebBrowser, StatusMessageEventArgs statusMessageArgs)
+ {
+
+ }
+
+ ///
+ bool IDisplayHandler.OnConsoleMessage(IWebBrowser chromiumWebBrowser, ConsoleMessageEventArgs consoleMessageArgs)
+ {
+ return OnConsoleMessage(chromiumWebBrowser, consoleMessageArgs);
+ }
+
+ ///
+ /// Called to display a console message.
+ ///
+ /// The ChromiumWebBrowser control
+ /// args
+ /// Return true to stop the message from being output to the console.
+ protected virtual bool OnConsoleMessage(IWebBrowser chromiumWebBrowser, ConsoleMessageEventArgs consoleMessageArgs)
+ {
+ return false;
+ }
+ }
+}
diff --git a/CefSharp/Handler/DownloadHandler.cs b/CefSharp/Handler/DownloadHandler.cs
new file mode 100644
index 000000000..7cd6df3f2
--- /dev/null
+++ b/CefSharp/Handler/DownloadHandler.cs
@@ -0,0 +1,61 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Class used to handle file downloads.
+ /// The methods of this class will called on the CEF UI thread.
+ ///
+ public class DownloadHandler : IDownloadHandler
+ {
+ ///
+ /// Called before a download begins.
+ ///
+ /// the ChromiumWebBrowser control
+ /// The browser instance
+ /// Represents the file being downloaded.
+ /// Callback interface used to asynchronously continue a download.
+ void IDownloadHandler.OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
+ {
+ OnBeforeDownload(chromiumWebBrowser, browser, downloadItem, callback);
+ }
+
+ ///
+ /// Called before a download begins.
+ ///
+ /// the ChromiumWebBrowser control
+ /// The browser instance
+ /// Represents the file being downloaded.
+ /// Callback interface used to asynchronously continue a download.
+ protected virtual void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
+ {
+
+ }
+
+ ///
+ /// Called when a download's status or progress information has been updated. This may be called multiple times before and after .
+ ///
+ /// the ChromiumWebBrowser control
+ /// The browser instance
+ /// Represents the file being downloaded.
+ /// The callback used to Cancel/Pause/Resume the process
+ void IDownloadHandler.OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
+ {
+ OnDownloadUpdated(chromiumWebBrowser, browser, downloadItem, callback);
+ }
+
+ ///
+ /// Called when a download's status or progress information has been updated. This may be called multiple times before and after .
+ ///
+ /// the ChromiumWebBrowser control
+ /// The browser instance
+ /// Represents the file being downloaded.
+ /// The callback used to Cancel/Pause/Resume the process
+ protected virtual void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
+ {
+
+ }
+ }
+}
diff --git a/CefSharp/Handler/DragHandler .cs b/CefSharp/Handler/DragHandler .cs
new file mode 100644
index 000000000..7eb6608ff
--- /dev/null
+++ b/CefSharp/Handler/DragHandler .cs
@@ -0,0 +1,72 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+using System.Collections.Generic;
+using CefSharp.Enums;
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Inherit from this class to handle events related to dragging.
+ /// The methods of this class will be called on the UI thread.
+ ///
+ public class DragHandler : IDragHandler
+ {
+ ///
+ /// Called when an external drag event enters the browser window.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// contains the drag event data
+ /// represents the type of drag operation
+ /// Return false for default drag handling behavior or true to cancel the drag event.
+ bool IDragHandler.OnDragEnter(IWebBrowser chromiumWebBrowser, IBrowser browser, IDragData dragData, DragOperationsMask mask)
+ {
+ return OnDragEnter(chromiumWebBrowser, browser, dragData, mask);
+ }
+
+ ///
+ /// Called when an external drag event enters the browser window.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// contains the drag event data
+ /// represents the type of drag operation
+ /// Return false for default drag handling behavior or true to cancel the drag event.
+ protected virtual bool OnDragEnter(IWebBrowser chromiumWebBrowser, IBrowser browser, IDragData dragData, DragOperationsMask mask)
+ {
+ return false;
+ }
+
+ ///
+ /// Called whenever draggable regions for the browser window change.
+ /// These can be specified using the '-webkit-app-region: drag/no-drag' CSS-property.
+ /// If draggable regions are never defined in a document this method will also never be called.
+ /// If the last draggable region is removed from a document this method will be called with an empty IList.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// The frame
+ /// List of objects or null if last region was removed.
+ void IDragHandler.OnDraggableRegionsChanged(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IList regions)
+ {
+ OnDraggableRegionsChanged(chromiumWebBrowser, browser, frame, regions);
+ }
+
+ ///
+ /// Called whenever draggable regions for the browser window change.
+ /// These can be specified using the '-webkit-app-region: drag/no-drag' CSS-property.
+ /// If draggable regions are never defined in a document this method will also never be called.
+ /// If the last draggable region is removed from a document this method will be called with an empty IList.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// The frame
+ /// List of objects or null if last region was removed.
+ protected virtual void OnDraggableRegionsChanged(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IList regions)
+ {
+
+ }
+ }
+}
diff --git a/CefSharp/Handler/ExtensionHandler .cs b/CefSharp/Handler/ExtensionHandler .cs
new file mode 100644
index 000000000..04f62a4dd
--- /dev/null
+++ b/CefSharp/Handler/ExtensionHandler .cs
@@ -0,0 +1,261 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+using System;
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Implement this interface to handle events related to browser extensions.
+ /// The methods of this class will be called on the CEF UI thread.
+ /// See for information about extension loading.
+ ///
+ public class ExtensionHandler : IExtensionHandler
+ {
+ private bool isDisposed;
+
+ ///
+ /// Called if the request fails.
+ ///
+ /// error code
+ void IExtensionHandler.OnExtensionLoadFailed(CefErrorCode errorCode)
+ {
+ OnExtensionLoadFailed(errorCode);
+ }
+
+ ///
+ /// Called if the request fails.
+ ///
+ /// error code
+ protected virtual void OnExtensionLoadFailed(CefErrorCode errorCode)
+ {
+
+ }
+
+ ///
+ /// Called if the request succeeds.
+ ///
+ /// is the loaded extension.
+ void IExtensionHandler.OnExtensionLoaded(IExtension extension)
+ {
+ OnExtensionLoaded(extension);
+ }
+
+ ///
+ /// Called if the request succeeds.
+ ///
+ /// is the loaded extension.
+ protected virtual void OnExtensionLoaded(IExtension extension)
+ {
+
+ }
+
+ ///
+ /// Called after the IExtension.Unload request has completed.
+ ///
+ /// is the unloaded extension
+ void IExtensionHandler.OnExtensionUnloaded(IExtension extension)
+ {
+ OnExtensionUnloaded(extension);
+ }
+
+ ///
+ /// Called after the IExtension.Unload request has completed.
+ ///
+ /// is the unloaded extension
+ protected virtual void OnExtensionUnloaded(IExtension extension)
+ {
+
+ }
+
+ ///
+ /// Called when an extension needs a browser to host a background script specified via the "background" manifest key.
+ /// The browser will have no visible window and cannot be displayed. To allow creation of the browser optionally
+ /// modify newBrowser and settings and return false. To cancel creation of the browser
+ /// (and consequently cancel load of the background script) return true. Successful creation will be indicated by a call to
+ /// ILifeSpanHandler.OnAfterCreated, and IBrowserHost.IsBackgroundHost
+ /// will return true for the resulting browser. See https://developer.chrome.com/extensions/event_pages for more information
+ /// about extension background script usage.
+ ///
+ /// is the extension that is loading the background script
+ /// is an internally generated reference to an HTML page that will be used to
+ /// load the background script via a script src attribute
+ /// browser settings
+ /// To cancel creation of the browser (and consequently cancel load of the background script) return true, otherwise return false.
+ bool IExtensionHandler.OnBeforeBackgroundBrowser(IExtension extension, string url, IBrowserSettings settings)
+ {
+ return OnBeforeBackgroundBrowser(extension, url, settings);
+ }
+
+ ///
+ /// Called when an extension needs a browser to host a background script specified via the "background" manifest key.
+ /// The browser will have no visible window and cannot be displayed. To allow creation of the browser optionally
+ /// modify newBrowser and settings and return false. To cancel creation of the browser
+ /// (and consequently cancel load of the background script) return true. Successful creation will be indicated by a call to
+ /// ILifeSpanHandler.OnAfterCreated, and IBrowserHost.IsBackgroundHost
+ /// will return true for the resulting browser. See https://developer.chrome.com/extensions/event_pages for more information
+ /// about extension background script usage.
+ ///
+ /// is the extension that is loading the background script
+ /// is an internally generated reference to an HTML page that will be used to
+ /// load the background script via a script src attribute
+ /// browser settings
+ /// To cancel creation of the browser (and consequently cancel load of the background script) return true, otherwise return false.
+ protected virtual bool OnBeforeBackgroundBrowser(IExtension extension, string url, IBrowserSettings settings)
+ {
+ return false;
+ }
+
+ ///
+ /// Called when an extension API (e.g. chrome.tabs.create) requests creation of a new browser.
+ /// Successful creation will be indicated by a call to .
+ ///
+ /// the source of the API call
+ /// the source of the API call
+ /// may optionally be specified via the windowId property or
+ /// returned via the GetActiveBrowser() callback and provides the default for the new browser
+ /// is the position value optionally specified via the index property
+ /// is the URL that will be loaded in the browser
+ /// is true if the new browser should be active when opened
+ /// optionally modify if you are going to allow creation of the browser
+ /// optionally modify browser settings
+ /// To cancel creation of the browser return true. To allow creation return false and optionally modify windowInfo and settings
+ bool IExtensionHandler.OnBeforeBrowser(IExtension extension, IBrowser browser, IBrowser activeBrowser, int index, string url, bool active, IWindowInfo windowInfo, IBrowserSettings settings)
+ {
+ return OnBeforeBrowser(extension, browser, activeBrowser, index, url, active, windowInfo, settings);
+ }
+
+ ///
+ /// Called when an extension API (e.g. chrome.tabs.create) requests creation of a new browser.
+ /// Successful creation will be indicated by a call to .
+ ///
+ /// the source of the API call
+ /// the source of the API call
+ /// may optionally be specified via the windowId property or
+ /// returned via the GetActiveBrowser() callback and provides the default for the new browser
+ /// is the position value optionally specified via the index property
+ /// is the URL that will be loaded in the browser
+ /// is true if the new browser should be active when opened
+ /// optionally modify if you are going to allow creation of the browser
+ /// optionally modify browser settings
+ /// To cancel creation of the browser return true. To allow creation return false and optionally modify windowInfo and settings
+ protected virtual bool OnBeforeBrowser(IExtension extension, IBrowser browser, IBrowser activeBrowser, int index, string url, bool active, IWindowInfo windowInfo, IBrowserSettings settings)
+ {
+ return false;
+ }
+
+ ///
+ /// Called when no tabId is specified to an extension API call that accepts a tabId parameter (e.g. chrome.tabs.*).
+ ///
+ /// extension the call originates from
+ /// browser the call originates from
+ /// Incognito browsers should not be considered unless the source extension has incognito
+ /// access enabled, inwhich case this will be true
+ /// Return the browser that will be acted on by the API call or return null to act on .
+ /// The returned browser must share the same IRequestContext as
+ IBrowser IExtensionHandler.GetActiveBrowser(IExtension extension, IBrowser browser, bool includeIncognito)
+ {
+ return GetActiveBrowser(extension, browser, includeIncognito);
+ }
+
+ ///
+ /// Called when no tabId is specified to an extension API call that accepts a tabId parameter (e.g. chrome.tabs.*).
+ ///
+ /// extension the call originates from
+ /// browser the call originates from
+ /// Incognito browsers should not be considered unless the source extension has incognito
+ /// access enabled, inwhich case this will be true
+ /// Return the browser that will be acted on by the API call or return null to act on .
+ /// The returned browser must share the same IRequestContext as
+ protected virtual IBrowser GetActiveBrowser(IExtension extension, IBrowser browser, bool includeIncognito)
+ {
+ return null;
+ }
+
+ ///
+ /// Called when the tabId associated with is specified to an extension API call that accepts a tabId
+ /// parameter (e.g. chrome.tabs.*).
+ ///
+ /// extension the call originates from
+ /// browser the call originates from
+ /// Access to incognito browsers should not be allowed unless the source extension has
+ /// incognito access
+ /// enabled, in which case this will be true.
+ ///
+ /// Return true to allow access of false to deny access.
+ bool IExtensionHandler.CanAccessBrowser(IExtension extension, IBrowser browser, bool includeIncognito, IBrowser targetBrowser)
+ {
+ return CanAccessBrowser(extension, browser, includeIncognito, targetBrowser);
+ }
+
+ ///
+ /// Called when the tabId associated with is specified to an extension API call that accepts a tabId
+ /// parameter (e.g. chrome.tabs.*).
+ ///
+ /// extension the call originates from
+ /// browser the call originates from
+ /// Access to incognito browsers should not be allowed unless the source extension has
+ /// incognito access
+ /// enabled, in which case this will be true.
+ ///
+ /// Return true to allow access of false to deny access.
+ protected virtual bool CanAccessBrowser(IExtension extension, IBrowser browser, bool includeIncognito, IBrowser targetBrowser)
+ {
+ return false;
+ }
+
+ ///
+ /// Called to retrieve an extension resource that would normally be loaded from disk
+ /// (e.g. if a file parameter is specified to chrome.tabs.executeScript).
+ /// Localization substitutions will not be applied to resources handled via this method.
+ ///
+ /// extension the call originates from
+ /// browser the call originates from
+ /// is the requested relative file path.
+ /// callback used to handle custom resource requests
+ /// To handle the resource request return true and execute either synchronously or asynchronously.
+ /// For the default behavior which reads the resource from the extension directory on disk return false
+ bool IExtensionHandler.GetExtensionResource(IExtension extension, IBrowser browser, string file, IGetExtensionResourceCallback callback)
+ {
+ return GetExtensionResource(extension, browser, file, callback);
+ }
+
+ ///
+ /// Called to retrieve an extension resource that would normally be loaded from disk
+ /// (e.g. if a file parameter is specified to chrome.tabs.executeScript).
+ /// Localization substitutions will not be applied to resources handled via this method.
+ ///
+ /// extension the call originates from
+ /// browser the call originates from
+ /// is the requested relative file path.
+ /// callback used to handle custom resource requests
+ /// To handle the resource request return true and execute either synchronously or asynchronously.
+ /// For the default behavior which reads the resource from the extension directory on disk return false
+ protected virtual bool GetExtensionResource(IExtension extension, IBrowser browser, string file, IGetExtensionResourceCallback callback)
+ {
+ return false;
+ }
+
+ ///
+ /// IsDisposed
+ ///
+ public bool IsDisposed
+ {
+ get { return isDisposed; }
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ isDisposed = true;
+ }
+
+ ///
+ void IDisposable.Dispose()
+ {
+ // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
+ }
+ }
+}
diff --git a/CefSharp/Handler/FindHandler.cs b/CefSharp/Handler/FindHandler.cs
new file mode 100644
index 000000000..ab8feb007
--- /dev/null
+++ b/CefSharp/Handler/FindHandler.cs
@@ -0,0 +1,45 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+using CefSharp.Structs;
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Implement this interface to handle events related to find results.
+ /// The methods of this class will be called on the CEF UI thread.
+ ///
+ public class FindHandler : IFindHandler
+ {
+ ///
+ /// Called to report find results returned by
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// is the identifier passed to Find()
+ /// is the number of matches currently identified
+ /// is the location of where the match was found (in window coordinates)
+ /// is the current position in the search results
+ /// is true if this is the last find notification.
+ void IFindHandler.OnFindResult(IWebBrowser chromiumWebBrowser, IBrowser browser, int identifier, int count, Rect selectionRect, int activeMatchOrdinal, bool finalUpdate)
+ {
+ OnFindResult(chromiumWebBrowser, browser, identifier, count, selectionRect, activeMatchOrdinal, finalUpdate);
+ }
+
+ ///
+ /// Called to report find results returned by
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// is the identifier passed to Find()
+ /// is the number of matches currently identified
+ /// is the location of where the match was found (in window coordinates)
+ /// is the current position in the search results
+ /// is true if this is the last find notification.
+ protected virtual void OnFindResult(IWebBrowser chromiumWebBrowser, IBrowser browser, int identifier, int count, Rect selectionRect, int activeMatchOrdinal, bool finalUpdate)
+ {
+
+ }
+ }
+}
diff --git a/CefSharp/Handler/FocusHandler.cs b/CefSharp/Handler/FocusHandler.cs
new file mode 100644
index 000000000..a4049ec5d
--- /dev/null
+++ b/CefSharp/Handler/FocusHandler.cs
@@ -0,0 +1,83 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Implement this interface to handle events related to focus.
+ /// The methods of this class will be called on the CEF UI thread.
+ ///
+ public class FocusHandler : IFocusHandler
+ {
+ ///
+ /// Called when the browser component has received focus.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ void IFocusHandler.OnGotFocus(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+ OnGotFocus(chromiumWebBrowser, browser);
+ }
+
+ ///
+ /// Called when the browser component has received focus.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ protected virtual void OnGotFocus(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+
+ }
+
+ ///
+ /// Called when the browser component is requesting focus.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object, do not keep a reference to this object outside of this method
+ /// Indicates where the focus request is originating from.
+ /// Return false to allow the focus to be set or true to cancel setting the focus.
+ bool IFocusHandler.OnSetFocus(IWebBrowser chromiumWebBrowser, IBrowser browser, CefFocusSource source)
+ {
+ return OnSetFocus(chromiumWebBrowser, browser, source);
+ }
+
+ ///
+ /// Called when the browser component is requesting focus.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object, do not keep a reference to this object outside of this method
+ /// Indicates where the focus request is originating from.
+ /// Return false to allow the focus to be set or true to cancel setting the focus.
+ protected virtual bool OnSetFocus(IWebBrowser chromiumWebBrowser, IBrowser browser, CefFocusSource source)
+ {
+ return false;
+ }
+
+ ///
+ /// Called when the browser component is about to lose focus.
+ /// For instance, if focus was on the last HTML element and the user pressed the TAB key.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// Will be true if the browser is giving focus to the next component
+ /// and false if the browser is giving focus to the previous component.
+ void IFocusHandler.OnTakeFocus(IWebBrowser chromiumWebBrowser, IBrowser browser, bool next)
+ {
+ OnTakeFocus(chromiumWebBrowser, browser, next);
+ }
+
+ ///
+ /// Called when the browser component is about to lose focus.
+ /// For instance, if focus was on the last HTML element and the user pressed the TAB key.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// Will be true if the browser is giving focus to the next component
+ /// and false if the browser is giving focus to the previous component.
+ protected virtual void OnTakeFocus(IWebBrowser chromiumWebBrowser, IBrowser browser, bool next)
+ {
+
+ }
+ }
+}
diff --git a/CefSharp/Handler/JsDialogHandler.cs b/CefSharp/Handler/JsDialogHandler.cs
new file mode 100644
index 000000000..f655d61f9
--- /dev/null
+++ b/CefSharp/Handler/JsDialogHandler.cs
@@ -0,0 +1,125 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Inherit from this class to handle events related to JavaScript dialogs.
+ /// The methods of this class will be called on the CEF UI thread.
+ ///
+ public class JsDialogHandler : IJsDialogHandler
+ {
+ ///
+ /// Called to run a JavaScript dialog.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// originating url
+ /// Dialog Type
+ /// Message Text
+ /// value will be specified for prompt dialogs only
+ /// Callback can be executed inline or in an async fashion
+ /// Set suppressMessage to true and return false to suppress the message (suppressing messages is preferable to immediately executing the callback as this is used to detect presumably malicious behavior like spamming alert messages in onbeforeunload). Set suppressMessage to false and return false to use the default implementation (the default implementation will show one modal dialog at a time and suppress any additional dialog requests until the displayed dialog is dismissed).
+ /// Return true if the application will use a custom dialog or if the callback has been executed immediately. Custom dialogs may be either modal or modeless. If a custom dialog is used the application must execute |callback| once the custom dialog is dismissed.
+ bool IJsDialogHandler.OnJSDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage)
+ {
+ return OnJSDialog(chromiumWebBrowser, browser, originUrl, dialogType, messageText, defaultPromptText, callback, ref suppressMessage);
+ }
+
+ ///
+ /// Called to run a JavaScript dialog.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// originating url
+ /// Dialog Type
+ /// Message Text
+ /// value will be specified for prompt dialogs only
+ /// Callback can be executed inline or in an async fashion
+ /// Set suppressMessage to true and return false to suppress the message (suppressing messages is preferable to immediately executing the callback as this is used to detect presumably malicious behavior like spamming alert messages in onbeforeunload). Set suppressMessage to false and return false to use the default implementation (the default implementation will show one modal dialog at a time and suppress any additional dialog requests until the displayed dialog is dismissed).
+ /// Return true if the application will use a custom dialog or if the callback has been executed immediately. Custom dialogs may be either modal or modeless. If a custom dialog is used the application must execute |callback| once the custom dialog is dismissed.
+ protected virtual bool OnJSDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage)
+ {
+ return false;
+ }
+
+ ///
+ /// Called to run a dialog asking the user if they want to leave a page. Return false to use the default dialog implementation.
+ /// Return true if the application will use a custom dialog or if the callback has been executed immediately.
+ /// Custom dialogs may be either modal or modeless. If a custom dialog is used the application must execute
+ /// once the custom dialog is dismissed.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// message text (optional)
+ /// indicates a page reload
+ /// Callback can be executed inline or in an async fashion
+ /// Return false to use the default dialog implementation otherwise return true to handle with your own custom implementation.
+ bool IJsDialogHandler.OnBeforeUnloadDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string messageText, bool isReload, IJsDialogCallback callback)
+ {
+ return OnBeforeUnloadDialog(chromiumWebBrowser, browser, messageText, isReload, callback);
+ }
+
+ ///
+ /// Called to run a dialog asking the user if they want to leave a page. Return false to use the default dialog implementation.
+ /// Return true if the application will use a custom dialog or if the callback has been executed immediately.
+ /// Custom dialogs may be either modal or modeless. If a custom dialog is used the application must execute
+ /// once the custom dialog is dismissed.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ /// message text (optional)
+ /// indicates a page reload
+ /// Callback can be executed inline or in an async fashion
+ /// Return false to use the default dialog implementation otherwise return true to handle with your own custom implementation.
+ protected virtual bool OnBeforeUnloadDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, string messageText, bool isReload, IJsDialogCallback callback)
+ {
+ return false;
+ }
+
+ ///
+ /// Called to cancel any pending dialogs and reset any saved dialog state. Will
+ /// be called due to events like page navigation irregardless of whether any
+ /// dialogs are currently pending.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ void IJsDialogHandler.OnResetDialogState(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+ OnResetDialogState(chromiumWebBrowser, browser);
+ }
+
+ ///
+ /// Called to cancel any pending dialogs and reset any saved dialog state. Will
+ /// be called due to events like page navigation irregardless of whether any
+ /// dialogs are currently pending.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ protected virtual void OnResetDialogState(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+
+ }
+
+ ///
+ /// Called when the default implementation dialog is closed.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ void IJsDialogHandler.OnDialogClosed(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+ OnDialogClosed(chromiumWebBrowser, browser);
+ }
+
+ ///
+ /// Called when the default implementation dialog is closed.
+ ///
+ /// the ChromiumWebBrowser control
+ /// the browser object
+ protected virtual void OnDialogClosed(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+
+ }
+ }
+}
diff --git a/CefSharp/Handler/KeyboardHandler.cs b/CefSharp/Handler/KeyboardHandler.cs
new file mode 100644
index 000000000..f62802cc6
--- /dev/null
+++ b/CefSharp/Handler/KeyboardHandler.cs
@@ -0,0 +1,118 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Inherit from this class to handle events related to keyboard input.
+ ///
+ public class KeyboardHandler : IKeyboardHandler
+ {
+ ///
+ /// Called before a keyboard event is sent to the renderer.
+ /// Return true if the event was handled or false
+ /// otherwise. If the event will be handled in as a keyboard
+ /// shortcut set isKeyboardShortcut to true and return false.
+ ///
+ /// the ChromiumWebBrowser control
+ /// The browser instance.
+ /// Whether this was a key up/down/raw/etc...
+ ///
+ /// The Windows key code for the key event. This value is used by the DOM
+ /// specification. Sometimes it comes directly from the event (i.e. on
+ /// Windows) and sometimes it's determined using a mapping function. See
+ /// WebCore/platform/chromium/KeyboardCodes.h for the list of values.
+ ///
+ /// The native key code. On Windows this appears to be in the format of WM_KEYDOWN/WM_KEYUP/etc... lParam data.
+ /// What other modifier keys are currently down: Shift/Control/Alt/OS X Command/etc...
+ ///
+ /// Indicates whether the event is considered a "system key" event (see
+ /// http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for details).
+ ///
+ /// See the summary for an explanation of when to set this to true.
+ /// Returns true if the event was handled or false otherwise.
+ bool IKeyboardHandler.OnPreKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
+ {
+ return OnPreKeyEvent(chromiumWebBrowser, browser, type, windowsKeyCode, nativeKeyCode, modifiers, isSystemKey, ref isKeyboardShortcut);
+ }
+
+ ///
+ /// Called before a keyboard event is sent to the renderer.
+ /// Return true if the event was handled or false
+ /// otherwise. If the event will be handled in as a keyboard
+ /// shortcut set isKeyboardShortcut to true and return false.
+ ///
+ /// the ChromiumWebBrowser control
+ /// The browser instance.
+ /// Whether this was a key up/down/raw/etc...
+ ///
+ /// The Windows key code for the key event. This value is used by the DOM
+ /// specification. Sometimes it comes directly from the event (i.e. on
+ /// Windows) and sometimes it's determined using a mapping function. See
+ /// WebCore/platform/chromium/KeyboardCodes.h for the list of values.
+ ///
+ /// The native key code. On Windows this appears to be in the format of WM_KEYDOWN/WM_KEYUP/etc... lParam data.
+ /// What other modifier keys are currently down: Shift/Control/Alt/OS X Command/etc...
+ ///
+ /// Indicates whether the event is considered a "system key" event (see
+ /// http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for details).
+ ///
+ /// See the summary for an explanation of when to set this to true.
+ /// Returns true if the event was handled or false otherwise.
+ protected virtual bool OnPreKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
+ {
+ return false;
+ }
+
+ ///
+ /// Called after the renderer and JavaScript in the page has had a chance to
+ /// handle the event. Return true if the keyboard event was handled or false otherwise.
+ ///
+ /// the ChromiumWebBrowser control
+ /// The browser instance.
+ /// Whether this was a key up/down/raw/etc...
+ ///
+ /// The Windows key code for the key event. This value is used by the DOM
+ /// specification. Sometimes it comes directly from the event (i.e. on
+ /// Windows) and sometimes it's determined using a mapping function. See
+ /// WebCore/platform/chromium/KeyboardCodes.h for the list of values.
+ ///
+ /// The native key code. On Windows this appears to be in the format of WM_KEYDOWN/WM_KEYUP/etc... lParam data.
+ /// What other modifier keys are currently down: Shift/Control/Alt/OS X Command/etc...
+ ///
+ /// Indicates whether the event is considered a "system key" event (see
+ /// http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for details).
+ ///
+ /// Return true if the keyboard event was handled or false otherwise.
+ bool IKeyboardHandler.OnKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
+ {
+ return OnKeyEvent(chromiumWebBrowser, browser, type, windowsKeyCode, nativeKeyCode, modifiers, isSystemKey);
+ }
+
+ ///
+ /// Called after the renderer and JavaScript in the page has had a chance to
+ /// handle the event. Return true if the keyboard event was handled or false otherwise.
+ ///
+ /// the ChromiumWebBrowser control
+ /// The browser instance.
+ /// Whether this was a key up/down/raw/etc...
+ ///
+ /// The Windows key code for the key event. This value is used by the DOM
+ /// specification. Sometimes it comes directly from the event (i.e. on
+ /// Windows) and sometimes it's determined using a mapping function. See
+ /// WebCore/platform/chromium/KeyboardCodes.h for the list of values.
+ ///
+ /// The native key code. On Windows this appears to be in the format of WM_KEYDOWN/WM_KEYUP/etc... lParam data.
+ /// What other modifier keys are currently down: Shift/Control/Alt/OS X Command/etc...
+ ///
+ /// Indicates whether the event is considered a "system key" event (see
+ /// http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for details).
+ ///
+ /// Return true if the keyboard event was handled or false otherwise.
+ protected virtual bool OnKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
+ {
+ return false;
+ }
+ }
+}
diff --git a/CefSharp/Handler/LifeSpanHandler.cs b/CefSharp/Handler/LifeSpanHandler.cs
new file mode 100644
index 000000000..dc56c9298
--- /dev/null
+++ b/CefSharp/Handler/LifeSpanHandler.cs
@@ -0,0 +1,180 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Default implementation of . This class provides default implementations of the methods from
+ /// , therefore providing a convenience base class for a custom implementation.
+ /// You need only override the methods you require.
+ /// IMPORTANT: behaviour of this implementation differs
+ /// from the default, the WM_CLOSE message is only sent by default for popups (return false), for the main browser
+ /// we return true to cancel this behaviour.
+ ///
+ ///
+ public class LifeSpanHandler : ILifeSpanHandler
+ {
+ ///
+ bool ILifeSpanHandler.DoClose(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+ return DoClose(chromiumWebBrowser, browser);
+ }
+
+ ///
+ /// Called when a browser has recieved a request to close. This may result
+ /// directly from a call to CefBrowserHost::CloseBrowser() or indirectly if the
+ /// browser is a top-level OS window created by CEF and the user attempts to
+ /// close the window. This method will be called after the JavaScript
+ /// 'onunload' event has been fired. It will not be called for browsers after
+ /// the associated OS window has been destroyed (for those browsers it is no
+ /// longer possible to cancel the close).
+ ///
+ /// If CEF created an OS window for the browser returning false will send an OS
+ /// close notification to the browser window's top-level owner (e.g. WM_CLOSE
+ /// on Windows). If no OS window exists (window rendering disabled) returning false
+ /// will cause the browser object to be destroyed immediately. Return true if
+ /// the browser is parented to another window and that other window needs to
+ /// receive close notification via some non-standard technique.
+ ///
+ /// !!IMPORTANT!!: Behaviour of this implementation differs from the default,
+ /// the WM_CLOSE message is only sent by default for popups (return false),
+ /// for the main browser we return true to cancel this behaviour.
+ ///
+ /// If an application provides its own top-level window it should handle OS
+ /// close notifications by calling CefBrowserHost::CloseBrowser(false) instead
+ /// of immediately closing (see the example below). This gives CEF an
+ /// opportunity to process the 'onbeforeunload' event and optionally cancel the
+ /// close before DoClose() is called.
+ ///
+ /// The CefLifeSpanHandler::OnBeforeClose() method will be called immediately
+ /// before the browser object is destroyed. The application should only exit
+ /// after OnBeforeClose() has been called for all existing browsers.
+ ///
+ /// If the browser represents a modal window and a custom modal loop
+ /// implementation was provided in CefLifeSpanHandler::RunModal() this callback
+ /// should be used to restore the opener window to a usable state.
+ ///
+ /// By way of example consider what should happen during window close when the
+ /// browser is parented to an application-provided top-level OS window.
+ /// 1. User clicks the window close button which sends an OS close
+ /// notification (e.g. WM_CLOSE on Windows, performClose: on OS-X and
+ /// "delete_event" on Linux).
+ /// 2. Application's top-level window receives the close notification and:
+ /// A. Calls CefBrowserHost::CloseBrowser(false).
+ /// B. Cancels the window close.
+ /// 3. JavaScript 'onbeforeunload' handler executes and shows the close
+ /// confirmation dialog (which can be overridden via
+ /// CefJSDialogHandler::OnBeforeUnloadDialog()).
+ /// 4. User approves the close.
+ /// 5. JavaScript 'onunload' handler executes.
+ /// 6. Application's DoClose() handler is called. Application will:
+ /// A. Set a flag to indicate that the next close attempt will be allowed.
+ /// B. Return false.
+ /// 7. CEF sends an OS close notification.
+ /// 8. Application's top-level window receives the OS close notification and
+ /// allows the window to close based on the flag from #6B.
+ /// 9. Browser OS window is destroyed.
+ /// 10. Application's CefLifeSpanHandler::OnBeforeClose() handler is called and
+ /// the browser object is destroyed.
+ /// 11. Application exits by calling CefQuitMessageLoop() if no other browsers
+ /// exist.
+ ///
+ /// the ChromiumWebBrowser control
+ /// The browser instance - check if IsDisposed as it's possible when the browser is disposing
+ /// For default behaviour return false
+ protected virtual bool DoClose(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+ //For popups by default are created by CEF and need to be closed via the default behaviour
+ //(Sending a WM_CLOSE message)
+ if (browser.IsPopup)
+ {
+ return false;
+ }
+
+ //For the main browser NO WM_CLOSE message will be sent.
+ return true;
+ }
+
+ ///
+ void ILifeSpanHandler.OnAfterCreated(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+ OnAfterCreated(chromiumWebBrowser, browser);
+ }
+
+ ///
+ /// Called after a new browser is created.
+ ///
+ /// the ChromiumWebBrowser control
+ /// The browser instance
+ protected virtual void OnAfterCreated(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+
+ }
+
+ ///
+ void ILifeSpanHandler.OnBeforeClose(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+ OnBeforeClose(chromiumWebBrowser, browser);
+ }
+
+ ///
+ /// Called before a CefBrowser window (either the main browser for ,
+ /// or one of its children)
+ ///
+ /// the ChromiumWebBrowser control
+ /// The browser instance
+ protected virtual void OnBeforeClose(IWebBrowser chromiumWebBrowser, IBrowser browser)
+ {
+
+ }
+
+ ///
+ 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);
+ }
+
+ ///
+ /// Called before a popup window is created.
+ ///
+ /// the ChromiumWebBrowser control
+ /// The browser instance that launched this popup.
+ /// The HTML frame that launched this popup.
+ /// The URL of the popup content. (This may be empty/null)
+ /// The name of the popup. (This may be empty/null)
+ /// The value indicates where the user intended to
+ /// open the popup (e.g. current tab, new tab, etc)
+ /// 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).
+ /// structure contains additional information about the requested popup window
+ /// window information
+ /// browser settings, defaults to source browsers
+ /// value indicates whether the new browser window should be scriptable
+ /// and in the same process as the source browser.
+ /// EXPERIMENTAL - A newly created browser that will host the popup. Set to null
+ /// for default behaviour.
+ /// To cancel creation of the popup window return true otherwise return false.
+ ///
+ /// 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.
+ ///
+ 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;
+ }
+ }
+}
diff --git a/CefSharp/Handler/LoadHandler.cs b/CefSharp/Handler/LoadHandler.cs
new file mode 100644
index 000000000..8745faf8c
--- /dev/null
+++ b/CefSharp/Handler/LoadHandler.cs
@@ -0,0 +1,144 @@
+// Copyright © 2021 The CefSharp Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+
+namespace CefSharp.Handler
+{
+ ///
+ /// Implement this interface to handle events related to browser load status.
+ /// The methods of this interface will be called on the CEF UI thread. Blocking in these methods
+ /// will likely cause your UI to become unresponsive and/or hang.
+ ///
+ public class LoadHandler : ILoadHandler
+ {
+ ///
+ /// Called when the loading state has changed. This callback will be executed twice
+ /// once when loading is initiated either programmatically or by user action,
+ /// and once when loading is terminated due to completion, cancellation of failure.
+ /// This method will be called on the CEF UI thread.
+ /// Blocking this thread will likely cause your UI to become unresponsive and/or hang.
+ ///
+ /// the ChromiumWebBrowser control
+ /// args
+ void ILoadHandler.OnLoadingStateChange(IWebBrowser chromiumWebBrowser, LoadingStateChangedEventArgs loadingStateChangedArgs)
+ {
+ OnLoadingStateChange(chromiumWebBrowser, loadingStateChangedArgs);
+ }
+
+ ///
+ /// Called when the loading state has changed. This callback will be executed twice
+ /// once when loading is initiated either programmatically or by user action,
+ /// and once when loading is terminated due to completion, cancellation of failure.
+ /// This method will be called on the CEF UI thread.
+ /// Blocking this thread will likely cause your UI to become unresponsive and/or hang.
+ ///
+ /// the ChromiumWebBrowser control
+ /// args
+ protected virtual void OnLoadingStateChange(IWebBrowser chromiumWebBrowser, LoadingStateChangedEventArgs loadingStateChangedArgs)
+ {
+
+ }
+
+ ///
+ /// Called when the browser begins loading a frame.
+ /// The value will never be empty
+ /// Check the method to see if this frame is the main frame.
+ /// Multiple frames may be loading at the same time. Sub-frames may start or continue loading after the main frame load has ended.
+ /// This method may not be called for a particular frame if the load request for that frame fails.
+ /// For notification of overall browser load status use instead.
+ /// This method will be called on the CEF UI thread.
+ /// Blocking this thread will likely cause your UI to become unresponsive and/or hang.
+ ///
+ /// the ChromiumWebBrowser control
+ /// args
+ /// Whilst thist may seem like a logical place to execute js, it's called before the DOM has been loaded, implement
+ /// as it's called when the underlying V8Context is created
+ /// (Only called for the main frame at this stage)
+ void ILoadHandler.OnFrameLoadStart(IWebBrowser chromiumWebBrowser, FrameLoadStartEventArgs frameLoadStartArgs)
+ {
+ OnFrameLoadStart(chromiumWebBrowser, frameLoadStartArgs);
+ }
+
+ ///
+ /// Called when the browser begins loading a frame.
+ /// The value will never be empty
+ /// Check the method to see if this frame is the main frame.
+ /// Multiple frames may be loading at the same time. Sub-frames may start or continue loading after the main frame load has ended.
+ /// This method may not be called for a particular frame if the load request for that frame fails.
+ /// For notification of overall browser load status use instead.
+ /// This method will be called on the CEF UI thread.
+ /// Blocking this thread will likely cause your UI to become unresponsive and/or hang.
+ ///
+ /// the ChromiumWebBrowser control
+ /// args
+ /// Whilst thist may seem like a logical place to execute js, it's called before the DOM has been loaded, implement
+ /// as it's called when the underlying V8Context is created
+ /// (Only called for the main frame at this stage)
+ protected virtual void OnFrameLoadStart(IWebBrowser chromiumWebBrowser, FrameLoadStartEventArgs frameLoadStartArgs)
+ {
+
+ }
+
+ ///
+ /// Called when the browser is done loading a frame.
+ /// The value will never be empty
+ /// Check the method to see if this frame is the main frame.
+ /// Multiple frames may be loading at the same time. Sub-frames may start or continue loading after the main frame load has ended.
+ /// This method will always be called for all frames irrespective of whether the request completes successfully.
+ /// This method will be called on the CEF UI thread.
+ /// Blocking this thread will likely cause your UI to become unresponsive and/or hang.
+ ///
+ /// the ChromiumWebBrowser control
+ /// args
+ void ILoadHandler.OnFrameLoadEnd(IWebBrowser chromiumWebBrowser, FrameLoadEndEventArgs frameLoadEndArgs)
+ {
+ OnFrameLoadEnd(chromiumWebBrowser, frameLoadEndArgs);
+ }
+
+ ///
+ /// Called when the browser is done loading a frame.
+ /// The value will never be empty
+ /// Check the method to see if this frame is the main frame.
+ /// Multiple frames may be loading at the same time. Sub-frames may start or continue loading after the main frame load has ended.
+ /// This method will always be called for all frames irrespective of whether the request completes successfully.
+ /// This method will be called on the CEF UI thread.
+ /// Blocking this thread will likely cause your UI to become unresponsive and/or hang.
+ ///
+ /// the ChromiumWebBrowser control
+ /// args
+ protected virtual void OnFrameLoadEnd(IWebBrowser chromiumWebBrowser, FrameLoadEndEventArgs frameLoadEndArgs)
+ {
+
+ }
+
+ ///
+ /// Called when the resource load for a navigation fails or is canceled.
+ /// is the error code number, is the error text and
+ /// is the URL that failed to load. See net\base\net_error_list.h
+ /// for complete descriptions of the error codes.
+ /// This method will be called on the CEF UI thread.
+ /// Blocking this thread will likely cause your UI to become unresponsive and/or hang.
+ ///
+ /// the ChromiumWebBrowser control
+ /// args
+ void ILoadHandler.OnLoadError(IWebBrowser chromiumWebBrowser, LoadErrorEventArgs loadErrorArgs)
+ {
+ OnLoadError(chromiumWebBrowser, loadErrorArgs);
+ }
+
+ ///
+ /// Called when the resource load for a navigation fails or is canceled.
+ /// is the error code number, is the error text and
+ /// is the URL that failed to load. See net\base\net_error_list.h
+ /// for complete descriptions of the error codes.
+ /// This method will be called on the CEF UI thread.
+ /// Blocking this thread will likely cause your UI to become unresponsive and/or hang.
+ ///
+ /// the ChromiumWebBrowser control
+ /// args
+ protected virtual void OnLoadError(IWebBrowser chromiumWebBrowser, LoadErrorEventArgs loadErrorArgs)
+ {
+
+ }
+ }
+}