protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
        {
            exception = null;
            switch (name)
            {
                case "CallCSharpMethod":
                    string methodName = arguments[0].GetStringValue();
                    string values = arguments[1].GetStringValue();
                    string res = Global.CallMethod(activeBrowser, methodName, values);
                    returnValue = CefV8Value.CreateString(res);
                    return true;
            }

            returnValue = null;
            return false;
        }
        private int execute(cef_v8handler_t* self, cef_string_t* name, cef_v8value_t* @object, UIntPtr argumentsCount, cef_v8value_t** arguments, cef_v8value_t** retval, cef_string_t* exception)
        {
            CheckSelf(self);

            var m_name = cef_string_t.ToString(name);
            var m_obj = CefV8Value.FromNative(@object);
            var argc = (int)argumentsCount;
            CefV8Value[] m_arguments;
            if (argc == 0) { m_arguments = emtpyArgs; }
            else
            {
                m_arguments = new CefV8Value[argc];
                for (var i = 0; i < argc; i++)
                {
                    m_arguments[i] = CefV8Value.FromNative(arguments[i]);
                }
            }

            CefV8Value m_returnValue;
            string m_exception;

            var handled = Execute(m_name, m_obj, m_arguments, out m_returnValue, out m_exception);

            if (handled)
            {
                if (m_exception != null)
                {
                    cef_string_t.Copy(m_exception, exception);
                }
                else if (m_returnValue != null)
                {
                    *retval = m_returnValue.ToNative();
                }
            }

            return handled ? 1 : 0;
        }
 /// <summary>
 /// Handle assignment of the accessor value identified by |name|. |object| is
 /// the receiver ('this' object) of the accessor. |value| is the new value
 /// being assigned to the accessor. If assignment fails set |exception| to the
 /// exception that will be thrown. Return true if accessor assignment was
 /// handled.
 /// </summary>
 protected abstract bool Set(string name, CefV8Value obj, CefV8Value value, out string exception);
 /// <summary>
 /// Handle retrieval the accessor value identified by |name|. |object| is the
 /// receiver ('this' object) of the accessor. If retrieval succeeds set
 /// |retval| to the return value. If retrieval fails set |exception| to the
 /// exception that will be thrown. Return true if accessor retrieval was
 /// handled.
 /// </summary>
 protected abstract bool Get(string name, CefV8Value obj, out CefV8Value returnValue, out string exception);
 /// <summary>
 /// Handle assignment of the accessor value identified by |name|. |object| is
 /// the receiver ('this' object) of the accessor. |value| is the new value
 /// being assigned to the accessor. If assignment fails set |exception| to the
 /// exception that will be thrown. Return true if accessor assignment was
 /// handled.
 /// </summary>
 protected abstract bool Set(string name, CefV8Value obj, CefV8Value value, out string exception);
Exemple #6
0
 /// <summary>
 /// Returns the global object for this context. The context must be entered
 /// before calling this method.
 /// </summary>
 public CefV8Value GetGlobal()
 {
     return(CefV8Value.FromNative(
                cef_v8context_t.get_global(_self)
                ));
 }
        /// <summary>
        /// Execute the function using the specified V8 context. |object| is the
        /// receiver ('this' object) of the function. If |object| is empty the
        /// specified context's global object will be used. |arguments| is the list of
        /// arguments that will be passed to the function. Returns the function return
        /// value on success. Returns NULL if this method is called incorrectly or an
        /// exception is thrown.
        /// </summary>
        public CefV8Value ExecuteFunctionWithContext(CefV8Context context, CefV8Value obj, CefV8Value[] arguments)
        {
            var n_arguments = CreateArguments(arguments);
            cef_v8value_t* n_retval;

            fixed (cef_v8value_t** n_arguments_ptr = n_arguments)
            {
                n_retval = cef_v8value_t.execute_function_with_context(
                    _self,
                    context.ToNative(),
                    obj != null ? obj.ToNative() : null,
                    n_arguments != null ? (UIntPtr)n_arguments.Length : UIntPtr.Zero,
                    n_arguments_ptr
                    );
            }

            return CefV8Value.FromNativeOrNull(n_retval);
        }
 /// <summary>
 /// Associates a value with the specified identifier and returns true on
 /// success. Returns false if this method is called incorrectly or an exception
 /// is thrown. For read-only values this method will return true even though
 /// assignment failed.
 /// </summary>
 public bool SetValue(string key, CefV8Value value, CefV8PropertyAttribute attribute)
 {
     fixed (char* key_str = key)
     {
         var n_key = new cef_string_t(key_str, key != null ? key.Length : 0);
         return cef_v8value_t.set_value_bykey(_self, &n_key, value.ToNative(), attribute) != 0;
     }
 }
 /// <summary>
 /// Handle execution of the function identified by |name|. |object| is the
 /// receiver ('this' object) of the function. |arguments| is the list of
 /// arguments passed to the function. If execution succeeds set |retval| to the
 /// function return value. If execution fails set |exception| to the exception
 /// that will be thrown. Return true if execution was handled.
 /// </summary>
 protected abstract bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception);
Exemple #10
0
 /// <summary>
 /// Returns the value with the specified identifier on success. Returns NULL
 /// if this method is called incorrectly or an exception is thrown.
 /// </summary>
 public CefV8Value GetValue(int index)
 {
     return(CefV8Value.FromNativeOrNull(
                cef_v8value_t.get_value_byindex(_self, index)
                ));
 }
