You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2014/04/23 20:57:31 UTC
[11/17] git commit: Make InAppBrowser work with embedded files,
using system behavior
Make InAppBrowser work with embedded files, using system behavior
The plugin is changed to work with embedded files, using the system behavior. If one needs the system behavior, they need to pass "_system" as target when using the plugin. As the InAppBrowser for WP8 does not handle by itself the embedded pdf files, system behavior is called.
The plugin also is tested and working for wp7
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/commit/2fc9f3da
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/tree/2fc9f3da
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/diff/2fc9f3da
Branch: refs/heads/master
Commit: 2fc9f3da1fc683442a4c41811e826476d2ca9dd6
Parents: e282cc9
Author: Nadya Atanasova <na...@gmail.com>
Authored: Fri Apr 11 17:57:45 2014 +0300
Committer: Nadya Atanasova <na...@gmail.com>
Committed: Fri Apr 11 17:57:45 2014 +0300
----------------------------------------------------------------------
src/wp/InAppBrowser.cs | 106 +++++++++++++++++++++++++++++++-------------
1 file changed, 75 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/2fc9f3da/src/wp/InAppBrowser.cs
----------------------------------------------------------------------
diff --git a/src/wp/InAppBrowser.cs b/src/wp/InAppBrowser.cs
index 454464d..ae88b51 100644
--- a/src/wp/InAppBrowser.cs
+++ b/src/wp/InAppBrowser.cs
@@ -1,21 +1,24 @@
using System;
-using System.Net;
+using System.Diagnostics;
+using System.IO;
+using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Documents;
-using System.Windows.Ink;
-using System.Windows.Input;
using System.Windows.Media;
-using System.Windows.Media.Animation;
-using System.Windows.Shapes;
using Microsoft.Phone.Controls;
-using System.Diagnostics;
-using System.Runtime.Serialization;
-using WPCordovaClassLib.Cordova;
-using WPCordovaClassLib.Cordova.Commands;
-using WPCordovaClassLib.Cordova.JSON;
using Microsoft.Phone.Shell;
+
+#if WP8
+using System.Threading.Tasks;
+using Windows.ApplicationModel;
+using Windows.Storage;
+using Windows.System;
+
+//Use alias in case Cordova File Plugin is enabled. Then the File class will be declared in both and error will occur.
+using IOFile = System.IO.File;
+#else
using Microsoft.Phone.Tasks;
+#endif
namespace WPCordovaClassLib.Cordova.Commands
{
@@ -53,27 +56,29 @@ namespace WPCordovaClassLib.Cordova.Commands
string target = args[1];
string featString = args[2];
- string[] features = featString.Split(',');
- foreach (string str in features)
+ if (!string.IsNullOrEmpty(featString))
{
- try
+ string[] features = featString.Split(',');
+ foreach (string str in features)
{
- string[] split = str.Split('=');
- switch (split[0])
+ try
{
- case "location":
- ShowLocation = split[1].ToLower().StartsWith("yes");
- break;
- case "hidden":
- StartHidden = split[1].ToLower().StartsWith("yes");
- break;
+ string[] split = str.Split('=');
+ switch (split[0])
+ {
+ case "location":
+ ShowLocation = split[1].StartsWith("yes", StringComparison.OrdinalIgnoreCase);
+ break;
+ case "hidden":
+ StartHidden = split[1].StartsWith("yes", StringComparison.OrdinalIgnoreCase);
+ break;
+ }
+ }
+ catch (Exception)
+ {
+ // some sort of invalid param was passed, moving on ...
}
}
- 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
@@ -184,7 +189,6 @@ namespace WPCordovaClassLib.Cordova.Commands
//throw new NotImplementedException("Windows Phone does not currently support 'insertCSS'");
}
-
private void ShowCordovaBrowser(string url)
{
Uri loc = new Uri(url, UriKind.RelativeOrAbsolute);
@@ -208,13 +212,53 @@ namespace WPCordovaClassLib.Cordova.Commands
});
}
+#if WP8
+ private async void ShowSystemBrowser(string url)
+ {
+ var pathUri = new Uri(url, UriKind.Absolute);
+ if (pathUri.Scheme == Uri.UriSchemeHttp || pathUri.Scheme == Uri.UriSchemeHttps)
+ {
+ Launcher.LaunchUriAsync(pathUri);
+ return;
+ }
+
+ var file = await GetFile(pathUri.AbsolutePath.Replace('/', Path.DirectorySeparatorChar));
+ if (file != null)
+ {
+ Launcher.LaunchFileAsync(file);
+ }
+ else
+ {
+ Debug.WriteLine("File not found.");
+ }
+ }
+
+ private async Task<StorageFile> GetFile(string fileName)
+ {
+ //first try to get the file from the isolated storage
+ var localFolder = ApplicationData.Current.LocalFolder;
+ if (IOFile.Exists(Path.Combine(localFolder.Path, fileName)))
+ {
+ return await localFolder.GetFileAsync(fileName);
+ }
+
+ //if file is not found try to get it from the xap
+ var filePath = Path.Combine(Package.Current.InstalledLocation.Path, fileName);
+ if (IOFile.Exists(filePath))
+ {
+ return await StorageFile.GetFileFromPathAsync(filePath);
+ }
+
+ return null;
+ }
+#else
private void ShowSystemBrowser(string url)
{
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri(url, UriKind.Absolute);
webBrowserTask.Show();
}
-
+#endif
private void ShowInAppBrowser(string url)
{
@@ -326,7 +370,7 @@ namespace WPCordovaClassLib.Cordova.Commands
{
#if WP8
browser.GoBack();
-#else
+#else
browser.InvokeScript("execScript", "history.back();");
#endif
}
@@ -405,4 +449,4 @@ namespace WPCordovaClassLib.Cordova.Commands
}
}
-}
+}
\ No newline at end of file