up
This commit is contained in:
Binary file not shown.
@@ -4,9 +4,7 @@ using System.Text;
|
||||
using System.Xml;
|
||||
using UnityEditor.Android;
|
||||
using UnityEditor.Callbacks;
|
||||
#if UNITY_IOS
|
||||
using UnityEditor.iOS.Xcode;
|
||||
#endif
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -25,6 +23,9 @@ public class UnityWebViewPostprocessBuild
|
||||
var changed = false;
|
||||
var androidManifest = new AndroidManifest(GetManifestPath(basePath));
|
||||
changed = (androidManifest.SetHardwareAccelerated(true) || changed);
|
||||
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
|
||||
changed = (androidManifest.SetUsesCleartextTraffic(true) || changed);
|
||||
#endif
|
||||
#if UNITYWEBVIEW_ANDROID_ENABLE_CAMERA
|
||||
changed = (androidManifest.AddCamera() || changed);
|
||||
#endif
|
||||
@@ -71,6 +72,9 @@ public class UnityWebViewPostprocessBuild
|
||||
var changed = false;
|
||||
var androidManifest = new AndroidManifest(manifest);
|
||||
changed = (androidManifest.SetHardwareAccelerated(true) || changed);
|
||||
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
|
||||
changed = (androidManifest.SetUsesCleartextTraffic(true) || changed);
|
||||
#endif
|
||||
#if UNITYWEBVIEW_ANDROID_ENABLE_CAMERA
|
||||
changed = (androidManifest.AddCamera() || changed);
|
||||
#endif
|
||||
@@ -86,8 +90,6 @@ public class UnityWebViewPostprocessBuild
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_IOS
|
||||
if (buildTarget == BuildTarget.iOS) {
|
||||
string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
|
||||
PBXProject proj = new PBXProject();
|
||||
@@ -99,7 +101,6 @@ public class UnityWebViewPostprocessBuild
|
||||
#endif
|
||||
File.WriteAllText(projPath, proj.WriteToString());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +155,16 @@ internal class AndroidManifest : AndroidXmlDocument {
|
||||
nsMgr);
|
||||
}
|
||||
|
||||
internal bool SetUsesCleartextTraffic(bool enabled) {
|
||||
// android:usesCleartextTraffic
|
||||
bool changed = false;
|
||||
if (ApplicationElement.GetAttribute("usesCleartextTraffic", AndroidXmlNamespace) != ((enabled) ? "true" : "false")) {
|
||||
ApplicationElement.SetAttribute("usesCleartextTraffic", AndroidXmlNamespace, (enabled) ? "true" : "false");
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
internal bool SetHardwareAccelerated(bool enabled) {
|
||||
bool changed = false;
|
||||
var activity = GetActivityWithLaunchIntent() as XmlElement;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>19E287</string>
|
||||
<string>19F101</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d8bb24d011b447b58e9ba755365cb0e
|
||||
guid: 63292b274abcf4fbd8bbb8dd511636c9
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
|
||||
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee5ba59c0146b49a88f62aa0e9c1ab88
|
||||
guid: 0886bac7b42ce4b238001e3ba567f243
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d405197ed59f4015860b82a0f9f5717
|
||||
guid: 5786bd43e3702474283e603cbec15704
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9afbbf70a5bb4304a15cf99106eac7f
|
||||
guid: ddcf9ff29e8ef4ef3a1b09503d23af6e
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
|
||||
@@ -344,6 +344,8 @@ public class WebViewObject : MonoBehaviour
|
||||
private static extern void _CWebViewPlugin_SaveCookies();
|
||||
[DllImport("__Internal")]
|
||||
private static extern string _CWebViewPlugin_GetCookies(string url);
|
||||
[DllImport("__Internal")]
|
||||
private static extern void _CWebViewPlugin_SetBasicAuthInfo(IntPtr instance, string userName, string password);
|
||||
#elif UNITY_WEBGL
|
||||
[DllImport("__Internal")]
|
||||
private static extern void _gree_unity_webview_init(string name);
|
||||
@@ -978,6 +980,25 @@ public class WebViewObject : MonoBehaviour
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetBasicAuthInfo(string userName, string password)
|
||||
{
|
||||
#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
|
||||
//TODO: UNSUPPORTED
|
||||
#elif UNITY_IPHONE
|
||||
if (webView == IntPtr.Zero)
|
||||
return;
|
||||
_CWebViewPlugin_SetBasicAuthInfo(webView, userName, password);
|
||||
#elif UNITY_ANDROID
|
||||
if (webView == null)
|
||||
return;
|
||||
webView.Call("SetBasicAuthInfo", userName, password);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
|
||||
void OnApplicationFocus(bool focus)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>19E287</string>
|
||||
<string>19F101</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 339b5b600628440f79bc7f2cac88de47
|
||||
guid: 388bc77ba5dbc4227b1522015cd14117
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
|
||||
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bb549cd3a3d142d49618c2fb5ebb251
|
||||
guid: 9ed83015d29134314a9d5bd678459f92
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60b1c105abb004192bf943c9edf22ddb
|
||||
guid: 2ff99eeeec8e740a895caf2c893f00dc
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83e294a735af0441b997ce35b3c269c1
|
||||
guid: ccc550b454f8b419293dc16c5e0c5999
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
|
||||
@@ -97,6 +97,8 @@ @interface CWebViewPlugin : NSObject<WKUIDelegate, WKNavigationDelegate, WKScrip
|
||||
NSRegularExpression *allowRegex;
|
||||
NSRegularExpression *denyRegex;
|
||||
NSRegularExpression *hookRegex;
|
||||
NSString *basicAuthUserName;
|
||||
NSString *basicAuthPassword;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -115,6 +117,8 @@ - (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)tra
|
||||
allowRegex = nil;
|
||||
denyRegex = nil;
|
||||
hookRegex = nil;
|
||||
basicAuthUserName = nil;
|
||||
basicAuthPassword = nil;
|
||||
if (ua != NULL && strcmp(ua, "") != 0) {
|
||||
[[NSUserDefaults standardUserDefaults]
|
||||
registerDefaults:@{ @"UserAgent": [[NSString alloc] initWithUTF8String:ua] }];
|
||||
@@ -174,6 +178,8 @@ - (void)dispose
|
||||
[webView0 removeFromSuperview];
|
||||
[webView0 removeObserver:self forKeyPath:@"loading"];
|
||||
}
|
||||
basicAuthPassword = nil;
|
||||
basicAuthUserName = nil;
|
||||
hookRegex = nil;
|
||||
denyRegex = nil;
|
||||
allowRegex = nil;
|
||||
@@ -452,6 +458,20 @@ - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSSt
|
||||
[UnityGetGLViewController() presentViewController:alertController animated:YES completion:^{}];
|
||||
}
|
||||
|
||||
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
|
||||
{
|
||||
NSURLSessionAuthChallengeDisposition disposition;
|
||||
NSURLCredential *credential;
|
||||
if (basicAuthUserName && basicAuthPassword && [challenge previousFailureCount] == 0) {
|
||||
disposition = NSURLSessionAuthChallengeUseCredential;
|
||||
credential = [NSURLCredential credentialWithUser:basicAuthUserName password:basicAuthPassword persistence:NSURLCredentialPersistenceForSession];
|
||||
} else {
|
||||
disposition = NSURLSessionAuthChallengePerformDefaultHandling;
|
||||
credential = nil;
|
||||
}
|
||||
completionHandler(disposition, credential);
|
||||
}
|
||||
|
||||
- (BOOL)isSetupedCustomHeader:(NSURLRequest *)targetRequest
|
||||
{
|
||||
// Check for additional custom header.
|
||||
@@ -669,6 +689,12 @@ - (const char *)getCustomRequestHeaderValue:(const char *)headerKey
|
||||
strcpy(r, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
- (void)setBasicAuthInfo:(const char *)userName password:(const char *)password
|
||||
{
|
||||
basicAuthUserName = [NSString stringWithUTF8String:userName];
|
||||
basicAuthPassword = [NSString stringWithUTF8String:password];
|
||||
}
|
||||
@end
|
||||
|
||||
extern "C" {
|
||||
@@ -695,6 +721,7 @@ void _CWebViewPlugin_SetMargins(
|
||||
void _CWebViewPlugin_SaveCookies();
|
||||
const char *_CWebViewPlugin_GetCookies(const char *url);
|
||||
const char *_CWebViewPlugin_GetCustomHeaderValue(void *instance, const char *headerKey);
|
||||
void _CWebViewPlugin_SetBasicAuthInfo(void *instance, const char *userName, const char *password);
|
||||
}
|
||||
|
||||
void *_CWebViewPlugin_Init(const char *gameObjectName, BOOL transparent, const char *ua, BOOL enableWKWebView)
|
||||
@@ -868,4 +895,12 @@ void _CWebViewPlugin_SaveCookies()
|
||||
return [webViewPlugin getCustomRequestHeaderValue:headerKey];
|
||||
}
|
||||
|
||||
void _CWebViewPlugin_SetBasicAuthInfo(void *instance, const char *userName, const char *password)
|
||||
{
|
||||
if (instance == NULL)
|
||||
return;
|
||||
CWebViewPlugin *webViewPlugin = (__bridge CWebViewPlugin *)instance;
|
||||
[webViewPlugin setBasicAuthInfo:userName password:password];
|
||||
}
|
||||
|
||||
#endif // !(__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
|
||||
|
||||
@@ -141,6 +141,8 @@ @interface CWebViewPlugin : NSObject<UIWebViewDelegate, WKUIDelegate, WKNavigati
|
||||
NSRegularExpression *allowRegex;
|
||||
NSRegularExpression *denyRegex;
|
||||
NSRegularExpression *hookRegex;
|
||||
NSString *basicAuthUserName;
|
||||
NSString *basicAuthPassword;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -159,6 +161,8 @@ - (id)initWithGameObjectName:(const char *)gameObjectName_ transparent:(BOOL)tra
|
||||
allowRegex = nil;
|
||||
denyRegex = nil;
|
||||
hookRegex = nil;
|
||||
basicAuthUserName = nil;
|
||||
basicAuthPassword = nil;
|
||||
if (ua != NULL && strcmp(ua, "") != 0) {
|
||||
[[NSUserDefaults standardUserDefaults]
|
||||
registerDefaults:@{ @"UserAgent": [[NSString alloc] initWithUTF8String:ua] }];
|
||||
@@ -223,6 +227,8 @@ - (void)dispose
|
||||
[webView0 removeFromSuperview];
|
||||
[webView0 removeObserver:self forKeyPath:@"loading"];
|
||||
}
|
||||
basicAuthPassword = nil;
|
||||
basicAuthUserName = nil;
|
||||
hookRegex = nil;
|
||||
denyRegex = nil;
|
||||
allowRegex = nil;
|
||||
@@ -383,7 +389,8 @@ - (BOOL)webView:(UIWebView *)uiWebView shouldStartLoadWithRequest:(NSURLRequest
|
||||
if (webView == nil)
|
||||
return YES;
|
||||
|
||||
NSString *url = [[request URL] absoluteString];
|
||||
NSURL *nsurl = [request URL];
|
||||
NSString *url = [nsurl absoluteString];
|
||||
BOOL pass = YES;
|
||||
if (allowRegex != nil && [allowRegex firstMatchInString:url options:0 range:NSMakeRange(0, url.length)]) {
|
||||
pass = YES;
|
||||
@@ -553,6 +560,20 @@ - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSSt
|
||||
[UnityGetGLViewController() presentViewController:alertController animated:YES completion:^{}];
|
||||
}
|
||||
|
||||
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
|
||||
{
|
||||
NSURLSessionAuthChallengeDisposition disposition;
|
||||
NSURLCredential *credential;
|
||||
if (basicAuthUserName && basicAuthPassword && [challenge previousFailureCount] == 0) {
|
||||
disposition = NSURLSessionAuthChallengeUseCredential;
|
||||
credential = [NSURLCredential credentialWithUser:basicAuthUserName password:basicAuthPassword persistence:NSURLCredentialPersistenceForSession];
|
||||
} else {
|
||||
disposition = NSURLSessionAuthChallengePerformDefaultHandling;
|
||||
credential = nil;
|
||||
}
|
||||
completionHandler(disposition, credential);
|
||||
}
|
||||
|
||||
- (BOOL)isSetupedCustomHeader:(NSURLRequest *)targetRequest
|
||||
{
|
||||
// Check for additional custom header.
|
||||
@@ -770,6 +791,12 @@ - (const char *)getCustomRequestHeaderValue:(const char *)headerKey
|
||||
strcpy(r, s);
|
||||
return r;
|
||||
}
|
||||
|
||||
- (void)setBasicAuthInfo:(const char *)userName password:(const char *)password
|
||||
{
|
||||
basicAuthUserName = [NSString stringWithUTF8String:userName];
|
||||
basicAuthPassword = [NSString stringWithUTF8String:password];
|
||||
}
|
||||
@end
|
||||
|
||||
extern "C" {
|
||||
@@ -796,6 +823,7 @@ void _CWebViewPlugin_SetMargins(
|
||||
void _CWebViewPlugin_SaveCookies();
|
||||
const char *_CWebViewPlugin_GetCookies(const char *url);
|
||||
const char *_CWebViewPlugin_GetCustomHeaderValue(void *instance, const char *headerKey);
|
||||
void _CWebViewPlugin_SetBasicAuthInfo(void *instance, const char *userName, const char *password);
|
||||
}
|
||||
|
||||
void *_CWebViewPlugin_Init(const char *gameObjectName, BOOL transparent, const char *ua, BOOL enableWKWebView)
|
||||
@@ -967,4 +995,12 @@ void _CWebViewPlugin_SaveCookies()
|
||||
return [webViewPlugin getCustomRequestHeaderValue:headerKey];
|
||||
}
|
||||
|
||||
void _CWebViewPlugin_SetBasicAuthInfo(void *instance, const char *userName, const char *password)
|
||||
{
|
||||
if (instance == NULL)
|
||||
return;
|
||||
CWebViewPlugin *webViewPlugin = (__bridge CWebViewPlugin *)instance;
|
||||
[webViewPlugin setBasicAuthInfo:userName password:password];
|
||||
}
|
||||
|
||||
#endif // __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0
|
||||
|
||||
Reference in New Issue
Block a user