Example #1
0
 private void CheckSelf(cef_v8handler_t *self)
 {
     if (_self != self)
     {
         throw ExceptionBuilder.InvalidSelfReference();
     }
 }
Example #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (_self != null)
     {
         cef_v8handler_t.Free(_self);
         _self = null;
     }
 }
Example #3
0
 protected virtual void Dispose(bool disposing)
 {
     if (_self != null)
     {
         cef_v8handler_t.Free(_self);
         _self = null;
     }
 }
Example #4
0
        internal static CefV8Handler FromNative(cef_v8handler_t *ptr)
        {
            var value = FromNativeOrNull(ptr);

            if (value == null)
            {
                throw ExceptionBuilder.ObjectNotFound();
            }
            return(value);
        }
Example #5
0
        public CefV8Handler()
        {
            cef_v8handler_t *self = this.NativeInstance;

                        #if NET_LESS_5_0
            self->execute = (void *)Marshal.GetFunctionPointerForDelegate(fnExecute);
                        #else
            self->execute = (delegate * unmanaged[Stdcall] < cef_v8handler_t *, cef_string_t *, cef_v8value_t *, UIntPtr, cef_v8value_t **, cef_v8value_t **, cef_string_t *, int >) & ExecuteImpl;
                        #endif
        }
Example #6
0
 private void add_ref(cef_v8handler_t *self)
 {
     lock (SyncRoot)
     {
         var result = ++_refct;
         if (result == 1)
         {
             lock (_roots) { _roots.Add((IntPtr)_self, this); }
         }
     }
 }
Example #7
0
        internal static CefV8Handler FromNativeOrNull(cef_v8handler_t *ptr)
        {
            CefV8Handler value = null;
            bool         found;

            lock (_roots)
            {
                found = _roots.TryGetValue((IntPtr)ptr, out value);
            }
            return(found ? value : null);
        }
Example #8
0
 private int release(cef_v8handler_t *self)
 {
     lock (SyncRoot)
     {
         var result = --_refct;
         if (result == 0)
         {
             lock (_roots) { _roots.Remove((IntPtr)_self); }
         }
         return(result);
     }
 }
Example #9
0
 protected CefV8Handler()
 {
     _self = cef_v8handler_t.Alloc();
 
     _ds0 = new cef_v8handler_t.add_ref_delegate(add_ref);
     _self->_base._add_ref = Marshal.GetFunctionPointerForDelegate(_ds0);
     _ds1 = new cef_v8handler_t.release_delegate(release);
     _self->_base._release = Marshal.GetFunctionPointerForDelegate(_ds1);
     _ds2 = new cef_v8handler_t.has_one_ref_delegate(has_one_ref);
     _self->_base._has_one_ref = Marshal.GetFunctionPointerForDelegate(_ds2);
     _ds3 = new cef_v8handler_t.execute_delegate(execute);
     _self->_execute = Marshal.GetFunctionPointerForDelegate(_ds3);
 }
Example #10
0
        protected CefV8Handler()
        {
            _self = cef_v8handler_t.Alloc();

            _ds0 = new cef_v8handler_t.add_ref_delegate(add_ref);
            _self->_base._add_ref = Marshal.GetFunctionPointerForDelegate(_ds0);
            _ds1 = new cef_v8handler_t.release_delegate(release);
            _self->_base._release = Marshal.GetFunctionPointerForDelegate(_ds1);
            _ds2 = new cef_v8handler_t.has_one_ref_delegate(has_one_ref);
            _self->_base._has_one_ref = Marshal.GetFunctionPointerForDelegate(_ds2);
            _ds3            = new cef_v8handler_t.execute_delegate(execute);
            _self->_execute = Marshal.GetFunctionPointerForDelegate(_ds3);
        }
Example #11
0
        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);
        }
