Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
andanteyk committed Apr 19, 2020
2 parents 5a0fe08 + 29488e2 commit 304ce00
Show file tree
Hide file tree
Showing 22 changed files with 406 additions and 87 deletions.
27 changes: 14 additions & 13 deletions Browser/Browser.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\CefSharp.WinForms.73.1.130\build\CefSharp.WinForms.props" Condition="Exists('..\packages\CefSharp.WinForms.73.1.130\build\CefSharp.WinForms.props')" />
<Import Project="..\packages\CefSharp.Common.73.1.130\build\CefSharp.Common.props" Condition="Exists('..\packages\CefSharp.Common.73.1.130\build\CefSharp.Common.props')" />
<Import Project="..\packages\cef.redist.x86.73.1.13\build\cef.redist.x86.props" Condition="Exists('..\packages\cef.redist.x86.73.1.13\build\cef.redist.x86.props')" />
<Import Project="..\packages\cef.redist.x64.73.1.13\build\cef.redist.x64.props" Condition="Exists('..\packages\cef.redist.x64.73.1.13\build\cef.redist.x64.props')" />
<Import Project="..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.props" Condition="Exists('..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.props')" />
<Import Project="..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.props" Condition="Exists('..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.props')" />
<Import Project="..\packages\cef.redist.x86.79.1.36\build\cef.redist.x86.props" Condition="Exists('..\packages\cef.redist.x86.79.1.36\build\cef.redist.x86.props')" />
<Import Project="..\packages\cef.redist.x64.79.1.36\build\cef.redist.x64.props" Condition="Exists('..\packages\cef.redist.x64.79.1.36\build\cef.redist.x64.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -82,10 +82,11 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CefOp\CustomRequestHandler.cs" />
<Compile Include="CefOp\CustomResourceRequestHandler.cs" />
<Compile Include="CefOp\DragHandler.cs" />
<Compile Include="CefOp\KeyboardHandler.cs" />
<Compile Include="CefOp\MenuHandler.cs" />
<Compile Include="CefOp\RequestHandler.cs" />
<Compile Include="CefOp\ResponseFilterPixiSetting.cs" />
<Compile Include="CefOp\ScreenShotPacket.cs" />
<Compile Include="FormBrowser.cs">
Expand Down Expand Up @@ -151,15 +152,15 @@
<PropertyGroup>
<ErrorText>このプロジェクトは、このコンピューター上にない NuGet パッケージを参照しています。それらのパッケージをダウンロードするには、[NuGet パッケージの復元] を使用します。詳細については、http://go.microsoft.com/fwlink/?LinkID=322105 を参照してください。見つからないファイルは {0} です。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\cef.redist.x64.73.1.13\build\cef.redist.x64.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\cef.redist.x64.73.1.13\build\cef.redist.x64.props'))" />
<Error Condition="!Exists('..\packages\cef.redist.x86.73.1.13\build\cef.redist.x86.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\cef.redist.x86.73.1.13\build\cef.redist.x86.props'))" />
<Error Condition="!Exists('..\packages\CefSharp.Common.73.1.130\build\CefSharp.Common.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Common.73.1.130\build\CefSharp.Common.props'))" />
<Error Condition="!Exists('..\packages\CefSharp.Common.73.1.130\build\CefSharp.Common.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Common.73.1.130\build\CefSharp.Common.targets'))" />
<Error Condition="!Exists('..\packages\CefSharp.WinForms.73.1.130\build\CefSharp.WinForms.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.WinForms.73.1.130\build\CefSharp.WinForms.props'))" />
<Error Condition="!Exists('..\packages\CefSharp.WinForms.73.1.130\build\CefSharp.WinForms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.WinForms.73.1.130\build\CefSharp.WinForms.targets'))" />
<Error Condition="!Exists('..\packages\cef.redist.x64.79.1.36\build\cef.redist.x64.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\cef.redist.x64.79.1.36\build\cef.redist.x64.props'))" />
<Error Condition="!Exists('..\packages\cef.redist.x86.79.1.36\build\cef.redist.x86.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\cef.redist.x86.79.1.36\build\cef.redist.x86.props'))" />
<Error Condition="!Exists('..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.props'))" />
<Error Condition="!Exists('..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.targets'))" />
<Error Condition="!Exists('..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.props'))" />
<Error Condition="!Exists('..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.targets'))" />
</Target>
<Import Project="..\packages\CefSharp.Common.73.1.130\build\CefSharp.Common.targets" Condition="Exists('..\packages\CefSharp.Common.73.1.130\build\CefSharp.Common.targets')" />
<Import Project="..\packages\CefSharp.WinForms.73.1.130\build\CefSharp.WinForms.targets" Condition="Exists('..\packages\CefSharp.WinForms.73.1.130\build\CefSharp.WinForms.targets')" />
<Import Project="..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.targets" Condition="Exists('..\packages\CefSharp.Common.79.1.360\build\CefSharp.Common.targets')" />
<Import Project="..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.targets" Condition="Exists('..\packages\CefSharp.WinForms.79.1.360\build\CefSharp.WinForms.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,30 @@

