Skip to content

Commit

Permalink
chore: get rid of channels layer
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Dec 11, 2023
1 parent ba2e378 commit 47249a0
Show file tree
Hide file tree
Showing 70 changed files with 231 additions and 1,439 deletions.
5 changes: 2 additions & 3 deletions src/Playwright/Core/APIRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Playwright.Helpers;
using Microsoft.Playwright.Transport.Channels;

namespace Microsoft.Playwright.Core;

Expand Down Expand Up @@ -67,9 +66,9 @@ async Task<IAPIRequestContext> IAPIRequest.NewContextAsync(APIRequestNewContextO
args.Add("storageState", JsonSerializer.Deserialize<StorageState>(storageState, Helpers.JsonExtensions.DefaultJsonSerializerOptions));
}

var context = (await _playwright.SendMessageToServerAsync<APIRequestContextChannel>(
var context = await _playwright.SendMessageToServerAsync<APIRequestContext>(
"newRequest",
args).ConfigureAwait(false)).Object;
args).ConfigureAwait(false);
context._request = this;
return context;
}
Expand Down
11 changes: 2 additions & 9 deletions src/Playwright/Core/APIRequestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,21 @@
using System.Threading.Tasks;
using Microsoft.Playwright.Helpers;
using Microsoft.Playwright.Transport;
using Microsoft.Playwright.Transport.Channels;
using Microsoft.Playwright.Transport.Protocol;

namespace Microsoft.Playwright.Core;

