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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Net;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Navigation;
using System.Windows.Threading;
using Gestor.Application.Properties;
using HtmlAgilityPack;
using mshtml;
namespace Gestor.Application.Componentes;
public class WebBrowser : UserControl, IComponentConnector
{
public HTMLDocument HtmlDocument;
public WebBrowser Browser;
public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register("IsReadOnly", typeof(bool), typeof(WebBrowser), new PropertyMetadata((object)false));
internal Grid GridWebBrowser;
private bool _contentLoaded;
public bool IsReadOnly
{
get
{
return (bool)((DependencyObject)this).GetValue(IsReadOnlyProperty);
}
set
{
((DependencyObject)this).SetValue(IsReadOnlyProperty, (object)value);
}
}
public WebBrowser()
{
InitializeComponent();
Dispatcher dispatcher = ((DispatcherObject)this).Dispatcher;
if (dispatcher != null)
{
dispatcher.BeginInvoke((DispatcherPriority)7, (Delegate)new Action(ContentLoad));
}
}
private void ContentLoad()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
((UIElement)this).PreviewKeyDown += new KeyEventHandler(Browser_PreviewKeyDown);
}
private void Browser_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (IsReadOnly)
{
((RoutedEventArgs)e).Handled = true;
}
}
public void InstanciateNew(string htmlData = null)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Expected O, but got Unknown
if (Browser != null)
{
Browser.LoadCompleted -= new LoadCompletedEventHandler(Completed);
((HwndHost)Browser).Dispose();
((Panel)GridWebBrowser).Children.Remove((UIElement)(object)Browser);
}
HtmlDocument?.clear();
Browser = new WebBrowser
{
IsEnabled = true
};
Browser.LoadCompleted += new LoadCompletedEventHandler(Completed);
((Panel)GridWebBrowser).Children.Add((UIElement)(object)Browser);
HideScriptErrors();
htmlData = HtmlEncode(htmlData);
Browser.NavigateToString(string.IsNullOrEmpty(htmlData) ? Resources.New : htmlData);
HtmlDocument = Browser.Document as HTMLDocument;
if (HtmlDocument != null)
{
HtmlDocument.charset = "ISO-8859-1";
HtmlDocument.designMode = "On";
}
}
public static string HtmlEncode(string html)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
if (html == null)
{
return null;
}
HtmlDocument val = new HtmlDocument();
val.LoadHtml(html);
val.OptionWriteEmptyNodes = true;
EncodeNode(val.DocumentNode);
return val.DocumentNode.InnerHtml;
}
private static void EncodeNode(HtmlNode node)
{
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Invalid comparison between Unknown and I4
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Invalid comparison between Unknown and I4
if (node.HasChildNodes)
{
foreach (HtmlNode item in (IEnumerable<HtmlNode>)node.ChildNodes)
{
if ((int)item.NodeType == 3)
{
item.InnerHtml = WebUtility.HtmlEncode(item.InnerHtml);
}
else
{
EncodeNode(item);
}
}
return;
}
if ((int)node.NodeType == 3)
{
node.InnerHtml = WebUtility.HtmlEncode(node.InnerHtml);
}
}
private void HideScriptErrors()
{
FieldInfo field = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
if (!(field == null))
{
object value = field.GetValue(Browser);
value?.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, value, new object[1] { true });
}
}
private void Completed(object sender, NavigationEventArgs e)
{
HtmlDocument = Browser.Document as HTMLDocument;
if (HtmlDocument != null)
{
HtmlDocument.designMode = "On";
}
}
public void ReadOnly(bool isReadOnly)
{
IsReadOnly = isReadOnly;
}
[DebuggerNonUserCode]
[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
public void InitializeComponent()
{
if (!_contentLoaded)
{
_contentLoaded = true;
Uri uri = new Uri("/Gestor.Application;component/componentes/webbrowser.xaml", UriKind.Relative);
Application.LoadComponent((object)this, uri);
}
}
[DebuggerNonUserCode]
[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
[EditorBrowsable(EditorBrowsableState.Never)]
void IComponentConnector.Connect(int connectionId, object target)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
if (connectionId == 1)
{
GridWebBrowser = (Grid)target;
}
else
{
_contentLoaded = true;
}
}
}
|