示例#1
0
 public void SetMappedJSValue(CefV8Value ijsobject, IJSCBridgeCache mapper)
 {
     _MappedJSValue = ijsobject;
     CefV8Value mapped = ((CefV8Value)_MappedJSValue);
     mapped.Bind("Execute", _CefV8Context,(c, o, e) => ExecuteCommand(e, mapper));
     mapped.Bind("CanExecute",_CefV8Context, (c, o, e) => CanExecuteCommand(e, mapper));
 }
示例#2
0
        private CefV8Value Check(CefV8Value ires)
        {
            if (ires == null)
                throw ExceptionHelper.NoKoExtension();

            return ires;
        }
 protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
 {
     returnValue = null;
     exception = null;
     _Action(name, obj, arguments);
     return false;
 }
示例#4
0
 private JSGenericObject(CefV8CompleteContext context, CefV8Value value)
 {
     JSValue = value;
     _MappedJSValue = value;
     CValue = null;
     _CefV8Context = context;
 }
示例#5
0
        private void SetResult(CefV8Value[] e, IJSCBridgeCache bridge, Task<object> resulttask)
        {
            _CefV8Context.RunAsync (() =>
                 {
                     if (e.Length < 2)
                         return;       
                    
                     CefV8Value promise = e[1];
                     if (!resulttask.IsFaulted)
                     {
                         bridge.RegisterInSession(resulttask.Result, (bridgevalue) =>
                         {
                             promise.InvokeAsync("fullfill", _CefV8Context, bridgevalue.GetJSSessionValue());
                         });
                     }
                     else
                     {
                         string error = (resulttask.IsCanceled) ? "Cancelled" :
                             ((resulttask.Exception == null) ? "Faulted" : resulttask.Exception.Flatten().InnerException.Message);

                         promise.InvokeAsync("reject", _CefV8Context, CefV8Value.CreateString(error));
                     }

                 });
        }
示例#6
0
        public bool HasRelevantId(CefV8Value iJSObject)
        {
            if (iJSObject.IsUserCreated)
                return false;

            return _CefV8Context.EvaluateAsync(() =>
            {
                return iJSObject.HasValue("_globalId_");
            }).Result;
        }
示例#7
0
        //public CefV8Value CreateDate(DateTime dt)
        //{
        //    return CefV8Value.CreateDate(dt);
        //}

        private CefV8Value UpdateObject(CefV8Value ires)
        {
            if (ires != null)
            {
                ires.SetValue("_MappedId", CefV8Value.CreateUInt(_MapCount++),
                    CefV8PropertyAttribute.ReadOnly | CefV8PropertyAttribute.DontEnum | CefV8PropertyAttribute.DontDelete);
            }

            return ires;
        }
示例#8
0
        public uint CreateAndGetID(CefV8Value iJSObject)
        {
            return _CefV8Context.Evaluate(() =>
            {
                var value = iJSObject.GetValue("_globalId_");
                if (value.IsUInt) return value.GetUIntValue();

                iJSObject.SetValue("_globalId_", CefV8Value.CreateUInt(++_Count), CefV8PropertyAttribute.DontDelete | CefV8PropertyAttribute.ReadOnly | CefV8PropertyAttribute.DontEnum);
                return _Count;
            });
        }
