Skip to content

Commit

Permalink
Merge pull request gree#11 from SlateScience/APPL-8689-fix-java-null-bug
Browse files Browse the repository at this point in the history
Fix Java Null Bug
  • Loading branch information
lavikabel authored Sep 22, 2024
2 parents 815ef27 + 840bb7d commit ae5da58
Show file tree
Hide file tree
Showing 22 changed files with 283 additions and 116 deletions.
214 changes: 100 additions & 114 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>23G93</string>
<string>23H124</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
Expand Down
Binary file not shown.
25 changes: 25 additions & 0 deletions dist/package-nofragment/Assets/Plugins/WebViewObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ public bool IsKeyboardVisible
private static extern IntPtr _CWebViewPlugin_InitStatic(
bool inEditor, bool useMetal);
[DllImport("WebView")]
private static extern bool _CWebViewPlugin_IsInitialized(
IntPtr instance);
[DllImport("WebView")]
private static extern IntPtr _CWebViewPlugin_Init(
string gameObject, bool transparent, bool zoom, int width, int height, string ua, bool separated);
[DllImport("WebView")]
Expand Down Expand Up @@ -507,6 +510,9 @@ private static extern void _CWebViewPlugin_Reload(
private static extern string _CWebViewPlugin_GetMessage(IntPtr instance);
#elif UNITY_IPHONE
[DllImport("__Internal")]
private static extern bool _CWebViewPlugin_IsInitialized(
IntPtr instance);
[DllImport("__Internal")]
private static extern IntPtr _CWebViewPlugin_Init(string gameObject, bool transparent, bool zoom, string ua, bool enableWKWebView, int wkContentMode, bool wkAllowsLinkPreview, bool wkAllowsBackForwardNavigationGestures, int radius);
[DllImport("__Internal")]
private static extern int _CWebViewPlugin_Destroy(IntPtr instance);
Expand Down Expand Up @@ -611,6 +617,25 @@ public static bool IsWebViewAvailable()
#endif
}

public bool IsInitialized()
{
#if UNITY_WEBPLAYER || UNITY_WEBGL
//TODO: UNSUPPORTED
return true;
#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX
//TODO: UNSUPPORTED
return true;
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return false;
return _CWebViewPlugin_IsInitialized(webView);
#elif UNITY_ANDROID
if (webView == null)
return false;
return webView.Call<bool>("IsInitialized");
#endif
}

