diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index 672d7fe52c..6a00fac224 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -8,6 +8,7 @@ public static class CefExample { public const string DefaultUrl = "custom://cefsharp/BindingTest.html"; public const string TestResourceUrl = "http://test/resource/load"; + public const string TestUnicodeResourceUrl = "http://test/resource/loadUnicode"; // Use when debugging the actual SubProcess, to make breakpoints etc. inside that project work. private static readonly bool DebuggingSubProcess = Debugger.IsAttached; @@ -52,6 +53,9 @@ public static void RegisterTestResources(IWebBrowser browser) { const string responseBody = "
This document is loaded from a System.IO.Stream
"; handler.RegisterHandler(TestResourceUrl, ResourceHandler.FromString(responseBody)); + + const string unicodeResponseBody = "整体满意度"; + handler.RegisterHandler(TestUnicodeResourceUrl, ResourceHandler.FromString(unicodeResponseBody)); } } } diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index 20affe0003..302962c700 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -5,6 +5,7 @@ using System; using System.Drawing; using System.Drawing.Imaging; +using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; @@ -240,6 +241,11 @@ public void Load(string url) } public void LoadHtml(string html, string url) + { + LoadHtml(html, url, Encoding.UTF8); + } + + public void LoadHtml(string html, string url, Encoding encoding) { var handler = ResourceHandler; if (handler == null) @@ -247,7 +253,7 @@ public void LoadHtml(string html, string url) throw new Exception("Implement IResourceHandler and assign to the ResourceHandler property to use this feature"); } - handler.RegisterHandler(url, CefSharp.ResourceHandler.FromString(html)); + handler.RegisterHandler(url, CefSharp.ResourceHandler.FromString(html, encoding, true)); Load(url); } diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 5f424d1596..08e33a5d9e 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -3,6 +3,7 @@ // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; +using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using CefSharp.Internals; @@ -103,6 +104,11 @@ public void Load(String url) } public void LoadHtml(string html, string url) + { + LoadHtml(html, url, Encoding.UTF8); + } + + public void LoadHtml(string html, string url, Encoding encoding) { var handler = ResourceHandler; if (handler == null) @@ -110,7 +116,7 @@ public void LoadHtml(string html, string url) throw new Exception("Implement IResourceHandler and assign to the ResourceHandler property to use this feature"); } - handler.RegisterHandler(url, CefSharp.ResourceHandler.FromString(html)); + handler.RegisterHandler(url, CefSharp.ResourceHandler.FromString(html, encoding, true)); Load(url); } diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index be8ace1aa9..f7320fb7b9 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -2,6 +2,7 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. +using System.Text; using CefSharp.Internals; using Microsoft.Win32.SafeHandles; using System; @@ -1007,6 +1008,11 @@ public void Load(string url) } public void LoadHtml(string html, string url) + { + LoadHtml(html, url, Encoding.UTF8); + } + + public void LoadHtml(string html, string url, Encoding encoding) { var handler = ResourceHandler; if (handler == null) @@ -1014,7 +1020,7 @@ public void LoadHtml(string html, string url) throw new Exception("Implement IResourceHandler and assign to the ResourceHandler property to use this feature"); } - handler.RegisterHandler(url, CefSharp.ResourceHandler.FromString(html)); + handler.RegisterHandler(url, CefSharp.ResourceHandler.FromString(html, encoding, true)); Load(url); } diff --git a/CefSharp/IWebBrowser.cs b/CefSharp/IWebBrowser.cs index db9dd8c765..32d34d98f2 100644 --- a/CefSharp/IWebBrowser.cs +++ b/CefSharp/IWebBrowser.cs @@ -3,6 +3,7 @@ // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; +using System.Text; using System.Threading.Tasks; namespace CefSharp @@ -59,11 +60,25 @@ public interface IWebBrowser : IDisposable /// `Cef` Native `LoadHtml` is unpredictable and only works sometimes, this method wraps /// the provided HTML in a