diff --git a/plugins/Android/src-nofragment/net/gree/unitywebview/CWebViewPlugin.java b/plugins/Android/src-nofragment/net/gree/unitywebview/CWebViewPlugin.java index b665de3b..48278716 100644 --- a/plugins/Android/src-nofragment/net/gree/unitywebview/CWebViewPlugin.java +++ b/plugins/Android/src-nofragment/net/gree/unitywebview/CWebViewPlugin.java @@ -533,6 +533,16 @@ public void GoForward() { }}); } + public void Reload() { + final Activity a = UnityPlayer.currentActivity; + a.runOnUiThread(new Runnable() {public void run() { + if (mWebView == null) { + return; + } + mWebView.reload(); + }}); + } + public void SetMargins(int left, int top, int right, int bottom) { final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( diff --git a/plugins/Android/src/net/gree/unitywebview/CWebViewPlugin.java b/plugins/Android/src/net/gree/unitywebview/CWebViewPlugin.java index 72512723..dd8e2841 100644 --- a/plugins/Android/src/net/gree/unitywebview/CWebViewPlugin.java +++ b/plugins/Android/src/net/gree/unitywebview/CWebViewPlugin.java @@ -722,6 +722,16 @@ public void GoForward() { }}); } + public void Reload() { + final Activity a = UnityPlayer.currentActivity; + a.runOnUiThread(new Runnable() {public void run() { + if (mWebView == null) { + return; + } + mWebView.reload(); + }}); + } + public void SetMargins(int left, int top, int right, int bottom) { final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( diff --git a/plugins/Mac/Sources/WebView.mm b/plugins/Mac/Sources/WebView.mm index 77015ef1..865b01c6 100644 --- a/plugins/Mac/Sources/WebView.mm +++ b/plugins/Mac/Sources/WebView.mm @@ -481,6 +481,13 @@ - (void)goForward [webView goForward]; } +- (void)reload +{ + if (webView == nil) + return; + [webView reload]; +} + - (void)sendMouseEvent:(int)x y:(int)y deltaY:(float)deltaY mouseState:(int)mouseState { if (webView == nil) @@ -752,6 +759,7 @@ - (const char *)getCustomRequestHeaderValue:(const char *)headerKey BOOL _CWebViewPlugin_CanGoForward(void *instance); void _CWebViewPlugin_GoBack(void *instance); void _CWebViewPlugin_GoForward(void *instance); + void _CWebViewPlugin_Reload(void *instance); void _CWebViewPlugin_SendMouseEvent(void *instance, int x, int y, float deltaY, int mouseState); void _CWebViewPlugin_SendKeyEvent(void *instance, int x, int y, char *keyChars, unsigned short keyCode, int keyState); void _CWebViewPlugin_Update(void *instance, BOOL refreshBitmap); @@ -872,6 +880,12 @@ void _CWebViewPlugin_GoForward(void *instance) [webViewPlugin goForward]; } +void _CWebViewPlugin_Reload(void *instance) +{ + CWebViewPlugin *webViewPlugin = (__bridge CWebViewPlugin *)instance; + [webViewPlugin reload]; +} + void _CWebViewPlugin_SendMouseEvent(void *instance, int x, int y, float deltaY, int mouseState) { CWebViewPlugin *webViewPlugin = (__bridge CWebViewPlugin *)instance; diff --git a/plugins/WebViewObject.cs b/plugins/WebViewObject.cs index efb07957..577bd70f 100644 --- a/plugins/WebViewObject.cs +++ b/plugins/WebViewObject.cs @@ -200,6 +200,9 @@ private static extern void _CWebViewPlugin_GoBack( private static extern void _CWebViewPlugin_GoForward( IntPtr instance); [DllImport("WebView")] + private static extern void _CWebViewPlugin_Reload( + IntPtr instance); + [DllImport("WebView")] private static extern void _CWebViewPlugin_SendMouseEvent(IntPtr instance, int x, int y, float deltaY, int mouseState); [DllImport("WebView")] private static extern void _CWebViewPlugin_SendKeyEvent(IntPtr instance, int x, int y, string keyChars, ushort keyCode, int keyState); @@ -270,6 +273,9 @@ private static extern void _CWebViewPlugin_GoBack( private static extern void _CWebViewPlugin_GoForward( IntPtr instance); [DllImport("__Internal")] + private static extern void _CWebViewPlugin_Reload( + IntPtr instance); + [DllImport("__Internal")] private static extern void _CWebViewPlugin_AddCustomHeader(IntPtr instance, string headerKey, string headerValue); [DllImport("__Internal")] private static extern string _CWebViewPlugin_GetCustomHeaderValue(IntPtr instance, string headerKey); @@ -744,6 +750,23 @@ public void GoForward() #endif } + public void Reload() + { +#if UNITY_WEBPLAYER || UNITY_WEBGL + //TODO: UNSUPPORTED +#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX + //TODO: UNSUPPORTED +#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE + if (webView == IntPtr.Zero) + return; + _CWebViewPlugin_Reload(webView); +#elif UNITY_ANDROID + if (webView == null) + return; + webView.Call("Reload"); +#endif + } + public void CallOnError(string error) { if (onError != null) diff --git a/plugins/iOS/WebView.mm b/plugins/iOS/WebView.mm index e01751dc..d01870e7 100644 --- a/plugins/iOS/WebView.mm +++ b/plugins/iOS/WebView.mm @@ -44,6 +44,7 @@ - (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void @property (nonatomic, readonly) BOOL canGoForward; - (void)goBack; - (void)goForward; +- (void)reload; - (void)stopLoading; - (void)setScrollBounce:(BOOL)enable; @end @@ -654,6 +655,13 @@ - (void)goForward [webView goForward]; } +- (void)reload +{ + if (webView == nil) + return; + [webView reload]; +} + - (void)addCustomRequestHeader:(const char *)headerKey value:(const char *)headerValue { NSString *keyString = [NSString stringWithUTF8String:headerKey]; @@ -714,6 +722,7 @@ void _CWebViewPlugin_SetMargins( BOOL _CWebViewPlugin_CanGoForward(void *instance); void _CWebViewPlugin_GoBack(void *instance); void _CWebViewPlugin_GoForward(void *instance); + void _CWebViewPlugin_Reload(void *instance); void _CWebViewPlugin_AddCustomHeader(void *instance, const char *headerKey, const char *headerValue); void _CWebViewPlugin_RemoveCustomHeader(void *instance, const char *headerKey); void _CWebViewPlugin_ClearCustomHeader(void *instance); @@ -848,6 +857,14 @@ void _CWebViewPlugin_GoForward(void *instance) [webViewPlugin goForward]; } +void _CWebViewPlugin_Reload(void *instance) +{ + if (instance == NULL) + return; + CWebViewPlugin *webViewPlugin = (__bridge CWebViewPlugin *)instance; + [webViewPlugin reload]; +} + void _CWebViewPlugin_AddCustomHeader(void *instance, const char *headerKey, const char *headerValue) { if (instance == NULL) diff --git a/plugins/iOS/WebViewWithUIWebView.mm b/plugins/iOS/WebViewWithUIWebView.mm index de44fa16..d3cf7fb5 100644 --- a/plugins/iOS/WebViewWithUIWebView.mm +++ b/plugins/iOS/WebViewWithUIWebView.mm @@ -45,6 +45,7 @@ - (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void @property (nonatomic, readonly) BOOL canGoForward; - (void)goBack; - (void)goForward; +- (void)reload; - (void)stopLoading; - (void)setScrollBounce:(BOOL)enable; @end @@ -756,6 +757,13 @@ - (void)goForward [webView goForward]; } +- (void)reload +{ + if (webView == nil) + return; + [webView reload]; +} + - (void)addCustomRequestHeader:(const char *)headerKey value:(const char *)headerValue { NSString *keyString = [NSString stringWithUTF8String:headerKey]; @@ -816,6 +824,7 @@ void _CWebViewPlugin_SetMargins( BOOL _CWebViewPlugin_CanGoForward(void *instance); void _CWebViewPlugin_GoBack(void *instance); void _CWebViewPlugin_GoForward(void *instance); + void _CWebViewPlugin_Reload(void *instance); void _CWebViewPlugin_AddCustomHeader(void *instance, const char *headerKey, const char *headerValue); void _CWebViewPlugin_RemoveCustomHeader(void *instance, const char *headerKey); void _CWebViewPlugin_ClearCustomHeader(void *instance); @@ -948,6 +957,14 @@ void _CWebViewPlugin_GoForward(void *instance) [webViewPlugin goForward]; } +void _CWebViewPlugin_Reload(void *instance) +{ + if (instance == NULL) + return; + CWebViewPlugin *webViewPlugin = (__bridge CWebViewPlugin *)instance; + [webViewPlugin reload]; +} + void _CWebViewPlugin_AddCustomHeader(void *instance, const char *headerKey, const char *headerValue) { if (instance == NULL) diff --git a/sample/Assets/Scripts/SampleWebView.cs b/sample/Assets/Scripts/SampleWebView.cs index d9d9e29f..d2d2b315 100644 --- a/sample/Assets/Scripts/SampleWebView.cs +++ b/sample/Assets/Scripts/SampleWebView.cs @@ -191,7 +191,11 @@ void OnGUI() } GUI.enabled = true; - GUI.TextField(new Rect(200, 10, 300, 80), "" + webViewObject.Progress()); + if (GUI.Button(new Rect(200, 10, 80, 80), "r")) { + webViewObject.Reload(); + } + + GUI.TextField(new Rect(300, 10, 200, 80), "" + webViewObject.Progress()); if (GUI.Button(new Rect(600, 10, 80, 80), "*")) { var g = GameObject.Find("WebViewObject");