private IJavascriptObject GetMapper(IJavascriptMapper iMapperListener)
        {
            _IJavascriptMapper.Enqueue(iMapperListener);

            if (_Mapper != null)
            {
                return(_Mapper);
            }

            _Mapper = _IWebView.Factory.CreateObject(false);

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

                if (_Current == null)
                {
                    return;
                }

                int count = e.Length;
                IJavascriptObject 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", _IWebView, (c, o, e) =>
            {
                if (_PullNextMapper)
                {
                    _Current = _IJavascriptMapper.Dequeue();
                }

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

            return(_Mapper);
        }
示例#2
0
        internal BulkJsHelper(ISessionCache cache, IWebView webView, IJavascriptObject helper)
        {
            _Cache = cache;

            BulkObjectsUpdater = helper.GetValue("bulkUpdateObjects");
            BulkArraysUpdater  = helper.GetValue("bulkUpdateArrays");
            CommandConstructor = helper.GetValue("Command");
            _CommandPrototype  = CommandConstructor.GetValue("prototype");
            _CommandPrototype.Bind("privateExecute", webView, ExecuteExecutable);
            _CommandPrototype.Bind("privateCanExecute", webView, CanExecuteCommand);

            ExecutableConstructor = helper.GetValue("Executable");
            _ExecutablePrototype  = ExecutableConstructor.GetValue("prototype");
            _ExecutablePrototype.Bind("privateExecute", webView, ExecuteExecutable);
        }
示例#3
0
        internal BulkJsHelper(IJavascriptSessionCache cache, IWebView webView, IJavascriptObject helper)
        {
            _Cache   = cache;
            _WebView = webView;

            BulkCreator        = helper.GetValue("bulkCreate");
            CommandConstructor = helper.GetValue("Command");
            _CommandPrototype  = CommandConstructor.GetValue("prototype");
            _CommandPrototype.Bind("privateExecute", _WebView, ExecuteExecutable);
            _CommandPrototype.Bind("privateCanExecute", _WebView, CanExecuteCommand);

            ExecutableConstructor = helper.GetValue("Executable");
            _ExecutablePrototype  = ExecutableConstructor.GetValue("prototype");
            _ExecutablePrototype.Bind("privateExecute", _WebView, ExecuteExecutable);
        }
        internal JavascriptSessionInjector(IWebView iWebView, IJavascriptListener iJavascriptListener)
        {
            _IWebView            = iWebView;
            _IJavascriptListener = iJavascriptListener;

            _IWebView.Run(() =>
            {
                _Listener = _IWebView.Factory.CreateObject(false);

                if (_IJavascriptListener != null)
                {
                    _Listener.Bind("TrackChanges", _IWebView, (c, o, e) => _IJavascriptListener.OnJavaScriptObjectChanges(e[0], e[1].GetStringValue(), e[2]));
                    _Listener.Bind("TrackCollectionChanges", _IWebView, (c, o, e) => _IJavascriptListener.OnJavaScriptCollectionChanges(e[0], e[1].GetArrayElements(), e[2].GetArrayElements(), e[3].GetArrayElements()));
                }
            });
        }
        internal JavascriptSessionInjector(IWebView iWebView, IJavascriptListener iJavascriptListener)
        {
            _IWebView = iWebView;
            _IJavascriptListener = iJavascriptListener;

            _IWebView.Run(() =>
                {
                    _Listener = _IWebView.Factory.CreateObject(false);

                    if (_IJavascriptListener != null)
                    {
                        _Listener.Bind("TrackChanges", _IWebView, (c, o, e) => _IJavascriptListener.OnJavaScriptObjectChanges(e[0], e[1].GetStringValue(), e[2]));
                        _Listener.Bind("TrackCollectionChanges", _IWebView, (c, o, e) => _IJavascriptListener.OnJavaScriptCollectionChanges(e[0], e[1].GetArrayElements(), e[2].GetArrayElements(), e[3].GetArrayElements()));
                    }
                });
        }
        private IJavascriptObject GetMapper(IJavascriptMapper iMapperListener)
        {
            _IJavascriptMapper.Enqueue(iMapperListener);
    
            if (_Mapper != null)
                return _Mapper;

            _Mapper = _IWebView.Factory.CreateObject(false);

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

                if (_Current == null)
                    return;

                int count = e.Length;
                IJavascriptObject 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", _IWebView, (c, o, e) =>
                {
                    if (_PullNextMapper)
                        _Current = _IJavascriptMapper.Dequeue();

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

            return _Mapper;
        }
示例#7
0
        public WebViewListener(IWebView webView)
        {
            _WebView = webView;

            _Listener = _WebView.Factory.CreateObject(false);
            _Listener.Bind("postMessage", _WebView, (e) => PostMessage(e[0].GetStringValue(), e[1].GetStringValue()));
            _WebView.GetGlobal().SetValue("__neutronium_listener__", _Listener, CreationOption.DontDelete | CreationOption.ReadOnly | CreationOption.DontEnum);

            var loader = new ResourceReader("Communication.script.dist", this);
            var data   = loader.Load("communication.js");

            _WebView.ExecuteJavaScript(data);
        }
        private IJavascriptObject GetKo()
        {
            if (_Ko != null)
                return _Ko;

            _Ko = _WebView.GetGlobal().GetValue("ko");
            if ((_Ko == null) || (!_Ko.IsObject))
                throw ExceptionHelper.Get("ko object not found! You should add a link to knockout.js script to the HML document!");

            _Ko.Bind("log", _WebView, (e) => _logger.Info(() => string.Join(" - ", e.Select(s => (s.GetStringValue().Replace("\n", " "))))));

            return _Ko;
        }
        private Task UnsafeRegister(IJavascriptObject ijvm)
        {
            var tcs = new TaskCompletionSource <object>();

            _Listener.Bind("fulfill", _WebView, _ =>
            {
                _Logger.Debug("Vue ready received");
                tcs.TrySetResult(null);
            });

            var vueHelper = _VueHelper.Value;

            vueHelper.GetValue("ready").Invoke("then", _WebView, _Listener.GetValue("fulfill"));
            vueHelper.Invoke("register", _WebView, ijvm, _Listener);
            return(tcs.Task);
        }
示例#10
0
        public Task RegisterMainViewModel(IJavascriptObject jsObject)
        {
            var tcs = new TaskCompletionSource <object>();

            _Listener.Bind("fulfill", _WebView, _ =>
            {
                _Logger.Debug("Vue ready received");
                tcs.TrySetResult(null);
            });

            var vueHelper = _VueHelper.Value;

            vueHelper.GetValue("ready").Invoke("then", _WebView, _Listener.GetValue("fulfill"));
            vueHelper.Invoke("register", _WebView, jsObject, _Listener);
            return(tcs.Task);
        }
        private IJavascriptObject GetKo()
        {
            if (_Ko != null)
            {
                return(_Ko);
            }

            _Ko = _WebView.GetGlobal().GetValue("ko");
            if ((_Ko == null) || (!_Ko.IsObject))
            {
                throw ExceptionHelper.Get("ko object not found! You should add a link to knockout.js script to the HML document!");
            }

            _Ko.Bind("log", _WebView, (e) => _logger.Info(() => string.Join(" - ", e.Select(s => (s.GetStringValue().Replace("\n", " "))))));

            return(_Ko);
        }
示例#12
0
 public void UpdateJsObject(IJavascriptObject javascriptObject)
 {
     javascriptObject.Bind("Execute", WebView, Execute);
     javascriptObject.Bind("CanExecute", WebView, CanExecuteCommand);
 }
        public static void Bind(this IJavascriptObject javascriptObject, string functionName, IWebView webView, Action <IJavascriptObject[]> action)
        {
            Action <string, IJavascriptObject, IJavascriptObject[]> neededAction = (n, t, arg) => action(arg);

            javascriptObject.Bind(functionName, webView, neededAction);
        }
示例#14
0
 public void SetMappedJSValue(IJavascriptObject ijsobject)
 {
     _MappedJSValue = ijsobject;
     _MappedJSValue.Bind("Execute", WebView, Execute);
 }
示例#15
0
 public void SetMappedJSValue(IJavascriptObject jsobject)
 {
     _MappedJSValue = jsobject;
     _MappedJSValue.Bind("Execute", WebView, ExecuteCommand);
     _MappedJSValue.Bind("CanExecute", WebView, CanExecuteCommand);
 }
 public void SetMappedJSValue(IJavascriptObject ijsobject)
 {
     _MappedJSValue = ijsobject;
     _MappedJSValue.Bind("Execute", _WebView, Execute);
 }
示例#17
0
        public void UpdateJsObject(IJavascriptObject javascriptObject)
        {
            IExecutableGlue executable = this;

            javascriptObject.Bind("Execute", WebView, executable.Execute);
        }
示例#18
0
 public void SetMappedJSValue(IJavascriptObject ijsobject)
 {
     _MappedJSValue = ijsobject;
     _MappedJSValue.Bind("Execute", WebView, ExecuteCommand);
     _MappedJSValue.Bind("CanExecute", WebView, CanExecuteCommand);
 }
示例#19
0
 public void SetMappedJSValue(IJavascriptObject ijsobject, IJSCBridgeCache mapper)
 {
     _MappedJSValue = ijsobject;
     _MappedJSValue.Bind("Execute", _IWebView, (c, o, e) => Execute(e, mapper));
 }
示例#20
0
 public void SetMappedJSValue(IJavascriptObject ijsobject, IJSCBridgeCache mapper)
 {
     _MappedJSValue = ijsobject;
     _MappedJSValue.Bind("Execute", _IWebView,(c, o, e) => Execute(e, mapper));
 }