forked from apache/cordova-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using the webview based on WebKit instead of UIKit (apache#663)
- Loading branch information
braginxv
authored and
bragin
committed
Jan 24, 2020
1 parent
266d339
commit 11a9ea9
Showing
13 changed files
with
862 additions
and
59 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
CordovaLib/Classes/Private/Plugins/CDVWKWebViewEngine/CDVWKProcessPoolFactory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
#import <WebKit/WebKit.h> | ||
|
||
@interface CDVWKProcessPoolFactory : NSObject | ||
@property (nonatomic, retain) WKProcessPool* sharedPool; | ||
|
||
+(instancetype) sharedFactory; | ||
-(WKProcessPool*) sharedProcessPool; | ||
@end |
49 changes: 49 additions & 0 deletions
49
CordovaLib/Classes/Private/Plugins/CDVWKWebViewEngine/CDVWKProcessPoolFactory.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <WebKit/WebKit.h> | ||
#import "CDVWKProcessPoolFactory.h" | ||
|
||
static CDVWKProcessPoolFactory *factory = nil; | ||
|
||
@implementation CDVWKProcessPoolFactory | ||
|
||
+ (instancetype)sharedFactory | ||
{ | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
factory = [[CDVWKProcessPoolFactory alloc] init]; | ||
}); | ||
|
||
return factory; | ||
} | ||
|
||
- (instancetype)init | ||
{ | ||
if (self = [super init]) { | ||
_sharedPool = [[WKProcessPool alloc] init]; | ||
} | ||
return self; | ||
} | ||
|
||
- (WKProcessPool*) sharedProcessPool { | ||
return _sharedPool; | ||
} | ||
@end |
28 changes: 28 additions & 0 deletions
28
CordovaLib/Classes/Private/Plugins/CDVWKWebViewEngine/CDVWKWebViewDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
#import <WebKit/WebKit.h> | ||
|
||
@interface CDVWKWebViewDelegate : NSObject <WKUIDelegate> | ||
|
||
@property (nonatomic, copy) NSString* title; | ||
|
||
- (instancetype)initWithTitle:(NSString*)title; | ||
|
||
@end |
123 changes: 123 additions & 0 deletions
123
CordovaLib/Classes/Private/Plugins/CDVWKWebViewEngine/CDVWKWebViewDelegate.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
#import "CDVWKWebViewDelegate.h" | ||
|
||
@implementation CDVWKWebViewDelegate | ||
|
||
- (instancetype)initWithTitle:(NSString*)title | ||
{ | ||
self = [super init]; | ||
if (self) { | ||
self.title = title; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void) webView:(WKWebView*)webView runJavaScriptAlertPanelWithMessage:(NSString*)message | ||
initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(void))completionHandler | ||
{ | ||
UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title | ||
message:message | ||
preferredStyle:UIAlertControllerStyleAlert]; | ||
|
||
UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK") | ||
style:UIAlertActionStyleDefault | ||
handler:^(UIAlertAction* action) | ||
{ | ||
completionHandler(); | ||
[alert dismissViewControllerAnimated:YES completion:nil]; | ||
}]; | ||
|
||
[alert addAction:ok]; | ||
|
||
UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController; | ||
|
||
[rootController presentViewController:alert animated:YES completion:nil]; | ||
} | ||
|
||
- (void) webView:(WKWebView*)webView runJavaScriptConfirmPanelWithMessage:(NSString*)message | ||
initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(BOOL result))completionHandler | ||
{ | ||
UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title | ||
message:message | ||
preferredStyle:UIAlertControllerStyleAlert]; | ||
|
||
UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK") | ||
style:UIAlertActionStyleDefault | ||
handler:^(UIAlertAction* action) | ||
{ | ||
completionHandler(YES); | ||
[alert dismissViewControllerAnimated:YES completion:nil]; | ||
}]; | ||
|
||
[alert addAction:ok]; | ||
|
||
UIAlertAction* cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel") | ||
style:UIAlertActionStyleDefault | ||
handler:^(UIAlertAction* action) | ||
{ | ||
completionHandler(NO); | ||
[alert dismissViewControllerAnimated:YES completion:nil]; | ||
}]; | ||
[alert addAction:cancel]; | ||
|
||
UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController; | ||
|
||
[rootController presentViewController:alert animated:YES completion:nil]; | ||
} | ||
|
||
- (void) webView:(WKWebView*)webView runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt | ||
defaultText:(NSString*)defaultText initiatedByFrame:(WKFrameInfo*)frame | ||
completionHandler:(void (^)(NSString* result))completionHandler | ||
{ | ||
UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title | ||
message:prompt | ||
preferredStyle:UIAlertControllerStyleAlert]; | ||
|
||
UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK") | ||
style:UIAlertActionStyleDefault | ||
handler:^(UIAlertAction* action) | ||
{ | ||
completionHandler(alert.textFields[0].text); | ||
[alert dismissViewControllerAnimated:YES completion:nil]; | ||
}]; | ||
|
||
[alert addAction:ok]; | ||
|
||
UIAlertAction* cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel") | ||
style:UIAlertActionStyleDefault | ||
handler:^(UIAlertAction* action) | ||
{ | ||
completionHandler(nil); | ||
[alert dismissViewControllerAnimated:YES completion:nil]; | ||
}]; | ||
[alert addAction:cancel]; | ||
|
||
[alert addTextFieldWithConfigurationHandler:^(UITextField* textField) { | ||
textField.text = defaultText; | ||
}]; | ||
|
||
UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController; | ||
|
||
[rootController presentViewController:alert animated:YES completion:nil]; | ||
} | ||
|
||
@end |
29 changes: 29 additions & 0 deletions
29
CordovaLib/Classes/Private/Plugins/CDVWKWebViewEngine/CDVWKWebViewEngine.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
#import <WebKit/WebKit.h> | ||
#import <Cordova/CDV.h> | ||
|
||
@interface CDVWKWebViewEngine : CDVPlugin <CDVWebViewEngineProtocol, WKScriptMessageHandler, WKNavigationDelegate> | ||
|
||
@property (nonatomic, strong, readonly) id <WKUIDelegate> uiDelegate; | ||
|
||
- (void)allowsBackForwardNavigationGestures:(CDVInvokedUrlCommand*)command; | ||
|
||
@end |
Oops, something went wrong.