Permalink
Browse files

wp8: execute_js fixed

  • Loading branch information...
1 parent 2e1b2db commit c9af95410c2332eb8492b76dd98551766a74cf80 @timashev timashev committed Mar 19, 2013
@@ -192,13 +192,18 @@ public void navigate(string url, int index)
((WebBrowser)((PivotItem)TabbarPivot.Items[getValidTabbarIndex(index)]).Content).Navigate(new Uri(url));
}
- public void executeScript(string script, int index)
+ public string executeScriptFunc(string script, int index)
{
- if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { executeScript(script, index); }); return; }
+ string[] codeString = { script };
if (isDefaultBrowser())
- RhodesWebBrowser.InvokeScript(script);
+ return RhodesWebBrowser.InvokeScript("eval", codeString).ToString();
else
- ((WebBrowser)((PivotItem)TabbarPivot.Items[getValidTabbarIndex(index)]).Content).InvokeScript(script);
+ return ((WebBrowser)((PivotItem)TabbarPivot.Items[getValidTabbarIndex(index)]).Content).InvokeScript("eval", codeString).ToString();
+ }
+
+ public string executeScript(string script, int index)
+ {
+ return StringValueByStringIntReturnAgent(executeScriptFunc, script, index);
}
public void GoBack()
@@ -781,5 +786,31 @@ private string StringValueByIntReturnAgent(Func<int, string> func, int index)
throw exception;
return return_value;
}
+
+ private string StringValueByStringIntReturnAgent(Func<string, int, string> func, string str, int index)
+ {
+ if (isUIThread)
+ return func(str, index);
+
+ Exception exception = null;
+ var waitEvent = new System.Threading.ManualResetEvent(false);
+ string return_value = "";
+ Dispatcher.BeginInvoke(() =>
+ {
+ try
+ {
+ return_value = func(str, index);
+ }
+ catch (Exception ex)
+ {
+ exception = ex;
+ }
+ waitEvent.Set();
+ });
+ waitEvent.WaitOne();
+ if (exception != null)
+ throw exception;
+ return return_value;
+ }
}
}
@@ -22,7 +22,7 @@ public class MainPageWrapper : rhoruntime.IMainPage
// webview
public void navigate(string url, int index) { _mainPage.navigate(url, index); }
- public void executeScript(string script, int index) { _mainPage.executeScript(script, index); }
+ public string executeScript(string script, int index) { return _mainPage.executeScript(script, index); }
public void GoBack() { _mainPage.GoBack(); }
public void GoForward() { _mainPage.GoForward(); }
public void Refresh(int index) { _mainPage.Refresh(index); }
@@ -26,10 +26,8 @@ extern "C" const char* rho_webview_execute_js(const char* js, int index)
{
rho::StringW jsW;
rho::common::convertToStringW(js, jsW);
- CRhoRuntime::getInstance()->getMainPage()->executeScript(ref new String(jsW.c_str()), index);
- // TODO: implement return value of rho_webview_execute_js
- // return strdup(...);
- return "";
+ rho::String urlA = rho::common::convertToStringA(CRhoRuntime::getInstance()->getMainPage()->executeScript(ref new String(jsW.c_str()), index)->Data());
+ return strdup(urlA.c_str());
}
extern "C" const char* rho_webview_current_location(int index)
@@ -41,7 +41,7 @@ namespace rhoruntime
// webview
void navigate(::Platform::String^ url, int index);
- void executeScript(::Platform::String^ script, int index);
+ ::Platform::String^ executeScript(::Platform::String^ script, int index);
void GoBack(void);
void GoForward(void);
void Refresh(int index);

0 comments on commit c9af954

Please sign in to comment.