diff --git a/HtmlRenderer/BuiltinFunctionHandler.cs b/HtmlRenderer/BuiltinFunctionHandler.cs
index 80e7f74e0..c34f331a2 100644
--- a/HtmlRenderer/BuiltinFunctionHandler.cs
+++ b/HtmlRenderer/BuiltinFunctionHandler.cs
@@ -11,10 +11,12 @@ class BuiltinFunctionHandler : CefV8Handler
{
public event EventHandler BroadcastMessage;
public event EventHandler SendMessage;
+ public event EventHandler OverlayMessage;
public event EventHandler EndEncounter;
public const string BroadcastMessageFunctionName = "broadcastMessage";
public const string SendMessageFunctionName = "sendMessage";
+ public const string OverlayMessageFunctionName = "overlayMessage";
public const string EndEncounterFunctionName = "endEncounter";
protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
@@ -54,6 +56,22 @@ protected override bool Execute(string name, CefV8Value obj, CefV8Value[] argume
return true;
}
+ else if (name == OverlayMessageFunctionName)
+ {
+ if (arguments.Length > 1)
+ {
+ if (OverlayMessage != null)
+ {
+ OverlayMessage(obj, new SendMessageEventArgs(arguments[0].GetStringValue(), arguments[1].GetStringValue()));
+ }
+ }
+ else
+ {
+ exception = "Invalid argument count.";
+ }
+
+ return true;
+ }
else if (name == EndEncounterFunctionName)
{
if (EndEncounter != null)
diff --git a/HtmlRenderer/LoadHandler.cs b/HtmlRenderer/LoadHandler.cs
index d14f3fa41..8a3cd045b 100644
--- a/HtmlRenderer/LoadHandler.cs
+++ b/HtmlRenderer/LoadHandler.cs
@@ -22,6 +22,7 @@ protected override void OnLoadStart(CefBrowser browser, CefFrame frame)
var message = CefProcessMessage.Create("SetOverlayAPI");
message.Arguments.SetString(0, frame.Name);
+ message.Arguments.SetString(1, this.renderer.OverlayName);
browser.SendProcessMessage(CefProcessId.Renderer, message);
}
diff --git a/HtmlRenderer/RenderProcessHandler.cs b/HtmlRenderer/RenderProcessHandler.cs
index 0646ffeea..2ed8b3146 100644
--- a/HtmlRenderer/RenderProcessHandler.cs
+++ b/HtmlRenderer/RenderProcessHandler.cs
@@ -22,6 +22,10 @@ public RenderProcessHandler()
{
Renderer.OnSendMessage(o, e);
};
+ this.builtinFunctionHandler.OverlayMessage += (o, e) =>
+ {
+ Renderer.OnOverlayMessage(o, e);
+ };
this.builtinFunctionHandler.EndEncounter += (o, e) =>
{
Renderer.OnRendererFeatureRequest(o, new RendererFeatureRequestEventArgs("EndEncounter"));
@@ -35,6 +39,7 @@ protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessI
// 対象のフレームを取得
var frameName = message.Arguments.GetString(0);
var frame = GetFrameByName(browser, frameName);
+ var overlayName = message.Arguments.GetString(1);
// API を設定
if (frame != null && frame.V8Context.Enter())
@@ -47,10 +52,15 @@ protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessI
var sendMessageFunction = CefV8Value.CreateFunction(
BuiltinFunctionHandler.SendMessageFunctionName,
builtinFunctionHandler);
+ var overlayMessageFunction = CefV8Value.CreateFunction(
+ BuiltinFunctionHandler.OverlayMessageFunctionName,
+ builtinFunctionHandler);
var endEncounterFunction = CefV8Value.CreateFunction(
BuiltinFunctionHandler.EndEncounterFunctionName,
builtinFunctionHandler);
+ apiObject.SetValue("overlayName", CefV8Value.CreateString(overlayName), CefV8PropertyAttribute.ReadOnly);
+
apiObject.SetValue(
BuiltinFunctionHandler.BroadcastMessageFunctionName,
broadcastMessageFunction,
@@ -59,6 +69,10 @@ protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessI
BuiltinFunctionHandler.SendMessageFunctionName,
sendMessageFunction,
CefV8PropertyAttribute.ReadOnly);
+ apiObject.SetValue(
+ BuiltinFunctionHandler.OverlayMessageFunctionName,
+ overlayMessageFunction,
+ CefV8PropertyAttribute.ReadOnly);
apiObject.SetValue(
BuiltinFunctionHandler.EndEncounterFunctionName,
endEncounterFunction,
diff --git a/HtmlRenderer/Renderer.cs b/HtmlRenderer/Renderer.cs
index 9cd5b3c8c..4cd4dc39f 100644
--- a/HtmlRenderer/Renderer.cs
+++ b/HtmlRenderer/Renderer.cs
@@ -16,6 +16,7 @@ public class Renderer : IDisposable
public static event EventHandler BroadcastMessage;
public static event EventHandler SendMessage;
+ public static event EventHandler OverlayMessage;
public static event EventHandler RendererFeatureRequest;
// Guards access to |allBrowsers| across threads.
@@ -43,6 +44,10 @@ public CefBrowser Browser
}
}
+ public string OverlayName {
+ get { return overlayName; }
+ }
+
private Client Client { get; set; }
private int clickCount;
@@ -50,10 +55,11 @@ public CefBrowser Browser
private DateTime lastClickTime;
private int lastClickPosX;
private int lastClickPosY;
+ private string overlayName;
- public Renderer()
+ public Renderer(string overlayName)
{
-
+ this.overlayName = overlayName;
}
public void BeginRender(int width, int height, string url, int maxFrameRate = 30)
@@ -286,6 +292,12 @@ internal static void OnSendMessage(object sender, SendMessageEventArgs e)
}
}
+ internal static void OnOverlayMessage(object sender, SendMessageEventArgs e) {
+ if (OverlayMessage != null) {
+ OverlayMessage(sender, e);
+ }
+ }
+
internal static void OnRendererFeatureRequest(object sender, RendererFeatureRequestEventArgs e)
{
if (RendererFeatureRequest != null)
diff --git a/OverlayPlugin.Common/IOverlay.cs b/OverlayPlugin.Common/IOverlay.cs
index 0af3b8929..a94eda2d9 100644
--- a/OverlayPlugin.Common/IOverlay.cs
+++ b/OverlayPlugin.Common/IOverlay.cs
@@ -57,5 +57,11 @@ public interface IOverlay : IDisposable
///
/// メッセージの内容。
void SendMessage(string message);
+
+ ///
+ /// A message from javascript for the overlay plugin to consume.
+ ///
+ /// A string message created by the plugin javascript.
+ void OverlayMessage(string message);
}
}
diff --git a/OverlayPlugin.Core/OverlayBase.cs b/OverlayPlugin.Core/OverlayBase.cs
index 56d13b377..64e1b0017 100644
--- a/OverlayPlugin.Core/OverlayBase.cs
+++ b/OverlayPlugin.Core/OverlayBase.cs
@@ -77,7 +77,7 @@ protected virtual void InitializeOverlay()
{
try
{
- this.Overlay = new OverlayForm("about:blank", this.Config.MaxFrameRate);
+ this.Overlay = new OverlayForm(this.Name, "about:blank", this.Config.MaxFrameRate);
// グローバルホットキーを設定
if (this.Config.GlobalHotkeyEnabled)
@@ -383,5 +383,9 @@ public void SendMessage(string message)
this.Overlay.Renderer.ExecuteScript(script);
}
}
+
+ public virtual void OverlayMessage(string message)
+ {
+ }
}
}
diff --git a/OverlayPlugin.Core/OverlayForm.cs b/OverlayPlugin.Core/OverlayForm.cs
index 477929561..aab658359 100644
--- a/OverlayPlugin.Core/OverlayForm.cs
+++ b/OverlayPlugin.Core/OverlayForm.cs
@@ -61,13 +61,13 @@ public bool IsClickThru
public bool Locked { get; set; }
- public OverlayForm(string url, int maxFrameRate = 30)
+ public OverlayForm(string overlayName, string url, int maxFrameRate = 30)
{
InitializeComponent();
Renderer.Initialize();
this.maxFrameRate = maxFrameRate;
- this.Renderer = new Renderer();
+ this.Renderer = new Renderer(overlayName);
this.Renderer.Render += renderer_Render;
this.MouseWheel += OverlayForm_MouseWheel;
diff --git a/OverlayPlugin.Core/PluginMain.cs b/OverlayPlugin.Core/PluginMain.cs
index 5d376ac39..dbf3fdc1a 100644
--- a/OverlayPlugin.Core/PluginMain.cs
+++ b/OverlayPlugin.Core/PluginMain.cs
@@ -84,6 +84,16 @@ public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText)
}
});
};
+ RainbowMage.HtmlRenderer.Renderer.OverlayMessage += (o, e) =>
+ {
+ Task.Run(() =>
+ {
+ var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
+ if (targetOverlay != null) {
+ targetOverlay.OverlayMessage(e.Message);
+ }
+ });
+ };
RainbowMage.HtmlRenderer.Renderer.RendererFeatureRequest += (o, e) =>
{
Task.Run(() =>