Exemplo n.º 1
0
 public void Reject(string error)
 {
     using (var cefV8Value = CefV8Value.CreateString(error))
     {
         reject.ExecuteFunction(null, new[] { cefV8Value });
     }
 }
Exemplo n.º 2
0
        internal static CefV8Value Invoke(CefV8Context context, XrayObject target, CefListValue args)
        {
            CefV8Value func    = target.Value;
            CefV8Value thisArg = CastCefValueToCefV8Value(context, args.GetValue(3), out bool isNewThisArg);

            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
            {
                for (int i = 0; i < fnArgs.Length; i++)
                {
                    if (!xraylist.Contains(i))
                    {
                        fnArgs[i].Dispose();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Execute(CallbackExecution <CefValue> execution)
        {
            CefV8Exception exception = null;

            using (new ContextHelper(context))
            {
                var cefV8Values = execution.Parameters.Select(s => (CefV8Value)v8Serializer.Deserialize(s, typeof(CefV8Value))).ToArray();
                var result      = function.ExecuteFunction(null, cefV8Values);


                var browser = context.GetBrowser();

                if (result == null && function.HasException)
                {
                    exception = function.GetException();
                    function.ClearException();
                }

                if (promiseService.IsPromise(result, context))
                {
                    promiseService.Then(result, context, a => CallbackDone(a, browser, execution.ExecutionId));
                }
                else
                {
                    CallbackDone(new PromiseResult
                    {
                        Success = result != null,
                        Result  = result,
                        Error   = exception?.Message
                    }, browser, execution.ExecutionId);
                }
            }
        }
Exemplo n.º 4
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();
                    }
                }
            }
        }
Exemplo n.º 5
0
 public static CefV8Value ExecuteFunction(this CefV8Value @this)
 {
     return(@this.ExecuteFunction(null, new CefV8Value[] { }));
 }
Exemplo n.º 6
0
        private object InvokeInternal(XrayHandle self, object[] args)
        {
            if (args is null || args.Length == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(args));
            }

            if (!CefApi.CurrentlyOn(CefThreadId.Renderer))
            {
                using (var callTask = new V8CallTask(() => InvokeInternal(self, args)))
                {
                    if (!CefApi.PostTask(CefThreadId.Renderer, callTask))
                    {
                        throw new InvalidOperationException();
                    }
                    return((bool)callTask.GetResult());
                }
            }

            XrayObject target = self.GetTarget(this.Frame);

            if (target is null || !target.Context.Enter())
            {
                throw new InvalidOperationException();
            }

            object retval;

            try
            {
                CefV8Value func    = target.Value;
                CefV8Value thisArg = CastDotnetTypeToCefV8Value(target.Context, args[0], out bool isNewThisArg);
                CefV8Value value;

                int size     = args.Length - 1;
                var xraylist = new List <int>(size);
                var fnArgs   = new CefV8Value[size];
                try
                {
                    for (int i = 0; i < fnArgs.Length; i++)
                    {
                        int index = (i + 1);
                        fnArgs[i] = CastDotnetTypeToCefV8Value(target.Context, args[index], out bool isNew);
                        if (!isNew)
                        {
                            xraylist.Add(index);
                        }
                    }
                    value = func.ExecuteFunction(thisArg, fnArgs);
                }
                finally
                {
                    for (int i = 0; i < fnArgs.Length; i++)
                    {
                        if (!xraylist.Contains(i))
                        {
                            fnArgs[i].Dispose();
                        }
                    }
                }
                retval = CastCefV8ValueToDotnetType(target.Context, value, out bool isxray);
                if (!isxray)
                {
                    value.Dispose();
                }
            }
            finally
            {
                target.Context.Exit();
            }
            return(retval);
        }
Exemplo n.º 7
0
        public object InvokeMemberInternal(XrayHandle self, string name, object[] args)
        {
            if (args is null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            if (!CefApi.CurrentlyOn(CefThreadId.Renderer))
            {
                using (var callTask = new V8CallTask(() => InvokeMemberInternal(self, name, args)))
                {
                    if (!CefApi.PostTask(CefThreadId.Renderer, callTask))
                    {
                        throw new InvalidOperationException();
                    }
                    return((bool)callTask.GetResult());
                }
            }

            XrayObject target = self.GetTarget(this.Frame);

            if (target is null || !target.Context.Enter())
            {
                throw new InvalidOperationException();
            }

            object retval;

            try
            {
                CefV8Value thisArg = target.Value;
                CefV8Value func    = thisArg.GetValueByKey(name);
                if (!func.IsFunction)
                {
                    func.Dispose();
                    throw new MissingMethodException(string.Format("'{0} is not a function.'", name));
                }

                CefV8Value value;
                var        xraylist = new List <int>(args.Length);
                var        fnArgs   = new CefV8Value[args.Length];
                try
                {
                    for (int i = 0; i < fnArgs.Length; i++)
                    {
                        fnArgs[i] = CastDotnetTypeToCefV8Value(target.Context, args[i], out bool isNew);
                        if (!isNew)
                        {
                            xraylist.Add(i);
                        }
                    }
                    value = func.ExecuteFunction(thisArg, fnArgs);
                }
                finally
                {
                    for (int i = 0; i < fnArgs.Length; i++)
                    {
                        if (!xraylist.Contains(i))
                        {
                            fnArgs[i].Dispose();
                        }
                    }
                }
                retval = CastCefV8ValueToDotnetType(target.Context, value, out bool isxray);
                if (!isxray)
                {
                    value.Dispose();
                }
            }
            finally
            {
                target.Context.Exit();
            }
            return(retval);
        }
 public IJavascriptObject ExecuteFunction(IWebView context)
 {
     return(Convert(_CefV8Value.ExecuteFunction()));
 }
Exemplo n.º 9
0
 public void Resolve(CefV8Value val)
 {
     resolve.ExecuteFunction(null, new[] { val });
 }
Exemplo n.º 10
0
 /// <summary>
 /// Create a JS promise by calling back into JS, returning a Promise that wraps the 
 /// provided fulfiller.
 /// </summary>
 /// <remarks>Must be inside a <see cref="CefV8Context"/></remarks>
 /// <param name="fulfiller">JS Function having 2 arguments: resolve, reject</param>
 public CefV8Value CreatePromise(CefV8Value fulfiller)
 {
     return jsPromiseFactory.ExecuteFunction(null, new CefV8Value[] { fulfiller });
 }
 public IJavascriptObject ExecuteFunction()
 {
     return(Convert(_CefV8Value.ExecuteFunction()));
 }