blob: fe4564e1909a3ec943b63d3bf2841fd1be692065 [file]
// <copyright file="BrowsingContextModule.cs" company="Selenium Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// </copyright>
using System.Text.Json.Serialization;
using static OpenQA.Selenium.BiDi.BrowsingContext.BrowsingContextJsonSerializerContext;
namespace OpenQA.Selenium.BiDi.BrowsingContext;
internal sealed class BrowsingContextModule : Module, IBrowsingContextModule
{
public async Task<CreateResult> CreateAsync(ContextType type, CreateOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new CreateParameters(type, options?.ReferenceContext, options?.Background, options?.UserContext);
return await ExecuteAsync("browsingContext.create", @params, Default.CreateParameters, Default.CreateResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<NavigateResult> NavigateAsync(BrowsingContext context, string url, NavigateOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new NavigateParameters(context, url, options?.Wait);
return await ExecuteAsync("browsingContext.navigate", @params, Default.NavigateParameters, Default.NavigateResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<ActivateResult> ActivateAsync(BrowsingContext context, ActivateOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new ActivateParameters(context);
return await ExecuteAsync("browsingContext.activate", @params, Default.ActivateParameters, Default.ActivateResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<LocateNodesResult> LocateNodesAsync(BrowsingContext context, Locator locator, LocateNodesOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new LocateNodesParameters(context, locator, options?.MaxNodeCount, options?.SerializationOptions, options?.StartNodes);
return await ExecuteAsync("browsingContext.locateNodes", @params, Default.LocateNodesParameters, Default.LocateNodesResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<CaptureScreenshotResult> CaptureScreenshotAsync(BrowsingContext context, CaptureScreenshotOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new CaptureScreenshotParameters(context, options?.Origin, options?.Format, options?.Clip, options?.ImageSize);
return await ExecuteAsync("browsingContext.captureScreenshot", @params, Default.CaptureScreenshotParameters, Default.CaptureScreenshotResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<CloseResult> CloseAsync(BrowsingContext context, CloseOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new CloseParameters(context, options?.PromptUnload);
return await ExecuteAsync("browsingContext.close", @params, Default.CloseParameters, Default.CloseResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<TraverseHistoryResult> TraverseHistoryAsync(BrowsingContext context, int delta, TraverseHistoryOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new TraverseHistoryParameters(context, delta);
return await ExecuteAsync("browsingContext.traverseHistory", @params, Default.TraverseHistoryParameters, Default.TraverseHistoryResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<ReloadResult> ReloadAsync(BrowsingContext context, ReloadOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new ReloadParameters(context, options?.IgnoreCache, options?.Wait);
return await ExecuteAsync("browsingContext.reload", @params, Default.ReloadParameters, Default.ReloadResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<SetViewportResult> SetViewportAsync(SetViewportOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new SetViewportParameters(options?.Context, options?.Viewport, options?.DevicePixelRatio, options?.UserContexts);
return await ExecuteAsync("browsingContext.setViewport", @params, Default.SetViewportParameters, Default.SetViewportResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<GetTreeResult> GetTreeAsync(GetTreeOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new GetTreeParameters(options?.MaxDepth, options?.Root);
return await ExecuteAsync("browsingContext.getTree", @params, Default.GetTreeParameters, Default.GetTreeResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<PrintResult> PrintAsync(BrowsingContext context, PrintOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new PrintParameters(context, options?.Background, options?.Margin, options?.Orientation, options?.Page, options?.PageRanges, options?.Scale, options?.ShrinkToFit);
return await ExecuteAsync("browsingContext.print", @params, Default.PrintParameters, Default.PrintResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<HandleUserPromptResult> HandleUserPromptAsync(BrowsingContext context, HandleUserPromptOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new HandleUserPromptParameters(context, options?.Accept, options?.UserText);
return await ExecuteAsync("browsingContext.handleUserPrompt", @params, Default.HandleUserPromptParameters, Default.HandleUserPromptResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<StartScreencastResult> StartScreencastAsync(BrowsingContext context, StartScreencastOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new StartScreencastParameters(context, options?.DestinationFolder, options?.MimeType, options?.Video, options?.Audio);
return await ExecuteAsync("browsingContext.startScreencast", @params, Default.StartScreencastParameters, Default.StartScreencastResult, options, cancellationToken).ConfigureAwait(false);
}
public async Task<StopScreencastResult> StopScreencastAsync(Screencast screencast, StopScreencastOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new StopScreencastParameters(screencast);
return await ExecuteAsync("browsingContext.stopScreencast", @params, Default.StopScreencastParameters, Default.StopScreencastResult, options, cancellationToken).ConfigureAwait(false);
}
public IEventSource<NavigationStartedEventArgs> NavigationStarted => _navigationStarted ?? Interlocked.CompareExchange(ref _navigationStarted, CreateEventSource(BrowsingContextEvent.NavigationStarted), null) ?? _navigationStarted;
private IEventSource<NavigationStartedEventArgs>? _navigationStarted;
public IEventSource<FragmentNavigatedEventArgs> FragmentNavigated => _fragmentNavigated ?? Interlocked.CompareExchange(ref _fragmentNavigated, CreateEventSource(BrowsingContextEvent.FragmentNavigated), null) ?? _fragmentNavigated;
private IEventSource<FragmentNavigatedEventArgs>? _fragmentNavigated;
public IEventSource<HistoryUpdatedEventArgs> HistoryUpdated => _historyUpdated ?? Interlocked.CompareExchange(ref _historyUpdated, CreateEventSource(BrowsingContextEvent.HistoryUpdated), null) ?? _historyUpdated;
private IEventSource<HistoryUpdatedEventArgs>? _historyUpdated;
public IEventSource<DomContentLoadedEventArgs> DomContentLoaded => _domContentLoaded ?? Interlocked.CompareExchange(ref _domContentLoaded, CreateEventSource(BrowsingContextEvent.DomContentLoaded), null) ?? _domContentLoaded;
private IEventSource<DomContentLoadedEventArgs>? _domContentLoaded;
public IEventSource<LoadEventArgs> Load => _load ?? Interlocked.CompareExchange(ref _load, CreateEventSource(BrowsingContextEvent.Load), null) ?? _load;
private IEventSource<LoadEventArgs>? _load;
public IEventSource<DownloadWillBeginEventArgs> DownloadWillBegin => _downloadWillBegin ?? Interlocked.CompareExchange(ref _downloadWillBegin, CreateEventSource(BrowsingContextEvent.DownloadWillBegin), null) ?? _downloadWillBegin;
private IEventSource<DownloadWillBeginEventArgs>? _downloadWillBegin;
public IEventSource<DownloadEndEventArgs> DownloadEnd => _downloadEnd ?? Interlocked.CompareExchange(ref _downloadEnd, CreateEventSource(BrowsingContextEvent.DownloadEnd), null) ?? _downloadEnd;
private IEventSource<DownloadEndEventArgs>? _downloadEnd;
public IEventSource<NavigationAbortedEventArgs> NavigationAborted => _navigationAborted ?? Interlocked.CompareExchange(ref _navigationAborted, CreateEventSource(BrowsingContextEvent.NavigationAborted), null) ?? _navigationAborted;
private IEventSource<NavigationAbortedEventArgs>? _navigationAborted;
public IEventSource<NavigationFailedEventArgs> NavigationFailed => _navigationFailed ?? Interlocked.CompareExchange(ref _navigationFailed, CreateEventSource(BrowsingContextEvent.NavigationFailed), null) ?? _navigationFailed;
private IEventSource<NavigationFailedEventArgs>? _navigationFailed;
public IEventSource<NavigationCommittedEventArgs> NavigationCommitted => _navigationCommitted ?? Interlocked.CompareExchange(ref _navigationCommitted, CreateEventSource(BrowsingContextEvent.NavigationCommitted), null) ?? _navigationCommitted;
private IEventSource<NavigationCommittedEventArgs>? _navigationCommitted;
public IEventSource<ContextCreatedEventArgs> ContextCreated => _contextCreated ?? Interlocked.CompareExchange(ref _contextCreated, CreateEventSource(BrowsingContextEvent.ContextCreated), null) ?? _contextCreated;
private IEventSource<ContextCreatedEventArgs>? _contextCreated;
public IEventSource<ContextDestroyedEventArgs> ContextDestroyed => _contextDestroyed ?? Interlocked.CompareExchange(ref _contextDestroyed, CreateEventSource(BrowsingContextEvent.ContextDestroyed), null) ?? _contextDestroyed;
private IEventSource<ContextDestroyedEventArgs>? _contextDestroyed;
public IEventSource<UserPromptOpenedEventArgs> UserPromptOpened => _userPromptOpened ?? Interlocked.CompareExchange(ref _userPromptOpened, CreateEventSource(BrowsingContextEvent.UserPromptOpened), null) ?? _userPromptOpened;
private IEventSource<UserPromptOpenedEventArgs>? _userPromptOpened;
public IEventSource<UserPromptClosedEventArgs> UserPromptClosed => _userPromptClosed ?? Interlocked.CompareExchange(ref _userPromptClosed, CreateEventSource(BrowsingContextEvent.UserPromptClosed), null) ?? _userPromptClosed;
private IEventSource<UserPromptClosedEventArgs>? _userPromptClosed;
}
[JsonSerializable(typeof(ActivateParameters))]
[JsonSerializable(typeof(ActivateResult))]
[JsonSerializable(typeof(CaptureScreenshotParameters))]
[JsonSerializable(typeof(CaptureScreenshotResult))]
[JsonSerializable(typeof(CloseParameters))]
[JsonSerializable(typeof(CloseResult))]
[JsonSerializable(typeof(CreateParameters))]
[JsonSerializable(typeof(CreateResult))]
[JsonSerializable(typeof(GetTreeParameters))]
[JsonSerializable(typeof(GetTreeResult))]
[JsonSerializable(typeof(HandleUserPromptParameters))]
[JsonSerializable(typeof(HandleUserPromptResult))]
[JsonSerializable(typeof(LocateNodesParameters))]
[JsonSerializable(typeof(LocateNodesResult))]
[JsonSerializable(typeof(NavigateParameters))]
[JsonSerializable(typeof(NavigateResult))]
[JsonSerializable(typeof(PrintParameters))]
[JsonSerializable(typeof(PrintResult))]
[JsonSerializable(typeof(ReloadParameters))]
[JsonSerializable(typeof(ReloadResult))]
[JsonSerializable(typeof(SetViewportParameters))]
[JsonSerializable(typeof(SetViewportResult))]
[JsonSerializable(typeof(StartScreencastParameters))]
[JsonSerializable(typeof(StartScreencastResult))]
[JsonSerializable(typeof(StopScreencastParameters))]
[JsonSerializable(typeof(StopScreencastResult))]
[JsonSerializable(typeof(TraverseHistoryParameters))]
[JsonSerializable(typeof(TraverseHistoryResult))]
[JsonSerializable(typeof(DownloadWillBeginEventArgs))]
[JsonSerializable(typeof(DownloadEndEventArgs))]
[JsonSerializable(typeof(DownloadCanceledEventArgs))]
[JsonSerializable(typeof(DownloadCompleteEventArgs))]
[JsonSerializable(typeof(HistoryUpdatedEventArgs))]
[JsonSerializable(typeof(NavigationInfo))]
[JsonSerializable(typeof(NavigationStartedEventArgs))]
[JsonSerializable(typeof(FragmentNavigatedEventArgs))]
[JsonSerializable(typeof(DomContentLoadedEventArgs))]
[JsonSerializable(typeof(LoadEventArgs))]
[JsonSerializable(typeof(NavigationAbortedEventArgs))]
[JsonSerializable(typeof(NavigationFailedEventArgs))]
[JsonSerializable(typeof(NavigationCommittedEventArgs))]
[JsonSerializable(typeof(ContextCreatedEventArgs))]
[JsonSerializable(typeof(ContextDestroyedEventArgs))]
[JsonSerializable(typeof(UserPromptClosedEventArgs))]
[JsonSerializable(typeof(UserPromptOpenedEventArgs))]
[JsonSourceGenerationOptions(
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
internal partial class BrowsingContextJsonSerializerContext : JsonSerializerContext;