Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update src/winphone/ChildBrowserCommand.cs #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/winphone/ChildBrowserCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -11,10 +11,12 @@
using Microsoft.Phone.Controls;
using System.Diagnostics;
using System.Runtime.Serialization;
using WP7GapClassLib.PhoneGap.UI;
using WP7CordovaClassLib.Cordova;
using WP7CordovaClassLib.Cordova.Commands;
using WP7CordovaClassLib.Cordova.JSON;
using Microsoft.Phone.Shell;

namespace WP7GapClassLib.PhoneGap.Commands
namespace WP7CordovaClassLib.Cordova.Commands
{
[DataContract]
public class BrowserOptions
Expand All @@ -38,12 +40,13 @@ public void showWebPage(string options)
{
BrowserOptions opts = JSON.JsonHelper.Deserialize<BrowserOptions>(options);

Uri loc = new Uri(opts.url);

Uri loc = new Uri(Uri.EscapeUriString(opts.url));
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
if (browser != null)
{
MessageBox.Show("--");
browser.IsGeolocationEnabled = opts.isGeolocationEnabled;
browser.Navigate(loc);
}
Expand All @@ -52,12 +55,14 @@ public void showWebPage(string options)
PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
if (frame != null)
{

PhoneApplicationPage page = frame.Content as PhoneApplicationPage;
if (page != null)
{
Grid grid = page.FindName("LayoutRoot") as Grid;
if (grid != null)
{

browser = new WebBrowser();
browser.Navigate(loc);

Expand Down Expand Up @@ -106,7 +111,7 @@ public void showWebPage(string options)

void browser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{

}

void fwdButton_Click(object sender, EventArgs e)
Expand All @@ -117,7 +122,7 @@ void fwdButton_Click(object sender, EventArgs e)
{
browser.InvokeScript("execScript", "history.forward();");
}
catch(Exception)
catch (Exception)
{

}
Expand Down Expand Up @@ -145,7 +150,7 @@ void closeBtn_Click(object sender, EventArgs e)
}


public void close(string options="")
public void close(string options = "")
{
if (browser != null)
{
Expand All @@ -166,29 +171,35 @@ public void close(string options="")
}
}
browser = null;
string message = JSON.JsonHelper.Serialize("{\"type\":\"close\"}");
PluginResult result = new PluginResult(PluginResult.Status.OK, message);
result.KeepCallback = false;
this.DispatchCommandResult(result);
});
}
}

void browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
string message = "{\"type\":\"locationChanged\", \"location\":\"" + e.Uri.AbsoluteUri + "\"}";
string message = JSON.JsonHelper.Serialize("{\"type\":\"locationChanged\",\"location\":\"" + e.Uri.AbsoluteUri + "\"}");
//string message = "'{\"type\":\"locationChanged\", \"location\":\"" + e.Uri.AbsoluteUri + "\"}'";
PluginResult result = new PluginResult(PluginResult.Status.OK, message);
result.KeepCallback = true;
this.DispatchCommandResult(result);
}

void browser_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
{
string message = "{\"type\":\"navigationError\",\"location\":\"" + e.Uri.AbsoluteUri + "\"}";
string message = JSON.JsonHelper.Serialize("{\"type\":\"navigationError\",\"location\":\"" + e.Uri.AbsoluteUri + "\"}");
PluginResult result = new PluginResult(PluginResult.Status.ERROR, message);
result.KeepCallback = true;
this.DispatchCommandResult(result);
}

void browser_Navigating(object sender, NavigatingEventArgs e)
{
string message = "{\"type\":\"locationAboutToChange\",\"location\":\"" + e.Uri.AbsoluteUri + "\"}";
string message = JSON.JsonHelper.Serialize("{\"type\":\"locationAboutToChange\",\"location\":\"" + e.Uri.AbsoluteUri + "\"}");
//string message = "'{\"type\":\"locationAboutToChange\",\"location\":\"" + e.Uri.AbsoluteUri + "\"}'";
PluginResult result = new PluginResult(PluginResult.Status.OK, message);
result.KeepCallback = true;
this.DispatchCommandResult(result);
Expand Down