Ejemplo n.º 1
0
        public static List <dynamic> ConvertToV8List(CefListValue arguments)
        {
            var args = new List <dynamic>();

            if (arguments != null)
            {
                for (var i = 0; i < arguments.Count; i++)
                {
                    var    type = arguments.GetValueType(i);
                    object value;
                    switch (type)
                    {
                    case CefValueType.Null: value = null; break;

                    case CefValueType.String: value = arguments.GetString(i); break;

                    case CefValueType.Int: value = arguments.GetInt(i); break;

                    case CefValueType.Double: value = arguments.GetDouble(i); break;

                    case CefValueType.Bool: value = arguments.GetBool(i); break;

                    default: value = null; break;
                    }
                    if (value != null)
                    {
                        args.Add(value);
                    }
                }
            }
            return(args);
        }
Ejemplo n.º 2
0
        public static void Set(CefV8Context context, XrayObject target, CefListValue args)
        {
            CefV8Value thisArg = GetSafeThisArg(context, target);
            CefV8Value value   = CastCefValueToCefV8Value(context, args.GetValue(4), out bool isNotXray);

            thisArg.SetValueByKey(args.GetString(3), value, CefV8PropertyAttribute.None);
            if (isNotXray)
            {
                value.Dispose();
            }
        }
Ejemplo n.º 3
0
        protected PluginMessage DeserializeProcessMessage(CefListValue args)
        {
            if (args.Count < 10)
            {
                throw new ArgumentNullException("args");
            }

            return(new PluginMessage
            {
                MessageId = new Guid(args.GetString(0)),
                MessageType = (PluginMessageType)args.GetInt(1),
                PluginId = args.GetString(2),
                MemberName = args.GetString(3),
                Data = args.GetString(4),
                BrowserId = args.GetInt(5),
                ContextId = args.GetInt(6),
                FrameId = (args.GetInt(8) << 32) | ((long)(args.GetInt(7))),
                V8CallbackId = new Guid(args.GetString(9))
            });
        }
Ejemplo n.º 4
0
        static XElement ToXElement(string name, CefListValue value)
        {
            var result = new XElement(name);
            var count  = value.Count;

            for (int i = 0; i < count; i++)
            {
                var type = value.GetValueType(i);
                switch (type)
                {
                case CefValueType.Invalid:
                    break;

                case CefValueType.Null:
                    result.Add(new XElement("item", null));
                    break;

                case CefValueType.Bool:
                    result.Add(new XElement("item", value.GetBool(i)));
                    break;

                case CefValueType.Int:
                    result.Add(new XElement("item", value.GetInt(i)));
                    break;

                case CefValueType.Double:
                    result.Add(new XElement("item", value.GetDouble(i)));
                    break;

                case CefValueType.String:
                    result.Add(new XElement("item", value.GetString(i)));
                    break;

                case CefValueType.Binary:
                    break;

                case CefValueType.Dictionary:
                    result.Add(ToXElement("item", value.GetDictionary(i)));
                    break;

                case CefValueType.List:
                    result.Add(ToXElement("item", value.GetList(i)));
                    break;

                default:
                    break;
                }
            }
            return(result);
        }
Ejemplo n.º 5
0
        public JSValue(CefListValue value)
        {
            if (value == null)
            {
                return;
            }

            var result = new List <Object>();

            for (var i = 0; i < value.Count; i++)
            {
                switch (value.GetValueType(i))
                {
                case CefValueType.List:
                    result.Add(new JSValue(value.GetList(i)).Value);
                    break;

                case CefValueType.Binary:
                    result.Add(new JSValue(value.GetBinary(i)).Value);
                    break;

                case CefValueType.String:
                    result.Add(value.GetString(i));
                    break;

                case CefValueType.Double:
                    result.Add(value.GetDouble(i));
                    break;

                case CefValueType.Int:
                    result.Add(value.GetInt(i));
                    break;

                case CefValueType.Bool:
                    result.Add(value.GetBool(i));
                    break;

                case CefValueType.Dictionary:
                    result.Add(new JSValue(value.GetDictionary(i)).Value);
                    break;

                default:
                    result.Add(null);
                    break;
                }
            }

            this.Value = result.ToArray();
        }
Ejemplo n.º 6
0
        public static void DispatchReply(CefListValue data)
        {
            Log.Trace("RpcBroker.DispatchReply");

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            var reply = new Message(data.GetString(0))
            {
                Procedure = data.GetString(1),
                Data      = new JSValue(data.GetList(2)),
            };

            RpcClient client;

            if (s_clientTokens.TryRemove(reply.Token, out client) == false)
            {
                throw new InvalidOperationException("This message has already been replied to");
            }

            client.OnReply(reply);
        }
