cronapp-cordova-plugin-ionic-webview 4.4.0-RC.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmrc +1 -0
- package/CHANGELOG.md +278 -0
- package/CONTRIBUTING.md +32 -0
- package/LICENSE +202 -0
- package/README.md +184 -0
- package/package.json +75 -0
- package/plugin.xml +80 -0
- package/src/android/com/ionicframework/cordova/webview/AndroidProtocolHandler.java +107 -0
- package/src/android/com/ionicframework/cordova/webview/IonicWebView.java +41 -0
- package/src/android/com/ionicframework/cordova/webview/IonicWebViewEngine.java +172 -0
- package/src/android/com/ionicframework/cordova/webview/UriMatcher.java +183 -0
- package/src/android/com/ionicframework/cordova/webview/WebViewLocalServer.java +645 -0
- package/src/ios/CDVWKProcessPoolFactory.h +27 -0
- package/src/ios/CDVWKProcessPoolFactory.m +49 -0
- package/src/ios/CDVWKWebViewEngine.h +31 -0
- package/src/ios/CDVWKWebViewEngine.m +886 -0
- package/src/ios/CDVWKWebViewUIDelegate.h +28 -0
- package/src/ios/CDVWKWebViewUIDelegate.m +123 -0
- package/src/ios/IONAssetHandler.h +13 -0
- package/src/ios/IONAssetHandler.m +92 -0
- package/src/ios/LICENSE +22 -0
- package/src/ios/wk-plugin.js +39 -0
- package/src/www/ios/ios-wkwebview-exec.js +174 -0
- package/src/www/util.js +30 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
|
4
|
+
distributed with this work for additional information
|
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
|
7
|
+
"License"); you may not use this file except in compliance
|
|
8
|
+
with the License. You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
|
13
|
+
software distributed under the License is distributed on an
|
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
KIND, either express or implied. See the License for the
|
|
16
|
+
specific language governing permissions and limitations
|
|
17
|
+
under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
#import <WebKit/WebKit.h>
|
|
21
|
+
|
|
22
|
+
@interface CDVWKWebViewUIDelegate : NSObject <WKUIDelegate>
|
|
23
|
+
|
|
24
|
+
@property (nonatomic, copy) NSString* title;
|
|
25
|
+
|
|
26
|
+
- (instancetype)initWithTitle:(NSString*)title;
|
|
27
|
+
|
|
28
|
+
@end
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
|
4
|
+
distributed with this work for additional information
|
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
|
7
|
+
"License"); you may not use this file except in compliance
|
|
8
|
+
with the License. You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
|
13
|
+
software distributed under the License is distributed on an
|
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
KIND, either express or implied. See the License for the
|
|
16
|
+
specific language governing permissions and limitations
|
|
17
|
+
under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
#import "CDVWKWebViewUIDelegate.h"
|
|
21
|
+
|
|
22
|
+
@implementation CDVWKWebViewUIDelegate
|
|
23
|
+
|
|
24
|
+
- (instancetype)initWithTitle:(NSString*)title
|
|
25
|
+
{
|
|
26
|
+
self = [super init];
|
|
27
|
+
if (self) {
|
|
28
|
+
self.title = title;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return self;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
- (void) webView:(WKWebView*)webView runJavaScriptAlertPanelWithMessage:(NSString*)message
|
|
35
|
+
initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(void))completionHandler
|
|
36
|
+
{
|
|
37
|
+
UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
|
|
38
|
+
message:message
|
|
39
|
+
preferredStyle:UIAlertControllerStyleAlert];
|
|
40
|
+
|
|
41
|
+
UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
|
|
42
|
+
style:UIAlertActionStyleDefault
|
|
43
|
+
handler:^(UIAlertAction* action)
|
|
44
|
+
{
|
|
45
|
+
completionHandler();
|
|
46
|
+
[alert dismissViewControllerAnimated:YES completion:nil];
|
|
47
|
+
}];
|
|
48
|
+
|
|
49
|
+
[alert addAction:ok];
|
|
50
|
+
|
|
51
|
+
UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
|
|
52
|
+
|
|
53
|
+
[rootController presentViewController:alert animated:YES completion:nil];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
- (void) webView:(WKWebView*)webView runJavaScriptConfirmPanelWithMessage:(NSString*)message
|
|
57
|
+
initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(BOOL result))completionHandler
|
|
58
|
+
{
|
|
59
|
+
UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
|
|
60
|
+
message:message
|
|
61
|
+
preferredStyle:UIAlertControllerStyleAlert];
|
|
62
|
+
|
|
63
|
+
UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
|
|
64
|
+
style:UIAlertActionStyleDefault
|
|
65
|
+
handler:^(UIAlertAction* action)
|
|
66
|
+
{
|
|
67
|
+
completionHandler(YES);
|
|
68
|
+
[alert dismissViewControllerAnimated:YES completion:nil];
|
|
69
|
+
}];
|
|
70
|
+
|
|
71
|
+
[alert addAction:ok];
|
|
72
|
+
|
|
73
|
+
UIAlertAction* cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
|
|
74
|
+
style:UIAlertActionStyleDefault
|
|
75
|
+
handler:^(UIAlertAction* action)
|
|
76
|
+
{
|
|
77
|
+
completionHandler(NO);
|
|
78
|
+
[alert dismissViewControllerAnimated:YES completion:nil];
|
|
79
|
+
}];
|
|
80
|
+
[alert addAction:cancel];
|
|
81
|
+
|
|
82
|
+
UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
|
|
83
|
+
|
|
84
|
+
[rootController presentViewController:alert animated:YES completion:nil];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
- (void) webView:(WKWebView*)webView runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt
|
|
88
|
+
defaultText:(NSString*)defaultText initiatedByFrame:(WKFrameInfo*)frame
|
|
89
|
+
completionHandler:(void (^)(NSString* result))completionHandler
|
|
90
|
+
{
|
|
91
|
+
UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
|
|
92
|
+
message:prompt
|
|
93
|
+
preferredStyle:UIAlertControllerStyleAlert];
|
|
94
|
+
|
|
95
|
+
UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
|
|
96
|
+
style:UIAlertActionStyleDefault
|
|
97
|
+
handler:^(UIAlertAction* action)
|
|
98
|
+
{
|
|
99
|
+
completionHandler(((UITextField*)alert.textFields[0]).text);
|
|
100
|
+
[alert dismissViewControllerAnimated:YES completion:nil];
|
|
101
|
+
}];
|
|
102
|
+
|
|
103
|
+
[alert addAction:ok];
|
|
104
|
+
|
|
105
|
+
UIAlertAction* cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
|
|
106
|
+
style:UIAlertActionStyleDefault
|
|
107
|
+
handler:^(UIAlertAction* action)
|
|
108
|
+
{
|
|
109
|
+
completionHandler(nil);
|
|
110
|
+
[alert dismissViewControllerAnimated:YES completion:nil];
|
|
111
|
+
}];
|
|
112
|
+
[alert addAction:cancel];
|
|
113
|
+
|
|
114
|
+
[alert addTextFieldWithConfigurationHandler:^(UITextField* textField) {
|
|
115
|
+
textField.text = defaultText;
|
|
116
|
+
}];
|
|
117
|
+
|
|
118
|
+
UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
|
|
119
|
+
|
|
120
|
+
[rootController presentViewController:alert animated:YES completion:nil];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <WebKit/WebKit.h>
|
|
3
|
+
|
|
4
|
+
@interface IONAssetHandler : NSObject <WKURLSchemeHandler>
|
|
5
|
+
|
|
6
|
+
@property (nonatomic, strong) NSString * basePath;
|
|
7
|
+
@property (nonatomic, strong) NSString * scheme;
|
|
8
|
+
|
|
9
|
+
-(void)setAssetPath:(NSString *)assetPath;
|
|
10
|
+
- (instancetype)initWithBasePath:(NSString *)basePath andScheme:(NSString *)scheme;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#import "IONAssetHandler.h"
|
|
2
|
+
#import <MobileCoreServices/MobileCoreServices.h>
|
|
3
|
+
#import "CDVWKWebViewEngine.h"
|
|
4
|
+
|
|
5
|
+
@implementation IONAssetHandler
|
|
6
|
+
|
|
7
|
+
-(void)setAssetPath:(NSString *)assetPath {
|
|
8
|
+
self.basePath = assetPath;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
- (instancetype)initWithBasePath:(NSString *)basePath andScheme:(NSString *)scheme {
|
|
12
|
+
self = [super init];
|
|
13
|
+
if (self) {
|
|
14
|
+
_basePath = basePath;
|
|
15
|
+
_scheme = scheme;
|
|
16
|
+
}
|
|
17
|
+
return self;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
- (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)urlSchemeTask
|
|
21
|
+
{
|
|
22
|
+
NSString * startPath = @"";
|
|
23
|
+
NSURL * url = urlSchemeTask.request.URL;
|
|
24
|
+
NSString * stringToLoad = url.path;
|
|
25
|
+
NSString * scheme = url.scheme;
|
|
26
|
+
|
|
27
|
+
if ([scheme isEqualToString:self.scheme]) {
|
|
28
|
+
if ([stringToLoad hasPrefix:@"/_app_file_"]) {
|
|
29
|
+
startPath = [stringToLoad stringByReplacingOccurrencesOfString:@"/_app_file_" withString:@""];
|
|
30
|
+
} else {
|
|
31
|
+
startPath = self.basePath ? self.basePath : @"";
|
|
32
|
+
if ([stringToLoad isEqualToString:@""] || [url.pathExtension isEqualToString:@""]) {
|
|
33
|
+
startPath = [startPath stringByAppendingString:@"/index.html"];
|
|
34
|
+
} else {
|
|
35
|
+
startPath = [startPath stringByAppendingString:stringToLoad];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
NSError * fileError = nil;
|
|
40
|
+
NSData * data = nil;
|
|
41
|
+
if ([self isMediaExtension:url.pathExtension]) {
|
|
42
|
+
data = [NSData dataWithContentsOfFile:startPath options:NSDataReadingMappedIfSafe error:&fileError];
|
|
43
|
+
}
|
|
44
|
+
if (!data || fileError) {
|
|
45
|
+
data = [[NSData alloc] initWithContentsOfFile:startPath];
|
|
46
|
+
}
|
|
47
|
+
NSInteger statusCode = 200;
|
|
48
|
+
if (!data) {
|
|
49
|
+
statusCode = 404;
|
|
50
|
+
}
|
|
51
|
+
NSURL * localUrl = [NSURL URLWithString:url.absoluteString];
|
|
52
|
+
NSString * mimeType = [self getMimeType:url.pathExtension];
|
|
53
|
+
id response = nil;
|
|
54
|
+
if (data && [self isMediaExtension:url.pathExtension]) {
|
|
55
|
+
response = [[NSURLResponse alloc] initWithURL:localUrl MIMEType:mimeType expectedContentLength:data.length textEncodingName:nil];
|
|
56
|
+
} else {
|
|
57
|
+
NSDictionary * headers = @{ @"Content-Type" : mimeType, @"Cache-Control": @"no-cache"};
|
|
58
|
+
response = [[NSHTTPURLResponse alloc] initWithURL:localUrl statusCode:statusCode HTTPVersion:nil headerFields:headers];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
[urlSchemeTask didReceiveResponse:response];
|
|
62
|
+
[urlSchemeTask didReceiveData:data];
|
|
63
|
+
[urlSchemeTask didFinish];
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
- (void)webView:(nonnull WKWebView *)webView stopURLSchemeTask:(nonnull id<WKURLSchemeTask>)urlSchemeTask
|
|
68
|
+
{
|
|
69
|
+
NSLog(@"stop");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
-(NSString *) getMimeType:(NSString *)fileExtension {
|
|
73
|
+
if (fileExtension && ![fileExtension isEqualToString:@""]) {
|
|
74
|
+
NSString *UTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtension, NULL);
|
|
75
|
+
NSString *contentType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)UTI, kUTTagClassMIMEType);
|
|
76
|
+
return contentType ? contentType : @"application/octet-stream";
|
|
77
|
+
} else {
|
|
78
|
+
return @"text/html";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
-(BOOL) isMediaExtension:(NSString *) pathExtension {
|
|
83
|
+
NSArray * mediaExtensions = @[@"m4v", @"mov", @"mp4",
|
|
84
|
+
@"aac", @"ac3", @"aiff", @"au", @"flac", @"m4a", @"mp3", @"wav"];
|
|
85
|
+
if ([mediaExtensions containsObject:pathExtension.lowercaseString]) {
|
|
86
|
+
return YES;
|
|
87
|
+
}
|
|
88
|
+
return NO;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@end
|
package/src/ios/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 Niklas von Hertzen
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following
|
|
10
|
+
conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
(function _wk_plugin() {
|
|
3
|
+
// Check if we are running in WKWebView
|
|
4
|
+
if (!window.webkit || !window.webkit.messageHandlers) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Initialize Ionic
|
|
9
|
+
window.Ionic = window.Ionic || {};
|
|
10
|
+
|
|
11
|
+
var stopScrollHandler = window.webkit.messageHandlers.stopScroll;
|
|
12
|
+
if (!stopScrollHandler) {
|
|
13
|
+
console.error('Can not find stopScroll handler');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var stopScrollFunc = null;
|
|
18
|
+
var stopScroll = {
|
|
19
|
+
stop: function stop(callback) {
|
|
20
|
+
if (!stopScrollFunc) {
|
|
21
|
+
stopScrollFunc = callback;
|
|
22
|
+
stopScrollHandler.postMessage('');
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
fire: function fire() {
|
|
26
|
+
stopScrollFunc && stopScrollFunc();
|
|
27
|
+
stopScrollFunc = null;
|
|
28
|
+
},
|
|
29
|
+
cancel: function cancel() {
|
|
30
|
+
stopScrollFunc = null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
window.Ionic.StopScroll = stopScroll;
|
|
35
|
+
// deprecated
|
|
36
|
+
window.IonicStopScroll = stopScroll;
|
|
37
|
+
|
|
38
|
+
console.debug("Ionic Stop Scroll injected!");
|
|
39
|
+
})();
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
* or more contributor license agreements. See the NOTICE file
|
|
5
|
+
* distributed with this work for additional information
|
|
6
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
* to you under the Apache License, Version 2.0 (the
|
|
8
|
+
* "License"); you may not use this file except in compliance
|
|
9
|
+
* with the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing,
|
|
14
|
+
* software distributed under the License is distributed on an
|
|
15
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
* KIND, either express or implied. See the License for the
|
|
17
|
+
* specific language governing permissions and limitations
|
|
18
|
+
* under the License.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates the exec bridge used to notify the native code of
|
|
24
|
+
* commands.
|
|
25
|
+
*/
|
|
26
|
+
var cordova = require('cordova');
|
|
27
|
+
var utils = require('cordova/utils');
|
|
28
|
+
var base64 = require('cordova/base64');
|
|
29
|
+
|
|
30
|
+
function massageArgsJsToNative (args) {
|
|
31
|
+
if (!args || utils.typeName(args) !== 'Array') {
|
|
32
|
+
return args;
|
|
33
|
+
}
|
|
34
|
+
var ret = [];
|
|
35
|
+
args.forEach(function (arg, i) {
|
|
36
|
+
if (utils.typeName(arg) === 'ArrayBuffer') {
|
|
37
|
+
ret.push({
|
|
38
|
+
'CDVType': 'ArrayBuffer',
|
|
39
|
+
'data': base64.fromArrayBuffer(arg)
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
ret.push(arg);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return ret;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function massageMessageNativeToJs (message) {
|
|
49
|
+
if (message.CDVType === 'ArrayBuffer') {
|
|
50
|
+
var stringToArrayBuffer = function (str) {
|
|
51
|
+
var ret = new Uint8Array(str.length);
|
|
52
|
+
for (var i = 0; i < str.length; i++) {
|
|
53
|
+
ret[i] = str.charCodeAt(i);
|
|
54
|
+
}
|
|
55
|
+
return ret.buffer;
|
|
56
|
+
};
|
|
57
|
+
var base64ToArrayBuffer = function (b64) {
|
|
58
|
+
return stringToArrayBuffer(atob(b64)); // eslint-disable-line no-undef
|
|
59
|
+
};
|
|
60
|
+
message = base64ToArrayBuffer(message.data);
|
|
61
|
+
}
|
|
62
|
+
return message;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function convertMessageToArgsNativeToJs (message) {
|
|
66
|
+
var args = [];
|
|
67
|
+
if (!message || !message.hasOwnProperty('CDVType')) {
|
|
68
|
+
args.push(message);
|
|
69
|
+
} else if (message.CDVType === 'MultiPart') {
|
|
70
|
+
message.messages.forEach(function (e) {
|
|
71
|
+
args.push(massageMessageNativeToJs(e));
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
args.push(massageMessageNativeToJs(message));
|
|
75
|
+
}
|
|
76
|
+
return args;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var iOSExec = function () {
|
|
80
|
+
// detect change in bridge, if there is a change, we forward to new bridge
|
|
81
|
+
|
|
82
|
+
// if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.cordova && window.webkit.messageHandlers.cordova.postMessage) {
|
|
83
|
+
// bridgeMode = jsToNativeModes.WK_WEBVIEW_BINDING;
|
|
84
|
+
// }
|
|
85
|
+
|
|
86
|
+
var successCallback, failCallback, service, action, actionArgs;
|
|
87
|
+
var callbackId = null;
|
|
88
|
+
if (typeof arguments[0] !== 'string') {
|
|
89
|
+
// FORMAT ONE
|
|
90
|
+
successCallback = arguments[0];
|
|
91
|
+
failCallback = arguments[1];
|
|
92
|
+
service = arguments[2];
|
|
93
|
+
action = arguments[3];
|
|
94
|
+
actionArgs = arguments[4];
|
|
95
|
+
|
|
96
|
+
// Since we need to maintain backwards compatibility, we have to pass
|
|
97
|
+
// an invalid callbackId even if no callback was provided since plugins
|
|
98
|
+
// will be expecting it. The Cordova.exec() implementation allocates
|
|
99
|
+
// an invalid callbackId and passes it even if no callbacks were given.
|
|
100
|
+
callbackId = 'INVALID';
|
|
101
|
+
} else {
|
|
102
|
+
throw new Error('The old format of this exec call has been removed (deprecated since 2.1). Change to: ' + // eslint-disable-line
|
|
103
|
+
'cordova.exec(null, null, \'Service\', \'action\', [ arg1, arg2 ]);');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// If actionArgs is not provided, default to an empty array
|
|
107
|
+
actionArgs = actionArgs || [];
|
|
108
|
+
|
|
109
|
+
// Register the callbacks and add the callbackId to the positional
|
|
110
|
+
// arguments if given.
|
|
111
|
+
if (successCallback || failCallback) {
|
|
112
|
+
callbackId = service + cordova.callbackId++;
|
|
113
|
+
cordova.callbacks[callbackId] =
|
|
114
|
+
{success: successCallback, fail: failCallback};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
actionArgs = massageArgsJsToNative(actionArgs);
|
|
118
|
+
|
|
119
|
+
// CB-10133 DataClone DOM Exception 25 guard (fast function remover)
|
|
120
|
+
var command = [callbackId, service, action, JSON.parse(JSON.stringify(actionArgs))];
|
|
121
|
+
window.webkit.messageHandlers.cordova.postMessage(command);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
iOSExec.nativeCallback = function (callbackId, status, message, keepCallback, debug) {
|
|
125
|
+
var success = status === 0 || status === 1;
|
|
126
|
+
var args = convertMessageToArgsNativeToJs(message);
|
|
127
|
+
Promise.resolve().then(function () {
|
|
128
|
+
cordova.callbackFromNative(callbackId, success, status, args, keepCallback); // eslint-disable-line
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// for backwards compatibility
|
|
133
|
+
iOSExec.nativeEvalAndFetch = function (func) {
|
|
134
|
+
try {
|
|
135
|
+
func();
|
|
136
|
+
} catch (e) {
|
|
137
|
+
console.log(e);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// Proxy the exec for bridge changes. See CB-10106
|
|
142
|
+
|
|
143
|
+
function cordovaExec () {
|
|
144
|
+
var cexec = require('cordova/exec');
|
|
145
|
+
var cexec_valid = (typeof cexec.nativeFetchMessages === 'function') && (typeof cexec.nativeEvalAndFetch === 'function') && (typeof cexec.nativeCallback === 'function');
|
|
146
|
+
return (cexec_valid && execProxy !== cexec) ? cexec : iOSExec;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function execProxy () {
|
|
150
|
+
cordovaExec().apply(null, arguments);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
execProxy.nativeFetchMessages = function () {
|
|
154
|
+
return cordovaExec().nativeFetchMessages.apply(null, arguments);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
execProxy.nativeEvalAndFetch = function () {
|
|
158
|
+
return cordovaExec().nativeEvalAndFetch.apply(null, arguments);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
execProxy.nativeCallback = function () {
|
|
162
|
+
return cordovaExec().nativeCallback.apply(null, arguments);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
module.exports = execProxy;
|
|
166
|
+
|
|
167
|
+
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.cordova && window.webkit.messageHandlers.cordova.postMessage) {
|
|
168
|
+
// unregister the old bridge
|
|
169
|
+
cordova.define.remove('cordova/exec');
|
|
170
|
+
// redefine bridge to our new bridge
|
|
171
|
+
cordova.define('cordova/exec', function (require, exports, module) {
|
|
172
|
+
module.exports = execProxy;
|
|
173
|
+
});
|
|
174
|
+
}
|
package/src/www/util.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var exec = require('cordova/exec');
|
|
2
|
+
|
|
3
|
+
var WebView = {
|
|
4
|
+
convertFileSrc: function(url) {
|
|
5
|
+
if (!url) {
|
|
6
|
+
return url;
|
|
7
|
+
}
|
|
8
|
+
if (url.indexOf('/')===0) {
|
|
9
|
+
return window.WEBVIEW_SERVER_URL + '/_app_file_' + url;
|
|
10
|
+
}
|
|
11
|
+
if (url.indexOf('file://')===0) {
|
|
12
|
+
return window.WEBVIEW_SERVER_URL + url.replace('file://', '/_app_file_');
|
|
13
|
+
}
|
|
14
|
+
if (url.indexOf('content://')===0) {
|
|
15
|
+
return window.WEBVIEW_SERVER_URL + url.replace('content:/', '/_app_content_');
|
|
16
|
+
}
|
|
17
|
+
return url;
|
|
18
|
+
},
|
|
19
|
+
setServerBasePath: function(path) {
|
|
20
|
+
exec(null, null, 'IonicWebView', 'setServerBasePath', [path]);
|
|
21
|
+
},
|
|
22
|
+
getServerBasePath: function(callback) {
|
|
23
|
+
exec(callback, null, 'IonicWebView', 'getServerBasePath', []);
|
|
24
|
+
},
|
|
25
|
+
persistServerBasePath: function() {
|
|
26
|
+
exec(null, null, 'IonicWebView', 'persistServerBasePath', []);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = WebView;
|