Skip to content

Commit 1fb3389

Browse files
committed
Hold json context per module
Forgot BrowserModule Unnecessary Command/EmptyResult types in context? Move BrowsingContext Move Session Move Storage Move WebExtension Move Script Move Network Move Log Move Emulation Move Input Delete global json context
1 parent 4a9fa75 commit 1fb3389

File tree

13 files changed

+359
-341
lines changed

13 files changed

+359
-341
lines changed

dotnet/src/webdriver/BiDi/BiDi.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ internal Session.SessionModule SessionModule
5555
if (_sessionModule is not null) return _sessionModule;
5656
lock (_moduleLock)
5757
{
58-
_sessionModule ??= Module.Create<Session.SessionModule>(_broker);
58+
_sessionModule ??= Module.Create<Session.SessionModule>(this, _broker);
5959
}
6060
return _sessionModule;
6161
}
@@ -68,7 +68,7 @@ public BrowsingContext.BrowsingContextModule BrowsingContext
6868
if (_browsingContextModule is not null) return _browsingContextModule;
6969
lock (_moduleLock)
7070
{
71-
_browsingContextModule ??= Module.Create<BrowsingContext.BrowsingContextModule>(_broker);
71+
_browsingContextModule ??= Module.Create<BrowsingContext.BrowsingContextModule>(this, _broker);
7272
}
7373
return _browsingContextModule;
7474
}
@@ -81,7 +81,7 @@ public Browser.BrowserModule Browser
8181
if (_browserModule is not null) return _browserModule;
8282
lock (_moduleLock)
8383
{
84-
_browserModule ??= Module.Create<Browser.BrowserModule>(_broker);
84+
_browserModule ??= Module.Create<Browser.BrowserModule>(this, _broker);
8585
}
8686
return _browserModule;
8787
}
@@ -94,7 +94,7 @@ public Network.NetworkModule Network
9494
if (_networkModule is not null) return _networkModule;
9595
lock (_moduleLock)
9696
{
97-
_networkModule ??= Module.Create<Network.NetworkModule>(_broker);
97+
_networkModule ??= Module.Create<Network.NetworkModule>(this, _broker);
9898
}
9999
return _networkModule;
100100
}
@@ -107,7 +107,7 @@ internal Input.InputModule InputModule
107107
if (_inputModule is not null) return _inputModule;
108108
lock (_moduleLock)
109109
{
110-
_inputModule ??= Module.Create<Input.InputModule>(_broker);
110+
_inputModule ??= Module.Create<Input.InputModule>(this, _broker);
111111
}
112112
return _inputModule;
113113
}
@@ -120,7 +120,7 @@ public Script.ScriptModule Script
120120
if (_scriptModule is not null) return _scriptModule;
121121
lock (_moduleLock)
122122
{
123-
_scriptModule ??= Module.Create<Script.ScriptModule>(_broker);
123+
_scriptModule ??= Module.Create<Script.ScriptModule>(this, _broker);
124124
}
125125
return _scriptModule;
126126
}
@@ -133,7 +133,7 @@ public Log.LogModule Log
133133
if (_logModule is not null) return _logModule;
134134
lock (_moduleLock)
135135
{
136-
_logModule ??= Module.Create<Log.LogModule>(_broker);
136+
_logModule ??= Module.Create<Log.LogModule>(this, _broker);
137137
}
138138
return _logModule;
139139
}
@@ -146,7 +146,7 @@ public Storage.StorageModule Storage
146146
if (_storageModule is not null) return _storageModule;
147147
lock (_moduleLock)
148148
{
149-
_storageModule ??= Module.Create<Storage.StorageModule>(_broker);
149+
_storageModule ??= Module.Create<Storage.StorageModule>(this, _broker);
150150
}
151151
return _storageModule;
152152
}
@@ -159,7 +159,7 @@ public WebExtension.WebExtensionModule WebExtension
159159
if (_webExtensionModule is not null) return _webExtensionModule;
160160
lock (_moduleLock)
161161
{
162-
_webExtensionModule ??= Module.Create<WebExtension.WebExtensionModule>(_broker);
162+
_webExtensionModule ??= Module.Create<WebExtension.WebExtensionModule>(this, _broker);
163163
}
164164
return _webExtensionModule;
165165
}
@@ -172,7 +172,7 @@ public Emulation.EmulationModule Emulation
172172
if (_emulationModule is not null) return _emulationModule;
173173
lock (_moduleLock)
174174
{
175-
_emulationModule ??= Module.Create<Emulation.EmulationModule>(_broker);
175+
_emulationModule ??= Module.Create<Emulation.EmulationModule>(this, _broker);
176176
}
177177
return _emulationModule;
178178
}

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,59 +27,61 @@ namespace OpenQA.Selenium.BiDi.Browser;
2727

2828
public sealed class BrowserModule : Module
2929
{
30+
private BrowserModuleJsonSerializerContext _jsonContext = null!;
31+
3032
public async Task<EmptyResult> CloseAsync(CloseOptions? options = null)
3133
{
32-
return await Broker.ExecuteCommandAsync<CloseCommand, EmptyResult>(new CloseCommand(), options, JsonContext).ConfigureAwait(false);
34+
return await Broker.ExecuteCommandAsync<CloseCommand, EmptyResult>(new CloseCommand(), options, _jsonContext).ConfigureAwait(false);
3335
}
3436

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

39-
return await Broker.ExecuteCommandAsync<CreateUserContextCommand, UserContextInfo>(new CreateUserContextCommand(@params), options, JsonContext).ConfigureAwait(false);
41+
return await Broker.ExecuteCommandAsync<CreateUserContextCommand, UserContextInfo>(new CreateUserContextCommand(@params), options, _jsonContext).ConfigureAwait(false);
4042
}
4143

4244
public async Task<GetUserContextsResult> GetUserContextsAsync(GetUserContextsOptions? options = null)
4345
{
44-
return await Broker.ExecuteCommandAsync<GetUserContextsCommand, GetUserContextsResult>(new GetUserContextsCommand(), options, JsonContext).ConfigureAwait(false);
46+
return await Broker.ExecuteCommandAsync<GetUserContextsCommand, GetUserContextsResult>(new GetUserContextsCommand(), options, _jsonContext).ConfigureAwait(false);
4547
}
4648

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

51-
return await Broker.ExecuteCommandAsync<RemoveUserContextCommand, EmptyResult>(new RemoveUserContextCommand(@params), options, JsonContext).ConfigureAwait(false);
53+
return await Broker.ExecuteCommandAsync<RemoveUserContextCommand, EmptyResult>(new RemoveUserContextCommand(@params), options, _jsonContext).ConfigureAwait(false);
5254
}
5355

5456
public async Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindowsOptions? options = null)
5557
{
56-
return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options, JsonContext).ConfigureAwait(false);
58+
return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options, _jsonContext).ConfigureAwait(false);
5759
}
5860

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

63-
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, JsonContext).ConfigureAwait(false);
65+
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _jsonContext).ConfigureAwait(false);
6466
}
6567

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

70-
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, JsonContext).ConfigureAwait(false);
72+
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _jsonContext).ConfigureAwait(false);
7173
}
7274

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

77-
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, JsonContext).ConfigureAwait(false);
79+
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _jsonContext).ConfigureAwait(false);
7880
}
7981

80-
protected internal override JsonSerializerContext ConfigureJson(JsonSerializerOptions options)
82+
protected internal override void Initialize(JsonSerializerOptions options)
8183
{
82-
return new BrowserModuleJsonSerializerContext(options);
84+
_jsonContext = new(options);
8385
}
8486
}
8587

0 commit comments

Comments
 (0)