Example #12
0
        /// <summary>
        /// Execute with the specified argument list and return value. Return
        /// true if the method was handled. To invoke V8 callback functions
        /// outside the scope of this method you need to keep references to the
        /// current V8 context (CefV8Context) along with any necessary callback
        /// objects.
        /// </summary>
        internal virtual int execute(cef_v8handler_t *self, /*const*/ cef_string_t *name, cef_v8value_t * @object, int argumentCount, cef_v8value_t * /*const*/ *arguments, cef_v8value_t **retval, cef_string_t *exception)
        {
            ThrowIfObjectDisposed();

            var m_name = cef_string_t.ToString(name);
            var m_obj  = CefV8Value.From(@object);

            CefV8Value[] m_arguments;
            if (argumentCount == 0)
            {
                m_arguments = null;
            }
            else
            {
                m_arguments = new CefV8Value[argumentCount];
                for (var i = 0; i < argumentCount; i++)
                {
                    m_arguments[i] = CefV8Value.From(arguments[i]);
                }
            }

            CefV8Value m_returnValue;
            string     m_exception;

            var handled = this.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.GetNativePointerAndAddRef();
                }
            }

            return(handled ? 1 : 0);
        }
Example #13
0
        public CefV8Handler()
        {
            cef_v8handler_t *self = this.NativeInstance;

            self->execute = (void *)Marshal.GetFunctionPointerForDelegate(fnExecute);
        }
Example #14
0
 private int get_refct(cef_v8handler_t *self)
 {
     return(_refct);
 }
 /// <summary>
 /// Create a new CefV8Value object of type function. This method should only be
 /// called from within the scope of a CefRenderProcessHandler, CefV8Handler or
 /// CefV8Accessor callback, or in combination with calling Enter() and Exit()
 /// on a stored CefV8Context reference.
 /// </summary>
 public static cef_v8value_t *CreateFunction(cef_string_t *name, cef_v8handler_t *handler)
 {
     throw new NotImplementedException(); // TODO: CefV8Value.CreateFunction
 }
Example #16
0
 private int has_at_least_one_ref(cef_v8handler_t *self)
 {
     lock (SyncRoot) { return(_refct != 0 ? 1 : 0); }
 }
Example #17
0
 internal static void Free(cef_v8handler_t *ptr)
 {
     Marshal.FreeHGlobal((IntPtr)ptr);
 }
        internal unsafe override int execute(cef_v8handler_t *self, cef_string_t *name, cef_v8value_t * @object, int argumentCount, cef_v8value_t **arguments, cef_v8value_t **retval, cef_string_t *exception)
        {
            var method = this.dispatchTable.GetOrDefault(name);

            if (method == null)
            {
                return(0);
            }

            // check method visibility
            var methodAttributes = method.Attributes;

            if ((methodAttributes & MethodDefAttributes.Hidden) != 0)
            {
                if ((methodAttributes & (MethodDefAttributes.Getter | MethodDefAttributes.Setter)) != 0)
                {
                    if (this.v8Extension)
                    {
                        // allow invoke of hidden property accessor's method for v8 extension handler
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }
            }

            var instance = this.instance;

            if (instance == null)
            {
                // TODO: self must be got from obj's userdata
                throw new NotImplementedException();
            }

            // TODO: invoke method
            try
            {
                method.Invoke(instance, argumentCount, arguments, retval);
            }
            catch (Exception ex)
            {
                // TODO: how exceptions must be formatted ?
                // TODO: message for invoke errors
                cef_string_t.Copy(ex.ToString(), exception);
            }

            // release v8 values
            // TODO: this method must be typed (i.e. cef_v8value_t.invoke_release(@object);)
            cef_v8value_t.invoke_release((cef_base_t *)@object);
            for (var i = 0; i < argumentCount; i++)
            {
                cef_v8value_t.invoke_release((cef_base_t *)arguments[i]);
            }

            return(1);
        }
Example #19
0
 public CefV8Handler(cef_v8handler_t *instance)
     : base((cef_base_ref_counted_t *)instance)
 {
 }
Example #20
0
 public static extern cef_v8value_t *create_function(cef_string_t *name, cef_v8handler_t *handler);
Example #21
0
 private int has_one_ref(cef_v8handler_t *self)
 {
     lock (SyncRoot) { return(_refct == 1 ? 1 : 0); }
 }
Example #22
0
 public static extern int register_extension(cef_string_t *extension_name, cef_string_t *javascript_code, cef_v8handler_t *handler);
 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);
     throw new NotImplementedException(); // TODO: CefV8Handler.Execute
 }