From 8f2ad211ad60a10d7234124ff3c815e6a3b70ff1 Mon Sep 17 00:00:00 2001 From: sgrebnov Date: Fri, 18 Apr 2014 10:47:20 -0700 Subject: [PATCH] CB-6474 InAppBrowser. Add data urls support to WP8 --- src/wp/InAppBrowser.cs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/wp/InAppBrowser.cs b/src/wp/InAppBrowser.cs index 454464d..844ae16 100644 --- a/src/wp/InAppBrowser.cs +++ b/src/wp/InAppBrowser.cs @@ -200,7 +200,7 @@ namespace WPCordovaClassLib.Cordova.Commands if (cView != null) { WebBrowser br = cView.Browser; - br.Navigate(loc); + br.Navigate2(loc); } } @@ -225,7 +225,7 @@ namespace WPCordovaClassLib.Cordova.Commands if (browser != null) { //browser.IsGeolocationEnabled = opts.isGeolocationEnabled; - browser.Navigate(loc); + browser.Navigate2(loc); } else { @@ -248,7 +248,7 @@ namespace WPCordovaClassLib.Cordova.Commands browser.Navigating += new EventHandler(browser_Navigating); browser.NavigationFailed += new System.Windows.Navigation.NavigationFailedEventHandler(browser_NavigationFailed); browser.Navigated += new EventHandler(browser_Navigated); - browser.Navigate(loc); + browser.Navigate2(loc); if (StartHidden) { @@ -405,4 +405,29 @@ namespace WPCordovaClassLib.Cordova.Commands } } + + internal static class WebBrowserExtensions + { + /// + /// Improved method to initiate request to the provided URI. Supports 'data:text/html' urls. + /// + /// The browser instance + /// The requested uri + internal static void Navigate2(this WebBrowser browser, Uri uri) + { + // IE10 does not support data uri so we use NavigateToString method instead + if (uri.Scheme == "data") + { + // we should remove the scheme identifier and unescape the uri + string uriString = Uri.UnescapeDataString(uri.AbsoluteUri); + // format is 'data:text/html, ...' + string html = new System.Text.RegularExpressions.Regex("^data:text/html,").Replace(uriString, ""); + browser.NavigateToString(html); + } + else + { + browser.Navigate(uri); + } + } + } }