示例#9
0
        public void UpdateCSharpProperty(string PropertyName, IJSCBridgeCache converter, CefV8Value newValue)
        {
            PropertyInfo propertyInfo = CValue.GetType().GetProperty(PropertyName, BindingFlags.Public | BindingFlags.Instance);
            if (!propertyInfo.CanWrite)
                return;

            var type = propertyInfo.PropertyType.GetUnderlyingNullableType() ?? propertyInfo.PropertyType;
            IJSCSGlue glue = converter.GetCachedOrCreateBasic(newValue, type);
            _Attributes[PropertyName] = glue;
            propertyInfo.SetValue(CValue, glue.CValue, null);
        }
        public bool GetSimpleValue(CefV8Value ijsvalue, out object res, Type iTargetType = null)
        {
            res = null;

            if ((ijsvalue.IsUndefined) || (ijsvalue.IsNull))
            {
                return true;
            }

            if (ijsvalue.IsString)
            {
                res = ijsvalue.GetStringValue();
                return true;
            }

            if (ijsvalue.IsBool)
            {
                res = ijsvalue.GetBoolValue();
                return true;
            } 
            
            if (IsUnsigned(iTargetType))
            {
                if (ijsvalue.IsUInt)
                    res = ijsvalue.GetUIntValue();
            }
            else
            {
                if (ijsvalue.IsInt)
                    res = ijsvalue.GetIntValue();
            }  

            if ((res==null) && (ijsvalue.IsDouble))
            {
                res = ijsvalue.GetDoubleValue();
            }

            if (res!=null)
            {
                if (iTargetType != null)
                    res = Convert.ChangeType(res, iTargetType);

                return true;
            }

            if (ijsvalue.IsDate)
            { 
                res = ijsvalue.GetDateValue();
                return true;
            }

            return false;
        }
        private CefV8Value GetMapper(IJavascriptMapper iMapperListener)
        {
            _IJavascriptMapper.Enqueue(iMapperListener);
    
            if (_Mapper != null)
                return _Mapper;

            _Mapper = _GlobalBuilder.CreateJSO();

            _Mapper.Bind("Register", _CefV8Context, (c, o, e) =>
            {
                if (_PullNextMapper)
                { 
                    _Current = _IJavascriptMapper.Dequeue();
                    _PullNextMapper = false;
                }

                if (_Current == null)
                    return;

                int count = e.Length;
                CefV8Value registered = e[0];

                switch (count)
                {
                    case 1:
                        _Current.RegisterFirst(registered);
                        break;

                    case 3:
                        _Current.RegisterMapping(e[1], e[2].GetStringValue(), registered);
                        break;

                    case 4:
                        _Current.RegisterCollectionMapping(e[1], e[2].GetStringValue(), e[3].GetIntValue(), registered);
                        break;
                }
             });

            _Mapper.Bind("End", _CefV8Context, (c, o, e) =>
                {
                    if (_PullNextMapper)
                        _Current = _IJavascriptMapper.Dequeue();

                    if (_Current!=null)
                        _Current.End(e[0]);
                    _Current = null;
                    _PullNextMapper = true;
                });

            return _Mapper;
        }
        internal JavascriptSessionInjector(CefV8CompleteContext iWebView, IJSOBuilder iGlobalBuilder, IJavascriptListener iJavascriptListener)
        {
            _CefV8Context = iWebView;
            _GlobalBuilder = iGlobalBuilder;
            _IJavascriptListener = iJavascriptListener;


            if (_IJavascriptListener != null)
            {
                _Listener = _GlobalBuilder.CreateJSO();
                _Listener.Bind("TrackChanges",_CefV8Context, (c, o, e) => _IJavascriptListener.OnJavaScriptObjectChanges(e[0], e[1].GetStringValue(), e[2]));
                _Listener.Bind("TrackCollectionChanges", _CefV8Context, (c, o, e) => _IJavascriptListener.OnJavaScriptCollectionChanges(e[0], e[1].GetArrayElements(), e[2].GetArrayElements(), e[3].GetArrayElements()));
            }
            else
                _Listener = _GlobalBuilder.CreateJSO();
        }
        protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
        {
            exception = "";
            returnValue = CefV8Value.CreateUndefined();

            if (name == BroadcastMessageFunctionName)
            {
                if (arguments.Length > 0)
                {
                    if (BroadcastMessage != null)
                    {
                        BroadcastMessage(obj, new BroadcastMessageEventArgs(arguments[0].GetStringValue()));
                    }
                }
                else
                {
                    exception = "Invalid argument count.";
                }

                return true;
            }
            else if (name == SendMessageFunctionName)
            {
                if (arguments.Length > 1)
                {
                    if (SendMessage != null)
                    {
                        SendMessage(obj, new SendMessageEventArgs(arguments[0].GetStringValue(), arguments[1].GetStringValue()));
                    }
                }
                else
                {
                    exception = "Invalid argument count.";
                }

                return true;
            }

            return false;
        }
示例#14
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;
        }
