Skip to content

Commit

Permalink
Merge 02be189 into b0b5103
Browse files Browse the repository at this point in the history
  • Loading branch information
amaitland authored Sep 4, 2020
2 parents b0b5103 + 02be189 commit 94a907c
Show file tree
Hide file tree
Showing 233 changed files with 12,854 additions and 107 deletions.
1 change: 0 additions & 1 deletion CefSharp.Example/CefSharp.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
<ItemGroup>
<Compile Include="Callback\RunFileDialogCallback.cs" />
<Compile Include="DevTools\DevToolsExtensions.cs" />
<Compile Include="DevTools\TaskMethodDevToolsMessageObserver.cs" />
<Compile Include="Handlers\AudioHandler.cs" />
<Compile Include="Handlers\ExampleResourceRequestHandler.cs" />
<Compile Include="Handlers\ExtensionHandler.cs" />
Expand Down
46 changes: 7 additions & 39 deletions CefSharp.Example/DevTools/DevToolsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace CefSharp.Example.DevTools
{
public static class DevToolsExtensions
{
private static int LastMessageId = 600000;
/// <summary>
/// Calls Page.captureScreenshot without any optional params
/// (Results in PNG image of default viewport)
Expand All @@ -23,58 +20,29 @@ public static async Task<byte[]> CaptureScreenShotAsPng(this IWebBrowser chromiu
// throw new System.Exception("Page hasn't loaded");
//}

var host = chromiumWebBrowser.GetBrowserHost();
var browser = chromiumWebBrowser.GetBrowser();

if (host == null || host.IsDisposed)
if (browser == null || browser.IsDisposed)
{
throw new Exception("BrowserHost is Null or Disposed");
throw new Exception("browser is Null or Disposed");
}

//var param = new Dictionary<string, object>
//{
// { "format", "png" },
//}

var msgId = Interlocked.Increment(ref LastMessageId);

var observer = new TaskMethodDevToolsMessageObserver(msgId);

//Make sure to dispose of our observer registration when done
//TODO: Create a single observer that maps tasks to Id's
//Or at least create one for each type, events and method
using (var observerRegistration = host.AddDevToolsMessageObserver(observer))
using (var devToolsClient = browser.GetDevToolsClient())
{
//Page.captureScreenshot defaults to PNG, all params are optional
//for this DevTools method
int id = 0;
const string methodName = "Page.captureScreenshot";

//TODO: Simplify this, we can use an Func to reduce code duplication
if (Cef.CurrentlyOnThread(CefThreadIds.TID_UI))
{
id = host.ExecuteDevToolsMethod(msgId, methodName);
}
else
{
id = await Cef.UIThreadTaskFactory.StartNew(() =>
{
return host.ExecuteDevToolsMethod(msgId, methodName);
});
}

if (id != msgId)
{
throw new Exception("Message Id doesn't match the provided Id");
}

var result = await observer.Task;

var success = result.Item1;
var result = await devToolsClient.ExecuteDevToolsMethodAsync(methodName);

dynamic response = JsonConvert.DeserializeObject<dynamic>(Encoding.UTF8.GetString(result.Item2));
dynamic response = JsonConvert.DeserializeObject<dynamic>(result.ResultAsJsonString);

//Success
if (success)
if (result.Success)
{
return Convert.FromBase64String((string)response.data);
}
Expand Down
67 changes: 0 additions & 67 deletions CefSharp.Example/DevTools/TaskMethodDevToolsMessageObserver.cs

This file was deleted.

7 changes: 7 additions & 0 deletions CefSharp.OffScreen.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ private static async void MainAsync(string cachePath, double zoomLevel)
}
await LoadPageAsync(browser);

using (var devToolsClient = browser.GetDevToolsClient())
{
var response = await devToolsClient.Browser.GetVersionAsync();
var jsVersion = response.JsVersion;
//var success = await devToolsClient.Network.ClearBrowserCacheAsync();
}

//Check preferences on the CEF UI Thread
await Cef.UIThreadTaskFactory.StartNew(delegate
{
Expand Down
Loading

0 comments on commit 94a907c

Please sign in to comment.