Ejemplo n.º 7
0
        public static void DispatchRequest(CefListValue data)
        {
            Log.Trace("RpcBroker.DispatchRequest");

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            var request = new Message(data.GetString(0))
            {
                Procedure = data.GetString(1),
                Data      = new JSValue(data.GetList(2)),
            };

            RpcServer server;

            if (s_serverMethods.TryGetValue(request.Procedure, out server) == false)
            {
                throw new InvalidOperationException("No server is registered to handle procedure '" + request.Procedure + "'");
            }

            server.OnRequest(request);
        }
Ejemplo n.º 8
0
        internal static CefV8Value InvokeMember(CefV8Context context, XrayObject target, CefListValue args)
        {
            CefV8Value thisArg = GetSafeThisArg(context, target);
            CefV8Value func    = thisArg.GetValue(args.GetString(3));

            if (!func.IsFunction)
            {
                func.Dispose();
                throw new MissingMethodException();
            }

            int size     = (int)(args.GetSize() - 4);
            var xraylist = new List <int>(size);
            var fnArgs   = new CefV8Value[size];

            try
            {
                for (int i = 0; i < fnArgs.Length; i++)
                {
                    int index = (i + 4);
                    fnArgs[i] = CastCefValueToCefV8Value(context, args.GetValue(index), out bool isNew);
                    if (!isNew)
                    {
                        xraylist.Add(index);
                    }
                }
                return(func.ExecuteFunction(thisArg, fnArgs));
            }
            finally
            {
                func.Dispose();
                for (int i = 0; i < fnArgs.Length; i++)
                {
                    if (!xraylist.Contains(i))
                    {
                        fnArgs[i].Dispose();
                    }
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Called after the render process main thread has been created.
        /// </summary>
        /// <param name="extraInfo"></param>
        protected override void OnRenderThreadCreated(CefListValue extraInfo)
        {
            if (extraInfo == null)
            {
                throw new ArgumentNullException("extraInfo");
            }

            var syncProperties = JsonConvert.DeserializeObject <Dictionary <string, object> >(extraInfo.GetString(0));

            foreach (var propertyName in syncProperties.Keys)
            {
                Application.SetSyncProperty(propertyName, syncProperties[propertyName]);
            }

            Logger.Info("Render process thread created.");
        }
Ejemplo n.º 10
0
        protected override void OnRenderThreadCreated(CefListValue extraInfo)
        {
            Logger.Info("Render thread created");
            if (extraInfo != null && extraInfo.Count > 0)
            {
                var plugins = extraInfo.GetList(0);
                IApplicationPackage package         = null;
                List <IPluginInfo>  renderPlugins   = new List <IPluginInfo>();
                List <IPluginInfo>  renderJsPlugins = new List <IPluginInfo>();
                if (extraInfo.Count > 1)
                {
                    var renderSidePluginData = extraInfo.GetString(1);
                    Logger.Info("Render-side plugin information : " + (renderSidePluginData ?? string.Empty));
                    try
                    {
                        if (!string.IsNullOrEmpty(renderSidePluginData))
                        {
                            RenderSidePluginData renderPluginInfo = JsonConvert.DeserializeObject <RenderSidePluginData>(renderSidePluginData);
                            package = (renderPlugins != null &&
                                       !string.IsNullOrEmpty(renderPluginInfo.PackagePath) &&
                                       renderPluginInfo.Plugins != null &&
                                       renderPluginInfo.Plugins.Count > 0) ? new ApplicationPackage(renderPluginInfo.PackagePath, p => p) : null;
                            Logger.Info(string.Format("Found {0} render-side plugins in package {1}",
                                                      (renderPlugins != null && renderPluginInfo.Plugins != null) ? renderPluginInfo.Plugins.Count : 0,
                                                      package != null ? package.PackageFilePath : string.Empty));
                            if (package != null)
                            {
                                foreach (var pluginInfo in renderPluginInfo.Plugins)
                                {
                                    if (pluginInfo != null && pluginInfo.Assembly.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        renderJsPlugins.Add(pluginInfo);
                                    }
                                    else
                                    {
                                        renderPlugins.Add(pluginInfo);
                                    }
                                }

                                if (renderJsPlugins.Count > 0)
                                {
                                    _jsExtensions = PackagedPluginAssemblyResolver.LoadJavaScriptPlugins(package, renderJsPlugins);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Error resolving render-side plugins.", ex);
                    }
                }

                if (plugins != null || (package != null && renderPlugins.Count > 0))
                {
                    Logger.Info("Initializing managed plugins");
                    try
                    {
                        if (package != null && renderPlugins != null && renderPlugins.Count > 0)
                        {
                            _router.OnPluginContextCreated += delegate(IPluginContext context)
                            {
                                _renderSidePlugins = PackagedPluginAssemblyResolver.LoadManagedPlugins(context.PluginManager, package, renderPlugins);
                            };
                        }
                        _router.InitializePlugins(plugins);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Error initializing managed plugins.", ex);
                    }
                }

                extraInfo.Clear();
            }

            base.OnRenderThreadCreated(extraInfo);
        }