namespace Browser.CefOp
{
public class RequestHandler : DefaultRequestHandler
public class CustomRequestHandler : RequestHandler
{
public delegate void RenderProcessTerminatedEventHandler(string message);
public event RenderProcessTerminatedEventHandler RenderProcessTerminated;

bool pixiSettingEnabled;


public RequestHandler(bool pixiSettingEnabled) : base()

public CustomRequestHandler(bool pixiSettingEnabled) : base()
{
this.pixiSettingEnabled = pixiSettingEnabled;
}

/// <summary>
/// レスポンスの置換制御を行います。
/// </summary>
public override IResponseFilter GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
protected override IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
{
if (pixiSettingEnabled && request.Url.Contains(@"/kcs2/index.php"))
return new ResponseFilterPixiSetting();

return base.GetResourceResponseFilter(browserControl, browser, frame, request, response);
return new CustomResourceRequestHandler(pixiSettingEnabled);
}

/// <summary>
/// 特定の通信をブロックします。
/// </summary>
public override CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
{
// ログイン直後に勝手に遷移させられ、ブラウザがホワイトアウトすることがあるためブロックする
if (request.Url.Contains(@"/rt.gsspat.jp/"))
{
return CefReturnValue.Cancel;
}

return base.OnBeforeResourceLoad(browserControl, browser, frame, request, callback);
}

/// <summary>
/// 戻る/進む操作をブロックします。
/// </summary>
public override bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect)
protected override bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect)
{
if ((request.TransitionType & TransitionType.ForwardBack) != 0)
{
Expand All @@ -61,7 +43,7 @@ public override bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser
/// <summary>
/// 描画プロセスが何らかの理由で落ちた際の処理を行います。
/// </summary>
public override void OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status)
protected override void OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status)
{
// note: out of memory (例外コード: 0xe0000008) でクラッシュした場合、このイベントは呼ばれない

Expand Down
48 changes: 48 additions & 0 deletions Browser/CefOp/CustomResourceRequestHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using CefSharp;
using CefSharp.Handler;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Browser.CefOp
{
public class CustomResourceRequestHandler : ResourceRequestHandler
{

bool pixiSettingEnabled;

public CustomResourceRequestHandler(bool pixiSettingEnabled) : base()
{
this.pixiSettingEnabled = pixiSettingEnabled;
}


/// <summary>
/// レスポンスの置換制御を行います。
/// </summary>
protected override IResponseFilter GetResourceResponseFilter(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response)
{
if (pixiSettingEnabled && request.Url.Contains(@"/kcs2/index.php"))
return new ResponseFilterPixiSetting();

return base.GetResourceResponseFilter(chromiumWebBrowser, browser, frame, request, response);
}

/// <summary>
/// 特定の通信をブロックします。
/// </summary>
protected override CefReturnValue OnBeforeResourceLoad(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
{
// ログイン直後に勝手に遷移させられ、ブラウザがホワイトアウトすることがあるためブロックする
if (request.Url.Contains(@"/rt.gsspat.jp/"))
{
return CefReturnValue.Cancel;
}

return base.OnBeforeResourceLoad(chromiumWebBrowser, browser, frame, request, callback);
}

}
}
4 changes: 2 additions & 2 deletions Browser/CefOp/DragHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public bool OnDragEnter(IWebBrowser browserControl, IBrowser browser, IDragData
return true;
}

public void OnDraggableRegionsChanged(IWebBrowser browserControl, IBrowser browser, IList<DraggableRegion> regions)
public void OnDraggableRegionsChanged(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IList<DraggableRegion> regions)
{
// nop?
// nop
}
}
}
28 changes: 24 additions & 4 deletions Browser/FormBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private bool StyleSheetApplied
/// </summary>
private bool IsKanColleLoaded { get; set; }