示例#15
0
 public JSGenericObject(CefV8CompleteContext context, CefV8Value value, object icValue)
 {
     JSValue = value;
     CValue = icValue;
     _CefV8Context = context;
 }
 public void RegisterMapping(CefV8Value iFather, string att, CefV8Value iChild)
 {
     _LiveMapper.RegisterMapping(iFather, att, iChild);
 }
        private IJSCSGlue GetCachedLocal(CefV8Value localkey)
        {
            if (!_LocalBuilder.HasRelevantId(localkey))
                return null;

            IJSCSGlue res = null;
            _FromJavascript_Local.TryGetValue(_LocalBuilder.GetID(localkey), out res);
            return res;
        }
        public IJSCSGlue GetCached(CefV8Value globalkey)
        {
            if (!_GlobalBuilder.HasRelevantId(globalkey))
                return null;

            IJSCSGlue res = null;
            _FromJavascript_Global.TryGetValue(_GlobalBuilder.GetID(globalkey), out res);
            return res;
        }
        public void OnJavaScriptObjectChanges(CefV8Value objectchanged, string PropertyName, CefV8Value newValue)
        {
            try
            {
                var res = GetFromJavascript(objectchanged) as JSGenericObject;
                if (res == null)
                    return;

                INotifyPropertyChanged inc = (!_IsListening) ? null : res.CValue as INotifyPropertyChanged;
                if (inc != null) inc.PropertyChanged -= Object_PropertyChanged;
                res.UpdateCSharpProperty(PropertyName, this, newValue);
                if (inc != null) inc.PropertyChanged += Object_PropertyChanged;
            }
            catch (Exception e)
            {
                ExceptionHelper.Log(string.Format("Unable to update ViewModel from View, exception raised: {0}", e));
            }
        }
 public void RegisterMapping(CefV8Value iFather, string att, CefV8Value iChild)
 {
     JSGenericObject jso = GetFromJavascript(iFather) as JSGenericObject;
     Update(jso.Attributes[att] as IJSObservableBridge, iChild);
 }
 private IJSCSGlue GetFromJavascript(CefV8Value jsobject)
 {
     return _FromJavascript_Global[_GlobalBuilder.GetID(jsobject)];
 }
示例#22
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)
                ));
 }
示例#23
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);
 }
示例#24
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)
                ));
 }
示例#25
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)
                ));
 }
示例#26
0
 /// <summary>
 /// Create a new CefV8Value object of type null.
 /// </summary>
 public static CefV8Value CreateNull()
 {
     return(CefV8Value.FromNative(
                cef_v8value_t.create_null()
                ));
 }
示例#27
0
 /// <summary>
 /// Create a new CefV8Value object of type undefined.
 /// </summary>
 public static CefV8Value CreateUndefined()
 {
     return(CefV8Value.FromNative(
                cef_v8value_t.create_undefined()
                ));
 }
示例#28
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 CefRenderProcessHandler,
 /// 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)
                ));
 }
 public void End(CefV8Value iRoot)
 {
     _TCS.TrySetResult(null);
 }
示例#30
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)
                ));
 }
 private void Update(IJSObservableBridge ibo, CefV8Value jsobject)
 {
     _GlobalBuilder.CreateAndGetID(jsobject);
     ibo.SetMappedJSValue(jsobject, this);
     _FromJavascript_Global[_GlobalBuilder.GetID(jsobject)] = ibo;
 }
