From 9768ec2ef0154aeba71a7de68b5e57feffc00836 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Mon, 2 Dec 2013 17:50:57 -0800 Subject: [PATCH] CB-3420 WP feature hidden=yes implemented --- src/wp/InAppBrowser.cs | 135 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 2 deletions(-) diff --git a/src/wp/InAppBrowser.cs b/src/wp/InAppBrowser.cs index 46e1384..4b3d18d 100644 --- a/src/wp/InAppBrowser.cs +++ b/src/wp/InAppBrowser.cs @@ -36,12 +36,45 @@ namespace WPCordovaClassLib.Cordova.Commands private static ApplicationBarIconButton backButton; private static ApplicationBarIconButton fwdButton; + protected ApplicationBar AppBar; + + protected bool ShowLocation {get;set;} + protected bool StartHidden {get;set;} + public void open(string options) { + // reset defaults on ShowLocation + StartHidden features + ShowLocation = true; + StartHidden = false; + string[] args = JSON.JsonHelper.Deserialize(options); //BrowserOptions opts = JSON.JsonHelper.Deserialize(options); string urlLoc = args[0]; string target = args[1]; + string featString = args[2]; + + string[] features = featString.Split(','); + foreach (string str in features) + { + try + { + string[] split = str.Split('='); + switch (split[0]) + { + case "location": + ShowLocation = split[1].ToLower().StartsWith("yes"); + break; + case "hidden": + StartHidden = split[1].ToLower().StartsWith("yes"); + break; + } + } + catch(Exception) + { + // some sort of invalid param was passed, moving on ... + } + + } /* _self - opens in the Cordova WebView if url is in the white-list, else it opens in the InAppBrowser _blank - always open in the InAppBrowser @@ -59,10 +92,99 @@ namespace WPCordovaClassLib.Cordova.Commands ShowSystemBrowser(urlLoc); break; } - - } + public void show(string options) + { + string[] args = JSON.JsonHelper.Deserialize(options); + + + if (browser != null) + { + Deployment.Current.Dispatcher.BeginInvoke(() => + { + browser.Visibility = Visibility.Visible; + AppBar.IsVisible = true; + }); + } + } + + public void injectScriptCode(string options) + { + string[] args = JSON.JsonHelper.Deserialize(options); + + bool bCallback = false; + if (bool.TryParse(args[1], out bCallback)) { }; + + string callbackId = args[2]; + + if (browser != null) + { + Deployment.Current.Dispatcher.BeginInvoke(() => + { + var res = browser.InvokeScript("eval", new string[] { args[0] }); + + if (bCallback) + { + PluginResult result = new PluginResult(PluginResult.Status.OK, res.ToString()); + result.KeepCallback = false; + this.DispatchCommandResult(result); + } + + }); + } + } + + public void injectScriptFile(string options) + { + Debug.WriteLine("Error : Windows Phone org.apache.cordova.inappbrowser does not currently support executeScript"); + string[] args = JSON.JsonHelper.Deserialize(options); + // throw new NotImplementedException("Windows Phone does not currently support 'executeScript'"); + } + + public void injectStyleCode(string options) + { + Debug.WriteLine("Error : Windows Phone org.apache.cordova.inappbrowser does not currently support insertCSS"); + return; + + //string[] args = JSON.JsonHelper.Deserialize(options); + //bool bCallback = false; + //if (bool.TryParse(args[1], out bCallback)) { }; + + //string callbackId = args[2]; + + //if (browser != null) + //{ + //Deployment.Current.Dispatcher.BeginInvoke(() => + //{ + // if (bCallback) + // { + // string cssInsertString = "try{(function(doc){var c = ''; doc.head.innerHTML += c;})(document);}catch(ex){alert('oops : ' + ex.message);}"; + // //cssInsertString = cssInsertString.Replace("_VALUE_", args[0]); + // Debug.WriteLine("cssInsertString = " + cssInsertString); + // var res = browser.InvokeScript("eval", new string[] { cssInsertString }); + // if (bCallback) + // { + // PluginResult result = new PluginResult(PluginResult.Status.OK, res.ToString()); + // result.KeepCallback = false; + // this.DispatchCommandResult(result); + // } + // } + + //}); + //} + } + + public void injectStyleFile(string options) + { + Debug.WriteLine("Error : Windows Phone org.apache.cordova.inappbrowser does not currently support insertCSS"); + return; + + //string[] args = JSON.JsonHelper.Deserialize(options); + //throw new NotImplementedException("Windows Phone does not currently support 'insertCSS'"); + } + + private void ShowCordovaBrowser(string url) { Uri loc = new Uri(url, UriKind.RelativeOrAbsolute); @@ -127,6 +249,12 @@ namespace WPCordovaClassLib.Cordova.Commands browser.NavigationFailed += new System.Windows.Navigation.NavigationFailedEventHandler(browser_NavigationFailed); browser.Navigated += new EventHandler(browser_Navigated); browser.Navigate(loc); + + if (StartHidden) + { + browser.Visibility = Visibility.Collapsed; + } + //browser.IsGeolocationEnabled = opts.isGeolocationEnabled; grid.Children.Add(browser); } @@ -156,6 +284,9 @@ namespace WPCordovaClassLib.Cordova.Commands bar.Buttons.Add(closeBtn); page.ApplicationBar = bar; + bar.IsVisible = !StartHidden; + AppBar = bar; + } }