UNPKG

5.14 kBPlain TextView Raw
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 "CDVWKInAppBrowserUIDelegate.h"
21
22@implementation CDVWKInAppBrowserUIDelegate
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 [[self getViewController] presentViewController:alert animated:YES completion:nil];
52}
53
54- (void) webView:(WKWebView*)webView runJavaScriptConfirmPanelWithMessage:(NSString*)message
55 initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(BOOL result))completionHandler
56{
57 UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
58 message:message
59 preferredStyle:UIAlertControllerStyleAlert];
60
61 UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
62 style:UIAlertActionStyleDefault
63 handler:^(UIAlertAction* action)
64 {
65 completionHandler(YES);
66 [alert dismissViewControllerAnimated:YES completion:nil];
67 }];
68
69 [alert addAction:ok];
70
71 UIAlertAction* cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
72 style:UIAlertActionStyleDefault
73 handler:^(UIAlertAction* action)
74 {
75 completionHandler(NO);
76 [alert dismissViewControllerAnimated:YES completion:nil];
77 }];
78 [alert addAction:cancel];
79
80 [[self getViewController] presentViewController:alert animated:YES completion:nil];
81}
82
83- (void) webView:(WKWebView*)webView runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt
84 defaultText:(NSString*)defaultText initiatedByFrame:(WKFrameInfo*)frame
85 completionHandler:(void (^)(NSString* result))completionHandler
86{
87 UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
88 message:prompt
89 preferredStyle:UIAlertControllerStyleAlert];
90
91 UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
92 style:UIAlertActionStyleDefault
93 handler:^(UIAlertAction* action)
94 {
95 completionHandler(((UITextField*)alert.textFields[0]).text);
96 [alert dismissViewControllerAnimated:YES completion:nil];
97 }];
98
99 [alert addAction:ok];
100
101 UIAlertAction* cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
102 style:UIAlertActionStyleDefault
103 handler:^(UIAlertAction* action)
104 {
105 completionHandler(nil);
106 [alert dismissViewControllerAnimated:YES completion:nil];
107 }];
108 [alert addAction:cancel];
109
110 [alert addTextFieldWithConfigurationHandler:^(UITextField* textField) {
111 textField.text = defaultText;
112 }];
113
114 [[self getViewController] presentViewController:alert animated:YES completion:nil];
115}
116
117-(UIViewController*) getViewController
118{
119 return _viewController;
120}
121
122-(void) setViewController:(UIViewController*) viewController
123{
124 _viewController = viewController;
125}
126
127@end