-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
UrlLoadingEventArgs.cs
45 lines (40 loc) · 1.46 KB
/
UrlLoadingEventArgs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
namespace Microsoft.AspNetCore.Components.WebView
{
/// <summary>
/// Used to provide information about a link (<![CDATA[<a>]]>) clicked within a Blazor WebView.
/// <para>
/// Anchor tags with target="_blank" will always open in the default
/// browser and the UrlLoading event won't be called.
/// </para>
/// </summary>
public class UrlLoadingEventArgs : EventArgs
{
internal static UrlLoadingEventArgs CreateWithDefaultLoadingStrategy(Uri urlToLoad, Uri appOriginUri)
{
var strategy = appOriginUri.IsBaseOf(urlToLoad) ?
UrlLoadingStrategy.OpenInWebView :
UrlLoadingStrategy.OpenExternally;
return new(urlToLoad, strategy);
}
private UrlLoadingEventArgs(Uri url, UrlLoadingStrategy urlLoadingStrategy)
{
Url = url;
UrlLoadingStrategy = urlLoadingStrategy;
}
/// <summary>
/// Gets the <see cref="Url">URL</see> to be loaded.
/// </summary>
public Uri Url { get; }
/// <summary>
/// The policy to use when loading links from the webview.
/// Defaults to <see cref="UrlLoadingStrategy.OpenExternally"/> unless <see cref="Url"/> has a host
/// matching the app origin, in which case the default becomes <see cref="UrlLoadingStrategy.OpenInWebView"/>.
/// <para>
/// This value should not be changed to <see cref="UrlLoadingStrategy.OpenInWebView"/> for external links
/// unless you can ensure they are fully trusted.
/// </para>
/// </summary>
public UrlLoadingStrategy UrlLoadingStrategy { get; set; }
}
}