Files
cefsharp/CefSharp/DevTools/IDevToolsClient.cs
T
Alex Maitland cf00a45833 DevTools Client - Simplify Strongly Typed Event handling (#3777)
* DevTools Client - Simplify Strongly Typed Event handling

Now it's only possible to register one System.Type per event.

- Remove RegisterEventHandler
- Add AddEventHandler and RemoveEventHandler
- Change constraint from DevToolsDomainEventArgsBase to EventArgs

https://github.com/cefsharp/CefSharp/issues/3666

* Changes were based on https://github.com/CefNet/CefNet.DevTools.Protocol

Add links to original source files

* Reset stream position

* AddEventHandler - Use GetOrAdd for Thread safety

* AddEventHandler - Fix double event handler registration for first call

* RemoveEventHandler - Remove IEventProxy when handler null
2021-09-03 20:10:42 +10:00

54 lines
2.9 KiB
C#

// Copyright © 2020 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 System.Collections.Generic;
using System.Threading.Tasks;
namespace CefSharp.DevTools
{
/// <summary>
/// DevTools Client
/// </summary>
public interface IDevToolsClient
{
/// <summary>
/// Will be called on receipt of a DevTools protocol event. Events by default are disabled and need to be
/// enabled on a per domain basis, e.g. Sending Network.enable (or calling <see cref="Network.NetworkClient.EnableAsync(int?, int?, int?)"/>)
/// to enable network related events.
/// </summary>
event EventHandler<DevToolsEventArgs> DevToolsEvent;
/// <summary>
/// Add event handler for a DevTools protocol event. Events by default are disabled and need to be
/// enabled on a per domain basis, e.g. Sending Network.enable (or calling <see cref="Network.NetworkClient.EnableAsync(int?, int?, int?)"/>)
/// to enable network related events.
/// </summary>
/// <typeparam name="T">The event args type to which the event will be deserialized to.</typeparam>
/// <param name="eventName">is the event name to listen to</param>
/// <param name="eventHandler">event handler to call when the event occurs</param>
void AddEventHandler<T>(string eventName, EventHandler<T> eventHandler) where T : EventArgs;
/// <summary>
/// Remove event handler for a DevTools protocol event.
/// </summary>
/// <typeparam name="T">The event args type to which the event will be deserialized to.</typeparam>
/// <param name="eventName">is the event name to listen to</param>
/// <param name="eventHandler">event handler to call when the event occurs</param>
void RemoveEventHandler<T>(string eventName, EventHandler<T> eventHandler) where T : EventArgs;
/// <summary>
/// Execute a method call over the DevTools protocol. This method can be called on any thread.
/// See the DevTools protocol documentation at https://chromedevtools.github.io/devtools-protocol/ for details
/// of supported methods and the expected <paramref name="parameters"/> dictionary contents.
/// </summary>
/// <typeparam name="T">The type to which the method result will be deserialzed to.</typeparam>
/// <param name="method">is the method name</param>
/// <param name="parameters">are the method parameters represented as a dictionary,
/// which may be empty.</param>
/// <returns>return a Task that can be awaited to obtain the method result</returns>
Task<T> ExecuteDevToolsMethodAsync<T>(string method, IDictionary<string, object> parameters = null) where T : DevToolsDomainResponseBase;
}
}