This commit is contained in:
2020-07-14 22:04:03 +08:00
parent e54411e2c2
commit a47cabede2
119 changed files with 5115 additions and 1061 deletions

View File

@@ -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