Skip to content

Commit

Permalink
Merge branch 'feature/cordova-2.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
grgar committed Apr 19, 2013
2 parents 43bb148 + cf78ac4 commit 2eca1a1
Show file tree
Hide file tree
Showing 41 changed files with 1,365 additions and 4,193 deletions.
3 changes: 1 addition & 2 deletions CordovaLib/Classes/CDV.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#import "CDVConnection.h"
#import "CDVContact.h"
#import "CDVContacts.h"
#import "CDVCordovaView.h"
#import "CDVDebug.h"
#import "CDVDebugConsole.h"
#import "CDVDevice.h"
Expand All @@ -55,4 +54,4 @@
#import "NSMutableArray+QueueAdditions.h"
#import "UIDevice+Extensions.h"

#import "JSONKit.h"
#import "CDVJSON.h"
3 changes: 2 additions & 1 deletion CordovaLib/Classes/CDVAvailability.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#define __CORDOVA_2_1_0 20100
#define __CORDOVA_2_2_0 20200
#define __CORDOVA_2_3_0 20300
#define __CORDOVA_2_4_0 20400
#define __CORDOVA_NA 99999 /* not available */

/*
Expand All @@ -45,7 +46,7 @@
#endif
*/
#ifndef CORDOVA_VERSION_MIN_REQUIRED
#define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_2_3_0
#define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_2_4_0
#endif

/*
Expand Down
3 changes: 2 additions & 1 deletion CordovaLib/Classes/CDVCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

enum CDVDestinationType {
DestinationTypeDataUrl = 0,
DestinationTypeFileUri
DestinationTypeFileUri,
DestinationTypeNativeUri
};
typedef NSUInteger CDVDestinationType;

Expand Down
3 changes: 3 additions & 0 deletions CordovaLib/Classes/CDVCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingM
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[[NSURL fileURLWithPath:filePath] absoluteString]];
}
} else if (cameraPicker.returnType == DestinationTypeNativeUri) {
NSString* nativeUri = [(NSURL*)[info objectForKey:UIImagePickerControllerReferenceURL] absoluteString];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nativeUri];
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[data base64EncodedString]];
}
Expand Down
4 changes: 2 additions & 2 deletions CordovaLib/Classes/CDVCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one
*/

#import "CDVCapture.h"
#import "JSONKit.h"
#import "CDVJSON.h"
#import "CDVAvailability.h"
#import "CDVViewController.h"

Expand Down Expand Up @@ -329,7 +329,7 @@ - (void)getMediaModes:(CDVInvokedUrlCommand*)command
movieArray ? (NSObject*) movieArray:[NSNull null], @"video",
audioArray ? (NSObject*) audioArray:[NSNull null], @"audio",
nil];
NSString* jsString = [NSString stringWithFormat:@"navigator.device.capture.setSupportedModes(%@);", [modes cdvjk_JSONString]];
NSString* jsString = [NSString stringWithFormat:@"navigator.device.capture.setSupportedModes(%@);", [modes JSONString]];
[self.commandDelegate evalJs:jsString];
}

