forked from alexziskind1/nativescript-oauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtns-oauth-webview-helper.ios.ts
46 lines (35 loc) · 1.67 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
/// <reference path="references.d.ts" />
import { WebView } from 'ui/web-view';
export class TnsOAuthWebViewHelper extends NSObject implements UIWebViewDelegate {
public static ObjCProtocols = [UIWebViewDelegate];
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: UIWebView, request: NSURLRequest, navigationType: number) {
return this._origDelegate.webViewShouldStartLoadWithRequestNavigationType(webView, request, navigationType);
}
public webViewDidStartLoad(webView: UIWebView) {
this._origDelegate.webViewDidStartLoad(webView);
}
public webViewDidFinishLoad(webView: UIWebView) {
this._checkCodeIntercept(webView, null);
this._origDelegate.webViewDidFinishLoad(webView);
}
public webViewDidFailLoadWithError(webView: UIWebView, error: NSError) {
this._checkCodeIntercept(webView, error);
this._origDelegate.webViewDidFailLoadWithError(webView, error);
}
}