UNPKG

3.01 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 "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