internal class APIRequestContext : ChannelOwnerBase, IChannelOwner<APIRequestContext>, IAPIRequestContext
internal class APIRequestContext : ChannelOwnerBase, IAPIRequestContext
{
internal readonly APIRequestContextChannel _channel;
internal readonly Tracing _tracing;

internal APIRequest _request;

public APIRequestContext(IChannelOwner parent, string guid, APIRequestContextInitializer initializer) : base(parent, guid)
public APIRequestContext(ChannelOwnerBase parent, string guid, APIRequestContextInitializer initializer) : base(parent, guid)
{
_channel = new(guid, parent.Connection, this);
_tracing = initializer.Tracing;
}

ChannelBase IChannelOwner.Channel => _channel;

IChannel<APIRequestContext> IChannelOwner<APIRequestContext>.Channel => _channel;

[MethodImpl(MethodImplOptions.NoInlining)]
public ValueTask DisposeAsync() => new(SendMessageToServerAsync("dispose"));

Expand Down
11 changes: 5 additions & 6 deletions src/Playwright/Core/Accessibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,25 @@
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Playwright.Transport.Channels;

namespace Microsoft.Playwright.Core;

internal class Accessibility : IAccessibility
{
private readonly PageChannel _channel;
private readonly Page _page;

public Accessibility(PageChannel channel)
public Accessibility(Page page)
{
_channel = channel;
_page = page;
}

public async Task<JsonElement?> SnapshotAsync(AccessibilitySnapshotOptions options = default)
{
options ??= new();
if ((await _channel.Object.SendMessageToServerAsync("accessibilitySnapshot", new Dictionary<string, object>
if ((await _page.SendMessageToServerAsync("accessibilitySnapshot", new Dictionary<string, object>
{
["interestingOnly"] = options?.InterestingOnly,
["root"] = (options.Root as ElementHandle)?.ElementChannel,
["root"] = options.Root,
}).ConfigureAwait(false)).Value.TryGetProperty("rootAXNode", out var jsonElement))
{
return jsonElement;
Expand Down
3 changes: 1 addition & 2 deletions src/Playwright/Core/AndroidDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
*/

using Microsoft.Playwright.Transport;
using Microsoft.Playwright.Transport.Channels;
using Microsoft.Playwright.Transport.Protocol;

namespace Microsoft.Playwright.Core;

internal class AndroidDevice : ChannelOwnerBase
{
internal AndroidDevice(IChannelOwner parent, string guid, BrowserInitializer initializer) : base(parent, guid)
internal AndroidDevice(ChannelOwnerBase parent, string guid, BrowserInitializer initializer) : base(parent, guid)
{
}
}
14 changes: 2 additions & 12 deletions src/Playwright/Core/Artifact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,17 @@
using System.Threading.Tasks;
using Microsoft.Playwright.Helpers;
using Microsoft.Playwright.Transport;
using Microsoft.Playwright.Transport.Channels;
using Microsoft.Playwright.Transport.Protocol;

namespace Microsoft.Playwright.Core;

internal class Artifact : ChannelOwnerBase, IChannelOwner<Artifact>
internal class Artifact : ChannelOwnerBase
{
private readonly ArtifactChannel _channel;

internal Artifact(IChannelOwner parent, string guid, ArtifactInitializer initializer) : base(parent, guid)
internal Artifact(ChannelOwnerBase parent, string guid, ArtifactInitializer initializer) : base(parent, guid)
{
_channel = new(guid, parent.Connection, this);
AbsolutePath = initializer.AbsolutePath;
}

Connection IChannelOwner.Connection => _connection;

ChannelBase IChannelOwner.Channel => _channel;

IChannel<Artifact> IChannelOwner<Artifact>.Channel => _channel;

internal string AbsolutePath { get; }

[MethodImpl(MethodImplOptions.NoInlining)]
Expand Down
11 changes: 2 additions & 9 deletions src/Playwright/Core/BindingCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,23 @@
using System.Threading.Tasks;
using Microsoft.Playwright.Helpers;
using Microsoft.Playwright.Transport;
using Microsoft.Playwright.Transport.Channels;
using Microsoft.Playwright.Transport.Protocol;

namespace Microsoft.Playwright.Core;

internal class BindingCall : ChannelOwnerBase, IChannelOwner<BindingCall>
internal class BindingCall : ChannelOwnerBase
{
private static readonly Type VoidTaskResultType = Type.GetType("System.Threading.Tasks.VoidTaskResult");

private readonly BindingCallChannel _channel;
private readonly BindingCallInitializer _initializer;

public BindingCall(IChannelOwner parent, string guid, BindingCallInitializer initializer) : base(parent, guid)
public BindingCall(ChannelOwnerBase parent, string guid, BindingCallInitializer initializer) : base(parent, guid)
{
_channel = new(guid, parent.Connection, this);
_initializer = initializer;
}

public string Name => _initializer.Name;

ChannelBase IChannelOwner.Channel => _channel;

IChannel<BindingCall> IChannelOwner<BindingCall>.Channel => _channel;

internal async Task CallAsync(Delegate binding)
{
try
Expand Down
22 changes: 7 additions & 15 deletions src/Playwright/Core/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,26 @@
using System.Threading.Tasks;
using Microsoft.Playwright.Helpers;
using Microsoft.Playwright.Transport;
using Microsoft.Playwright.Transport.Channels;
using Microsoft.Playwright.Transport.Protocol;

namespace Microsoft.Playwright.Core;

internal class Browser : ChannelOwnerBase, IChannelOwner<Browser>, IBrowser
internal class Browser : ChannelOwnerBase, IBrowser
{
private readonly BrowserInitializer _initializer;
private readonly TaskCompletionSource<bool> _closedTcs = new();
internal readonly List<BrowserContext> _contexts = new();
internal BrowserType _browserType;
internal string _closeReason;

internal Browser(IChannelOwner parent, string guid, BrowserInitializer initializer) : base(parent, guid)
internal Browser(ChannelOwnerBase parent, string guid, BrowserInitializer initializer) : base(parent, guid)
{
Channel = new(guid, parent.Connection, this);
IsConnected = true;
_initializer = initializer;
}

public event EventHandler<IBrowser> Disconnected;

ChannelBase IChannelOwner.Channel => Channel;

IChannel<Browser> IChannelOwner<Browser>.Channel => Channel;

public IReadOnlyList<IBrowserContext> Contexts => _contexts.ToArray();

public bool IsConnected { get; private set; }
Expand All @@ -66,8 +60,6 @@ internal Browser(IChannelOwner parent, string guid, BrowserInitializer initializ

public string Version => _initializer.Version;

internal BrowserChannel Channel { get; }

public IBrowserType BrowserType => _browserType;

internal override void OnMessage(string method, JsonElement? serverParams)
Expand All @@ -88,11 +80,11 @@ public async Task CloseAsync(BrowserCloseOptions options = default)
{
if (ShouldCloseConnectionOnClose)
{
Channel.Connection.DoClose();
_connection.DoClose();
}
else
{
await SendMessageToServerAsync<BrowserContextChannel>("close", new Dictionary<string, object>
await SendMessageToServerAsync("close", new Dictionary<string, object>
{
["reason"] = options?.Reason,
}).ConfigureAwait(false);
Expand Down Expand Up @@ -175,7 +167,7 @@ public async Task<IBrowserContext> NewContextAsync(BrowserNewContextOptions opti
args.Add("screen", options.ScreenSize);
}

var context = (await SendMessageToServerAsync<BrowserContextChannel>("newContext", args).ConfigureAwait(false)).Object;
var context = await SendMessageToServerAsync<BrowserContext>("newContext", args).ConfigureAwait(false);

_browserType.DidCreateContext(context, options, null);
return context;
Expand Down Expand Up @@ -274,8 +266,8 @@ internal void DidClose()

[MethodImpl(MethodImplOptions.NoInlining)]
public async Task<ICDPSession> NewBrowserCDPSessionAsync()
=> (await SendMessageToServerAsync<CDPChannel>(
"newBrowserCDPSession").ConfigureAwait(false)).Object;
=> await SendMessageToServerAsync<CDPSession>(
"newBrowserCDPSession").ConfigureAwait(false);

internal static Dictionary<string, object> PrepareHarOptions(
HarContentPolicy? recordHarContent,
Expand Down
Loading

0 comments on commit 47249a0

Please sign in to comment.