/// <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 CefV8Value CreateFunction(string name, CefV8Handler handler)
        {
            fixed(char *name_str = name)
            {
                var n_name = new cef_string_t(name_str, name != null ? name.Length : 0);

                return(CefV8Value.FromNative(
                           cef_v8value_t.create_function(&n_name, handler.ToNative())
                           ));
            }
        }
Beispiel #2
0
        // TODO: CefBeginTracing
        //[DllImport(libcef.DllName, EntryPoint = "cef_begin_tracing", CallingConvention = libcef.CEF_CALL)]
        //public static extern int begin_tracing(cef_trace_client_t* client, cef_string_t* categories);

        // TODO: CefGetTraceBufferPercentFullAsync
        //[DllImport(libcef.DllName, EntryPoint = "cef_get_trace_buffer_percent_full_async", CallingConvention = libcef.CEF_CALL)]
        //public static extern int get_trace_buffer_percent_full_async();

        // TODO: CefEndTracingAsync
        //[DllImport(libcef.DllName, EntryPoint = "cef_end_tracing_async", CallingConvention = libcef.CEF_CALL)]
        //public static extern int end_tracing_async();

        // TODO: functions from cef_trace_event.h (not generated automatically)

        #endregion

        #region cef_url
        // TODO: CefRuntime.ParseUrl
        // TODO: CefRuntime.CreateUrl

        /*
         * // CefParseURL
         * [DllImport(libcef.DllName, EntryPoint = "cef_parse_url", CallingConvention = libcef.CEF_CALL)]
         * public static extern int parse_url(cef_string_t* url, cef_urlparts_t* parts);
         *
         * // CefCreateURL
         * [DllImport(libcef.DllName, EntryPoint = "cef_create_url", CallingConvention = libcef.CEF_CALL)]
         * public static extern int create_url(cef_urlparts_t* parts, cef_string_t* url);
         */

        #endregion

        #region cef_v8

        /// <summary>
        /// Register a new V8 extension with the specified JavaScript extension code and
        /// handler. Functions implemented by the handler are prototyped using the
        /// keyword 'native'. The calling of a native function is restricted to the scope
        /// in which the prototype of the native function is defined. This function may
        /// only be called on the render process main thread.
        ///
        /// Example JavaScript extension code:
        /// <code>
        ///   // create the 'example' global object if it doesn't already exist.
        ///   if (!example)
        ///     example = {};
        ///   // create the 'example.test' global object if it doesn't already exist.
        ///   if (!example.test)
        ///     example.test = {};
        ///   (function() {
        ///     // Define the function 'example.test.myfunction'.
        ///     example.test.myfunction = function() {
        ///       // Call CefV8Handler::Execute() with the function name 'MyFunction'
        ///       // and no arguments.
        ///       native function MyFunction();
        ///       return MyFunction();
        ///     };
        ///     // Define the getter function for parameter 'example.test.myparam'.
        ///     example.test.__defineGetter__('myparam', function() {
        ///       // Call CefV8Handler::Execute() with the function name 'GetMyParam'
        ///       // and no arguments.
        ///       native function GetMyParam();
        ///       return GetMyParam();
        ///     });
        ///     // Define the setter function for parameter 'example.test.myparam'.
        ///     example.test.__defineSetter__('myparam', function(b) {
        ///       // Call CefV8Handler::Execute() with the function name 'SetMyParam'
        ///       // and a single argument.
        ///       native function SetMyParam();
        ///       if(b) SetMyParam(b);
        ///     });
        ///
        ///     // Extension definitions can also contain normal JavaScript variables
        ///     // and functions.
        ///     var myint = 0;
        ///     example.test.increment = function() {
        ///       myint += 1;
        ///       return myint;
        ///     };
        ///   })();
        /// </code>
        /// Example usage in the page:
        /// <code>
        ///   // Call the function.
        ///   example.test.myfunction();
        ///   // Set the parameter.
        ///   example.test.myparam = value;
        ///   // Get the parameter.
        ///   value = example.test.myparam;
        ///   // Call another function.
        ///   example.test.increment();
        /// </code>
        /// </summary>
        public static bool RegisterExtension(string extensionName, string javascriptCode, CefV8Handler handler)
        {
            if (string.IsNullOrEmpty(extensionName))
            {
                throw new ArgumentNullException("extensionName");
            }
            if (string.IsNullOrEmpty(javascriptCode))
            {
                throw new ArgumentNullException("javascriptCode");

                fixed(char *extensionName_str = extensionName)
                fixed(char *javascriptCode_str = javascriptCode)
                {
                    var n_extensionName  = new cef_string_t(extensionName_str, extensionName.Length);
                    var n_javascriptCode = new cef_string_t(javascriptCode_str, javascriptCode.Length);

                    return(libcef.register_extension(&n_extensionName, &n_javascriptCode, handler != null ? handler.ToNative() : null) != 0);
                }
        }
Beispiel #3
0
        /// <summary>
        /// Create a new CefV8Value object of type function. 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 CreateFunction(string name, CefV8Handler handler)
        {
            fixed (char* name_str = name)
            {
                var n_name = new cef_string_t(name_str, name != null ? name.Length : 0);

                return CefV8Value.FromNative(
                    cef_v8value_t.create_function(&n_name, handler.ToNative())
                    );
            }
        }
Beispiel #4
0
        /// <summary>
        /// Register a new V8 extension with the specified JavaScript extension code and
        /// handler. Functions implemented by the handler are prototyped using the
        /// keyword 'native'. The calling of a native function is restricted to the scope
        /// in which the prototype of the native function is defined. This function may
        /// only be called on the render process main thread.
        ///
        /// Example JavaScript extension code:
        /// <code>
        ///   // create the 'example' global object if it doesn't already exist.
        ///   if (!example)
        ///     example = {};
        ///   // create the 'example.test' global object if it doesn't already exist.
        ///   if (!example.test)
        ///     example.test = {};
        ///   (function() {
        ///     // Define the function 'example.test.myfunction'.
        ///     example.test.myfunction = function() {
        ///       // Call CefV8Handler::Execute() with the function name 'MyFunction'
        ///       // and no arguments.
        ///       native function MyFunction();
        ///       return MyFunction();
        ///     };
        ///     // Define the getter function for parameter 'example.test.myparam'.
        ///     example.test.__defineGetter__('myparam', function() {
        ///       // Call CefV8Handler::Execute() with the function name 'GetMyParam'
        ///       // and no arguments.
        ///       native function GetMyParam();
        ///       return GetMyParam();
        ///     });
        ///     // Define the setter function for parameter 'example.test.myparam'.
        ///     example.test.__defineSetter__('myparam', function(b) {
        ///       // Call CefV8Handler::Execute() with the function name 'SetMyParam'
        ///       // and a single argument.
        ///       native function SetMyParam();
        ///       if(b) SetMyParam(b);
        ///     });
        ///
        ///     // Extension definitions can also contain normal JavaScript variables
        ///     // and functions.
        ///     var myint = 0;
        ///     example.test.increment = function() {
        ///       myint += 1;
        ///       return myint;
        ///     };
        ///   })();
        /// </code>
        /// Example usage in the page:
        /// <code>
        ///   // Call the function.
        ///   example.test.myfunction();
        ///   // Set the parameter.
        ///   example.test.myparam = value;
        ///   // Get the parameter.
        ///   value = example.test.myparam;
        ///   // Call another function.
        ///   example.test.increment();
        /// </code>
        /// </summary>
        public static bool RegisterExtension(string extensionName, string javascriptCode, CefV8Handler handler)
        {
            if (string.IsNullOrEmpty(extensionName)) throw new ArgumentNullException("extensionName");
            if (string.IsNullOrEmpty(javascriptCode)) throw new ArgumentNullException("javascriptCode");

            fixed (char* extensionName_str = extensionName)
            fixed (char* javascriptCode_str = javascriptCode)
            {
                var n_extensionName = new cef_string_t(extensionName_str, extensionName.Length);
                var n_javascriptCode = new cef_string_t(javascriptCode_str, javascriptCode.Length);

                return libcef.register_extension(&n_extensionName, &n_javascriptCode, handler != null ? handler.ToNative() : null) != 0;
            }
        }