private VolumeManager _volumeManager;
private VolumeManager _volumeManager = null;

private string _lastScreenShotPath;

Expand All @@ -116,7 +116,6 @@ public FormBrowser(string serverUri)

ServerUri = serverUri;
StyleSheetApplied = false;
_volumeManager = new VolumeManager((uint)Process.GetCurrentProcess().Id);


// 音量設定用コントロールの追加
Expand Down Expand Up @@ -237,7 +236,7 @@ void InitializeBrowser()
Cef.Initialize(settings, false, (IBrowserProcessHandler)null);


var requestHandler = new RequestHandler(pixiSettingEnabled: Configuration.PreserveDrawingBuffer);
var requestHandler = new CustomRequestHandler(pixiSettingEnabled: Configuration.PreserveDrawingBuffer);
requestHandler.RenderProcessTerminated += (mes) => AddLog(3, mes);

Browser = new ChromiumWebBrowser(@"about:blank")
Expand Down Expand Up @@ -493,7 +492,7 @@ public void DestroyDMMreloadDialog()
// その場合ロードに失敗してブラウザが白画面でスタートしてしまう(手動でログインページを開けば続行は可能だが)
// 応急処置として失敗したとき後で再試行するようにしてみる
private string navigateCache = null;
private void Browser_IsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs e)
private void Browser_IsBrowserInitializedChanged(object sender, EventArgs e)
{
if (IsBrowserInitialized && navigateCache != null)
{
Expand Down Expand Up @@ -839,6 +838,11 @@ public void SetIconResource(byte[] canvas)
}


private void TryGetVolumeManager()
{
_volumeManager = VolumeManager.CreateInstanceByProcessName("CefSharp.BrowserSubprocess");
}

private void SetVolumeState()
{

Expand All @@ -847,13 +851,19 @@ private void SetVolumeState()

try
{
if (_volumeManager == null)
{
TryGetVolumeManager();
}

mute = _volumeManager.IsMute;
volume = _volumeManager.Volume * 100;

}
catch (Exception)
{
// 音量データ取得不能時
_volumeManager = null;
mute = false;
volume = 100;
}
Expand Down Expand Up @@ -954,6 +964,11 @@ private void ToolMenu_Zoom_DropDownOpening(object sender, EventArgs e)

private void ToolMenu_Other_Mute_Click(object sender, EventArgs e)
{
if (_volumeManager == null)
{
TryGetVolumeManager();
}

try
{
_volumeManager.ToggleMute();
Expand All @@ -972,6 +987,11 @@ void ToolMenu_Other_Volume_ValueChanged(object sender, EventArgs e)

var control = ToolMenu_Other_Volume_VolumeControl;

if (_volumeManager == null)
{
TryGetVolumeManager();
}

try
{
if ((bool)control.Tag)
Expand Down
8 changes: 4 additions & 4 deletions Browser/packages.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="cef.redist.x64" version="73.1.13" targetFramework="net452" />
<package id="cef.redist.x86" version="73.1.13" targetFramework="net452" />
<package id="CefSharp.Common" version="73.1.130" targetFramework="net452" />
<package id="CefSharp.WinForms" version="73.1.130" targetFramework="net452" />
<package id="cef.redist.x64" version="79.1.36" targetFramework="net452" />
<package id="cef.redist.x86" version="79.1.36" targetFramework="net452" />
<package id="CefSharp.Common" version="79.1.360" targetFramework="net452" />
<package id="CefSharp.WinForms" version="79.1.360" targetFramework="net452" />
<package id="log4net" version="2.0.8" targetFramework="net452" />
<package id="Nekoxy" version="1.5.3.21" targetFramework="net45" />
</packages>
Loading

0 comments on commit 304ce00

Please sign in to comment.