summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.Componentes/WebBrowser.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Decompiler/Gestor.Application.Componentes/WebBrowser.cs')
-rw-r--r--Decompiler/Gestor.Application.Componentes/WebBrowser.cs199
1 files changed, 199 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.Componentes/WebBrowser.cs b/Decompiler/Gestor.Application.Componentes/WebBrowser.cs
new file mode 100644
index 0000000..57a468f
--- /dev/null
+++ b/Decompiler/Gestor.Application.Componentes/WebBrowser.cs
@@ -0,0 +1,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;
+ }
+ }
+}