Skip to content

Commit

Permalink
[dotnet] [bidi] Hide context from command options in contextual env
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko committed Sep 14, 2024
1 parent 1a3d451 commit 210012b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ public Task HandleUserPromptAsync(HandleUserPromptOptions? options = null)

public Task<IReadOnlyList<BrowsingContextInfo>> GetTreeAsync(BrowsingContextGetTreeOptions? options = null)
{
options ??= new();
GetTreeOptions getTreeOptions = new(options)
{
Root = this
};

options.Root = this;

return _bidi.BrowsingContextModule.GetTreeAsync(options);
return _bidi.BrowsingContextModule.GetTreeAsync(getTreeOptions);
}

public Task<Subscription> OnNavigationStartedAsync(Func<NavigationInfo, Task> handler, SubscriptionOptions? options = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ public class BrowsingContextNetworkModule(BrowsingContext context, NetworkModule
{
public async Task<Intercept> InterceptRequestAsync(Func<BeforeRequestSentEventArgs, Task> handler, BrowsingContextAddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
{
interceptOptions ??= new();
AddInterceptOptions addInterceptOptions = new(interceptOptions)
{
Contexts = [context]
};

interceptOptions.Contexts = [context];

var intercept = await networkModule.AddInterceptAsync([InterceptPhase.BeforeRequestSent], interceptOptions).ConfigureAwait(false);
var intercept = await networkModule.AddInterceptAsync([InterceptPhase.BeforeRequestSent], addInterceptOptions).ConfigureAwait(false);

await intercept.OnBeforeRequestSentAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }).ConfigureAwait(false);

Expand All @@ -21,11 +22,12 @@ public async Task<Intercept> InterceptRequestAsync(Func<BeforeRequestSentEventAr

public async Task<Intercept> InterceptResponseAsync(Func<ResponseStartedEventArgs, Task> handler, BrowsingContextAddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
{
interceptOptions ??= new();

interceptOptions.Contexts = [context];
AddInterceptOptions addInterceptOptions = new(interceptOptions)
{
Contexts = [context]
};

var intercept = await networkModule.AddInterceptAsync([InterceptPhase.ResponseStarted], interceptOptions).ConfigureAwait(false);
var intercept = await networkModule.AddInterceptAsync([InterceptPhase.ResponseStarted], addInterceptOptions).ConfigureAwait(false);

await intercept.OnResponseStartedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }).ConfigureAwait(false);

Expand All @@ -34,11 +36,12 @@ public async Task<Intercept> InterceptResponseAsync(Func<ResponseStartedEventArg

public async Task<Intercept> InterceptAuthenticationAsync(Func<AuthRequiredEventArgs, Task> handler, BrowsingContextAddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
{
interceptOptions ??= new();

interceptOptions.Contexts = [context];
AddInterceptOptions addInterceptOptions = new(interceptOptions)
{
Contexts = [context]
};

var intercept = await networkModule.AddInterceptAsync([InterceptPhase.AuthRequired], interceptOptions).ConfigureAwait(false);
var intercept = await networkModule.AddInterceptAsync([InterceptPhase.AuthRequired], addInterceptOptions).ConfigureAwait(false);

await intercept.OnAuthRequiredAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ public class BrowsingContextScriptModule(BrowsingContext context, ScriptModule s
{
public async Task<PreloadScript> AddPreloadScriptAsync(string functionDeclaration, BrowsingContextAddPreloadScriptOptions? options = null)
{
options ??= new();

options.Contexts = [context];
AddPreloadScriptOptions addPreloadScriptOptions = new(options)
{
Contexts = [context]
};

return await scriptModule.AddPreloadScriptAsync(functionDeclaration, options).ConfigureAwait(false);
return await scriptModule.AddPreloadScriptAsync(functionDeclaration, addPreloadScriptOptions).ConfigureAwait(false);
}

public async Task<IReadOnlyList<RealmInfo>> GetRealmsAsync(GetRealmsOptions? options = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ internal record GetTreeCommandParameters : CommandParameters

public record GetTreeOptions : CommandOptions
{
public GetTreeOptions() { }

internal GetTreeOptions(BrowsingContextGetTreeOptions? options)
{
MaxDepth = options?.MaxDepth;
}

public long? MaxDepth { get; set; }

public BrowsingContext? Root { get; set; }
}

public record BrowsingContextGetTreeOptions : GetTreeOptions
public record BrowsingContextGetTreeOptions
{
internal new BrowsingContext? Root
{
get => base.Root;
set => base.Root = value;
}
public long? MaxDepth { get; set; }
}

public record GetTreeResult(IReadOnlyList<BrowsingContextInfo> Contexts);
15 changes: 9 additions & 6 deletions dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ internal record AddInterceptCommandParameters(IEnumerable<InterceptPhase> Phases

public record AddInterceptOptions : CommandOptions
{
public AddInterceptOptions() { }

internal AddInterceptOptions(BrowsingContextAddInterceptOptions? options)
{
UrlPatterns = options?.UrlPatterns;
}

public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }

public IEnumerable<UrlPattern>? UrlPatterns { get; set; }
}

public record BrowsingContextAddInterceptOptions : AddInterceptOptions
public record BrowsingContextAddInterceptOptions
{
internal new IEnumerable<BrowsingContext.BrowsingContext>? Contexts
{
get => base.Contexts;
set => base.Contexts = value;
}
public IEnumerable<UrlPattern>? UrlPatterns { get; set; }
}

public record AddInterceptResult(Intercept Intercept);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ internal record AddPreloadScriptCommandParameters(string FunctionDeclaration) :

public record AddPreloadScriptOptions : CommandOptions
{
public AddPreloadScriptOptions() { }

internal AddPreloadScriptOptions(BrowsingContextAddPreloadScriptOptions? options)
{
Arguments = options?.Arguments;
Sandbox = options?.Sandbox;
}

public IEnumerable<ChannelValue>? Arguments { get; set; }

public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }

public string? Sandbox { get; set; }
}

public record BrowsingContextAddPreloadScriptOptions : AddPreloadScriptOptions
public record BrowsingContextAddPreloadScriptOptions
{
internal new IEnumerable<BrowsingContext.BrowsingContext>? Contexts
{
get => base.Contexts;
set => base.Contexts = value;
}
public IEnumerable<ChannelValue>? Arguments { get; set; }

public string? Sandbox { get; set; }
}

internal record AddPreloadScriptResult(PreloadScript Script);

0 comments on commit 210012b

Please sign in to comment.