/
WebBrowserPopupInfo.cs
67 lines (56 loc) · 1.82 KB
/
WebBrowserPopupInfo.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// UnityWebBrowser (UWB)
// Copyright (c) 2021-2022 Voltstro-Studios
//
// This project is under the MIT license. See the LICENSE.md file for more details.
using System;
using System.Diagnostics;
using VoltstroStudios.UnityWebBrowser.Shared.Popups;
namespace VoltstroStudios.UnityWebBrowser.Core.Popups
{
public class WebBrowserPopupInfo : EnginePopupInfo
{
private readonly WebBrowserPopupService popupService;
internal WebBrowserPopupInfo(Guid guid, WebBrowserPopupService popupService)
: base(guid)
{
IsValid = true;
this.popupService = popupService;
}
/// <summary>
/// Is this <see cref="WebBrowserPopupInfo" /> still valid?
/// </summary>
public bool IsValid { get; private set; }
/// <summary>
/// Called when this <see cref="WebBrowserPopupInfo" /> is destroyed in anyway
/// </summary>
public event Action OnDestroyed;
/// <inheritdoc />
public override void ExecuteJs(string js)
{
ThrowIfInvalid();
popupService.PopupExecuteJs(PopupGuid, js);
}
/// <inheritdoc />
public override void Dispose()
{
ThrowIfInvalid();
popupService.PopupClose(PopupGuid);
base.Dispose();
}
/// <summary>
/// Invalidates this popup without sending a request
/// </summary>
internal void DisposeNoSend()
{
IsValid = false;
OnDestroyed?.Invoke();
}
[DebuggerStepThrough]
private void ThrowIfInvalid()
{
if (!IsValid)
throw new ObjectDisposedException(nameof(WebBrowserPopupInfo),
"This popup has already been disposed of!");
}
}
}