Skip to content
Merged
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
27 changes: 11 additions & 16 deletions dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using System;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;

namespace OpenQA.Selenium.BiDi.BrowsingContext;
Expand All @@ -29,39 +30,33 @@ internal BrowsingContext(BiDi bidi, string id)
{
BiDi = bidi;
Id = id;

_logModule = new Lazy<BrowsingContextLogModule>(() => new BrowsingContextLogModule(this, BiDi.Log));
_networkModule = new Lazy<BrowsingContextNetworkModule>(() => new BrowsingContextNetworkModule(this, BiDi.Network));
_scriptModule = new Lazy<BrowsingContextScriptModule>(() => new BrowsingContextScriptModule(this, BiDi.Script));
_storageModule = new Lazy<BrowsingContextStorageModule>(() => new BrowsingContextStorageModule(this, BiDi.Storage));
_inputModule = new Lazy<BrowsingContextInputModule>(() => new BrowsingContextInputModule(this, BiDi.InputModule));
}

private readonly Lazy<BrowsingContextLogModule> _logModule;
private readonly Lazy<BrowsingContextNetworkModule> _networkModule;
private readonly Lazy<BrowsingContextScriptModule> _scriptModule;
private readonly Lazy<BrowsingContextStorageModule> _storageModule;
private readonly Lazy<BrowsingContextInputModule> _inputModule;
private BrowsingContextLogModule? _logModule;
private BrowsingContextNetworkModule? _networkModule;
private BrowsingContextScriptModule? _scriptModule;
private BrowsingContextStorageModule? _storageModule;
private BrowsingContextInputModule? _inputModule;

internal string Id { get; }

[JsonIgnore]
public BiDi BiDi { get; }

[JsonIgnore]
public BrowsingContextLogModule Log => _logModule.Value;
public BrowsingContextLogModule Log => _logModule ?? Interlocked.CompareExchange(ref _logModule, new BrowsingContextLogModule(this, BiDi.Log), null) ?? _logModule;

[JsonIgnore]
public BrowsingContextNetworkModule Network => _networkModule.Value;
public BrowsingContextNetworkModule Network => _networkModule ?? Interlocked.CompareExchange(ref _networkModule, new BrowsingContextNetworkModule(this, BiDi.Network), null) ?? _networkModule;

[JsonIgnore]
public BrowsingContextScriptModule Script => _scriptModule.Value;
public BrowsingContextScriptModule Script => _scriptModule ?? Interlocked.CompareExchange(ref _scriptModule, new BrowsingContextScriptModule(this, BiDi.Script), null) ?? _scriptModule;

[JsonIgnore]
public BrowsingContextStorageModule Storage => _storageModule.Value;
public BrowsingContextStorageModule Storage => _storageModule ?? Interlocked.CompareExchange(ref _storageModule, new BrowsingContextStorageModule(this, BiDi.Storage), null) ?? _storageModule;

[JsonIgnore]
public BrowsingContextInputModule Input => _inputModule.Value;
public BrowsingContextInputModule Input => _inputModule ?? Interlocked.CompareExchange(ref _inputModule, new BrowsingContextInputModule(this, BiDi.InputModule), null) ?? _inputModule;

public Task<NavigateResult> NavigateAsync(string url, NavigateOptions? options = null)
{
Expand Down