1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | #import "CDVInAppBrowser.h"
|
21 | #import <Cordova/CDVPluginResult.h>
|
22 |
|
23 | #define kInAppBrowserTargetSelf @"_self"
|
24 | #define kInAppBrowserTargetSystem @"_system"
|
25 | #define kInAppBrowserTargetBlank @"_blank"
|
26 |
|
27 | @interface CDVInAppBrowser () {
|
28 | }
|
29 | @end
|
30 |
|
31 | @implementation CDVInAppBrowser
|
32 |
|
33 | - (void)pluginInitialize
|
34 | {
|
35 | }
|
36 |
|
37 | - (BOOL) isSystemUrl:(NSURL*)url
|
38 | {
|
39 | if ([[url host] isEqualToString:@"itunes.apple.com"]) {
|
40 | return YES;
|
41 | }
|
42 |
|
43 | return NO;
|
44 | }
|
45 |
|
46 | - (void)open:(CDVInvokedUrlCommand*)command
|
47 | {
|
48 | CDVPluginResult* pluginResult;
|
49 |
|
50 | NSString* url = [command argumentAtIndex:0];
|
51 | NSString* target = [command argumentAtIndex:1 withDefault:kInAppBrowserTargetSelf];
|
52 |
|
53 | self.callbackId = command.callbackId;
|
54 |
|
55 | if (url != nil) {
|
56 |
|
57 | NSURL* baseUrl = [NSURL URLWithString:url];
|
58 |
|
59 | NSURL* absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl] absoluteURL];
|
60 |
|
61 | if ([self isSystemUrl:absoluteUrl]) {
|
62 | target = kInAppBrowserTargetSystem;
|
63 | }
|
64 |
|
65 | if ([target isEqualToString:kInAppBrowserTargetSelf]) {
|
66 | //[self openInCordovaWebView:absoluteUrl withOptions:options];
|
67 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not Yet Implemented for OSX: [self openInCordovaWebView:absoluteUrl withOptions:options]"];
|
68 | } else if ([target isEqualToString:kInAppBrowserTargetSystem]) {
|
69 | [self openInSystem:absoluteUrl];
|
70 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
71 | } else { // _blank or anything else
|
72 | //[self openInInAppBrowser:absoluteUrl withOptions:options];
|
73 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not Yet Implemented for OSX: [self openInInAppBrowser:absoluteUrl withOptions:options]"];
|
74 | }
|
75 |
|
76 | } else {
|
77 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"incorrect number of arguments"];
|
78 | }
|
79 | [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
|
80 | [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
81 | }
|
82 |
|
83 | - (void)openInSystem:(NSURL*)url
|
84 | {
|
85 | [[NSWorkspace sharedWorkspace] openURL:url];
|
86 | }
|
87 |
|
88 | @end
|
89 |
|