Exemple #11
0
 /// <summary>
 /// Create a new CefV8Value object of type bool.
 /// </summary>
 public static CefV8Value CreateBool(bool value)
 {
     return(CefV8Value.FromNative(
                cef_v8value_t.create_bool(value ? 1 : 0)
                ));
 }
Exemple #12
0
 /// <summary>
 /// Create a new CefV8Value object of type null.
 /// </summary>
 public static CefV8Value CreateNull()
 {
     return(CefV8Value.FromNative(
                cef_v8value_t.create_null()
                ));
 }
Exemple #13
0
 /// <summary>
 /// Create a new CefV8Value object of type undefined.
 /// </summary>
 public static CefV8Value CreateUndefined()
 {
     return(CefV8Value.FromNative(
                cef_v8value_t.create_undefined()
                ));
 }
Exemple #14
0
 /// <summary>
 /// Create a new CefV8Value object of type array with the specified |length|.
 /// If |length| is negative the returned array will have length 0. This method
 /// should only be called from within the scope of a CefV8ContextHandler,
 /// CefV8Handler or CefV8Accessor callback, or in combination with calling
 /// Enter() and Exit() on a stored CefV8Context reference.
 /// </summary>
 public static CefV8Value CreateArray(int length)
 {
     return(CefV8Value.FromNative(
                cef_v8value_t.create_array(length)
                ));
 }
Exemple #15
0
 /// <summary>
 /// Create a new CefV8Value object of type object with optional accessor. This
 /// method should only be called from within the scope of a
 /// CefV8ContextHandler, CefV8Handler or CefV8Accessor callback, or in
 /// combination with calling Enter() and Exit() on a stored CefV8Context
 /// reference.
 /// </summary>
 public static CefV8Value CreateObject(CefV8Accessor accessor)
 {
     return(CefV8Value.FromNative(
                cef_v8value_t.create_object(accessor != null ? accessor.ToNative() : null)
                ));
 }
Exemple #16
0
 /// <summary>
 /// Handle execution of the function identified by |name|. |object| is the
 /// receiver ('this' object) of the function. |arguments| is the list of
 /// arguments passed to the function. If execution succeeds set |retval| to the
 /// function return value. If execution fails set |exception| to the exception
 /// that will be thrown. Return true if execution was handled.
 /// </summary>
 protected abstract bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception);
Exemple #17
0
 /// <summary>
 /// Associates a value with the specified identifier and returns true on
 /// success. Returns false if this method is called incorrectly or an exception
 /// is thrown. For read-only values this method will return true even though
 /// assignment failed.
 /// </summary>
 public bool SetValue(int index, CefV8Value value)
 {
     return(cef_v8value_t.set_value_byindex(_self, index, value.ToNative()) != 0);
 }
Exemple #18
0
 /// <summary>
 /// Create a new CefV8Value object of type unsigned int.
 /// </summary>
 public static CefV8Value CreateUInt(uint value)
 {
     return(CefV8Value.FromNative(
                cef_v8value_t.create_uint(value)
                ));
 }
        /// <summary>
        /// Returns true if this object is pointing to the same handle as |that|
        /// object.
        /// </summary>
        public bool IsSame(CefV8Value that)
        {
            if (that == null) return false;

            return cef_v8value_t.is_same(_self, that.ToNative()) != 0;
        }
Exemple #20
0
 /// <summary>
 /// Create a new CefV8Value object of type double.
 /// </summary>
 public static CefV8Value CreateDouble(double value)
 {
     return(CefV8Value.FromNative(
                cef_v8value_t.create_double(value)
                ));
 }
 /// <summary>
 /// Associates a value with the specified identifier and returns true on
 /// success. Returns false if this method is called incorrectly or an exception
 /// is thrown. For read-only values this method will return true even though
 /// assignment failed.
 /// </summary>
 public bool SetValue(int index, CefV8Value value)
 {
     return cef_v8value_t.set_value_byindex(_self, index, value.ToNative()) != 0;
 }
Exemple #22
0
 /// <summary>
 /// Handle retrieval the accessor value identified by |name|. |object| is the
 /// receiver ('this' object) of the accessor. If retrieval succeeds set
 /// |retval| to the return value. If retrieval fails set |exception| to the
 /// exception that will be thrown. Return true if accessor retrieval was
 /// handled.
 /// </summary>
 protected abstract bool Get(string name, CefV8Value obj, out CefV8Value returnValue, out string exception);
        private static cef_v8value_t*[] CreateArguments(CefV8Value[] arguments)
        {
            if (arguments == null) return null;

            var length = arguments.Length;
            if (length == 0) return null;

            var result = new cef_v8value_t*[arguments.Length];

            for (var i = 0; i < length; i++)
            {
                result[i] = arguments[i].ToNative();
            }

            return result;
        }
        /// <summary>
        /// Evaluates the specified JavaScript code using this context's global object.
        /// On success |retval| will be set to the return value, if any, and the
        /// function will return true. On failure |exception| will be set to the
        /// exception, if any, and the function will return false.
        /// </summary>
        public bool TryEval(string code, out CefV8Value returnValue, out CefV8Exception exception)
        {
            bool result;
            cef_v8value_t* n_retval = null;
            cef_v8exception_t* n_exception = null;

            fixed (char* code_str = code)
            {
                var n_code = new cef_string_t(code_str, code != null ? code.Length : 0);
                result = cef_v8context_t.eval(_self, &n_code, &n_retval, &n_exception) != 0;
            }

            returnValue = n_retval != null ? CefV8Value.FromNative(n_retval) : null;
            exception = n_exception != null ? CefV8Exception.FromNative(n_exception) : null;

            return result;
        }