|
5 | 5 | #import "ChildBrowserCommand.h"
|
6 | 6 | #import <Cordova/CDVViewController.h>
|
7 | 7 |
|
8 |
| - |
9 |
| - |
10 | 8 | @implementation ChildBrowserCommand
|
11 | 9 |
|
12 | 10 | @synthesize childBrowser;
|
13 | 11 |
|
14 |
| -- (void) showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url |
| 12 | +- (void)showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url |
15 | 13 | {
|
16 |
| - if(childBrowser == NULL) |
17 |
| - { |
18 |
| - childBrowser = [[ ChildBrowserViewController alloc ] initWithScale:FALSE ]; |
19 |
| - childBrowser.delegate = self; |
| 14 | + if (self.childBrowser == nil) { |
| 15 | +#if __has_feature(objc_arc) |
| 16 | + self.childBrowser = [[ChildBrowserViewController alloc] initWithScale:NO]; |
| 17 | +#else |
| 18 | + self.childBrowser = [[[ChildBrowserViewController alloc] initWithScale:NO] autorelease]; |
| 19 | +#endif |
| 20 | + self.childBrowser.delegate = self; |
| 21 | + self.childBrowser.orientationDelegate = self.viewController; |
20 | 22 | }
|
21 | 23 |
|
22 | 24 | /* // TODO: Work in progress
|
23 | 25 | NSString* strOrientations = [ options objectForKey:@"supportedOrientations"];
|
24 | 26 | NSArray* supportedOrientations = [strOrientations componentsSeparatedByString:@","];
|
25 | 27 | */
|
26 | 28 |
|
27 |
| - CDVViewController* cont = (CDVViewController*)[ super viewController ]; |
28 |
| - childBrowser.supportedOrientations = cont.supportedOrientations; |
29 |
| - [ cont presentModalViewController:childBrowser animated:YES ]; |
| 29 | + [self.viewController presentModalViewController:childBrowser animated:YES]; |
30 | 30 |
|
31 |
| - NSString *url = (NSString*) [arguments objectAtIndex:0]; |
| 31 | + NSString* url = (NSString*)[arguments objectAtIndex:0]; |
32 | 32 |
|
33 |
| - [childBrowser loadURL:url ]; |
34 |
| - |
35 |
| -} |
36 |
| -- (void) getPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options { |
37 |
| - NSString *url = (NSString*) [arguments objectAtIndex:0]; |
38 |
| - [childBrowser loadURL:url ]; |
| 33 | + [self.childBrowser loadURL:url]; |
39 | 34 | }
|
40 | 35 |
|
41 |
| --(void) close:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url |
| 36 | +- (void)getPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options |
42 | 37 | {
|
43 |
| - [ childBrowser closeBrowser]; |
| 38 | + NSString* url = (NSString*)[arguments objectAtIndex:0]; |
44 | 39 |
|
| 40 | + [self.childBrowser loadURL:url]; |
45 | 41 | }
|
46 | 42 |
|
47 |
| --(void) onClose |
| 43 | +- (void)close:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url |
48 | 44 | {
|
49 |
| - NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.childBrowser.onClose();",@""]; |
50 |
| - [self.webView stringByEvaluatingJavaScriptFromString:jsCallback]; |
| 45 | + [self.childBrowser closeBrowser]; |
51 | 46 | }
|
52 | 47 |
|
53 |
| --(void) onOpenInSafari |
| 48 | +- (void)onClose |
54 | 49 | {
|
55 |
| - NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.childBrowser.onOpenExternal();",@""]; |
56 |
| - [self.webView stringByEvaluatingJavaScriptFromString:jsCallback]; |
| 50 | + [self.webView stringByEvaluatingJavaScriptFromString:@"window.plugins.childBrowser.onClose();"]; |
57 | 51 | }
|
58 | 52 |
|
59 |
| - |
60 |
| --(void) onChildLocationChange:(NSString*)newLoc |
| 53 | +- (void)onOpenInSafari |
61 | 54 | {
|
| 55 | + [self.webView stringByEvaluatingJavaScriptFromString:@"window.plugins.childBrowser.onOpenExternal();"]; |
| 56 | +} |
62 | 57 |
|
63 |
| - NSString* tempLoc = [NSString stringWithFormat:@"%@",newLoc]; |
| 58 | +- (void)onChildLocationChange:(NSString*)newLoc |
| 59 | +{ |
| 60 | + NSString* tempLoc = [NSString stringWithFormat:@"%@", newLoc]; |
64 | 61 | NSString* encUrl = [tempLoc stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
65 | 62 |
|
66 |
| - NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.childBrowser.onLocationChange('%@');",encUrl]; |
| 63 | + NSString* jsCallback = [NSString stringWithFormat:@"window.plugins.childBrowser.onLocationChange('%@');", encUrl]; |
| 64 | + |
67 | 65 | [self.webView stringByEvaluatingJavaScriptFromString:jsCallback];
|
| 66 | +} |
| 67 | + |
68 | 68 |
|
| 69 | +#if !__has_feature(objc_arc) |
| 70 | +- (void)dealloc |
| 71 | +{ |
| 72 | + self.childBrowser = nil; |
| 73 | + |
| 74 | + [super dealloc]; |
69 | 75 | }
|
| 76 | +#endif |
| 77 | + |
70 | 78 | @end
|
0 commit comments