Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions dotnet/src/webdriver/BiDi/BiDi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal Session.SessionModule SessionModule
if (_sessionModule is not null) return _sessionModule;
lock (_moduleLock)
{
_sessionModule ??= new Session.SessionModule(_broker);
_sessionModule ??= Module.Create<Session.SessionModule>(_broker);
}
return _sessionModule;
}
Expand All @@ -68,7 +68,7 @@ public BrowsingContext.BrowsingContextModule BrowsingContext
if (_browsingContextModule is not null) return _browsingContextModule;
lock (_moduleLock)
{
_browsingContextModule ??= new BrowsingContext.BrowsingContextModule(_broker);
_browsingContextModule ??= Module.Create<BrowsingContext.BrowsingContextModule>(_broker);
}
return _browsingContextModule;
}
Expand All @@ -81,7 +81,7 @@ public Browser.BrowserModule Browser
if (_browserModule is not null) return _browserModule;
lock (_moduleLock)
{
_browserModule ??= new Browser.BrowserModule(_broker);
_browserModule ??= Module.Create<Browser.BrowserModule>(_broker);
}
return _browserModule;
}
Expand All @@ -94,7 +94,7 @@ public Network.NetworkModule Network
if (_networkModule is not null) return _networkModule;
lock (_moduleLock)
{
_networkModule ??= new Network.NetworkModule(_broker);
_networkModule ??= Module.Create<Network.NetworkModule>(_broker);
}
return _networkModule;
}
Expand All @@ -107,7 +107,7 @@ internal Input.InputModule InputModule
if (_inputModule is not null) return _inputModule;
lock (_moduleLock)
{
_inputModule ??= new Input.InputModule(_broker);
_inputModule ??= Module.Create<Input.InputModule>(_broker);
}
return _inputModule;
}
Expand All @@ -120,7 +120,7 @@ public Script.ScriptModule Script
if (_scriptModule is not null) return _scriptModule;
lock (_moduleLock)
{
_scriptModule ??= new Script.ScriptModule(_broker);
_scriptModule ??= Module.Create<Script.ScriptModule>(_broker);
}
return _scriptModule;
}
Expand All @@ -133,7 +133,7 @@ public Log.LogModule Log
if (_logModule is not null) return _logModule;
lock (_moduleLock)
{
_logModule ??= new Log.LogModule(_broker);
_logModule ??= Module.Create<Log.LogModule>(_broker);
}
return _logModule;
}
Expand All @@ -146,7 +146,7 @@ public Storage.StorageModule Storage
if (_storageModule is not null) return _storageModule;
lock (_moduleLock)
{
_storageModule ??= new Storage.StorageModule(_broker);
_storageModule ??= Module.Create<Storage.StorageModule>(_broker);
}
return _storageModule;
}
Expand All @@ -159,7 +159,7 @@ public WebExtension.WebExtensionModule WebExtension
if (_webExtensionModule is not null) return _webExtensionModule;
lock (_moduleLock)
{
_webExtensionModule ??= new WebExtension.WebExtensionModule(_broker);
_webExtensionModule ??= Module.Create<WebExtension.WebExtensionModule>(_broker);
}
return _webExtensionModule;
}
Expand All @@ -172,7 +172,7 @@ public Emulation.EmulationModule Emulation
if (_emulationModule is not null) return _emulationModule;
lock (_moduleLock)
{
_emulationModule ??= new Emulation.EmulationModule(_broker);
_emulationModule ??= Module.Create<Emulation.EmulationModule>(_broker);
}
return _emulationModule;
}
Expand Down
45 changes: 35 additions & 10 deletions dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,85 @@
// under the License.
// </copyright>

using System.Threading.Tasks;
using OpenQA.Selenium.BiDi.Communication;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace OpenQA.Selenium.BiDi.Browser;

public sealed class BrowserModule(Broker broker) : Module(broker)
public sealed class BrowserModule : Module
{
private BrowserModuleJsonSerializerContext _context = null!;
public async Task<EmptyResult> CloseAsync(CloseOptions? options = null)
{
return await Broker.ExecuteCommandAsync<CloseCommand, EmptyResult>(new CloseCommand(), options).ConfigureAwait(false);
return await Broker.ExecuteCommandAsync<CloseCommand, EmptyResult>(new CloseCommand(), options, _context).ConfigureAwait(false);
}

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

return await Broker.ExecuteCommandAsync<CreateUserContextCommand, UserContextInfo>(new CreateUserContextCommand(@params), options).ConfigureAwait(false);
return await Broker.ExecuteCommandAsync<CreateUserContextCommand, UserContextInfo>(new CreateUserContextCommand(@params), options, _context).ConfigureAwait(false);
}

public async Task<GetUserContextsResult> GetUserContextsAsync(GetUserContextsOptions? options = null)
{
return await Broker.ExecuteCommandAsync<GetUserContextsCommand, GetUserContextsResult>(new GetUserContextsCommand(), options).ConfigureAwait(false);
return await Broker.ExecuteCommandAsync<GetUserContextsCommand, GetUserContextsResult>(new GetUserContextsCommand(), options, _context).ConfigureAwait(false);
}

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

return await Broker.ExecuteCommandAsync<RemoveUserContextCommand, EmptyResult>(new RemoveUserContextCommand(@params), options).ConfigureAwait(false);
return await Broker.ExecuteCommandAsync<RemoveUserContextCommand, EmptyResult>(new RemoveUserContextCommand(@params), options, _context).ConfigureAwait(false);
}

public async Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindowsOptions? options = null)
{
return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options).ConfigureAwait(false);
return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options, _context).ConfigureAwait(false);
}

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

return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _context).ConfigureAwait(false);
}

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

return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _context).ConfigureAwait(false);
}

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

return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _context).ConfigureAwait(false);
}

protected internal override void Initialize(JsonSerializerOptions options)
{
_context = new BrowserModuleJsonSerializerContext(options);
}
}

[JsonSerializable(typeof(Command))]
[JsonSerializable(typeof(EmptyResult))]

[JsonSerializable(typeof(CloseCommand))]
[JsonSerializable(typeof(CreateUserContextCommand))]
[JsonSerializable(typeof(GetUserContextsCommand))]
[JsonSerializable(typeof(GetUserContextsResult))]
[JsonSerializable(typeof(RemoveUserContextCommand))]
[JsonSerializable(typeof(GetClientWindowsCommand))]
[JsonSerializable(typeof(GetClientWindowsResult))]
[JsonSerializable(typeof(SetDownloadBehaviorCommand))]
[JsonSerializable(typeof(UserContextInfo))]
[JsonSerializable(typeof(IReadOnlyList<UserContextInfo>))]
[JsonSerializable(typeof(IReadOnlyList<ClientWindowInfo>))]
internal partial class BrowserModuleJsonSerializerContext : JsonSerializerContext;
Loading