Skip to content

Commit

Permalink
Fixing issue #37 preventing resourcehandler garbage collecting
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Desmaisons committed Nov 16, 2017
1 parent 93cd714 commit 1f143a4
Show file tree
Hide file tree
Showing 5 changed files with 34,612 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@
<Name>Example.ChromiumFX.Vue.Infra</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Resource Include="View\Main\main.js" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\Unofficial.Cef.for.Chromiumfx.3.2924.0\build\Unofficial.Cef.for.Chromiumfx.targets" Condition="Exists('..\..\packages\Unofficial.Cef.for.Chromiumfx.3.2924.0\build\Unofficial.Cef.for.Chromiumfx.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
2 changes: 2 additions & 0 deletions Examples/Example.ChromiumFX.PackUri/View/Main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ <h2>location.href:<span>{{href}}</span></h2>
});

</script>
<script src="main.js"></script>

</body>
</html>
34,597 changes: 34,597 additions & 0 deletions Examples/Example.ChromiumFX.PackUri/View/Main/main.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand All @@ -18,21 +19,21 @@ internal class ChromiumFxWpfWindow : IWPFCfxWebWindow
{
private readonly ChromiumFxControl _ChromiumFxControl;
private readonly ChromiumWebBrowser _ChromiumWebBrowser;
private readonly ChromiumFxControlWebBrowserWindow _chromiumFxControlWebBrowserWindow;
private readonly IWebSessionLogger _Logger;
private readonly ChromiumFxControlWebBrowserWindow _ChromiumFxControlWebBrowserWindow;
private IntPtr _DebugWindowHandle;
private CfxClient _DebugCfxClient;
private CfxLifeSpanHandler _DebugCfxLifeSpanHandler;

public UIElement UIElement => _ChromiumFxControl;
public bool IsUIElementAlwaysTopMost => true;
public IWebBrowserWindow HTMLWindow => _chromiumFxControlWebBrowserWindow;
public IWebBrowserWindow HTMLWindow => _ChromiumFxControlWebBrowserWindow;
public ChromiumWebBrowser ChromiumWebBrowser => _ChromiumWebBrowser;
public event EventHandler<DebugEventArgs> DebugToolOpened;
private readonly List<PackUriResourceHandler> _PackPackUriResourceHandlers = new List<PackUriResourceHandler>();

public ChromiumFxWpfWindow(IWebSessionLogger logger)
{
_Logger = logger;
var logger1 = logger;
_ChromiumFxControl = new ChromiumFxControl()
{
Visibility = Visibility.Hidden,
Expand All @@ -52,11 +53,13 @@ public ChromiumFxWpfWindow(IWebSessionLogger logger)
return;
}
e.SetReturnValue(new PackUriResourceHandler(uri, _Logger));
var newResourceHandler= new PackUriResourceHandler(uri, logger1);
_PackPackUriResourceHandlers.Add(newResourceHandler);
e.SetReturnValue(newResourceHandler);
};

var dispatcher = new WPFUIDispatcher(_ChromiumFxControl.Dispatcher);
_chromiumFxControlWebBrowserWindow = new ChromiumFxControlWebBrowserWindow(_ChromiumWebBrowser, dispatcher, _Logger);
_ChromiumFxControlWebBrowserWindow = new ChromiumFxControlWebBrowserWindow(_ChromiumWebBrowser, dispatcher, logger1);
}

public void Inject(Key keyToInject)
Expand Down Expand Up @@ -127,6 +130,7 @@ public void CloseDebugTools()
public void Dispose()
{
_ChromiumWebBrowser.Dispose();
_PackPackUriResourceHandlers.Clear();
_DebugCfxClient = null;
_DebugCfxLifeSpanHandler = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public PackUriResourceHandler(Uri packUri, IWebSessionLogger logger)
{
e1.Response.Status = 404;
e1.Response.StatusText = "Not Found";
}
};
ReadResponse += (s2, e2) =>
{
Expand All @@ -44,7 +42,6 @@ public PackUriResourceHandler(Uri packUri, IWebSessionLogger logger)
var bytesRead = resInfo.Stream.Read(buffer, 0, e2.BytesToRead);
System.Runtime.InteropServices.Marshal.Copy(buffer, 0, e2.DataOut, bytesRead);
e2.BytesRead = bytesRead;
e2.Callback.Continue();
}
e2.SetReturnValue(true);
Expand Down

0 comments on commit 1f143a4

Please sign in to comment.