Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/master' into cef/2171
Browse files Browse the repository at this point in the history
  • Loading branch information
amaitland committed Dec 16, 2014
2 parents ffac7e6 + 6089015 commit d3d8d53
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 6 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*.exe.config
*.exp
*.ipch
*.manifest
*.metagen
*.ncb
*.nupkg
Expand Down
4 changes: 4 additions & 0 deletions CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\CefSharp.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -93,6 +96,7 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="app.manifest" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CefSharp.BrowserSubprocess.Core\CefSharp.BrowserSubprocess.Core.vcxproj">
Expand Down
54 changes: 54 additions & 0 deletions CefSharp.BrowserSubprocess/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>

<asmv1:assembly
manifestVersion="1.0"
xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<assemblyIdentity version="37.0.0.0" name="CefSharp.BrowserSubprocess.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel node will disable file and registry virtualization.
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with.
Windows will automatically select the most compatible environment.-->

<!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->

<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->

<!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->

<!-- If your application is designed to work with Windows 8.1, uncomment the following supportedOS node-->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>-->
</application>
</compatibility>
</asmv1:assembly>
4 changes: 4 additions & 0 deletions CefSharp.Example/CefExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,6 +53,9 @@ public static void RegisterTestResources(IWebBrowser browser)
{
const string responseBody = "<html><body><h1>Success</h1><p>This document is loaded from a System.IO.Stream</p></body></html>";
handler.RegisterHandler(TestResourceUrl, ResourceHandler.FromString(responseBody));

const string unicodeResponseBody = "<html><body>整体满意度</body></html>";
handler.RegisterHandler(TestUnicodeResourceUrl, ResourceHandler.FromString(unicodeResponseBody));
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion CefSharp.OffScreen/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -251,14 +252,19 @@ 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)
{
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);
}
Expand Down Expand Up @@ -502,6 +508,12 @@ void IWebBrowserInternal.SetNavState(bool canGoBack, bool canGoForward, bool can
CanGoBack = canGoBack;
CanGoForward = canGoForward;
CanReload = canReload;

var handler = NavStateChanged;
if (handler != null)
{
handler(this, new NavStateChangedEventArgs(canGoBack, canGoForward, canReload));
}
}

void IWebBrowserInternal.SetTitle(string title)
Expand Down
4 changes: 4 additions & 0 deletions CefSharp.WinForms.Example/CefSharp.WinForms.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
Expand Down Expand Up @@ -111,6 +114,7 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="app.manifest" />
<None Include="packages.config" />
<None Include="Resources\nav_left_green.png" />
</ItemGroup>
Expand Down
54 changes: 54 additions & 0 deletions CefSharp.WinForms.Example/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>

<asmv1:assembly
manifestVersion="1.0"
xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<assemblyIdentity version="37.0.0.0" name="CefSharp.WinForms.Example.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel node will disable file and registry virtualization.
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with.
Windows will automatically select the most compatible environment.-->

<!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->

<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->

<!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->

<!-- If your application is designed to work with Windows 8.1, uncomment the following supportedOS node-->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>-->
</application>
</compatibility>
</asmv1:assembly>
8 changes: 7 additions & 1 deletion CefSharp.WinForms/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,14 +104,19 @@ 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)
{
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);
}
Expand Down
8 changes: 7 additions & 1 deletion CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1012,14 +1013,19 @@ 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)
{
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);
}
Expand Down
15 changes: 15 additions & 0 deletions CefSharp/IWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <see cref="ResourceHandler"/> and loads the provided url using
/// the <see cref="Load"/> method.
/// Defaults to using <see cref="Encoding.UTF8"/> for character encoding
/// </remarks>
/// <param name="html">The HTML content.</param>
/// <param name="url">The URL that will be treated as the address of the content.</param>
void LoadHtml(string html, string url);

/// <summary>
/// Registers and loads a <see cref="ResourceHandler"/> that represents the HTML content.
/// </summary>
/// <remarks>
/// `Cef` Native `LoadHtml` is unpredictable and only works sometimes, this method wraps
/// the provided HTML in a <see cref="ResourceHandler"/> and loads the provided url using
/// the <see cref="Load"/> method.
/// </remarks>
/// <param name="html">The HTML content.</param>
/// <param name="url">The URL that will be treated as the address of the content.</param>
/// <param name="encoding">Character Encoding</param>
void LoadHtml(string html, string url, Encoding encoding);

/// <summary>
/// Registers a Javascript object in this specific browser instance.
/// </summary>
Expand Down
50 changes: 48 additions & 2 deletions CefSharp/ResourceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,59 @@ public static ResourceHandler FromFileName(string fileName, string fileExtension
}

/// <summary>
/// Gets the resource from the string.
/// Gets a <see cref="ResourceHandler"/> that represents a string.
/// Defaults to <see cref="Encoding.UTF8"/> and includes encoding preamble
/// </summary>
/// <param name="text">The text.</param>
/// <returns>ResourceHandler.</returns>
public static ResourceHandler FromString(string text)
{
return new ResourceHandler { Stream = new MemoryStream(Encoding.UTF8.GetBytes(text)) };
return FromString(text, Encoding.UTF8, true);
}

/// <summary>
/// Gets a <see cref="ResourceHandler"/> that represents a string.
/// Uses the specified encoding and includes encoding preamble.
/// </summary>
/// <param name="text">The html string</param>
/// <param name="encoding">Character Encoding</param>
/// <returns>ResourceHandler</returns>
public static ResourceHandler FromString(string text, Encoding encoding)
{
return FromString(text, encoding, true);
}

/// <summary>
/// Gets a <see cref="ResourceHandler"/> that represents a string.
/// Without a Preamble, Cef will use BrowserSettings.DefaultEncoding to load the html.
/// </summary>
/// <param name="text">The html string</param>
/// <param name="encoding">Character Encoding</param>
/// <param name="includePreamble">Include encoding preamble</param>
/// <returns>ResourceHandler</returns>
public static ResourceHandler FromString(string text, Encoding encoding, bool includePreamble)
{
return new ResourceHandler { Stream = GetStream(text, encoding, includePreamble) };
}

private static MemoryStream GetStream(string text, Encoding encoding, bool includePreamble)
{
if (includePreamble)
{
var preamble = encoding.GetPreamble();
var bytes = encoding.GetBytes(text);

var memoryStream = new MemoryStream(preamble.Length + bytes.Length);

memoryStream.Write(preamble, 0, preamble.Length);
memoryStream.Write(bytes, 0, bytes.Length);

memoryStream.Position = 0;

return memoryStream;
}

return new MemoryStream(encoding.GetBytes(text));
}

/// <summary>
Expand Down

0 comments on commit d3d8d53

Please sign in to comment.