123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- using System;
- using Xilium.CefGlue.Common.Shared.Serialization;
- namespace Xilium.CefGlue.Common.Shared.RendererProcessCommunication
- {
- internal static class Messages
- {
- public struct JsEvaluationRequest
- {
- public const string Name = nameof(JsEvaluationRequest);
- public int TaskId;
- public string Script;
- public string Url;
- public int Line;
- public CefProcessMessage ToCefProcessMessage()
- {
- var message = CefProcessMessage.Create(Name);
- var arguments = message.Arguments;
- arguments.SetInt(0, TaskId);
- arguments.SetString(1, Script);
- arguments.SetString(2, Url);
- arguments.SetInt(3, Line);
- return message;
- }
- public static JsEvaluationRequest FromCefMessage(CefProcessMessage message)
- {
- var arguments = message.Arguments;
- return new JsEvaluationRequest()
- {
- TaskId = arguments.GetInt(0),
- Script = arguments.GetString(1),
- Url = arguments.GetString(2),
- Line = arguments.GetInt(3)
- };
- }
- }
- public struct JsEvaluationResult
- {
- public const string Name = nameof(JsEvaluationResult);
- public int TaskId;
- public bool Success;
- public CefValueHolder Result;
- public string Exception;
- public CefProcessMessage ToCefProcessMessage()
- {
- var message = CefProcessMessage.Create(Name);
- var arguments = message.Arguments;
- arguments.SetInt(0, TaskId);
- arguments.SetBool(1, Success);
- Result?.CopyTo(arguments, 2);
- arguments.SetString(3, Exception);
- return message;
- }
- public static JsEvaluationResult FromCefMessage(CefProcessMessage message)
- {
- var arguments = message.Arguments;
- return new JsEvaluationResult()
- {
- TaskId = arguments.GetInt(0),
- Success = arguments.GetBool(1),
- Result = new CefValueHolder(arguments, 2, isReadOnly: true),
- Exception = arguments.GetString(3)
- };
- }
- }
- public struct NativeObjectRegistrationRequest
- {
- public const string Name = nameof(NativeObjectRegistrationRequest);
- public string ObjectName;
- public string[] MethodsNames;
- public CefProcessMessage ToCefProcessMessage()
- {
- var message = CefProcessMessage.Create(Name);
- var arguments = message.Arguments;
- arguments.SetString(0, ObjectName);
- var methods = CefListValue.Create();
- for (var i = 0; i < MethodsNames.Length; i++)
- {
- methods.SetString(i, MethodsNames[i]);
- }
- arguments.SetList(1, methods);
- return message;
- }
- public static NativeObjectRegistrationRequest FromCefMessage(CefProcessMessage message)
- {
- var arguments = message.Arguments;
- var methodsNames = arguments.GetList(1);
- return new NativeObjectRegistrationRequest()
- {
- ObjectName = arguments.GetString(0),
- MethodsNames = CefValueSerialization.DeserializeCefList<string>(methodsNames)
- };
- }
- }
- public struct NativeObjectUnregistrationRequest
- {
- public const string Name = nameof(NativeObjectUnregistrationRequest);
- public string ObjectName;
- public CefProcessMessage ToCefProcessMessage()
- {
- var message = CefProcessMessage.Create(Name);
- var arguments = message.Arguments;
- arguments.SetString(0, ObjectName);
- return message;
- }
- public static NativeObjectRegistrationRequest FromCefMessage(CefProcessMessage message)
- {
- var arguments = message.Arguments;
- return new NativeObjectRegistrationRequest()
- {
- ObjectName = arguments.GetString(0),
- };
- }
- }
- public struct NativeObjectCallRequest : IDisposable
- {
- public const string Name = nameof(NativeObjectCallRequest);
- public int CallId;
- public string ObjectName;
- public string MemberName;
- public ICefListValue Arguments;
- public CefProcessMessage ToCefProcessMessage()
- {
- var message = CefProcessMessage.Create(Name);
- var arguments = message.Arguments;
- arguments.SetInt(0, CallId);
- arguments.SetString(1, ObjectName);
- arguments.SetString(2, MemberName);
- arguments.SetList(3, Arguments);
- return message;
- }
- public static NativeObjectCallRequest FromCefMessage(CefProcessMessage message)
- {
- var arguments = message.Arguments;
- return new NativeObjectCallRequest()
- {
- CallId = arguments.GetInt(0),
- ObjectName = arguments.GetString(1),
- MemberName = arguments.GetString(2),
- Arguments = arguments.GetList(3)
- };
- }
- public void Dispose()
- {
- Arguments?.Dispose();
- }
- }
- public struct NativeObjectCallResult
- {
- public const string Name = nameof(NativeObjectCallResult);
- public int CallId;
- public bool Success;
- public CefValueHolder Result;
- public string Exception;
- public CefProcessMessage ToCefProcessMessage()
- {
- var message = CefProcessMessage.Create(Name);
- var arguments = message.Arguments;
- arguments.SetInt(0, CallId);
- arguments.SetBool(1, Success);
- Result?.CopyTo(arguments, 2);
- arguments.SetString(3, Exception);
- return message;
- }
- public static NativeObjectCallResult FromCefMessage(CefProcessMessage message)
- {
- var arguments = message.Arguments;
- return new NativeObjectCallResult() {
- CallId = arguments.GetInt(0),
- Success = arguments.GetBool(1),
- Result = new CefValueHolder(arguments, 2, isReadOnly: true),
- Exception = arguments.GetString(3)
- };
- }
- }
- public struct JsContextCreated
- {
- public const string Name = nameof(JsContextCreated);
- public CefProcessMessage ToCefProcessMessage()
- {
- return CefProcessMessage.Create(Name);
- }
- public static JsContextCreated FromCefMessage(CefProcessMessage message)
- {
- return new JsContextCreated();
- }
- }
- public struct JsContextReleased
- {
- public const string Name = nameof(JsContextReleased);
- public CefProcessMessage ToCefProcessMessage()
- {
- return CefProcessMessage.Create(Name);
- }
- public static JsContextReleased FromCefMessage(CefProcessMessage message)
- {
- return new JsContextReleased();
- }
- }
- public struct JsUncaughtException
- {
- public const string Name = nameof(JsUncaughtException);
- public string Message;
- public JsStackFrame[] StackFrames;
- public CefProcessMessage ToCefProcessMessage()
- {
- var message = CefProcessMessage.Create(Name);
- var arguments = message.Arguments;
- arguments.SetString(0, Message);
- var frames = CefListValue.Create();
- for (var i = 0; i < StackFrames.Length; i++)
- {
- frames.SetList(i, StackFrames[i].ToCefValue());
- }
- arguments.SetList(1, frames);
- return message;
- }
- public static JsUncaughtException FromCefMessage(CefProcessMessage message)
- {
- var arguments = message.Arguments;
- var cefFrames = arguments.GetList(1);
- var frames = new JsStackFrame[cefFrames.Count];
- for (var i = 0; i < cefFrames.Count; i++)
- {
- var cefFrame = cefFrames.GetList(i);
- frames[i] = JsStackFrame.FromCefValue(cefFrame);
- }
- return new JsUncaughtException()
- {
- Message = arguments.GetString(0),
- StackFrames = frames
- };
- }
- }
- public struct JsStackFrame
- {
- public int Column;
- public string FunctionName;
- public int LineNumber;
- public string ScriptNameOrSourceUrl;
- internal CefListValue ToCefValue()
- {
- var result = CefListValue.Create();
- result.SetString(0, FunctionName);
- result.SetString(1, ScriptNameOrSourceUrl);
- result.SetInt(2, LineNumber);
- result.SetInt(3, Column);
- return result;
- }
- internal static JsStackFrame FromCefValue(ICefListValue frame)
- {
- return new JsStackFrame()
- {
- FunctionName = frame.GetString(0),
- ScriptNameOrSourceUrl = frame.GetString(1),
- LineNumber = frame.GetInt(2),
- Column = frame.GetInt(3)
- };
- }
- }
- public struct UnhandledException
- {
- public const string Name = nameof(UnhandledException);
- public string ExceptionType;
- public string Message;
- public string StackTrace;
- public CefProcessMessage ToCefProcessMessage()
- {
- var message = CefProcessMessage.Create(Name);
- var arguments = message.Arguments;
- arguments.SetString(0, ExceptionType);
- arguments.SetString(1, Message);
- arguments.SetString(2, StackTrace);
- return message;
- }
- public static UnhandledException FromCefMessage(CefProcessMessage message)
- {
- var arguments = message.Arguments;
- return new UnhandledException()
- {
- ExceptionType = arguments.GetString(0),
- Message = arguments.GetString(1),
- StackTrace = arguments.GetString(2),
- };
- }
- }
- }
- }
|