Skip to content

Commit 87fef04

Browse files
authored
[dotnet] [bidi] Remove browsing scoped events at core level (#16694)
1 parent d9d1d79 commit 87fef04

13 files changed

+86
-43
lines changed

dotnet/src/webdriver/BiDi/Broker.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using System;
2222
using System.Collections.Concurrent;
2323
using System.Collections.Generic;
24-
using System.Linq;
2524
using System.Text.Json;
2625
using System.Text.Json.Serialization.Metadata;
2726
using System.Threading;
@@ -113,16 +112,7 @@ private async Task ProcessEventsAwaiterAsync()
113112

114113
args.BiDi = _bidi;
115114

116-
// handle browsing context subscriber
117-
if (handler.Contexts is not null && args is BrowsingContextEventArgs browsingContextEventArgs && handler.Contexts.Contains(browsingContextEventArgs.Context))
118-
{
119-
await handler.InvokeAsync(args).ConfigureAwait(false);
120-
}
121-
// handle only session subscriber
122-
else if (handler.Contexts is null)
123-
{
124-
await handler.InvokeAsync(args).ConfigureAwait(false);
125-
}
115+
await handler.InvokeAsync(args).ConfigureAwait(false);
126116
}
127117
}
128118
}
@@ -164,7 +154,7 @@ public async Task<Subscription> SubscribeAsync<TEventArgs>(string eventName, Act
164154

165155
var subscribeResult = await _bidi.SessionModule.SubscribeAsync([eventName], new() { Contexts = options?.Contexts, UserContexts = options?.UserContexts }).ConfigureAwait(false);
166156

167-
var eventHandler = new SyncEventHandler<TEventArgs>(eventName, action, options?.Contexts);
157+
var eventHandler = new SyncEventHandler<TEventArgs>(eventName, action);
168158

169159
handlers.Add(eventHandler);
170160

@@ -180,7 +170,7 @@ public async Task<Subscription> SubscribeAsync<TEventArgs>(string eventName, Fun
180170

181171
var subscribeResult = await _bidi.SessionModule.SubscribeAsync([eventName], new() { Contexts = options?.Contexts, UserContexts = options?.UserContexts }).ConfigureAwait(false);
182172

183-
var eventHandler = new AsyncEventHandler<TEventArgs>(eventName, func, options?.Contexts);
173+
var eventHandler = new AsyncEventHandler<TEventArgs>(eventName, func);
184174

185175
handlers.Add(eventHandler);
186176

dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
namespace OpenQA.Selenium.BiDi.BrowsingContext;
2323

2424
public sealed record BrowsingContextInfo(IReadOnlyList<BrowsingContextInfo>? Children, Browser.ClientWindow ClientWindow, BrowsingContext Context, BrowsingContext? OriginalOpener, string Url, Browser.UserContext UserContext, BrowsingContext? Parent)
25-
: BrowsingContextEventArgs(Context);
25+
: EventArgs;

dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,52 +91,112 @@ public Task<SetCacheBehaviorResult> SetCacheBehaviorAsync(CacheBehavior behavior
9191

9292
public Task<Subscription> OnBeforeRequestSentAsync(Func<BeforeRequestSentEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
9393
{
94-
return networkModule.OnBeforeRequestSentAsync(handler, options.WithContext(context));
94+
return networkModule.OnBeforeRequestSentAsync(async e =>
95+
{
96+
if (context.Equals(e.Context))
97+
{
98+
await handler(e).ConfigureAwait(false);
99+
}
100+
}, options.WithContext(context));
95101
}
96102

97103
public Task<Subscription> OnBeforeRequestSentAsync(Action<BeforeRequestSentEventArgs> handler, ContextSubscriptionOptions? options = null)
98104
{
99-
return networkModule.OnBeforeRequestSentAsync(handler, options.WithContext(context));
105+
return networkModule.OnBeforeRequestSentAsync(e =>
106+
{
107+
if (context.Equals(e.Context))
108+
{
109+
handler(e);
110+
}
111+
}, options.WithContext(context));
100112
}
101113

102114
public Task<Subscription> OnResponseStartedAsync(Func<ResponseStartedEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
103115
{
104-
return networkModule.OnResponseStartedAsync(handler, options.WithContext(context));
116+
return networkModule.OnResponseStartedAsync(async e =>
117+
{
118+
if (context.Equals(e.Context))
119+
{
120+
await handler(e).ConfigureAwait(false);
121+
}
122+
}, options.WithContext(context));
105123
}
106124

107125
public Task<Subscription> OnResponseStartedAsync(Action<ResponseStartedEventArgs> handler, ContextSubscriptionOptions? options = null)
108126
{
109-
return networkModule.OnResponseStartedAsync(handler, options.WithContext(context));
127+
return networkModule.OnResponseStartedAsync(e =>
128+
{
129+
if (context.Equals(e.Context))
130+
{
131+
handler(e);
132+
}
133+
}, options.WithContext(context));
110134
}
111135

112136
public Task<Subscription> OnResponseCompletedAsync(Func<ResponseCompletedEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
113137
{
114-
return networkModule.OnResponseCompletedAsync(handler, options.WithContext(context));
138+
return networkModule.OnResponseCompletedAsync(async e =>
139+
{
140+
if (context.Equals(e.Context))
141+
{
142+
await handler(e).ConfigureAwait(false);
143+
}
144+
}, options.WithContext(context));
115145
}
116146

117147
public Task<Subscription> OnResponseCompletedAsync(Action<ResponseCompletedEventArgs> handler, ContextSubscriptionOptions? options = null)
118148
{
119-
return networkModule.OnResponseCompletedAsync(handler, options.WithContext(context));
149+
return networkModule.OnResponseCompletedAsync(e =>
150+
{
151+
if (context.Equals(e.Context))
152+
{
153+
handler(e);
154+
}
155+
}, options.WithContext(context));
120156
}
121157

122158
public Task<Subscription> OnFetchErrorAsync(Func<FetchErrorEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
123159
{
124-
return networkModule.OnFetchErrorAsync(handler, options.WithContext(context));
160+
return networkModule.OnFetchErrorAsync(async e =>
161+
{
162+
if (context.Equals(e.Context))
163+
{
164+
await handler(e).ConfigureAwait(false);
165+
}
166+
}, options.WithContext(context));
125167
}
126168

127169
public Task<Subscription> OnFetchErrorAsync(Action<FetchErrorEventArgs> handler, ContextSubscriptionOptions? options = null)
128170
{
129-
return networkModule.OnFetchErrorAsync(handler, options.WithContext(context));
171+
return networkModule.OnFetchErrorAsync(e =>
172+
{
173+
if (context.Equals(e.Context))
174+
{
175+
handler(e);
176+
}
177+
}, options.WithContext(context));
130178
}
131179

132180
public Task<Subscription> OnAuthRequiredAsync(Func<AuthRequiredEventArgs, Task> handler, ContextSubscriptionOptions? options = null)
133181
{
134-
return networkModule.OnAuthRequiredAsync(handler, options.WithContext(context));
182+
return networkModule.OnAuthRequiredAsync(async e =>
183+
{
184+
if (context.Equals(e.Context))
185+
{
186+
await handler(e).ConfigureAwait(false);
187+
}
188+
}, options.WithContext(context));
135189
}
136190

137191
public Task<Subscription> OnAuthRequiredAsync(Action<AuthRequiredEventArgs> handler, ContextSubscriptionOptions? options = null)
138192
{
139-
return networkModule.OnAuthRequiredAsync(handler, options.WithContext(context));
193+
return networkModule.OnAuthRequiredAsync(e =>
194+
{
195+
if (context.Equals(e.Context))
196+
{
197+
handler(e);
198+
}
199+
}, options.WithContext(context));
140200
}
141201
}
142202

dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextScriptModule.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// </copyright>
1919

2020
using OpenQA.Selenium.BiDi.Script;
21-
using OpenQA.Selenium.Internal;
2221
using System.Diagnostics.CodeAnalysis;
2322
using System.Threading.Tasks;
2423

dotnet/src/webdriver/BiDi/BrowsingContext/DownloadEndEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext;
2929
//[JsonDerivedType(typeof(DownloadCompleteEventArgs), "complete")]
3030
[JsonConverter(typeof(DownloadEndEventArgsConverter))]
3131
public abstract record DownloadEndEventArgs(BrowsingContext Context)
32-
: BrowsingContextEventArgs(Context);
32+
: EventArgs;
3333

3434
public sealed record DownloadCanceledEventArgs(BrowsingContext Context, Navigation? Navigation, DateTimeOffset Timestamp, string Url)
3535
: DownloadEndEventArgs(Context), IBaseNavigationInfo;

dotnet/src/webdriver/BiDi/BrowsingContext/DownloadWillBeginEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
namespace OpenQA.Selenium.BiDi.BrowsingContext;
2323

2424
public sealed record DownloadWillBeginEventArgs(string SuggestedFilename, BrowsingContext Context, Navigation? Navigation, DateTimeOffset Timestamp, string Url)
25-
: BrowsingContextEventArgs(Context), IBaseNavigationInfo;
25+
: EventArgs, IBaseNavigationInfo;

dotnet/src/webdriver/BiDi/BrowsingContext/HistoryUpdatedEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
namespace OpenQA.Selenium.BiDi.BrowsingContext;
2323

2424
public sealed record HistoryUpdatedEventArgs(BrowsingContext Context, DateTimeOffset Timestamp, string Url)
25-
: BrowsingContextEventArgs(Context);
25+
: EventArgs;

dotnet/src/webdriver/BiDi/BrowsingContext/NavigationInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
namespace OpenQA.Selenium.BiDi.BrowsingContext;
2323

2424
public sealed record NavigationInfo(BrowsingContext Context, Navigation? Navigation, DateTimeOffset Timestamp, string Url)
25-
: BrowsingContextEventArgs(Context), IBaseNavigationInfo;
25+
: EventArgs, IBaseNavigationInfo;

dotnet/src/webdriver/BiDi/BrowsingContext/UserPromptClosedEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
namespace OpenQA.Selenium.BiDi.BrowsingContext;
2121

2222
public sealed record UserPromptClosedEventArgs(BrowsingContext Context, bool Accepted, string? UserText)
23-
: BrowsingContextEventArgs(Context);
23+
: EventArgs;

dotnet/src/webdriver/BiDi/BrowsingContext/UserPromptOpenedEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
namespace OpenQA.Selenium.BiDi.BrowsingContext;
2424

2525
public sealed record UserPromptOpenedEventArgs(BrowsingContext Context, Session.UserPromptHandlerType Handler, UserPromptType Type, string Message, string? DefaultValue)
26-
: BrowsingContextEventArgs(Context);
26+
: EventArgs;
2727

2828
[JsonConverter(typeof(CamelCaseEnumConverter<UserPromptType>))]
2929
public enum UserPromptType

0 commit comments

Comments
 (0)