Exemple #1
0
        /// <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>
        /// 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);
        }
        protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context)
        {
            /*缓存数据库*/
            string extensionCode =
                    "var cachedb;" +
                    "if(!cachedb)" +
                    "	cachedb={};" +
                    "(function() {" +
                    " cachedb.Connect = function(dbName) {" +
                    "	native function Connect(dbName);" +
                    "	return Connect(dbName);" +
                    " };" +

                    " cachedb.Execute = function(commandText) {" +
                    "	native function Execute(commandText);" +
                    "	return Execute(commandText);" +
                    " };" +

                    " cachedb.Query = function(commandText) {" +
                    "	native function Query(commandText);" +
                    "	return Query(commandText);" +
                    " };" +

                    " cachedb.Close = function() {" +
                    "	native function Close();" +
                    "	return Close();" +
                    " };"+

					"})();";
            CefV8Handler ExtendsionHandler = new CwbJsExtendHandler(browser);
            CefRuntime.RegisterExtension("v8/cachedb", extensionCode, ExtendsionHandler);

            /*屏幕分辨率设置*/
            int w = webBrowser.screenWidth;
            int h = webBrowser.screenHeight;
            if (w > 0 && h > 0)
		    {
			    string jscode =
				     "Object.defineProperty(window.screen, 'height', {" +
				     "    get: function() {"+
				      "        return "+h+";"+
				      "    }"+
				      "});"+
				     "Object.defineProperty(window.screen, 'width', {"+
				     "    get: function() {"+
				     "        return "+w+";"+
				     "    }"+
				     "});";
			    frame.ExecuteJavaScript(jscode,frame.Url,0);
		    }
            /*注册执行C#方法*/
            CefV8Value globalValue = context.GetGlobal();
            CefV8Handler callHandler = new CwbJsExtendHandler(browser);
            CefV8Value callMethod = CefV8Value.CreateFunction("CallCSharpMethod", callHandler);
            globalValue.SetValue("CallCSharpMethod", callMethod, CefV8PropertyAttribute.None);
            base.OnContextCreated(browser, frame, context);
            
        }
Exemple #4
0
 /// <summary>
 /// Called immediately before the V8 context for a frame is released. No
 /// references to the context should be kept after this method is called.
 /// </summary>
 protected virtual void OnContextReleased(CefBrowser browser, CefFrame frame, CefV8Context context)
 {
 }
Exemple #5
0
 /// <summary>
 /// Called for global uncaught exceptions in a frame. Execution of this
 /// callback is disabled by default. To enable set
 /// CefSettings.uncaught_exception_stack_size &gt; 0.
 /// </summary>
 protected virtual void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
 }
Exemple #6
0
 /// <summary>
 /// Returns the entered (bottom) context object in the V8 context stack.
 /// </summary>
 public static CefV8Context GetEnteredContext()
 {
     return(CefV8Context.FromNative(
                cef_v8context_t.get_entered_context()
                ));
 }
Exemple #7
0
 /// <summary>
 /// Returns the current (top) context object in the V8 context stack.
 /// </summary>
 public static CefV8Context GetCurrentContext()
 {
     return(CefV8Context.FromNative(
                cef_v8context_t.get_current_context()
                ));
 }
 /// <summary>
 /// Returns true if this object is pointing to the same handle as |that|
 /// object.
 /// </summary>
 public bool IsSame(CefV8Context that)
 {
     if (that == null) return false;
     return cef_v8context_t.is_same(_self, that.ToNative()) != 0;
 }
 /// <summary>
 /// Called for global uncaught exceptions in a frame. Execution of this
 /// callback is disabled by default. To enable set
 /// CefSettings.uncaught_exception_stack_size &gt; 0.
 /// </summary>
 protected virtual void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace)
 {
 }
 /// <summary>
 /// Called immediately before the V8 context for a frame is released. No
 /// references to the context should be kept after this method is called.
 /// </summary>
 protected virtual void OnContextReleased(CefBrowser browser, CefFrame frame, CefV8Context context)
 {
 }