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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 14
0
 public void SetMappedJSValue(IJavascriptObject ijsobject)
 {
     _MappedJSValue = ijsobject;
     _MappedJSValue.Bind("Execute", WebView, Execute);
 }
Exemplo n.º 15
0
 public void SetMappedJSValue(IJavascriptObject jsobject)
 {
     _MappedJSValue = jsobject;
     _MappedJSValue.Bind("Execute", WebView, ExecuteCommand);
     _MappedJSValue.Bind("CanExecute", WebView, CanExecuteCommand);
 }
Exemplo n.º 16
0
 public void SetMappedJSValue(IJavascriptObject ijsobject)
 {
     _MappedJSValue = ijsobject;
     _MappedJSValue.Bind("Execute", _WebView, Execute);
 }
Exemplo n.º 17
0
        public void UpdateJsObject(IJavascriptObject javascriptObject)
        {
            IExecutableGlue executable = this;

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