Ejemplo n.º 1
0
        public CefListValue AsCefListValue()
        {
            var result = CefListValue.Create();

            if (this.Value is IList)
            {
                var v = (IList)this.Value;

                var vList = new Object[v.Count];

                v.CopyTo(vList, 0);

                for (var i = 0; i < vList.Length; i++)
                {
                    if (vList[i] is Byte[])
                    {
                        result.SetBinary(i, new JSValue(vList[i]).AsCefBinaryValue());
                    }
                    else if (vList[i] is Boolean)
                    {
                        result.SetBool(i, (Boolean)vList[i]);
                    }
                    else if (vList[i] is IDictionary)
                    {
                        result.SetDictionary(i, new JSValue(vList[i]).AsCefDictionaryValue());
                    }
                    else if (vList[i] is Single || vList[i] is Double || vList[i] is Decimal || vList[i] is UInt32 || vList[i] is UInt64 || vList[i] is Int64)
                    {
                        result.SetDouble(i, (Double)vList[i]);
                    }
                    else if (vList[i] is Byte || vList[i] is SByte || vList[i] is UInt16 || vList[i] is Int16 || vList[i] is Int32)
                    {
                        result.SetInt(i, (Int32)vList[i]);
                    }
                    else if (vList[i] is IList)
                    {
                        result.SetList(i, new JSValue(vList[i]).AsCefListValue());
                    }
                    else if (vList[i] is String)
                    {
                        result.SetString(i, (String)vList[i]);
                    }
                    else
                    {
                        result.SetNull(i);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
            static CefListValue ToListValue(CefV8Value value, CompositeDisposable disposable)
            {
                var result = CefListValue.Create();
                var count  = value.GetArrayLength();

                result.SetSize(count);
                for (int i = 0; i < count; i++)
                {
                    var val = value.GetValue(i);
                    if (val != null)
                    {
                        if (val.IsBool)
                        {
                            result.SetBool(i, val.GetBoolValue());
                        }
                        else if (val.IsInt)
                        {
                            result.SetInt(i, val.GetIntValue());
                        }
                        else if (val.IsDouble)
                        {
                            result.SetDouble(i, val.GetDoubleValue());
                        }
                        else if (val.IsString)
                        {
                            result.SetString(i, val.GetStringValue());
                        }
                        else if (val.IsNull)
                        {
                            result.SetNull(i);
                        }
                        else if (val.IsArray)
                        {
                            result.SetList(i, ToListValue(val, disposable));
                        }
                        else if (val.IsObject)
                        {
                            result.SetDictionary(i, ToDictionaryValue(val, disposable));
                        }
                    }
                }
                disposable.Add(result);
                return(result);
            }
Ejemplo n.º 3
0
        public static void SendReply(this RpcServer server, Message reply)
        {
            Log.Trace("RpcBroker.SendReply");

            var processMessage = CefProcessMessage.Create(reply.Token);

            processMessage.Arguments.SetString(0, reply.Token);
            processMessage.Arguments.SetString(1, reply.Procedure);
            if (reply.Data != null)
            {
                processMessage.Arguments.SetList(2, reply.Data.AsCefListValue());
            }
            else
            {
                processMessage.Arguments.SetList(2, CefListValue.Create());
            }

            server.Browser.SendProcessMessage(CefProcessId.Browser, processMessage);
        }
        public CefListValue CreatePluginInitMessage()
        {
            Logger.Info("Creating browser initialization message");
            var initializeMessage = new PluginMessage
            {
                MessageType = PluginMessageType.InitializePlugins,
                MessageId   = _pluginGroupId,
                BrowserId   = 0
            };

            var pluginGroup = new PluginGroup
            {
                PluginDescriptors = PluginManager.GetAllLocalPlugins().Select(p => p.Descriptor).ToList()
            };

            initializeMessage.Data = JsonConvert.SerializeObject(pluginGroup);
            var retVal = CefListValue.Create();

            SerializeProcessMessage(initializeMessage, retVal);
            return(retVal);
        }
Ejemplo n.º 5
0
        public CefValue Serialize(object obj, HashSet <object> seen, ObjectSerializer objectSerializer)
        {
            var type = obj?.GetType();

            if (!CanHandle(type))
            {
                throw new InvalidOperationException();
            }

            var array = (Array)obj;

            using (var value = CefListValue.Create())
            {
                for (var i = 0; i < array.Length; i++)
                {
                    value.SetValue(i, objectSerializer.Serialize(array.GetValue(i), seen));
                }

                var result = CefValue.Create();
                result.SetList(value);
                return(result);
            }
        }
Ejemplo n.º 6
0
        public static void SendRequest(this RpcClient client, Message request)
        {
            Log.Trace("RpcBroker.SendRequest");

            if (s_clientTokens.TryAdd(request.Token, client) == false)
            {
                throw new InvalidOperationException("This message has already been sent");
            }

            var processMessage = CefProcessMessage.Create(request.Token);

            processMessage.Arguments.SetString(0, request.Token);
            processMessage.Arguments.SetString(1, request.Procedure);
            if (request.Data != null)
            {
                processMessage.Arguments.SetList(2, request.Data.AsCefListValue());
            }
            else
            {
                processMessage.Arguments.SetList(2, CefListValue.Create());
            }

            client.Browser.SendProcessMessage(CefProcessId.Renderer, processMessage);
        }
Ejemplo n.º 7
0
        public CefValue Serialize(object source, HashSet <object> seen, ObjectSerializer objectSerializer)
        {
            if (!CanHandle(source?.GetType()))
            {
                throw new InvalidOperationException();
            }

            long frameId = 0;

            using (var context = CefV8Context.GetCurrentContext())
            {
                frameId = context.GetFrame().Identifier;
            }
            var result = CefValue.Create();

            result.SetNull();

            var value = (CefV8Value)source;

            if (value.IsString)
            {
                result.SetString(value.GetStringValue());
            }
            else if (value.IsBool)
            {
                result.SetBool(value.GetBoolValue());
            }
            else if (value.IsDouble)
            {
                result.SetDouble(value.GetDoubleValue());
            }
            else if (value.IsInt)
            {
                result.SetInt(value.GetIntValue());
            }
            else if (value.IsUInt)
            {
                result.SetDouble(value.GetUIntValue());
            }
            else if (value.IsDate)
            {
                result.SetTime(value.GetDateValue());
            }
            else if (value.IsArray)
            {
                using (var list = CefListValue.Create())
                {
                    list.SetSize(value.GetArrayLength());
                    for (var i = 0; i < value.GetArrayLength(); i++)
                    {
                        list.SetValue(i, objectSerializer.Serialize(value.GetValue(i), seen));
                    }
                    result.SetList(list);
                }
            }
            else if (value.IsFunction)
            {
                var callback = new Callback(value, promiseService, objectSerializer);
                var id       = callbackRegistry.Save(frameId, callback);

                using (var list = CefDictionaryValue.Create())
                    using (var actualValue = CefDictionaryValue.Create())
                    {
                        list.SetString(ObjectSerializer.TypeIdPropertyName, CallbackDescriptor.TypeId);

                        actualValue.SetInt64(nameof(CallbackDescriptor.FunctionId), id);

                        list.SetDictionary(ObjectSerializer.ValuePropertyName, actualValue);
                        result.SetDictionary(list);
                    }
            }
            else if (value.IsObject)
            {
                using (var dict = CefDictionaryValue.Create())
                    using (var actualValue = CefDictionaryValue.Create())
                    {
                        dict.SetString(ObjectSerializer.TypeIdPropertyName, ObjectSerializer.DictionaryTypeId);
                        if (value.TryGetKeys(out var keys))
                        {
                            foreach (var key in keys)
                            {
                                actualValue.SetValue(key, objectSerializer.Serialize(value.GetValue(key), seen));
                            }
                        }

                        dict.SetDictionary(ObjectSerializer.ValuePropertyName, actualValue);
                        result.SetDictionary(dict);
                    }
            }


            return(result);
        }
 private static ICefListValue CreateList()
 {
     return(new CefListValueImpl(CefListValue.Create()));
 }