Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8AEC6D69F for ; Sat, 9 Mar 2013 00:37:34 +0000 (UTC) Received: (qmail 36609 invoked by uid 500); 9 Mar 2013 00:37:34 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 36548 invoked by uid 500); 9 Mar 2013 00:37:34 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 36343 invoked by uid 99); 9 Mar 2013 00:37:34 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Mar 2013 00:37:34 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 0154053DE; Sat, 9 Mar 2013 00:37:33 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: shazron@apache.org To: commits@cordova.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [2/6] Move CordovaLib folder into its own CordovaFramework project, add as a sub-project to a CordovaMac project. Message-Id: <20130309003734.0154053DE@tyr.zones.apache.org> Date: Sat, 9 Mar 2013 00:37:33 +0000 (UTC) http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaFramework/CordovaFramework/CordovaFramework-Info.plist ---------------------------------------------------------------------- diff --git a/CordovaFramework/CordovaFramework/CordovaFramework-Info.plist b/CordovaFramework/CordovaFramework/CordovaFramework-Info.plist new file mode 100644 index 0000000..384517e --- /dev/null +++ b/CordovaFramework/CordovaFramework/CordovaFramework-Info.plist @@ -0,0 +1,30 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + + CFBundleIdentifier + org.apache.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + NSHumanReadableCopyright + Copyright © 2013 Apache Foundation. All rights reserved. + NSPrincipalClass + + + http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaFramework/CordovaFramework/CordovaFramework-Prefix.pch ---------------------------------------------------------------------- diff --git a/CordovaFramework/CordovaFramework/CordovaFramework-Prefix.pch b/CordovaFramework/CordovaFramework/CordovaFramework-Prefix.pch new file mode 100644 index 0000000..6037546 --- /dev/null +++ b/CordovaFramework/CordovaFramework/CordovaFramework-Prefix.pch @@ -0,0 +1,7 @@ +// +// Prefix header for all source files of the 'CordovaFramework' target in the 'CordovaFramework' project +// + +#ifdef __OBJC__ + #import +#endif http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaFramework/CordovaFramework/en.lproj/InfoPlist.strings ---------------------------------------------------------------------- diff --git a/CordovaFramework/CordovaFramework/en.lproj/InfoPlist.strings b/CordovaFramework/CordovaFramework/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..477b28f --- /dev/null +++ b/CordovaFramework/CordovaFramework/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaFramework/CordovaFrameworkTests/CordovaFrameworkTests-Info.plist ---------------------------------------------------------------------- diff --git a/CordovaFramework/CordovaFrameworkTests/CordovaFrameworkTests-Info.plist b/CordovaFramework/CordovaFrameworkTests/CordovaFrameworkTests-Info.plist new file mode 100644 index 0000000..b96525e --- /dev/null +++ b/CordovaFramework/CordovaFrameworkTests/CordovaFrameworkTests-Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + org.apache.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaFramework/CordovaFrameworkTests/CordovaFrameworkTests.h ---------------------------------------------------------------------- diff --git a/CordovaFramework/CordovaFrameworkTests/CordovaFrameworkTests.h b/CordovaFramework/CordovaFrameworkTests/CordovaFrameworkTests.h new file mode 100644 index 0000000..49d7c77 --- /dev/null +++ b/CordovaFramework/CordovaFrameworkTests/CordovaFrameworkTests.h @@ -0,0 +1,13 @@ +// +// CordovaFrameworkTests.h +// CordovaFrameworkTests +// +// Created by Shazron Abdullah on 3/8/13. +// Copyright (c) 2013 Apache Foundation. All rights reserved. +// + +#import + +@interface CordovaFrameworkTests : SenTestCase + +@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaFramework/CordovaFrameworkTests/CordovaFrameworkTests.m ---------------------------------------------------------------------- diff --git a/CordovaFramework/CordovaFrameworkTests/CordovaFrameworkTests.m b/CordovaFramework/CordovaFrameworkTests/CordovaFrameworkTests.m new file mode 100644 index 0000000..e57d0a0 --- /dev/null +++ b/CordovaFramework/CordovaFrameworkTests/CordovaFrameworkTests.m @@ -0,0 +1,32 @@ +// +// CordovaFrameworkTests.m +// CordovaFrameworkTests +// +// Created by Shazron Abdullah on 3/8/13. +// Copyright (c) 2013 Apache Foundation. All rights reserved. +// + +#import "CordovaFrameworkTests.h" + +@implementation CordovaFrameworkTests + +- (void)setUp +{ + [super setUp]; + + // Set-up code here. +} + +- (void)tearDown +{ + // Tear-down code here. + + [super tearDown]; +} + +- (void)testExample +{ + STFail(@"Unit tests are not implemented yet in CordovaFrameworkTests"); +} + +@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaFramework/CordovaFrameworkTests/en.lproj/InfoPlist.strings ---------------------------------------------------------------------- diff --git a/CordovaFramework/CordovaFrameworkTests/en.lproj/InfoPlist.strings b/CordovaFramework/CordovaFrameworkTests/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..477b28f --- /dev/null +++ b/CordovaFramework/CordovaFrameworkTests/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/CDVBridge.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/CDVBridge.h b/CordovaMac/CordovaLib/CDVBridge.h deleted file mode 100644 index aa9e087..0000000 --- a/CordovaMac/CordovaLib/CDVBridge.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import -@class WebView; -@class CDVViewController; - -@interface CDVBridge : NSObject { - -} - -@property (nonatomic, weak) WebView* webView; -@property (nonatomic, weak) CDVViewController* viewController; - -- (id) initWithWebView:(WebView*)webView andViewController:(CDVViewController*)viewController; -- (void) exec:(NSString*)callbackId withService:(NSString*)service andAction:(NSString*)action andArguments:(NSArray*)arguments; - - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/CDVBridge.m ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/CDVBridge.m b/CordovaMac/CordovaLib/CDVBridge.m deleted file mode 100644 index fade163..0000000 --- a/CordovaMac/CordovaLib/CDVBridge.m +++ /dev/null @@ -1,204 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import -#import -#import -#include - -#import "CDVBridge.h" -#import "CDVViewController.h" - -@implementation CDVBridge - -- (BOOL) isArray:(id)item -{ - id win = [self.webView windowScriptObject]; - NSNumber* result = [win callWebScriptMethod:@"CordovaBridgeUtil.isArray" withArguments:[NSArray arrayWithObject:item]]; - - return [result boolValue]; -} - -- (BOOL) isDictionary:(id)item -{ - id win = [self.webView windowScriptObject]; - NSNumber* result = [win callWebScriptMethod:@"CordovaBridgeUtil.isObject" withArguments:[NSArray arrayWithObject:item]]; - return [result boolValue]; -} - -- (NSDictionary*) convertWebScriptObjectToNSDictionary:(WebScriptObject*)webScriptObject -{ - // Assumption: webScriptObject has already been tested using isDictionary: - - id win = [self.webView windowScriptObject]; - - WebScriptObject* keysObject = [win callWebScriptMethod:@"CordovaBridgeUtil.getDictionaryKeys" withArguments:[NSArray arrayWithObject:webScriptObject]]; - NSArray* keys = [self convertWebScriptObjectToNSArray:keysObject]; - NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:[keys count]]; - - NSEnumerator* enumerator = [keys objectEnumerator]; - id key; - while (key = [enumerator nextObject]) { - [dict setObject:[webScriptObject valueForKey:key] forKey:key]; - } - - return dict; -} - -- (NSArray*) convertWebScriptObjectToNSArray:(WebScriptObject*)webScriptObject -{ - // Assumption: webScriptObject has already been tested using isArray: - - NSUInteger count = [[webScriptObject valueForKey:@"length"] integerValue]; - NSMutableArray *a = [NSMutableArray array]; - for (unsigned i = 0; i < count; i++) { - id item = [webScriptObject webScriptValueAtIndex:i]; - if ([item isKindOfClass:[WebScriptObject class]]) { - if ([self isArray:item]) { - [a addObject:[self convertWebScriptObjectToNSArray:item]]; - } else if ([self isDictionary:item]) { - [a addObject:[self convertWebScriptObjectToNSDictionary:item]]; - }; - } else { - [a addObject:item]; - } - } - - return a; -} - -- (void) registerJavaScriptHelpers -{ - NSString* cordovaBridgeUtil = @"CordovaBridgeUtil = {};"; - NSString* isArray = [NSString stringWithFormat:@"CordovaBridgeUtil.isArray = function(obj) { return obj.constructor == Array; };"]; - NSString* isObject = [NSString stringWithFormat:@"CordovaBridgeUtil.isObject = function(obj) { return obj.constructor == Object; };"]; - NSString* dictionaryKeys = [NSString stringWithFormat: - @" \ - CordovaBridgeUtil.getDictionaryKeys = function(obj) { \ - var a = []; \ - for (var key in obj) { \ - if (!obj.hasOwnProperty(key)) { \ - continue; \ - } \ - a.push(key); \ - } \ - return a; \ - }" - ]; - - id win = [self.webView windowScriptObject]; - [win evaluateWebScript:cordovaBridgeUtil]; - [win evaluateWebScript:isArray]; - [win evaluateWebScript:isObject]; - [win evaluateWebScript:dictionaryKeys]; -} - -- (id) initWithWebView:(WebView *)webView andViewController:(CDVViewController*)viewController -{ - if ((self = [super init]) != nil) { - self.webView = webView; - self.viewController = viewController; - [self registerJavaScriptHelpers]; - } - - return self; -} - -- (void) exec:(NSString*)callbackId withService:(NSString*)service andAction:(NSString*)action andArguments:(WebScriptObject*)webScriptObject -{ - // We are going with the iOS method of passing in a callbackId. - // Note that we can use the JavaScriptCore C API to pass in the JavaScript function references - // and context and call them directly, but this is done this way for possible plugin sharing - // between iOS and OS X. Also we are going async as well. - - // we're just going to assume the webScriptObject passed in is an NSArray - NSArray* arguments = [self convertWebScriptObjectToNSArray:webScriptObject]; - - CDVInvokedUrlCommand* command = [[CDVInvokedUrlCommand alloc] initWithArguments:arguments callbackId:callbackId className:service methodName:action]; - - if ((command.className == nil) || (command.methodName == nil)) { - NSLog(@"ERROR: Classname and/or methodName not found for command."); - return; - } - - // Fetch an instance of this class - CDVPlugin* obj = [_viewController.commandDelegate getCommandInstance:command.className]; - - if (!([obj isKindOfClass:[CDVPlugin class]])) { - NSLog(@"ERROR: Plugin '%@' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.", command.className); - return; - } - - // Find the proper selector to call. - NSString* methodName = [NSString stringWithFormat:@"%@:", command.methodName]; - SEL normalSelector = NSSelectorFromString(methodName); - if ([obj respondsToSelector:normalSelector]) { - // [obj performSelector:normalSelector withObject:command]; - objc_msgSend(obj, normalSelector, command); - } else { - // There's no method to call, so throw an error. - NSLog(@"ERROR: Method '%@' not defined in Plugin '%@'", methodName, command.className); - } -} - -#pragma mark WebScripting Protocol - -/* checks whether a selector is acceptable to be called from JavaScript */ -+ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector -{ - BOOL result = YES; - - int i = 0; - static SEL * acceptableList = NULL; - SEL currentSelector; - - if (acceptableList == NULL && (acceptableList = calloc(256, sizeof(SEL)))) // up to 256 selectors - { - acceptableList[i++] = @selector(exec:withService:andAction:andArguments:); - } - - i = 0; - while (result == YES && (currentSelector = acceptableList[i++])) - { - //checking for exclusions - result = !(selector == currentSelector); - } - - return result; -} - -/* helper function so we don't have to have underscores and stuff in js to refer to the right method */ -+ (NSString*) webScriptNameForSelector:(SEL)aSelector -{ - id result = nil; - - if (aSelector == @selector(exec:withService:andAction:andArguments:)) { - result = @"exec"; - } - - return result; -} - -// right now exclude all properties (eg keys) -+ (BOOL) isKeyExcludedFromWebScript:(const char*)name -{ - return YES; -} - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/CDVViewController.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/CDVViewController.h b/CordovaMac/CordovaLib/CDVViewController.h deleted file mode 100644 index 490b1ee..0000000 --- a/CordovaMac/CordovaLib/CDVViewController.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import -#import -#import -#import "CDVAvailability.h" -#import "CDVInvokedUrlCommand.h" -#import "CDVCommandDelegate.h" -#import "CDVCommandQueue.h" -#import "CDVPlugin.h" -#import "CDVWebViewDelegate.h" - -@interface CDVViewController : NSWindowController -{ - @protected - id _commandDelegate; - @protected - CDVCommandQueue* _commandQueue; - NSString* _userAgent; -} - -@property (nonatomic, strong) IBOutlet NSView* contentView; -@property (nonatomic, strong) IBOutlet WebView* webView; -@property (nonatomic, strong) IBOutlet CDVWebViewDelegate* webViewDelegate; - -@property (nonatomic, readonly, strong) NSMutableDictionary* pluginObjects; -@property (nonatomic, readonly, strong) NSDictionary* pluginsMap; -@property (nonatomic, readonly, strong) NSMutableDictionary* settings; -@property (nonatomic, readonly, strong) NSXMLParser* configParser; -@property (nonatomic, readonly, assign) BOOL loadFromString; - -@property (nonatomic, readwrite, copy) NSString* wwwFolderName; -@property (nonatomic, readwrite, copy) NSString* startPage; -@property (nonatomic, readonly, strong) CDVCommandQueue* commandQueue; -@property (nonatomic, readonly, strong) id commandDelegate; - -- (id)getCommandInstance:(NSString*)pluginName; -- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className; - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/CDVViewController.m ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/CDVViewController.m b/CordovaMac/CordovaLib/CDVViewController.m deleted file mode 100644 index 5324871..0000000 --- a/CordovaMac/CordovaLib/CDVViewController.m +++ /dev/null @@ -1,192 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVViewController.h" -#import "CDVConfigParser.h" -#import "CDVCommandDelegateImpl.h" - -@interface CDVViewController () - -@property (nonatomic, readwrite, strong) NSXMLParser* configParser; -@property (nonatomic, readwrite, strong) NSMutableDictionary* settings; -@property (nonatomic, readwrite, strong) NSMutableDictionary* pluginObjects; -@property (nonatomic, readwrite, strong) NSArray* startupPluginNames; -@property (nonatomic, readwrite, strong) NSDictionary* pluginsMap; -@property (nonatomic, readwrite, assign) BOOL loadFromString; - -@end - -@implementation CDVViewController - -@synthesize webView; -@synthesize pluginObjects, pluginsMap, startupPluginNames; -@synthesize configParser, settings, loadFromString; -@synthesize wwwFolderName, startPage; -@synthesize commandDelegate = _commandDelegate; -@synthesize commandQueue = _commandQueue; - -- (void) awakeFromNib -{ - _commandDelegate = [[CDVCommandDelegateImpl alloc] initWithViewController:self]; - self.webViewDelegate.viewController = self; - - NSURL* appURL = nil; - NSString* loadErr = nil; - - if ([self.startPage rangeOfString:@"://"].location != NSNotFound) { - appURL = [NSURL URLWithString:self.startPage]; - } else if ([self.wwwFolderName rangeOfString:@"://"].location != NSNotFound) { - appURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", self.wwwFolderName, self.startPage]]; - } else { - NSString* startFilePath = [self.commandDelegate pathForResource:self.startPage]; - if (startFilePath == nil) { - loadErr = [NSString stringWithFormat:@"ERROR: Start Page at '%@/%@' was not found.", self.wwwFolderName, self.startPage]; - NSLog(@"%@", loadErr); - self.loadFromString = YES; - appURL = nil; - } else { - appURL = [NSURL fileURLWithPath:startFilePath]; - } - } - - if (!loadErr) { - NSURLRequest* appReq = [NSURLRequest requestWithURL:appURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0]; - [[self.webView mainFrame] loadRequest:appReq]; - - } else { - NSString* html = [NSString stringWithFormat:@" %@ ", loadErr]; - [[self.webView mainFrame] loadHTMLString:html baseURL:nil]; - } - - for (NSString* pluginName in self.startupPluginNames) { - [self getCommandInstance:pluginName]; - } -} - -- (void) __init -{ - [self loadSettings]; -} - -- (id) init -{ - self = [super init]; - if (self) { - // Initialization code here. - [self __init]; - } - return self; -} - -- (id)initWithWindowNibName:(NSString*)nibNameOrNil -{ - self = [super initWithWindowNibName:nibNameOrNil]; - if (self) { - // Initialization code here. - [self __init]; - } - return self; -} - -- (void)loadSettings -{ - CDVConfigParser* delegate = [[CDVConfigParser alloc] init]; - - // read from config.xml in the app bundle - NSString* path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"xml"]; - - if (![[NSFileManager defaultManager] fileExistsAtPath:path]) { - NSAssert(NO, @"ERROR: config.xml does not exist. Please run cordova-ios/bin/cordova_plist_to_config_xml path/to/project."); - return; - } - - NSURL* url = [NSURL fileURLWithPath:path]; - - configParser = [[NSXMLParser alloc] initWithContentsOfURL:url]; - if (configParser == nil) { - NSLog(@"Failed to initialize XML parser."); - return; - } - [configParser setDelegate:((id < NSXMLParserDelegate >)delegate)]; - [configParser parse]; - - // Get the plugin dictionary, whitelist and settings from the delegate. - self.pluginsMap = delegate.pluginsDict; - self.startupPluginNames = delegate.startupPluginNames; - self.settings = delegate.settings; - - // And the start folder/page. - self.wwwFolderName = @"www"; - self.startPage = delegate.startPage; - if (self.startPage == nil) { - self.startPage = @"index.html"; - } - - // Initialize the plugin objects dict. - self.pluginObjects = [[NSMutableDictionary alloc] initWithCapacity:20]; -} - -- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className -{ - if ([plugin respondsToSelector:@selector(setViewController:)]) { - [plugin setViewController:self]; - } - - if ([plugin respondsToSelector:@selector(setCommandDelegate:)]) { - [plugin setCommandDelegate:_commandDelegate]; - } - - [self.pluginObjects setObject:plugin forKey:className]; - [plugin pluginInitialize]; -} - -/** - Returns an instance of a CordovaCommand object, based on its name. If one exists already, it is returned. - */ -- (id)getCommandInstance:(NSString*)pluginName -{ - // first, we try to find the pluginName in the pluginsMap - // (acts as a whitelist as well) if it does not exist, we return nil - // NOTE: plugin names are matched as lowercase to avoid problems - however, a - // possible issue is there can be duplicates possible if you had: - // "org.apache.cordova.Foo" and "org.apache.cordova.foo" - only the lower-cased entry will match - NSString* className = [self.pluginsMap objectForKey:[pluginName lowercaseString]]; - - if (className == nil) { - return nil; - } - - id obj = [self.pluginObjects objectForKey:className]; - if (!obj) { - obj = [[NSClassFromString (className)alloc] initWithWebView:webView]; - - if (obj != nil) { - [self registerPlugin:obj withClassName:className]; - } else { - NSLog(@"CDVPlugin class %@ (pluginName: %@) does not exist.", className, pluginName); - } - } - return obj; -} - -- (void) windowResized:(NSNotification*)notification; -{ -} - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/CDVWebViewDelegate.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/CDVWebViewDelegate.h b/CordovaMac/CordovaLib/CDVWebViewDelegate.h deleted file mode 100644 index c2a33f4..0000000 --- a/CordovaMac/CordovaLib/CDVWebViewDelegate.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import -#import - -@class CDVConsole; -@class CDVBridge; -@class CDVViewController; - -@interface CDVWebViewDelegate : NSObject { -} - -@property (nonatomic, strong) CDVConsole* console; -@property (nonatomic, strong) CDVBridge* bridge; -@property (nonatomic, weak) CDVViewController* viewController; - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/CDVWebViewDelegate.m ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/CDVWebViewDelegate.m b/CordovaMac/CordovaLib/CDVWebViewDelegate.m deleted file mode 100644 index 144c8fd..0000000 --- a/CordovaMac/CordovaLib/CDVWebViewDelegate.m +++ /dev/null @@ -1,87 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - - -#import "CDVWebViewDelegate.h" -#import "CDVConsole.h" -#import "CDVBridge.h" - -@implementation CDVWebViewDelegate - -@synthesize console; - -- (void) webView:(WebView*)webView windowScriptObjectAvailable:(WebScriptObject*)windowScriptObject -{ - if (self.console == nil) { - self.console = [CDVConsole new]; - } - [windowScriptObject setValue:self.console forKey:@"console"]; - - if (self.bridge == nil) { - self.bridge = [[CDVBridge alloc] initWithWebView:webView andViewController:self.viewController]; - } - [windowScriptObject setValue:self.bridge forKey:@"cordovabridge"]; -} - -- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame -{ - id win = [sender windowScriptObject]; - NSString* nativeReady = @"try{cordova.require('cordova/channel').onNativeReady.fire();}catch(e){window._nativeReady = true;}"; - [win evaluateWebScript:nativeReady]; -} - -/* This logs all errors from Javascript, nifty */ -- (void) webView:(WebView*)webView addMessageToConsole:(NSDictionary*)message -{ - if (![message isKindOfClass:[NSDictionary class]]) { - return; - } - - NSLog(@"JavaScript error: %@:%@: %@", - [[message objectForKey:@"sourceURL"] lastPathComponent], // could be nil - [message objectForKey:@"lineNumber"], - [message objectForKey:@"message"]); -} - -#pragma mark WebScripting protocol - -/* checks whether a selector is acceptable to be called from JavaScript */ -+ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector -{ - return YES; -} - -// right now exclude all properties (eg keys) -+ (BOOL) isKeyExcludedFromWebScript:(const char*)name -{ - return YES; -} - -#pragma mark WebPolicyDelegate - -- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener -{ - NSString* url = [[request URL] description]; - NSLog(@"navigating to %@", url); - - [listener use]; -} - - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDV.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDV.h b/CordovaMac/CordovaLib/Commands/CDV.h deleted file mode 100644 index 6fe45d8..0000000 --- a/CordovaMac/CordovaLib/Commands/CDV.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVAvailability.h" - -#import "CDVJSON.h" -#import "CDVDebug.h" -#import "CDVPluginResult.h" -#import "CDVInvokedUrlCommand.h" -#import "CDVPlugin.h" -#import "CDVDevice.h" http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVAvailability.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVAvailability.h b/CordovaMac/CordovaLib/Commands/CDVAvailability.h deleted file mode 100644 index 955051e..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVAvailability.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#define __CORDOVA_2_6_0 20600 -#define __CORDOVA_NA 99999 /* not available */ - -/* - #if CORDOVA_VERSION_MIN_REQUIRED >= __CORDOVA_1_7_0 - // do something when its at least 1.7.0 - #else - // do something else (non 1.7.0) - #endif - */ -#ifndef CORDOVA_VERSION_MIN_REQUIRED - #define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_2_6_0 -#endif - - -/* Return the string version of the decimal version */ -#define CDV_VERSION [NSString stringWithFormat:@"%d.%d.%d", \ - (CORDOVA_VERSION_MIN_REQUIRED / 10000), \ - (CORDOVA_VERSION_MIN_REQUIRED % 10000) / 100, \ - (CORDOVA_VERSION_MIN_REQUIRED % 10000) % 100] - -#ifdef __clang__ - #define CDV_DEPRECATED(version, msg) __attribute__((deprecated("Deprecated in Cordova " #version ". " msg))) -#else - #define CDV_DEPRECATED(version, msg) __attribute__((deprecated())) -#endif - -// Enable this to log all exec() calls. -#define CDV_ENABLE_EXEC_LOGGING 0 -#if CDV_ENABLE_EXEC_LOGGING - #define CDV_EXEC_LOG NSLog -#else - #define CDV_EXEC_LOG(...) do {} while (NO) -#endif http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVCommandDelegate.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVCommandDelegate.h b/CordovaMac/CordovaLib/Commands/CDVCommandDelegate.h deleted file mode 100644 index e177c63..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVCommandDelegate.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVAvailability.h" -#import "CDVInvokedUrlCommand.h" - -@class CDVPlugin; -@class CDVPluginResult; -@class CDVWhitelist; - -@protocol CDVCommandDelegate - -@property (nonatomic, readonly) NSDictionary* settings; - -- (NSString*)pathForResource:(NSString*)resourcepath; -- (id)getCommandInstance:(NSString*)pluginName; -- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className CDV_DEPRECATED(2.2, "Use CDVViewController to register plugins, or use config.xml."); - -// Plugins should not be using this interface to call other plugins since it -// will result in bogus callbacks being made. -- (BOOL)execute:(CDVInvokedUrlCommand*)command CDV_DEPRECATED(2.2, "Use direct method calls instead."); - -// Sends a plugin result to the JS. This is thread-safe. -- (void)sendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId; -// Evaluates the given JS. This is thread-safe. -- (void)evalJs:(NSString*)js; -// Can be used to evaluate JS right away instead of scheduling it on the run-loop. -// This is required for dispatch resign and pause events, but should not be used -// without reason. Without the run-loop delay, alerts used in JS callbacks may result -// in dead-lock. This method must be called from the UI thread. -- (void)evalJs:(NSString*)js scheduledOnRunLoop:(BOOL)scheduledOnRunLoop; -// Runs the given block on a background thread using a shared thread-pool. -- (void)runInBackground:(void (^)())block; -// Returns the User-Agent of the associated UIWebView. -- (NSString*)userAgent; -// Returns whether the given URL passes the white-list. -- (BOOL)URLIsWhitelisted:(NSURL*)url; - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVCommandDelegateImpl.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVCommandDelegateImpl.h b/CordovaMac/CordovaLib/Commands/CDVCommandDelegateImpl.h deleted file mode 100644 index db0bd09..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVCommandDelegateImpl.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVCommandDelegate.h" - -@class CDVViewController; -@class CDVCommandQueue; - -@interface CDVCommandDelegateImpl : NSObject { -// @private - __weak CDVViewController* _viewController; - @protected - __weak CDVCommandQueue* _commandQueue; -} -- (id)initWithViewController:(CDVViewController*)viewController; -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVCommandDelegateImpl.m ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVCommandDelegateImpl.m b/CordovaMac/CordovaLib/Commands/CDVCommandDelegateImpl.m deleted file mode 100644 index ed082aa..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVCommandDelegateImpl.m +++ /dev/null @@ -1,156 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVCommandDelegateImpl.h" -#import "CDVJSON.h" -#import "CDVCommandQueue.h" -#import "CDVPluginResult.h" -#import "CDVViewController.h" - -@implementation CDVCommandDelegateImpl - -- (id)initWithViewController:(CDVViewController*)viewController -{ - self = [super init]; - if (self != nil) { - _viewController = viewController; - // TODO: - //_commandQueue = _viewController.commandQueue; - } - return self; -} - -- (NSString*)pathForResource:(NSString*)resourcepath -{ - NSBundle* mainBundle = [NSBundle mainBundle]; - NSMutableArray* directoryParts = [NSMutableArray arrayWithArray:[resourcepath componentsSeparatedByString:@"/"]]; - NSString* filename = [directoryParts lastObject]; - - [directoryParts removeLastObject]; - - NSString* directoryPartsJoined = [directoryParts componentsJoinedByString:@"/"]; - NSString* directoryStr = _viewController.wwwFolderName; - - if ([directoryPartsJoined length] > 0) { - directoryStr = [NSString stringWithFormat:@"%@/%@", _viewController.wwwFolderName, [directoryParts componentsJoinedByString:@"/"]]; - } - - return [mainBundle pathForResource:filename ofType:@"" inDirectory:directoryStr]; -} - -- (void)evalJsHelper2:(NSString*)js -{ - CDV_EXEC_LOG(@"Exec: evalling: %@", [js substringToIndex:MIN([js length], 160)]); - NSString* commandsJSON = [_viewController.webView stringByEvaluatingJavaScriptFromString:js]; - if ([commandsJSON length] > 0) { - CDV_EXEC_LOG(@"Exec: Retrieved new exec messages by chaining."); - } - - // TODO: -// [_commandQueue enqueCommandBatch:commandsJSON]; -} - -- (void)evalJsHelper:(NSString*)js -{ - // Cycle the run-loop before executing the JS. - // This works around a bug where sometimes alerts() within callbacks can cause - // dead-lock. - // If the commandQueue is currently executing, then we know that it is safe to - // execute the callback immediately. - // Using (dispatch_get_main_queue()) does *not* fix deadlocks for some reaon, - // but performSelectorOnMainThread: does. - - if (![NSThread isMainThread] || !_commandQueue.currentlyExecuting) { - [self performSelectorOnMainThread:@selector(evalJsHelper2:) withObject:js waitUntilDone:NO]; - } else { - [self evalJsHelper2:js]; - } -} - -- (void)sendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId -{ - CDV_EXEC_LOG(@"Exec(%@): Sending result. Status=%@", callbackId, result.status); - // This occurs when there is are no win/fail callbacks for the call. - if ([@"INVALID" isEqualToString:callbackId]) { - return; - } - int status = [result.status intValue]; - BOOL keepCallback = [result.keepCallback boolValue]; - NSString* argumentsAsJSON = [result argumentsAsJSON]; - - NSString* js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeCallback('%@',%d,%@,%d)", callbackId, status, argumentsAsJSON, keepCallback]; - - [self evalJsHelper:js]; -} - -- (void)evalJs:(NSString*)js -{ - [self evalJs:js scheduledOnRunLoop:YES]; -} - -- (void)evalJs:(NSString*)js scheduledOnRunLoop:(BOOL)scheduledOnRunLoop -{ - js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeEvalAndFetch(function(){%@})", js]; - if (scheduledOnRunLoop) { - [self evalJsHelper:js]; - } else { - [self evalJsHelper2:js]; - } -} - -- (BOOL)execute:(CDVInvokedUrlCommand*)command -{ - return [_commandQueue execute:command]; -} - -- (id)getCommandInstance:(NSString*)pluginName -{ - return [_viewController getCommandInstance:pluginName]; -} - -- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className -{ - [_viewController registerPlugin:plugin withClassName:className]; -} - -- (void)runInBackground:(void (^)())block -{ - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block); -} - -- (NSString*)userAgent -{ - //return [_viewController userAgent]; - return nil; -} - -- (BOOL)URLIsWhitelisted:(NSURL*)url -{ -// TODO: -// return ![_viewController.whitelist schemeIsAllowed:[url scheme]] || -// [_viewController.whitelist URLIsAllowed:url]; - return NO; -} - -- (NSDictionary*)settings -{ - return _viewController.settings; -} - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVCommandQueue.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVCommandQueue.h b/CordovaMac/CordovaLib/Commands/CDVCommandQueue.h deleted file mode 100644 index 27c47b5..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVCommandQueue.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import - -@class CDVInvokedUrlCommand; -@class CDVViewController; - -@interface CDVCommandQueue : NSObject - -@property (nonatomic, readonly) BOOL currentlyExecuting; - -- (id)initWithViewController:(CDVViewController*)viewController; -- (void)dispose; - -- (void)resetRequestId; -- (void)enqueCommandBatch:(NSString*)batchJSON; - -- (void)maybeFetchCommandsFromJs:(NSNumber*)requestId; -- (void)fetchCommandsFromJs; -- (void)executePending; -- (BOOL)execute:(CDVInvokedUrlCommand*)command; - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVCommandQueue.m ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVCommandQueue.m b/CordovaMac/CordovaLib/Commands/CDVCommandQueue.m deleted file mode 100644 index d80115e..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVCommandQueue.m +++ /dev/null @@ -1,164 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#include -#import "CDV.h" -#import "CDVCommandQueue.h" -#import "CDVCommandDelegateImpl.h" - -@interface CDVCommandQueue () { - NSInteger _lastCommandQueueFlushRequestId; - __weak NSViewController* _viewController; - NSMutableArray* _queue; - BOOL _currentlyExecuting; -} -@end - -@implementation CDVCommandQueue - -@synthesize currentlyExecuting = _currentlyExecuting; - -- (id)initWithViewController:(NSViewController*)viewController -{ - self = [super init]; - if (self != nil) { - _viewController = viewController; - _queue = [[NSMutableArray alloc] init]; - } - return self; -} - -- (void)dispose -{ - // TODO(agrieve): Make this a zeroing weak ref once we drop support for 4.3. - _viewController = nil; -} - -- (void)resetRequestId -{ - _lastCommandQueueFlushRequestId = 0; -} - -- (void)enqueCommandBatch:(NSString*)batchJSON -{ - if ([batchJSON length] > 0) { - [_queue addObject:batchJSON]; - [self executePending]; - } -} - -- (void)maybeFetchCommandsFromJs:(NSNumber*)requestId -{ - // Use the request ID to determine if we've already flushed for this request. - // This is required only because the NSURLProtocol enqueues the same request - // multiple times. - if ([requestId integerValue] > _lastCommandQueueFlushRequestId) { - _lastCommandQueueFlushRequestId = [requestId integerValue]; - [self fetchCommandsFromJs]; - } -} - -- (void)fetchCommandsFromJs -{ - // TODO: -// // Grab all the queued commands from the JS side. -// NSString* queuedCommandsJSON = [_viewController.webView stringByEvaluatingJavaScriptFromString: -// @"cordova.require('cordova/exec').nativeFetchMessages()"]; -// -// [self enqueCommandBatch:queuedCommandsJSON]; -// if ([queuedCommandsJSON length] > 0) { -// CDV_EXEC_LOG(@"Exec: Retrieved new exec messages by request."); -// } -} - -- (void)executePending -{ - // Make us re-entrant-safe. - if (_currentlyExecuting) { - return; - } - @try { - _currentlyExecuting = YES; - - for (NSUInteger i = 0; i < [_queue count]; ++i) { - // Parse the returned JSON array. - NSArray* commandBatch = [[_queue objectAtIndex:i] JSONObject]; - - // Iterate over and execute all of the commands. - for (NSArray* jsonEntry in commandBatch) { - CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonEntry]; - CDV_EXEC_LOG(@"Exec(%@): Calling %@.%@", command.callbackId, command.className, command.methodName); - - if (![self execute:command]) { -#ifdef DEBUG - NSString* commandJson = [jsonEntry JSONString]; - static NSUInteger maxLogLength = 1024; - NSString* commandString = ([commandJson length] > maxLogLength) ? - [NSString stringWithFormat:@"%@[...]", [commandJson substringToIndex:maxLogLength]] : - commandJson; - - DLog(@"FAILED pluginJSON = %@", commandString); -#endif - } - } - } - - [_queue removeAllObjects]; - } @finally - { - _currentlyExecuting = NO; - } -} - -- (BOOL)execute:(CDVInvokedUrlCommand*)command -{ - if ((command.className == nil) || (command.methodName == nil)) { - NSLog(@"ERROR: Classname and/or methodName not found for command."); - return NO; - } - - // Fetch an instance of this class - //TODO: -// CDVPlugin* obj = [_viewController.commandDelegate getCommandInstance:command.className]; -// - CDVPlugin* obj = nil; - - if (!([obj isKindOfClass:[CDVPlugin class]])) { - NSLog(@"ERROR: Plugin '%@' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.", command.className); - return NO; - } - BOOL retVal = YES; - - // Find the proper selector to call. - NSString* methodName = [NSString stringWithFormat:@"%@:", command.methodName]; - SEL normalSelector = NSSelectorFromString(methodName); - // Test for the legacy selector first in case they both exist. - if ([obj respondsToSelector:normalSelector]) { - // [obj performSelector:normalSelector withObject:command]; - objc_msgSend(obj, normalSelector, command); - } else { - // There's no method to call, so throw an error. - NSLog(@"ERROR: Method '%@' not defined in Plugin '%@'", methodName, command.className); - retVal = NO; - } - - return retVal; -} - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVConfigParser.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVConfigParser.h b/CordovaMac/CordovaLib/Commands/CDVConfigParser.h deleted file mode 100644 index 7392580..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVConfigParser.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -@interface CDVConfigParser : NSObject {} - -@property (nonatomic, readonly, strong) NSMutableDictionary* pluginsDict; -@property (nonatomic, readonly, strong) NSMutableDictionary* settings; -@property (nonatomic, readonly, strong) NSMutableArray* whitelistHosts; -@property (nonatomic, readonly, strong) NSMutableArray* startupPluginNames; -@property (nonatomic, readonly, strong) NSString* startPage; - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVConfigParser.m ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVConfigParser.m b/CordovaMac/CordovaLib/Commands/CDVConfigParser.m deleted file mode 100644 index 876d17a..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVConfigParser.m +++ /dev/null @@ -1,70 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVConfigParser.h" - -@interface CDVConfigParser () - -@property (nonatomic, readwrite, strong) NSMutableDictionary* pluginsDict; -@property (nonatomic, readwrite, strong) NSMutableDictionary* settings; -@property (nonatomic, readwrite, strong) NSMutableArray* whitelistHosts; -@property (nonatomic, readwrite, strong) NSMutableArray* startupPluginNames; -@property (nonatomic, readwrite, strong) NSString* startPage; - -@end - -@implementation CDVConfigParser - -@synthesize pluginsDict, settings, whitelistHosts, startPage, startupPluginNames; - -- (id)init -{ - self = [super init]; - if (self != nil) { - self.pluginsDict = [[NSMutableDictionary alloc] initWithCapacity:30]; - self.settings = [[NSMutableDictionary alloc] initWithCapacity:30]; - self.whitelistHosts = [[NSMutableArray alloc] initWithCapacity:30]; - self.startupPluginNames = [[NSMutableArray alloc] initWithCapacity:8]; - } - return self; -} - -- (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict -{ - if ([elementName isEqualToString:@"preference"]) { - settings[attributeDict[@"name"]] = attributeDict[@"value"]; - } else if ([elementName isEqualToString:@"plugin"]) { - NSString* name = [attributeDict[@"name"] lowercaseString]; - pluginsDict[name] = attributeDict[@"value"]; - if ([@"true" isEqualToString:attributeDict[@"onload"]]) { - [self.startupPluginNames addObject:name]; - } - } else if ([elementName isEqualToString:@"access"]) { - [whitelistHosts addObject:attributeDict[@"origin"]]; - } else if ([elementName isEqualToString:@"content"]) { - self.startPage = attributeDict[@"src"]; - } -} - -- (void)parser:(NSXMLParser*)parser parseErrorOccurred:(NSError*)parseError -{ - NSAssert(NO, @"config.xml parse error line %ld col %ld", (long)[parser lineNumber], (long)[parser columnNumber]); -} - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVConnection.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVConnection.h b/CordovaMac/CordovaLib/Commands/CDVConnection.h deleted file mode 100644 index d3e8c5d..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVConnection.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import -#import "CDVPlugin.h" -#import "CDVReachability.h" - -@interface CDVConnection : CDVPlugin { - NSString* type; - NSString* _callbackId; - - CDVReachability* internetReach; -} - -@property (copy) NSString* connectionType; -@property (strong) CDVReachability* internetReach; - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVConnection.m ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVConnection.m b/CordovaMac/CordovaLib/Commands/CDVConnection.m deleted file mode 100644 index 61030d3..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVConnection.m +++ /dev/null @@ -1,125 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVConnection.h" -#import "CDVReachability.h" - -@interface CDVConnection (PrivateMethods) -- (void)updateOnlineStatus; -- (void)sendPluginResult; -@end - -@implementation CDVConnection - -@synthesize connectionType, internetReach; - -- (void)getConnectionInfo:(CDVInvokedUrlCommand*)command -{ - _callbackId = command.callbackId; - [self sendPluginResult]; -} - -- (void)sendPluginResult -{ - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:self.connectionType]; - - [result setKeepCallbackAsBool:YES]; - [self.commandDelegate sendPluginResult:result callbackId:_callbackId]; -} - -- (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability -{ - NetworkStatus networkStatus = [reachability currentReachabilityStatus]; - - switch (networkStatus) { - case NotReachable: - return @"none"; - - case ReachableViaWWAN: - return @"2g"; // no generic default, so we use the lowest common denominator - - case ReachableViaWiFi: - return @"wifi"; - - default: - return @"unknown"; - } -} - -- (BOOL)isCellularConnection:(NSString*)theConnectionType -{ - return [theConnectionType isEqualToString:@"2g"] || - [theConnectionType isEqualToString:@"3g"] || - [theConnectionType isEqualToString:@"4g"]; -} - -- (void)updateReachability:(CDVReachability*)reachability -{ - if (reachability) { - // check whether the connection type has changed - NSString* newConnectionType = [self w3cConnectionTypeFor:reachability]; - if ([newConnectionType isEqualToString:self.connectionType]) { // the same as before, remove dupes - return; - } else { - self.connectionType = [self w3cConnectionTypeFor:reachability]; - } - } - [self sendPluginResult]; -} - -- (void)updateConnectionType:(NSNotification*)note -{ - CDVReachability* curReach = [note object]; - - if ((curReach != nil) && [curReach isKindOfClass:[CDVReachability class]]) { - [self updateReachability:curReach]; - } -} - -- (void)onPause -{ - [self.internetReach stopNotifier]; -} - -- (void)onResume -{ - [self.internetReach startNotifier]; - [self updateReachability:self.internetReach]; -} - -- (CDVPlugin*)initWithWebView:(WebView*)theWebView -{ - self = [super initWithWebView:theWebView]; - if (self) { - self.connectionType = @"none"; - self.internetReach = [CDVReachability reachabilityForInternetConnection]; - self.connectionType = [self w3cConnectionTypeFor:self.internetReach]; - [self.internetReach startNotifier]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateConnectionType:) - name:kReachabilityChangedNotification object:nil]; -// TODO: -// if (&UIApplicationDidEnterBackgroundNotification && &UIApplicationWillEnterForegroundNotification) { -// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onPause) name:UIApplicationDidEnterBackgroundNotification object:nil]; -// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResume) name:UIApplicationWillEnterForegroundNotification object:nil]; -// } - } - return self; -} - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVConsole.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVConsole.h b/CordovaMac/CordovaLib/Commands/CDVConsole.h deleted file mode 100644 index bb44368..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVConsole.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import - - -@interface CDVConsole : NSObject { - -} - -- (void) log:(NSString*)message; - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVConsole.m ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVConsole.m b/CordovaMac/CordovaLib/Commands/CDVConsole.m deleted file mode 100644 index fc4b879..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVConsole.m +++ /dev/null @@ -1,75 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVConsole.h" - - -@implementation CDVConsole - - -- (void) log:(NSString*)message -{ - NSLog(@"%@", message); -} - -#pragma mark WebScripting Protocol - -/* checks whether a selector is acceptable to be called from JavaScript */ -+ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector -{ - BOOL result = YES; - - int i = 0; - static SEL * acceptableList = NULL; - SEL currentSelector; - - if (acceptableList == NULL && (acceptableList = calloc(256, sizeof(SEL)))) // up to 256 selectors - { - acceptableList[i++] = @selector(log:); - } - - i = 0; - while (result == YES && (currentSelector = acceptableList[i++])) - { - //checking for exclusions - result = !(selector == currentSelector); - } - - return result; -} - -/* helper function so we don't have to have underscores and stuff in js to refer to the right method */ -+ (NSString*) webScriptNameForSelector:(SEL)aSelector -{ - id result = nil; - - if (aSelector == @selector(log:)) { - result = @"log"; - } - - return result; -} - -// right now exclude all properties (eg keys) -+ (BOOL) isKeyExcludedFromWebScript:(const char*)name -{ - return YES; -} - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVDebug.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVDebug.h b/CordovaMac/CordovaLib/Commands/CDVDebug.h deleted file mode 100644 index 4a0d9f9..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVDebug.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#ifdef DEBUG - #define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) -#else - #define DLog(...) -#endif -#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVDevice.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVDevice.h b/CordovaMac/CordovaLib/Commands/CDVDevice.h deleted file mode 100644 index 81cffb7..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVDevice.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVPlugin.h" - -@interface CDVDevice : CDVPlugin -{} - -+ (NSString*)cordovaVersion; - -- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command; - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVDevice.m ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVDevice.m b/CordovaMac/CordovaLib/Commands/CDVDevice.m deleted file mode 100644 index 2338374..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVDevice.m +++ /dev/null @@ -1,116 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#include -#include - -#import "CDVDevice.h" -#import "CDVAvailability.h" - -#define SYSTEM_VERSION_PLIST @"/System/Library/CoreServices/SystemVersion.plist" - -@implementation CDVDevice - -- (NSString*)modelVersion -{ - size_t size; - - sysctlbyname("hw.machine", NULL, &size, NULL, 0); - char* machine = malloc(size); - sysctlbyname("hw.machine", machine, &size, NULL, 0); - NSString* modelVersion = [NSString stringWithUTF8String:machine]; - free(machine); - - return modelVersion; -} - -- (NSString*)model -{ - size_t size; - - sysctlbyname("hw.model", NULL, &size, NULL, 0); - char* model = malloc(size); - sysctlbyname("hw.model", model, &size, NULL, 0); - NSString* name = [NSString stringWithUTF8String:model]; - free(model); - - return name; -} - -- (NSString*)uniqueAppInstanceIdentifier -{ - NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; - static NSString* UUID_KEY = @"CDVUUID"; - - NSString* app_uuid = [userDefaults stringForKey:UUID_KEY]; - - if (app_uuid == nil) { - CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault); - CFStringRef uuidString = CFUUIDCreateString(kCFAllocatorDefault, uuidRef); - - app_uuid = [NSString stringWithString:(__bridge NSString*)uuidString]; - [userDefaults setObject:app_uuid forKey:UUID_KEY]; - [userDefaults synchronize]; - - CFRelease(uuidString); - CFRelease(uuidRef); - } - - return app_uuid; -} - -- (NSString*) platform -{ - return [[NSDictionary dictionaryWithContentsOfFile:SYSTEM_VERSION_PLIST] objectForKey:@"ProductName"]; -} - -- (NSString*)systemVersion -{ - return [[NSDictionary dictionaryWithContentsOfFile:SYSTEM_VERSION_PLIST] objectForKey:@"ProductVersion"]; -} - -- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command -{ - NSDictionary* deviceProperties = [self deviceProperties]; - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties]; - - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; -} - -- (NSDictionary*)deviceProperties -{ - NSMutableDictionary* devProps = [NSMutableDictionary dictionaryWithCapacity:4]; - - [devProps setObject:[self modelVersion] forKey:@"model"]; - [devProps setObject:[self platform] forKey:@"platform"]; - [devProps setObject:[self systemVersion] forKey:@"version"]; - [devProps setObject:[self uniqueAppInstanceIdentifier] forKey:@"uuid"]; - [devProps setObject:[self model] forKey:@"name"]; - [devProps setObject:[[self class] cordovaVersion] forKey:@"cordova"]; - - NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps]; - return devReturn; -} - -+ (NSString*)cordovaVersion -{ - return CDV_VERSION; -} - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVInvokedUrlCommand.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVInvokedUrlCommand.h b/CordovaMac/CordovaLib/Commands/CDVInvokedUrlCommand.h deleted file mode 100644 index 5f7e204..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVInvokedUrlCommand.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import - -@interface CDVInvokedUrlCommand : NSObject { - NSString* __weak _callbackId; - NSString* __weak _className; - NSString* __weak _methodName; - NSArray* __weak _arguments; -} - -@property (weak, nonatomic, readonly) NSArray* arguments; -@property (weak, nonatomic, readonly) NSString* callbackId; -@property (weak, nonatomic, readonly) NSString* className; -@property (weak, nonatomic, readonly) NSString* methodName; - -+ (CDVInvokedUrlCommand*)commandFromJson:(NSArray*)jsonEntry; - -- (id)initWithArguments:(NSArray*)arguments - callbackId :(NSString*)callbackId - className :(NSString*)className - methodName :(NSString*)methodName; - -- (id)initFromJson:(NSArray*)jsonEntry; - -// Returns the argument at the given index. -// If index >= the number of arguments, returns nil. -// If the argument at the given index is NSNull, returns nil. -- (id)argumentAtIndex:(NSUInteger)index; -// Same as above, but returns defaultValue instead of nil. -- (id)argumentAtIndex:(NSUInteger)index withDefault:(id)defaultValue; -// Same as above, but returns defaultValue instead of nil, and if the argument is not of the expected class, returns defaultValue -- (id)argumentAtIndex:(NSUInteger)index withDefault:(id)defaultValue andClass:(Class)aClass; - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVInvokedUrlCommand.m ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVInvokedUrlCommand.m b/CordovaMac/CordovaLib/Commands/CDVInvokedUrlCommand.m deleted file mode 100644 index 6c7a856..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVInvokedUrlCommand.m +++ /dev/null @@ -1,140 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVInvokedUrlCommand.h" -#import "CDVJSON.h" -#import "NSData+Base64.h" - -@implementation CDVInvokedUrlCommand - -@synthesize arguments = _arguments; -@synthesize callbackId = _callbackId; -@synthesize className = _className; -@synthesize methodName = _methodName; - -+ (CDVInvokedUrlCommand*)commandFromJson:(NSArray*)jsonEntry -{ - return [[CDVInvokedUrlCommand alloc] initFromJson:jsonEntry]; -} - -- (id)initFromJson:(NSArray*)jsonEntry -{ - id tmp = [jsonEntry objectAtIndex:0]; - NSString* callbackId = tmp == [NSNull null] ? nil : tmp; - NSString* className = [jsonEntry objectAtIndex:1]; - NSString* methodName = [jsonEntry objectAtIndex:2]; - NSMutableArray* arguments = [jsonEntry objectAtIndex:3]; - - return [self initWithArguments:arguments - callbackId:callbackId - className:className - methodName:methodName]; -} - -- (id)initWithArguments:(NSArray*)arguments - callbackId:(NSString*)callbackId - className:(NSString*)className - methodName:(NSString*)methodName -{ - self = [super init]; - if (self != nil) { - _arguments = arguments; - _callbackId = callbackId; - _className = className; - _methodName = methodName; - } - [self massageArguments]; - return self; -} - -- (void)massageArguments -{ - NSMutableArray* newArgs = nil; - - for (NSUInteger i = 0, count = [_arguments count]; i < count; ++i) { - id arg = [_arguments objectAtIndex:i]; - if (![arg isKindOfClass:[NSDictionary class]]) { - continue; - } - NSDictionary* dict = arg; - NSString* type = [dict objectForKey:@"CDVType"]; - if (!type || ![type isEqualToString:@"ArrayBuffer"]) { - continue; - } - NSString* data = [dict objectForKey:@"data"]; - if (!data) { - continue; - } - if (newArgs == nil) { - newArgs = [NSMutableArray arrayWithArray:_arguments]; - _arguments = newArgs; - } - [newArgs replaceObjectAtIndex:i withObject:[NSData dataFromBase64String:data]]; - } -} - -- (void)legacyArguments:(NSMutableArray**)legacyArguments andDict:(NSMutableDictionary**)legacyDict -{ - NSMutableArray* newArguments = [NSMutableArray arrayWithArray:_arguments]; - - for (NSUInteger i = 0; i < [newArguments count]; ++i) { - if ([[newArguments objectAtIndex:i] isKindOfClass:[NSDictionary class]]) { - if (legacyDict != NULL) { - *legacyDict = [newArguments objectAtIndex:i]; - } - [newArguments removeObjectAtIndex:i]; - break; - } - } - - // Legacy (two versions back) has no callbackId. - if (_callbackId != nil) { - [newArguments insertObject:_callbackId atIndex:0]; - } - if (legacyArguments != NULL) { - *legacyArguments = newArguments; - } -} - -- (id)argumentAtIndex:(NSUInteger)index -{ - return [self argumentAtIndex:index withDefault:nil]; -} - -- (id)argumentAtIndex:(NSUInteger)index withDefault:(id)defaultValue -{ - return [self argumentAtIndex:index withDefault:defaultValue andClass:nil]; -} - -- (id)argumentAtIndex:(NSUInteger)index withDefault:(id)defaultValue andClass:(Class)aClass -{ - if (index >= [_arguments count]) { - return defaultValue; - } - id ret = [_arguments objectAtIndex:index]; - if (ret == [NSNull null]) { - ret = defaultValue; - } - if ((aClass != nil) && ![ret isKindOfClass:aClass]) { - ret = defaultValue; - } - return ret; -} - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVJSON.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVJSON.h b/CordovaMac/CordovaLib/Commands/CDVJSON.h deleted file mode 100644 index eaa895e..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVJSON.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -@interface NSArray (CDVJSONSerializing) -- (NSString*)JSONString; -@end - -@interface NSDictionary (CDVJSONSerializing) -- (NSString*)JSONString; -@end - -@interface NSString (CDVJSONSerializing) -- (id)JSONObject; -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVJSON.m ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVJSON.m b/CordovaMac/CordovaLib/Commands/CDVJSON.m deleted file mode 100644 index 78267e5..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVJSON.m +++ /dev/null @@ -1,77 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVJSON.h" -#import - -@implementation NSArray (CDVJSONSerializing) - -- (NSString*)JSONString -{ - NSError* error = nil; - NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self - options:NSJSONWritingPrettyPrinted - error:&error]; - - if (error != nil) { - NSLog(@"NSArray JSONString error: %@", [error localizedDescription]); - return nil; - } else { - return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; - } -} - -@end - -@implementation NSDictionary (CDVJSONSerializing) - -- (NSString*)JSONString -{ - NSError* error = nil; - NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self - options:NSJSONWritingPrettyPrinted - error:&error]; - - if (error != nil) { - NSLog(@"NSDictionary JSONString error: %@", [error localizedDescription]); - return nil; - } else { - return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; - } -} - -@end - -@implementation NSString (CDVJSONSerializing) - -- (id)JSONObject -{ - NSError* error = nil; - id object = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding] - options:kNilOptions - error:&error]; - - if (error != nil) { - NSLog(@"NSString JSONObject error: %@", [error localizedDescription]); - } - - return object; -} - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/5a67ee70/CordovaMac/CordovaLib/Commands/CDVPlugin.h ---------------------------------------------------------------------- diff --git a/CordovaMac/CordovaLib/Commands/CDVPlugin.h b/CordovaMac/CordovaLib/Commands/CDVPlugin.h deleted file mode 100644 index f9debe5..0000000 --- a/CordovaMac/CordovaLib/Commands/CDVPlugin.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import -#import -#import "CDVPluginResult.h" -#import "CDVCommandDelegate.h" -#import "CDVViewController.h" - -NSString* const CDVPageDidLoadNotification; -NSString* const CDVPluginHandleOpenURLNotification; -NSString* const CDVPluginResetNotification; -NSString* const CDVLocalNotification; - -@interface CDVPlugin : NSObject {} - -@property (nonatomic, weak) WebView* webView; -@property (nonatomic, unsafe_unretained) CDVViewController* viewController; -@property (nonatomic, unsafe_unretained) id commandDelegate; - -@property (readonly, assign) BOOL hasPendingOperation; - -- (CDVPlugin*)initWithWebView:(WebView*)theWebView; -- (void)pluginInitialize; - -- (void)handleOpenURL:(NSNotification*)notification; -- (void)onAppTerminate; -- (void)onMemoryWarning; -- (void)onReset; -- (void)dispose; - -/* - // see initWithWebView implementation - - (void) onPause {} - - (void) onResume {} - - (void) onOrientationWillChange {} - - (void) onOrientationDidChange {} - - (void)didReceiveLocalNotification:(NSNotification *)notification; - */ - -- (id)appDelegate; - -@end