-
Notifications
You must be signed in to change notification settings - Fork 53
/
tns-oauth-webview-helper.ios.ts
67 lines (51 loc) · 2.58 KB
/
tns-oauth-webview-helper.ios.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/// <reference path="references.d.ts" />
import { WebView } from 'ui/web-view';
export class TnsOAuthWebViewHelper extends NSObject implements WKNavigationDelegate {
public static ObjCProtocols = [WKNavigationDelegate];
private _owner: WeakRef<WebView>;
private _origDelegate: any; //UIWebViewDelegateImpl
private _checkCodeIntercept: (WebView, error?, url?) => boolean;
constructor() {
super();
}
public static initWithWebViewAndIntercept(wv: WebView, checkCodeIntercept) {
(<any>wv)._delegate = TnsOAuthWebViewHelper.initWithOwner(new WeakRef(wv), checkCodeIntercept);
}
private static initWithOwner(owner: WeakRef<WebView>, checkCodeIntercept): TnsOAuthWebViewHelper {
let delegate = new TnsOAuthWebViewHelper();
delegate._owner = owner;
delegate._origDelegate = (<any>owner.get())._delegate;
delegate._checkCodeIntercept = checkCodeIntercept;
return delegate;
}
public webViewShouldStartLoadWithRequestNavigationType(webView: WKWebView, request: NSURLRequest, navigationType: number) {
return this._origDelegate.webViewShouldStartLoadWithRequestNavigationType(webView, request, navigationType);
}
public webViewDidStartLoad(webView: WKWebView) {
this._origDelegate.webViewDidStartLoad(webView);
}
public webViewDidFinishLoad(webView: WKWebView) {
this._checkCodeIntercept(webView, null);
this._origDelegate.webViewDidFinishLoad(webView);
}
public webViewDidFailLoadWithError(webView: WKWebView, error: NSError) {
this._checkCodeIntercept(webView, error);
this._origDelegate.webViewDidFailLoadWithError(webView, error);
}
public webViewDecidePolicyForNavigationActionDecisionHandler(webView, navigationAction, decisionHandler) {
//decisionHandler(WKNavigationActionPolicy.Allow);
this._checkCodeIntercept(webView, null);
this._origDelegate.webViewDecidePolicyForNavigationActionDecisionHandler(webView, navigationAction, decisionHandler);
}
public webViewDidStartProvisionalNavigation(webView, navigation) {
this._origDelegate.webViewDidStartProvisionalNavigation(webView, navigation);
}
public webViewDidFinishNavigation(webView, navigation) {
this._checkCodeIntercept(webView, null);
this._origDelegate.webViewDidFinishNavigation(webView, navigation);
}
public webViewDidFailNavigationWithError(webView, navigation, error) {
this._checkCodeIntercept(webView, error);
this._origDelegate.webViewDidFailNavigationWithError(webView, navigation, error);
}
}