/// <summary> /// Gets an array that contains the <see cref="CefNetCookie"/> instances. /// </summary> /// <param name="filter"> /// If the <paramref name="filter"/> function returns true, the cookie will be included in the result. /// </param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>The task object representing the asynchronous operation.</returns> /// <remarks>The result of the task can be null if cookies cannot be accessed.</remarks> public Task <CefNetCookie[]> GetCookiesAsync(Func <CefCookie, bool> filter, CancellationToken cancellationToken) { var cookieVisitor = new GetCookieVisitor(filter, cancellationToken); if (!VisitAllCookies(cookieVisitor)) { return(Task.FromResult <CefNetCookie[]>(null)); } return(cookieVisitor.Task); }
/// <summary> /// Gets an array that contains the <see cref="CefNetCookie"/> instances that are associated with a specific URI. /// </summary> /// <param name="url">The URI of the <see cref="CefNetCookie"/> instances desired.</param> /// <param name="includeHttpOnly"> /// A value indicating whether HTTP-only cookies should be included in the result. /// </param> /// <param name="filter"> /// If the <paramref name="filter"/> function returns true, the cookie will be included in the result. /// </param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>The task object representing the asynchronous operation.</returns> /// <remarks>The result of the task can be null if cookies cannot be accessed.</remarks> public Task <CefNetCookie[]> GetCookiesAsync(string url, bool includeHttpOnly, Func <CefCookie, bool> filter, CancellationToken cancellationToken) { if (Uri.TryCreate(url, UriKind.Absolute, out Uri uri) && (Uri.UriSchemeHttp.Equals(uri.Scheme, StringComparison.Ordinal) || Uri.UriSchemeHttps.Equals(uri.Scheme, StringComparison.Ordinal))) { var cookieVisitor = new GetCookieVisitor(filter, cancellationToken); if (!VisitUrlCookies(url, includeHttpOnly, cookieVisitor)) { return(Task.FromResult <CefNetCookie[]>(null)); } return(cookieVisitor.Task); } throw new ArgumentOutOfRangeException(nameof(url)); }