public void Init(
Callback cb = null,
Callback err = null,
Expand Down
14 changes: 14 additions & 0 deletions dist/package-nofragment/Assets/Plugins/iOS/WebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ @implementation CWebViewPlugin
static WKProcessPool *_sharedProcessPool;
static NSMutableArray *_instances = [[NSMutableArray alloc] init];

- (BOOL)isInitialized
{
return webView != nil;
}

- (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)transparent zoom:(BOOL)zoom ua:(const char *)ua enableWKWebView:(BOOL)enableWKWebView contentMode:(WKContentMode)contentMode allowsLinkPreview:(BOOL)allowsLinkPreview allowsBackForwardNavigationGestures:(BOOL)allowsBackForwardNavigationGestures radius:(int)radius
{
self = [super init];
Expand Down Expand Up @@ -939,6 +944,7 @@ - (void)setAllMediaPlaybackSuspended:(BOOL)suspended
@end

extern "C" {
BOOL _CWebViewPlugin_IsInitialized(void *instance);
void *_CWebViewPlugin_Init(const char *gameObjectName, BOOL transparent, BOOL zoom, const char *ua, BOOL enableWKWebView, int contentMode, BOOL allowsLinkPreview, BOOL allowsBackForwardNavigationGestures, int radius);
void _CWebViewPlugin_Destroy(void *instance);
void _CWebViewPlugin_SetMargins(
Expand Down Expand Up @@ -970,6 +976,14 @@ void _CWebViewPlugin_SetMargins(
void _CWebViewPlugin_SetSuspended(void *instance, BOOL suspended);
}

BOOL _CWebViewPlugin_IsInitialized(void *instance)
{
if (instance == NULL)
return NO;
CWebViewPlugin *webViewPlugin = (__bridge_transfer CWebViewPlugin *)instance;
return [webViewPlugin isInitialized];
}

void *_CWebViewPlugin_Init(const char *gameObjectName, BOOL transparent, BOOL zoom, const char *ua, BOOL enableWKWebView, int contentMode, BOOL allowsLinkPreview, BOOL allowsBackForwardNavigationGestures, int radius)
{
if (! (enableWKWebView && [WKWebView class]))
Expand Down
14 changes: 14 additions & 0 deletions dist/package-nofragment/Assets/Plugins/iOS/WebViewWithUIWebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ @implementation CWebViewPlugin
static WKProcessPool *_sharedProcessPool;
static NSMutableArray *_instances = [[NSMutableArray alloc] init];

- (BOOL)isInitialized
{
return webView != nil;
}

- (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)transparent zoom:(BOOL)zoom ua:(const char *)ua enableWKWebView:(BOOL)enableWKWebView contentMode:(WKContentMode)contentMode allowsLinkPreview:(BOOL)allowsLinkPreview allowsBackForwardNavigationGestures:(BOOL)allowsBackForwardNavigationGestures radius:(int)radius
{
self = [super init];
Expand Down Expand Up @@ -1032,6 +1037,7 @@ - (void)setBasicAuthInfo:(const char *)userName password:(const char *)password
@end

extern "C" {
BOOL _CWebViewPlugin_IsInitialized(void *instance);
void *_CWebViewPlugin_Init(const char *gameObjectName, BOOL transparent, BOOL zoom, const char *ua, BOOL enableWKWebView, int contentMode, BOOL allowsLinkPreview, BOOL allowsBackForwardNavigationGestures, int radius);
void _CWebViewPlugin_Destroy(void *instance);
void _CWebViewPlugin_SetMargins(
Expand Down Expand Up @@ -1063,6 +1069,14 @@ void _CWebViewPlugin_SetMargins(
void _CWebViewPlugin_SetSuspended(void *instance, BOOL suspended);
}

BOOL _CWebViewPlugin_IsInitialized(void *instance)
{
if (instance == NULL)
return NO;
CWebViewPlugin *webViewPlugin = (__bridge_transfer CWebViewPlugin *)instance;
return [webViewPlugin isInitialized];
}

void *_CWebViewPlugin_Init(const char *gameObjectName, BOOL transparent, BOOL zoom, const char *ua, BOOL enableWKWebView, int contentMode, BOOL allowsLinkPreview, BOOL allowsBackForwardNavigationGestures, int radius)
{
WKContentMode wkContentMode = WKContentModeRecommended;
Expand Down
Binary file modified dist/package/Assets/Plugins/Android/WebViewPlugin-release.aar.tmpl
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>23G93</string>
<string>23H124</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
Expand Down
Binary file modified dist/package/Assets/Plugins/WebView.bundle/Contents/MacOS/WebView
Binary file not shown.
25 changes: 25 additions & 0 deletions dist/package/Assets/Plugins/WebViewObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ public bool IsKeyboardVisible
private static extern IntPtr _CWebViewPlugin_InitStatic(
bool inEditor, bool useMetal);
[DllImport("WebView")]
private static extern bool _CWebViewPlugin_IsInitialized(
IntPtr instance);
[DllImport("WebView")]
private static extern IntPtr _CWebViewPlugin_Init(
string gameObject, bool transparent, bool zoom, int width, int height, string ua, bool separated);
[DllImport("WebView")]
Expand Down Expand Up @@ -516,6 +519,9 @@ private static extern void _CWebViewPlugin_Reload(
private static extern string _CWebViewPlugin_GetMessage(IntPtr instance);
#elif UNITY_IPHONE
[DllImport("__Internal")]
private static extern bool _CWebViewPlugin_IsInitialized(
IntPtr instance);
[DllImport("__Internal")]
private static extern IntPtr _CWebViewPlugin_Init(string gameObject, bool transparent, bool zoom, string ua, bool enableWKWebView, int wkContentMode, bool wkAllowsLinkPreview, bool wkAllowsBackForwardNavigationGestures, int radius);
[DllImport("__Internal")]
private static extern int _CWebViewPlugin_Destroy(IntPtr instance);
Expand Down Expand Up @@ -614,6 +620,25 @@ public static bool IsWebViewAvailable()
#endif
}

public bool IsInitialized()
{
#if UNITY_WEBPLAYER || UNITY_WEBGL
//TODO: UNSUPPORTED
return true;
#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX
//TODO: UNSUPPORTED
return true;
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return false;
return _CWebViewPlugin_IsInitialized(webView);
#elif UNITY_ANDROID
if (webView == null)
return false;
return webView.Call<bool>("IsInitialized");
#endif
}

public void Init(
Callback cb = null,
Callback err = null,
Expand Down
14 changes: 14 additions & 0 deletions dist/package/Assets/Plugins/iOS/WebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ @implementation CWebViewPlugin
static WKProcessPool *_sharedProcessPool;
static NSMutableArray *_instances = [[NSMutableArray alloc] init];

- (BOOL)isInitialized
{
return webView != nil;
}

- (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)transparent zoom:(BOOL)zoom ua:(const char *)ua enableWKWebView:(BOOL)enableWKWebView contentMode:(WKContentMode)contentMode allowsLinkPreview:(BOOL)allowsLinkPreview allowsBackForwardNavigationGestures:(BOOL)allowsBackForwardNavigationGestures radius:(int)radius
{
self = [super init];
Expand Down Expand Up @@ -939,6 +944,7 @@ - (void)setAllMediaPlaybackSuspended:(BOOL)suspended
@end

extern "C" {
BOOL _CWebViewPlugin_IsInitialized(void *instance);
void *_CWebViewPlugin_Init(const char *gameObjectName, BOOL transparent, BOOL zoom, const char *ua, BOOL enableWKWebView, int contentMode, BOOL allowsLinkPreview, BOOL allowsBackForwardNavigationGestures, int radius);
void _CWebViewPlugin_Destroy(void *instance);
void _CWebViewPlugin_SetMargins(
Expand Down Expand Up @@ -970,6 +976,14 @@ void _CWebViewPlugin_SetMargins(
void _CWebViewPlugin_SetSuspended(void *instance, BOOL suspended);
}

BOOL _CWebViewPlugin_IsInitialized(void *instance)
{
if (instance == NULL)
return NO;
CWebViewPlugin *webViewPlugin = (__bridge_transfer CWebViewPlugin *)instance;
return [webViewPlugin isInitialized];
}

void *_CWebViewPlugin_Init(const char *gameObjectName, BOOL transparent, BOOL zoom, const char *ua, BOOL enableWKWebView, int contentMode, BOOL allowsLinkPreview, BOOL allowsBackForwardNavigationGestures, int radius)
{
if (! (enableWKWebView && [WKWebView class]))
Expand Down
14 changes: 14 additions & 0 deletions dist/package/Assets/Plugins/iOS/WebViewWithUIWebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ @implementation CWebViewPlugin
static WKProcessPool *_sharedProcessPool;
static NSMutableArray *_instances = [[NSMutableArray alloc] init];

- (BOOL)isInitialized
{
return webView != nil;
}

- (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)transparent zoom:(BOOL)zoom ua:(const char *)ua enableWKWebView:(BOOL)enableWKWebView contentMode:(WKContentMode)contentMode allowsLinkPreview:(BOOL)allowsLinkPreview allowsBackForwardNavigationGestures:(BOOL)allowsBackForwardNavigationGestures radius:(int)radius
{
self = [super init];
Expand Down Expand Up @@ -1032,6 +1037,7 @@ - (void)setBasicAuthInfo:(const char *)userName password:(const char *)password
@end

extern "C" {
BOOL _CWebViewPlugin_IsInitialized(void *instance);
void *_CWebViewPlugin_Init(const char *gameObjectName, BOOL transparent, BOOL zoom, const char *ua, BOOL enableWKWebView, int contentMode, BOOL allowsLinkPreview, BOOL allowsBackForwardNavigationGestures, int radius);
void _CWebViewPlugin_Destroy(void *instance);
void _CWebViewPlugin_SetMargins(
Expand Down Expand Up @@ -1063,6 +1069,14 @@ void _CWebViewPlugin_SetMargins(
void _CWebViewPlugin_SetSuspended(void *instance, BOOL suspended);
}

BOOL _CWebViewPlugin_IsInitialized(void *instance)
{
if (instance == NULL)
return NO;
CWebViewPlugin *webViewPlugin = (__bridge_transfer CWebViewPlugin *)instance;
return [webViewPlugin isInitialized];
}

void *_CWebViewPlugin_Init(const char *gameObjectName, BOOL transparent, BOOL zoom, const char *ua, BOOL enableWKWebView, int contentMode, BOOL allowsLinkPreview, BOOL allowsBackForwardNavigationGestures, int radius)
{
WKContentMode wkContentMode = WKContentModeRecommended;
Expand Down
Binary file modified dist/unity-webview-nofragment.unitypackage
Binary file not shown.
Binary file modified dist/unity-webview-nofragment.zip
Binary file not shown.
Binary file modified dist/unity-webview.unitypackage
Binary file not shown.
Binary file modified dist/unity-webview.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,8 @@ public void SaveCookies()
public void GetCookies(String url)
{
CookieManager cookieManager = CookieManager.getInstance();
Log.i("CWebViewPlugin", "APPL-8689 cookieManager is null? " + ((cookieManager == null)? "true" : "false"));
Log.i("CWebViewPlugin", cookieManager.toString());
mWebViewPlugin.call("CallOnCookies", cookieManager.getCookie(url));
}

Expand Down
14 changes: 14 additions & 0 deletions plugins/Mac/Sources/WebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ @implementation CWebViewPlugin
{ NSModeSwitchFunctionKey, 0 },
};

- (BOOL)isInitialized
{
return webView != nil;
}

- (id)initWithGameObject:(const char *)gameObject_ transparent:(BOOL)transparent zoom:(BOOL)zoom width:(int)width height:(int)height ua:(const char *)ua separated:(BOOL)separated
{
self = [super init];
Expand Down Expand Up @@ -974,6 +979,7 @@ - (const char *)getCustomRequestHeaderValue:(const char *)headerKey
#endif
const char *_CWebViewPlugin_GetAppPath(void);
void _CWebViewPlugin_InitStatic(BOOL inEditor, BOOL useMetal);
BOOL _CWebViewPlugin_IsInitialized(void *instance);
void *_CWebViewPlugin_Init(
const char *gameObject, BOOL transparent, BOOL zoom, int width, int height, const char *ua, BOOL separated);
void _CWebViewPlugin_Destroy(void *instance);
Expand Down Expand Up @@ -1021,6 +1027,14 @@ void _CWebViewPlugin_InitStatic(BOOL inEditor, BOOL useMetal)
s_useMetal = useMetal;
}

BOOL _CWebViewPlugin_IsInitialized(void *instance)
{
if (instance == NULL)
return NO;
CWebViewPlugin *webViewPlugin = (__bridge_transfer CWebViewPlugin *)instance;
return [webViewPlugin isInitialized];
}

void *_CWebViewPlugin_Init(
const char *gameObject, BOOL transparent, BOOL zoom, int width, int height, const char *ua, BOOL separated)
{
Expand Down
25 changes: 25 additions & 0 deletions plugins/WebViewObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ public bool IsKeyboardVisible
private static extern IntPtr _CWebViewPlugin_InitStatic(
bool inEditor, bool useMetal);
[DllImport("WebView")]
private static extern bool _CWebViewPlugin_IsInitialized(
IntPtr instance);
[DllImport("WebView")]
private static extern IntPtr _CWebViewPlugin_Init(
string gameObject, bool transparent, bool zoom, int width, int height, string ua, bool separated);
[DllImport("WebView")]
Expand Down Expand Up @@ -517,6 +520,9 @@ private static extern void _CWebViewPlugin_Reload(
private static extern string _CWebViewPlugin_GetMessage(IntPtr instance);
#elif UNITY_IPHONE
[DllImport("__Internal")]
private static extern bool _CWebViewPlugin_IsInitialized(
IntPtr instance);
[DllImport("__Internal")]
private static extern IntPtr _CWebViewPlugin_Init(string gameObject, bool transparent, bool zoom, string ua, bool enableWKWebView, int wkContentMode, bool wkAllowsLinkPreview, bool wkAllowsBackForwardNavigationGestures, int radius);
[DllImport("__Internal")]
private static extern int _CWebViewPlugin_Destroy(IntPtr instance);
Expand Down Expand Up @@ -615,6 +621,25 @@ public static bool IsWebViewAvailable()
#endif
}

public bool IsInitialized()
{
#if UNITY_WEBPLAYER || UNITY_WEBGL
//TODO: UNSUPPORTED
return true;
#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX
//TODO: UNSUPPORTED
return true;
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return false;
return _CWebViewPlugin_IsInitialized(webView);
#elif UNITY_ANDROID
if (webView == null)
return false;
return webView.Call<bool>("IsInitialized");
#endif
}

public void Init(
Callback cb = null,
Callback err = null,
Expand Down
14 changes: 14 additions & 0 deletions plugins/iOS/WebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ @implementation CWebViewPlugin
static WKProcessPool *_sharedProcessPool;
static NSMutableArray *_instances = [[NSMutableArray alloc] init];

- (BOOL)isInitialized
{
return webView != nil;
}

- (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)transparent zoom:(BOOL)zoom ua:(const char *)ua enableWKWebView:(BOOL)enableWKWebView contentMode:(WKContentMode)contentMode allowsLinkPreview:(BOOL)allowsLinkPreview allowsBackForwardNavigationGestures:(BOOL)allowsBackForwardNavigationGestures radius:(int)radius
{
self = [super init];
Expand Down Expand Up @@ -939,6 +944,7 @@ - (void)setAllMediaPlaybackSuspended:(BOOL)suspended
@end

extern "C" {
BOOL _CWebViewPlugin_IsInitialized(void *instance);
void *_CWebViewPlugin_Init(const char *gameObjectName, BOOL transparent, BOOL zoom, const char *ua, BOOL enableWKWebView, int contentMode, BOOL allowsLinkPreview, BOOL allowsBackForwardNavigationGestures, int radius);
void _CWebViewPlugin_Destroy(void *instance);
void _CWebViewPlugin_SetMargins(
Expand Down Expand Up @@ -970,6 +976,14 @@ void _CWebViewPlugin_SetMargins(
void _CWebViewPlugin_SetSuspended(void *instance, BOOL suspended);
}

BOOL _CWebViewPlugin_IsInitialized(void *instance)
{
if (instance == NULL)
return NO;
CWebViewPlugin *webViewPlugin = (__bridge_transfer CWebViewPlugin *)instance;
return [webViewPlugin isInitialized];
}

void *_CWebViewPlugin_Init(const char *gameObjectName, BOOL transparent, BOOL zoom, const char *ua, BOOL enableWKWebView, int contentMode, BOOL allowsLinkPreview, BOOL allowsBackForwardNavigationGestures, int radius)
{
if (! (enableWKWebView && [WKWebView class]))
Expand Down
Loading

0 comments on commit ae5da58

Please sign in to comment.