Expand Down
2 changes: 2 additions & 0 deletions CordovaLib/Classes/CDVCommandDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@
- (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;

@end
13 changes: 11 additions & 2 deletions CordovaLib/Classes/CDVCommandDelegateImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one
*/

#import "CDVCommandDelegateImpl.h"

#import "CDVJSON.h"
#import "CDVCommandQueue.h"
#import "CDVPluginResult.h"
#import "CDVViewController.h"
Expand Down Expand Up @@ -78,13 +78,17 @@ - (void)evalJsHelper:(NSString*)js

- (void)sendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId
{
// 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];
id message = result.message == nil ? [NSNull null] : result.message;

// Use an array to encode the message as JSON.
message = [NSArray arrayWithObject:message];
NSString* encodedMessage = [message cdvjk_JSONString];
NSString* encodedMessage = [message JSONString];
// And then strip off the outer []s.
encodedMessage = [encodedMessage substringWithRange:NSMakeRange(1, [encodedMessage length] - 2)];
NSString* js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeCallback('%@',%d,%@,%d)",
Expand Down Expand Up @@ -128,4 +132,9 @@ - (void)runInBackground:(void (^)())block
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
}

- (NSString*)userAgent
{
return [_viewController userAgent];
}

@end
4 changes: 2 additions & 2 deletions CordovaLib/Classes/CDVCommandQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ - (void)executePending

for (NSUInteger i = 0; i < [_queue count]; ++i) {
// Parse the returned JSON array.
NSArray* commandBatch = [[_queue objectAtIndex:i] cdvjk_mutableObjectFromJSONString];
NSArray* commandBatch = [[_queue objectAtIndex:i] JSONObject];

// Iterate over and execute all of the commands.
for (NSArray* jsonEntry in commandBatch) {
CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonEntry];
if (![self execute:command]) {
#ifdef DEBUG
NSString* commandJson = [jsonEntry cdvjk_JSONString];
NSString* commandJson = [jsonEntry JSONString];
static NSUInteger maxLogLength = 1024;
NSString* commandString = ([commandJson length] > maxLogLength) ?
[NSString stringWithFormat:@"%@[...]", [commandJson substringToIndex:maxLogLength]] :
Expand Down
6 changes: 4 additions & 2 deletions CordovaLib/Classes/CDVConfigParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
under the License.
*/

@interface CDVConfigParser : NSObject <NSXMLParserDelegate> {
}
@interface CDVConfigParser : NSObject <NSXMLParserDelegate>{}

@property (nonatomic, readonly, strong) NSMutableDictionary* pluginsDict;
@property (nonatomic, readonly, strong) NSMutableDictionary* settings;
@property (nonatomic, readonly, strong) NSMutableArray* whitelistHosts;
@property (nonatomic, readonly, strong) NSString* startPage;

- (NSString*)getStartPage;

@end
14 changes: 13 additions & 1 deletion CordovaLib/Classes/CDVConfigParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ @interface CDVConfigParser ()
@property (nonatomic, readwrite, strong) NSMutableDictionary* pluginsDict;
@property (nonatomic, readwrite, strong) NSMutableDictionary* settings;
@property (nonatomic, readwrite, strong) NSMutableArray* whitelistHosts;
@property (nonatomic, readwrite, strong) NSString* startPage;

@end

@implementation CDVConfigParser

@synthesize pluginsDict, settings, whitelistHosts;
@synthesize pluginsDict, settings, whitelistHosts, startPage;

- (id)init
{
Expand All @@ -50,6 +51,8 @@ - (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName names
[pluginsDict setObject:[attributeDict objectForKey:@"value"] forKey:[attributeDict objectForKey:@"name"]];
} else if ([elementName isEqualToString:@"access"]) {
[whitelistHosts addObject:[attributeDict objectForKey:@"origin"]];
} else if ([elementName isEqualToString:@"content"]) {
self.startPage = [attributeDict objectForKey:@"src"];
}
}

Expand All @@ -58,4 +61,13 @@ - (void)parser:(NSXMLParser*)parser parseErrorOccurred:(NSError*)parseError
NSAssert(NO, @"config.xml parse error line %d col %d", [parser lineNumber], [parser columnNumber]);
}

- (NSString*)getStartPage
{
if (self.startPage != nil) {
return self.startPage;
} else {
return @"index.html";
}
}

@end
49 changes: 35 additions & 14 deletions CordovaLib/Classes/CDVContact.m
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ - (NSObject*)extractAddresses
if (fields == nil) { // no name fields requested
return nil;
}
id __weak value;
CFStringRef value;
NSObject* addresses;
ABMultiValueRef multi = ABRecordCopyValue(self.record, kABPersonAddressProperty);
CFIndex count = multi ? ABMultiValueGetCount(multi) : 0;
Expand Down Expand Up @@ -1174,7 +1174,13 @@ - (NSObject*)extractAddresses
id key = [[CDVContact defaultW3CtoAB] valueForKey:k];
if (key && ![k isKindOfClass:[NSNull class]]) {
bFound = CFDictionaryGetValueIfPresent(dict, (__bridge const void*)key, (void*)&value);
[newAddress setObject:(bFound && value != NULL) ? (id) value:[NSNull null] forKey:k];
if (bFound && (value != NULL)) {
CFRetain(value);
[newAddress setObject:(__bridge id)value forKey:k];
CFRelease(value);
} else {
[newAddress setObject:[NSNull null] forKey:k];
}
} else {
// was a property that iPhone doesn't support
[newAddress setObject:[NSNull null] forKey:k];
Expand Down Expand Up @@ -1221,16 +1227,28 @@ - (NSObject*)extractIms
NSMutableDictionary* newDict = [NSMutableDictionary dictionaryWithCapacity:3];
// iOS has label property (work, home, other) for each IM but W3C contact API doesn't use
CFDictionaryRef dict = (CFDictionaryRef)ABMultiValueCopyValueAtIndex(multi, i);
NSString* __weak value; // all values should be CFStringRefs / NSString*
CFStringRef value; // all values should be CFStringRefs / NSString*
bool bFound;
if ([fields containsObject:kW3ContactFieldValue]) {
// value = user name
bFound = CFDictionaryGetValueIfPresent(dict, kABPersonInstantMessageUsernameKey, (void*)&value);
[newDict setObject:(bFound && value != NULL) ? (id) value:[NSNull null] forKey:kW3ContactFieldValue];
if (bFound && (value != NULL)) {
CFRetain(value);
[newDict setObject:(__bridge id)value forKey:kW3ContactFieldValue];
CFRelease(value);
} else {
[newDict setObject:[NSNull null] forKey:kW3ContactFieldValue];
}
}
if ([fields containsObject:kW3ContactFieldType]) {
bFound = CFDictionaryGetValueIfPresent(dict, kABPersonInstantMessageServiceKey, (void*)&value);
[newDict setObject:(bFound && value != NULL) ? (id)[[CDVContact class] convertPropertyLabelToContactType:value]:[NSNull null] forKey:kW3ContactFieldType];
if (bFound && (value != NULL)) {
CFRetain(value);
[newDict setObject:(id)[[CDVContact class] convertPropertyLabelToContactType:(__bridge NSString*)value] forKey:kW3ContactFieldType];
CFRelease(value);
} else {
[newDict setObject:[NSNull null] forKey:kW3ContactFieldType];
}
}
// always set ID
id identifier = [NSNumber numberWithUnsignedInt:ABMultiValueGetIdentifierAtIndex(multi, i)];
Expand Down Expand Up @@ -1311,13 +1329,14 @@ - (NSObject*)extractPhotos
// get the temp directory path
NSString* docsPath = [NSTemporaryDirectory ()stringByStandardizingPath];
NSError* err = nil;
NSFileManager* fileMgr = [[NSFileManager alloc] init];
// generate unique file name
NSString* filePath;
int i = 1;
do {
filePath = [NSString stringWithFormat:@"%@/photo_%03d.jpg", docsPath, i++];
} while ([fileMgr fileExistsAtPath:filePath]);
NSString* filePath = [NSString stringWithFormat:@"%@/photo_XXXXX", docsPath];
char template[filePath.length + 1];
strcpy(template, [filePath cStringUsingEncoding:NSASCIIStringEncoding]);
mkstemp(template);
filePath = [[NSFileManager defaultManager]
stringWithFileSystemRepresentation:template
length:strlen(template)];

// save file
if ([data writeToFile:filePath options:NSAtomicWrite error:&err]) {
photos = [NSMutableArray arrayWithCapacity:1];
Expand Down Expand Up @@ -1694,7 +1713,7 @@ - (BOOL)searchContactFields:(NSArray*)fields forMVDictionaryProperty:(ABProperty

for (NSString* member in fields) {
NSString* abKey = [[CDVContact defaultW3CtoAB] valueForKey:member]; // im and address fields are all strings
NSString* __weak abValue = nil;
CFStringRef abValue = nil;
if (abKey) {
NSString* testString = nil;
if ([member isEqualToString:kW3ContactImType]) {
Expand All @@ -1708,8 +1727,10 @@ - (BOOL)searchContactFields:(NSArray*)fields forMVDictionaryProperty:(ABProperty
if (testString != nil) {
BOOL bExists = CFDictionaryGetValueIfPresent(dict, (__bridge const void*)abKey, (void*)&abValue);
if (bExists) {
CFRetain(abValue);
NSPredicate* containPred = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@", testString];
bFound = [containPred evaluateWithObject:abValue];
bFound = [containPred evaluateWithObject:(__bridge id)abValue];
CFRelease(abValue);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CordovaLib/Classes/CDVDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ - (void)getDeviceInfo:(CDVInvokedUrlCommand*)command
NSDictionary* temp = [CDVViewController getBundlePlist:@"Settings"];

if ([temp respondsToSelector:@selector(JSONString)]) {
NSString* js = [NSString stringWithFormat:@"window.Settings = %@;", [temp cdvjk_JSONString]];
NSString* js = [NSString stringWithFormat:@"window.Settings = %@;", [temp JSONString]];
[self.commandDelegate evalJs:js];
}

Expand Down
14 changes: 12 additions & 2 deletions CordovaLib/Classes/CDVEcho.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ @implementation CDVEcho

- (void)echo:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[command.arguments objectAtIndex:0]];
id message = [command.arguments objectAtIndex:0];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
Expand All @@ -36,9 +37,18 @@ - (void)echoAsyncHelper:(NSArray*)args

- (void)echoAsync:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[command.arguments objectAtIndex:0]];
id message = [command.arguments objectAtIndex:0];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];

[self performSelector:@selector(echoAsyncHelper:) withObject:[NSArray arrayWithObjects:pluginResult, command.callbackId, nil] afterDelay:0];
}

- (void)echoArrayBuffer:(CDVInvokedUrlCommand*)command
{
id message = [command.arguments objectAtIndex:0];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArrayBuffer:message];

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

@end
2 changes: 2 additions & 0 deletions CordovaLib/Classes/CDVFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ enum CDVFileSystemType {
};
typedef int CDVFileSystemType;

extern NSString* const kCDVAssetsLibraryPrefix;

@interface CDVFile : CDVPlugin {
NSString* appDocsPath;
NSString* appLibraryPath;
Expand Down
Loading

0 comments on commit 2eca1a1

Please sign in to comment.