Skip to content

Commit 8e50068

Browse files
committed
Refactor so each module controls its own JSON serialization
1 parent 1307265 commit 8e50068

File tree

12 files changed

+196
-159
lines changed

12 files changed

+196
-159
lines changed

dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,69 +19,74 @@
1919

2020
using OpenQA.Selenium.BiDi.Communication;
2121
using System.Collections.Generic;
22+
using System.Text.Json;
2223
using System.Text.Json.Serialization;
2324
using System.Threading.Tasks;
2425

2526
namespace OpenQA.Selenium.BiDi.Browser;
2627

2728
public sealed class BrowserModule : Module
2829
{
30+
private BrowserModuleJsonSerializerContext _context = null!;
2931
public async Task<EmptyResult> CloseAsync(CloseOptions? options = null)
3032
{
31-
return await Broker.ExecuteCommandAsync<CloseCommand, EmptyResult>(new CloseCommand(), options).ConfigureAwait(false);
33+
return await Broker.ExecuteCommandAsync<CloseCommand, EmptyResult>(new CloseCommand(), options, _context).ConfigureAwait(false);
3234
}
3335

3436
public async Task<UserContextInfo> CreateUserContextAsync(CreateUserContextOptions? options = null)
3537
{
3638
var @params = new CreateUserContextParameters(options?.AcceptInsecureCerts, options?.Proxy, options?.UnhandledPromptBehavior);
3739

38-
return await Broker.ExecuteCommandAsync<CreateUserContextCommand, UserContextInfo>(new CreateUserContextCommand(@params), options).ConfigureAwait(false);
40+
return await Broker.ExecuteCommandAsync<CreateUserContextCommand, UserContextInfo>(new CreateUserContextCommand(@params), options, _context).ConfigureAwait(false);
3941
}
4042

4143
public async Task<GetUserContextsResult> GetUserContextsAsync(GetUserContextsOptions? options = null)
4244
{
43-
return await Broker.ExecuteCommandAsync<GetUserContextsCommand, GetUserContextsResult>(new GetUserContextsCommand(), options).ConfigureAwait(false);
45+
return await Broker.ExecuteCommandAsync<GetUserContextsCommand, GetUserContextsResult>(new GetUserContextsCommand(), options, _context).ConfigureAwait(false);
4446
}
4547

4648
public async Task<EmptyResult> RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null)
4749
{
4850
var @params = new RemoveUserContextParameters(userContext);
4951

50-
return await Broker.ExecuteCommandAsync<RemoveUserContextCommand, EmptyResult>(new RemoveUserContextCommand(@params), options).ConfigureAwait(false);
52+
return await Broker.ExecuteCommandAsync<RemoveUserContextCommand, EmptyResult>(new RemoveUserContextCommand(@params), options, _context).ConfigureAwait(false);
5153
}
5254

5355
public async Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindowsOptions? options = null)
5456
{
55-
return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options).ConfigureAwait(false);
57+
return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options, _context).ConfigureAwait(false);
5658
}
5759

5860
public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null)
5961
{
6062
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(destinationFolder), options?.UserContexts);
6163

62-
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
64+
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _context).ConfigureAwait(false);
6365
}
6466

6567
public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null)
6668
{
6769
var @params = new SetDownloadBehaviorParameters(null, options?.UserContexts);
6870

69-
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
71+
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _context).ConfigureAwait(false);
7072
}
7173

7274
public async Task<EmptyResult> SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null)
7375
{
7476
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorDenied(), options?.UserContexts);
7577

76-
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
78+
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _context).ConfigureAwait(false);
7779
}
7880

79-
protected internal override void Initialize(Broker broker)
81+
protected internal override void Initialize(JsonSerializerOptions options)
8082
{
81-
broker.ConfigureJsonContext(opts => opts.TypeInfoResolverChain.Add(BrowserModuleJsonSerializerContext.Default));
83+
_context = new BrowserModuleJsonSerializerContext(options);
8284
}
8385
}
8486

87+
[JsonSerializable(typeof(Command))]
88+
[JsonSerializable(typeof(EmptyResult))]
89+
8590
[JsonSerializable(typeof(CloseCommand))]
8691
[JsonSerializable(typeof(CreateUserContextCommand))]
8792
[JsonSerializable(typeof(GetUserContextsCommand))]

0 commit comments

Comments
 (0)