示例#32
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)
                ));
 }
        public void RegisterCollectionMapping(CefV8Value iFather, string att, int index, CefV8Value iChild)
        {
            var father = GetFromJavascript(iFather);
            var jsos = (att == null) ? father : (father as JSGenericObject).Attributes[att];

            Update((jsos as JSArray).Items[index] as IJSObservableBridge, iChild);
        }
 /// <summary>
 /// Handle assignment of the interceptor value identified by |name|. |object|
 /// is the receiver ('this' object) of the interceptor. |value| is the new
 /// value being assigned to the interceptor. If assignment fails, set
 /// |exception| to the exception that will be thrown. This setter will always
 /// be called, even when the property has an associated accessor.
 /// Return true if interceptor assignment was handled, false otherwise.
 /// </summary>
 protected virtual bool SetByName(string name, CefV8Value @object, CefV8Value value, out string exception)
 {
     exception = null;
     return(false);
 }
        public void OnJavaScriptCollectionChanges(CefV8Value collectionchanged, CefV8Value[] value, CefV8Value[] status, CefV8Value[] index)
        {
            try
            {
                var res = GetFromJavascript(collectionchanged) as JSArray;
                if (res == null) return;

                CollectionChanges cc = res.GetChanger(value, status, index, this);

                using (ReListen(null))
                {
                    INotifyCollectionChanged inc = res.CValue as INotifyCollectionChanged;
                    if (inc != null) inc.CollectionChanged -= CollectionChanged;
                    res.UpdateEventArgsFromJavascript(cc);
                    if (inc != null) inc.CollectionChanged += CollectionChanged;
                }
            }
            catch (Exception e)
            {
                ExceptionHelper.Log(string.Format("Unable to update ViewModel from View, exception raised: {0}", e));
            }
        }
 /// <summary>
 /// Handle retrieval of the interceptor value identified by |index|. |object|
 /// is the receiver ('this' object) of the interceptor. If retrieval succeeds,
 /// set |retval| to the return value. If the requested value does not exist,
 /// don't set either |retval| or |exception|. If retrieval fails, set
 /// |exception| to the exception that will be thrown.
 /// Return true if interceptor retrieval was handled, false otherwise.
 /// </summary>
 protected virtual bool GetByIndex(int index, CefV8Value @object, out CefV8Value retval, out string exception)
 {
     retval    = null;
     exception = null;
     return(false);
 }
        public IJSCSGlue GetCachedOrCreateBasic(CefV8Value globalkey, Type iTargetType)
        {
            IJSCSGlue res = null;
            CefV8Value obj = globalkey;

            //Use local cache for objet not created in javascript session such as enum
            if ((obj != null) && ((res = GetCached(globalkey) ?? GetCachedLocal(globalkey)) != null))
                return res;

            object targetvalue = null;
            bool converted = _JavascriptToCSharpMapper.GetSimpleValue(globalkey, out targetvalue, iTargetType);
            if ((!converted) && (!globalkey.IsNull) && (!globalkey.IsUndefined))
                throw ExceptionHelper.Get(string.Format("Unable to convert javascript object: {0}", globalkey));

            return new JSBasicObject(globalkey, targetvalue);
        }
示例#38
0
 public void SetMappedJSValue(CefV8Value ijsobject, IJSCBridgeCache mapper)
 {
     _MappedJSValue = ijsobject;
 }
 public void RegisterFirst(CefV8Value iRoot)
 {
     _LiveMapper.Update(_Root, iRoot);
 }
 /// <summary>
 /// Handle retrieval of the interceptor value identified by |name|. |object| is
 /// the receiver ('this' object) of the interceptor. If retrieval succeeds, set
 /// |retval| to the return value. If the requested value does not exist, don't
 /// set either |retval| or |exception|. If retrieval fails, set |exception| to
 /// the exception that will be thrown. If the property has an associated
 /// accessor, it will be called only if you don't set |retval|.
 /// Return true if interceptor retrieval was handled, false otherwise.
 /// </summary>
 protected virtual bool GetByName(string name, CefV8Value @object, out CefV8Value retval, out string exception)
 {
     retval    = null;
     exception = null;
     return(false);
 }
 public void RegisterCollectionMapping(CefV8Value iFather, string att, int index, CefV8Value iChild)
 {
     _LiveMapper.RegisterCollectionMapping(iFather, att, index, iChild);
 }
示例#42
0
 public CollectionChanges GetChanger(CefV8Value[] value, CefV8Value[] status, CefV8Value[] index, IJSCBridgeCache bridge)
 {
     return new CollectionChanges(bridge, value, status, index, IndividualType);
 }
示例#43
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);
示例#44
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
 /// CefRenderProcessHandler, 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)
                ));
 }
示例#45
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 assignment of the interceptor value identified by |index|. |object|
 /// is the receiver ('this' object) of the interceptor. |value| is the new
 /// value being assigned to the interceptor. If assignment fails, set
 /// |exception| to the exception that will be thrown.
 /// Return true if interceptor assignment was handled, false otherwise.
 /// </summary>
 protected virtual bool SetByIndex(int index, CefV8Value @object, CefV8Value value, out string exception)
 {
     exception = null;
     return(false);
 }