private void ViewBackgroundImageSetter(string bindingName, string image)
        {
            string script = string.Format(
                "htmlViewBindingsSetBackgroundImage('{0}', '{1}');", bindingName, WebviewUtils.EscapeJavaScriptString(image));

            _htmlView.ExecuteJavaScript(script);
        }
        /// <inheritdoc/>
        public void ReplaceNode(string nodeId, string newHtml)
        {
            string encodedNewHtml = WebviewUtils.EscapeJavaScriptString(newHtml);
            string script         = string.Format("document.getElementById('{0}').outerHTML = \"{1}\";", nodeId, encodedNewHtml);

            ExecuteJavaScript(script);
        }
        private void ViewValueSetter(string bindingName, object value)
        {
            string valueText = WebviewUtils.EscapeJavaScriptString(value?.ToString());
            string script    = string.Format(
                "htmlViewBindingsSetValue('{0}', '{1}');", bindingName, valueText);

            _htmlView.ExecuteJavaScript(script);
        }
Exemple #4
0
 public void IsExternalUrlWorksWithKnownProtocols()
 {
     Assert.IsTrue(WebviewUtils.IsExternalUri("http://example.com"));
     Assert.IsTrue(WebviewUtils.IsExternalUri("https://www.example.com"));
     Assert.IsTrue(WebviewUtils.IsExternalUri("ftp://example.com/text.txt"));
     Assert.IsTrue(WebviewUtils.IsExternalUri("ftps://example.com/text.txt"));
     Assert.IsTrue(WebviewUtils.IsExternalUri("mailto://[email protected]"));
     Assert.IsTrue(WebviewUtils.IsExternalUri("news://example.com"));
     Assert.IsTrue(WebviewUtils.IsExternalUri("tel://+41 00 000 000"));
 }
Exemple #5
0
        private void ViewLoadedEventHandler(object sender, EventArgs e)
        {
            VueBindings.ViewLoadedEvent -= ViewLoadedEventHandler;
            View.Navigating             += NavigatingEventHandler;

            if (!string.IsNullOrEmpty(_startingSearchFilter))
            {
                string encodedSearchFilter = WebviewUtils.EscapeJavaScriptString(_startingSearchFilter);
                string script = string.Format("setStartingSearchFilter('{0}');", encodedSearchFilter);
                View.ExecuteJavaScript(script);
            }
        }
Exemple #6
0
        private void NavigationCompletedEventHandler(object sender, EventArgs e)
        {
            View.NavigationCompleted -= NavigationCompletedEventHandler;
            View.Navigating          += NavigatingEventHandler;

            if (_startedWithSendToSilentnotes)
            {
                // Let quill do the text import, so it can convert it safely to HTML and trigger
                // the "quill" event which eventually sets the modified property.
                string encodedNewText = WebviewUtils.EscapeJavaScriptString(_sendToSilentnotesText);
                string script         = string.Format("setNoteHtmlContent('{0}');", encodedNewText);
                View.ExecuteJavaScript(script);
            }
        }
Exemple #7
0
        internal bool TryFormatForView(VueBindingDescription binding, object value, out string formattedValue)
        {
            PropertyInfo propertyInfo = _dotnetViewModel.GetType().GetProperty(binding.PropertyName);

            if (propertyInfo != null)
            {
                Type propertyType = propertyInfo.PropertyType;
                if (value == null)
                {
                    formattedValue = "null";
                    return(true);
                }
                else if (propertyType == typeof(string))
                {
                    formattedValue = "'" + WebviewUtils.EscapeJavaScriptString(value.ToString()) + "'";
                    return(true);
                }
                else if (typeof(IEnumerable <string>).IsAssignableFrom(propertyType))
                {
                    IEnumerable <string> valueList = (IEnumerable <string>)value;
                    formattedValue = string.Join(
                        ",", valueList.Select(v => "'" + WebviewUtils.EscapeJavaScriptString(v) + "'"));
                    formattedValue = "[" + formattedValue + "]";
                    return(true);
                }
                else if (propertyType == typeof(bool))
                {
                    formattedValue = value.ToString().ToLowerInvariant();
                    return(true);
                }
                else if (propertyType == typeof(int))
                {
                    formattedValue = value.ToString();
                    return(true);
                }
                else if (propertyType == typeof(SecureString))
                {
                    // HTML doesn't know the concept of a SecureString, so this is the moment we have to switch.
                    string unprotectedValue = SecureStringExtensions.SecureStringToString((SecureString)value);
                    formattedValue = "'" + WebviewUtils.EscapeJavaScriptString(unprotectedValue) + "'";
                    return(true);
                }
            }
            formattedValue = null;
            return(false);
        }
Exemple #8
0
        private void ViewLoadedEventHandler(object sender, EventArgs e)
        {
            VueBindings.ViewLoadedEvent -= ViewLoadedEventHandler;
            View.Navigating             += NavigatingEventHandler;

            if (_startedWithSendToSilentnotes)
            {
                // Let quill do the text import, so it can convert it safely to HTML and trigger
                // the "quill" event which eventually sets the modified property.
                string encodedNewText = WebviewUtils.EscapeJavaScriptString(_sendToSilentnotesText);
                string script         = string.Format("setNoteHtmlContent('{0}');", encodedNewText);
                View.ExecuteJavaScript(script);
            }
            else if (!string.IsNullOrEmpty(_startingSearchFilter))
            {
                string encodedSearchFilter = WebviewUtils.EscapeJavaScriptString(_startingSearchFilter);
                string script = string.Format("setStartingSearchFilter('{0}');", encodedSearchFilter);
                View.ExecuteJavaScript(script);
            }
        }
Exemple #9
0
 private bool IsVueBindingUri(string uri)
 {
     return(!string.IsNullOrEmpty(uri) &&
            (uri.Contains("vuePropertyChanged?") || uri.Contains("vueCommandExecute?") || uri.Contains("vueLoaded")) &&
            !WebviewUtils.IsExternalUri(uri));
 }
Exemple #10
0
 private static bool IsHtmlViewBindingUri(string uri)
 {
     return(!string.IsNullOrEmpty(uri) && uri.Contains(JsNamespace) && !WebviewUtils.IsExternalUri(uri));
 }
Exemple #11
0
 public void IsExternalUrlRejectsWrongUrls()
 {
     Assert.IsFalse(WebviewUtils.IsExternalUri("webview://click#http"));
 }
Exemple #12
0
 public void IsExternalUrlWorksCaseInsensitive()
 {
     Assert.IsTrue(WebviewUtils.IsExternalUri("HttP://example.com/test"));
 }
Exemple #13
0
 public void IsExternalUrlWorksWithNullOrEmpty()
 {
     Assert.IsFalse(WebviewUtils.IsExternalUri(null));
     Assert.IsFalse(WebviewUtils.IsExternalUri(string.Empty));
 }
Exemple #14
0
 public void EscapeJavaScriptStringReturnsEmptyStringForNull()
 {
     Assert.AreEqual(string.Empty, WebviewUtils.EscapeJavaScriptString(null));
     Assert.AreEqual(string.Empty, WebviewUtils.EscapeJavaScriptString(string.Empty));
 }