Skip to content

Commit

Permalink
Merge branch 'release/1.2' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
grgar committed Jun 5, 2013
2 parents c092faf + 6267af8 commit 3ff6dc5
Show file tree
Hide file tree
Showing 68 changed files with 3,677 additions and 1,270 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ build
*~.xib
.DS_Store
xcuserdata/
*.diff
2 changes: 1 addition & 1 deletion CordovaLib/Classes/CDV.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#import "CDVContact.h"
#import "CDVContacts.h"
#import "CDVDebug.h"
#import "CDVDebugConsole.h"
#import "CDVDevice.h"
#import "CDVFile.h"
#import "CDVFileTransfer.h"
Expand All @@ -47,6 +46,7 @@
#import "CDVLocalStorage.h"
#import "CDVInAppBrowser.h"
#import "CDVScreenOrientationDelegate.h"
#import "CDVTimer.h"

#import "NSArray+Comparisons.h"
#import "NSData+Base64.h"
Expand Down
20 changes: 16 additions & 4 deletions CordovaLib/Classes/CDVAvailability.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
under the License.
*/

#define __CORDOVA_IOS__

#define __CORDOVA_0_9_6 906
#define __CORDOVA_1_0_0 10000
#define __CORDOVA_1_1_0 10100
Expand All @@ -37,6 +39,8 @@
#define __CORDOVA_2_3_0 20300
#define __CORDOVA_2_4_0 20400
#define __CORDOVA_2_5_0 20500
#define __CORDOVA_2_6_0 20600
#define __CORDOVA_2_7_0 20700
#define __CORDOVA_NA 99999 /* not available */

/*
Expand All @@ -47,7 +51,7 @@
#endif
*/
#ifndef CORDOVA_VERSION_MIN_REQUIRED
#define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_2_5_0
#define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_2_7_0
#endif

/*
Expand All @@ -65,12 +69,20 @@

/* 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]
(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
4 changes: 2 additions & 2 deletions CordovaLib/Classes/CDVCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ typedef NSUInteger CDVMediaType;
// ======================================================================= //

@interface CDVCamera : CDVPlugin <UIImagePickerControllerDelegate,
UINavigationControllerDelegate,
UIPopoverControllerDelegate>
UINavigationControllerDelegate,
UIPopoverControllerDelegate>
{}

@property (strong) CDVCameraPicker* pickerController;
Expand Down
24 changes: 18 additions & 6 deletions CordovaLib/Classes/CDVCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one
*/

#import "CDVCamera.h"
#import "CDVJpegHeaderWriter.h"
#import "NSArray+Comparisons.h"
#import "NSData+Base64.h"
#import "NSDictionary+Extensions.h"
Expand Down Expand Up @@ -60,6 +61,8 @@ - (BOOL)popoverSupported
* 7 allowsEdit
* 8 correctOrientation
* 9 saveToPhotoAlbum
* 10 popoverOptions
* 11 cameraDirection
*/
- (void)takePicture:(CDVInvokedUrlCommand*)command
{
Expand Down Expand Up @@ -122,18 +125,22 @@ - (void)takePicture:(CDVInvokedUrlCommand*)command
cameraPicker.returnType = ([arguments objectAtIndex:1]) ? [[arguments objectAtIndex:1] intValue] : DestinationTypeFileUri;

if (sourceType == UIImagePickerControllerSourceTypeCamera) {
// we only allow taking pictures (no video) in this api
// We only allow taking pictures (no video) in this API.
cameraPicker.mediaTypes = [NSArray arrayWithObjects:(NSString*)kUTTypeImage, nil];

// We can only set the camera device if we're actually using the camera.
NSNumber* cameraDirection = [command argumentAtIndex:11 withDefault:[NSNumber numberWithInteger:UIImagePickerControllerCameraDeviceRear]];
cameraPicker.cameraDevice = (UIImagePickerControllerCameraDevice)[cameraDirection intValue];
} else if (mediaType == MediaTypeAll) {
cameraPicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
} else {
NSArray* mediaArray = [NSArray arrayWithObjects:(NSString*)(mediaType == MediaTypeVideo ? kUTTypeMovie:kUTTypeImage), nil];
NSArray* mediaArray = [NSArray arrayWithObjects:(NSString*)(mediaType == MediaTypeVideo ? kUTTypeMovie : kUTTypeImage), nil];
cameraPicker.mediaTypes = mediaArray;
}

if ([self popoverSupported] && (sourceType != UIImagePickerControllerSourceTypeCamera)) {
if (cameraPicker.popoverController == nil) {
cameraPicker.popoverController = [[NSClassFromString (@"UIPopoverController")alloc] initWithContentViewController:cameraPicker];
cameraPicker.popoverController = [[NSClassFromString(@"UIPopoverController")alloc] initWithContentViewController:cameraPicker];
}
NSDictionary* options = [command.arguments objectAtIndex:10 withDefault:nil];
[self displayPopover:options];
Expand Down Expand Up @@ -289,12 +296,17 @@ - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingM
data = UIImagePNGRepresentation(scaledImage == nil ? image : scaledImage);
} else {
data = UIImageJPEGRepresentation(scaledImage == nil ? image : scaledImage, cameraPicker.quality / 100.0f);

/* splice loc */
CDVJpegHeaderWriter* exifWriter = [[CDVJpegHeaderWriter alloc] init];
NSString* headerstring = [exifWriter createExifAPP1:[info objectForKey:@"UIImagePickerControllerMediaMetadata"]];
data = [exifWriter spliceExifBlockIntoJpeg:data withExifBlock:headerstring];
}

if (cameraPicker.returnType == DestinationTypeFileUri) {
// write to temp directory and return URI
// get the temp directory path
NSString* docsPath = [NSTemporaryDirectory ()stringByStandardizingPath];
NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath];
NSError* err = nil;
NSFileManager* fileMgr = [[NSFileManager alloc] init]; // recommended by apple (vs [NSFileManager defaultManager]) to be threadsafe
// generate unique file name
Expand Down Expand Up @@ -419,7 +431,7 @@ - (UIImage*)imageCorrectedForCaptureOrientation:(UIImage*)anImage
rotation_radians = 0.0;
break;

case UIImageOrientationDown :
case UIImageOrientationDown:
rotation_radians = M_PI; // don't be scared of radians, if you're reading this, you're good at math
break;

Expand Down Expand Up @@ -518,7 +530,7 @@ - (void)postImage:(UIImage*)anImage withFilename:(NSString*)filename toUrl:(NSUR
// first parameter an image
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"upload\"; filename=\"%@\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Type: image/png\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Type: image/png\r\n\r\n" dataUsingEncoding : NSUTF8StringEncoding]];
[postBody appendData:imageData];

// // second parameter information
Expand Down
10 changes: 4 additions & 6 deletions CordovaLib/Classes/CDVCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ - (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCal
}

// write to temp directory and return URI
NSString* docsPath = [NSTemporaryDirectory ()stringByStandardizingPath]; // use file system temporary directory
NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath]; // use file system temporary directory
NSError* err = nil;
NSFileManager* fileMgr = [[NSFileManager alloc] init];

Expand Down Expand Up @@ -439,7 +439,7 @@ - (NSDictionary*)getMediaDictionaryFromPath:(NSString*)fullPath ofType:(NSString
if ([command isKindOfClass:[CDVFile class]]) {
CDVFile* cdvFile = (CDVFile*)command;
NSString* mimeType = [cdvFile getMimeTypeFromPath:fullPath];
[fileDict setObject:(mimeType != nil ? (NSObject*)mimeType:[NSNull null]) forKey:@"type"];
[fileDict setObject:(mimeType != nil ? (NSObject*)mimeType : [NSNull null]) forKey:@"type"];
}
}
NSDictionary* fileAttrs = [fileMgr attributesOfItemAtPath:fullPath error:nil];
Expand Down Expand Up @@ -533,7 +533,6 @@ - (NSUInteger)supportedInterfaceOrientations
// delegate to CVDAudioRecorderViewController
return [self.topViewController supportedInterfaceOrientations];
}

#endif

@end
Expand Down Expand Up @@ -663,7 +662,7 @@ - (void)viewDidLoad

// create file to record to in temporary dir

NSString* docsPath = [NSTemporaryDirectory ()stringByStandardizingPath]; // use file system temporary directory
NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath]; // use file system temporary directory
NSError* err = nil;
NSFileManager* fileMgr = [[NSFileManager alloc] init];

Expand Down Expand Up @@ -701,7 +700,6 @@ - (NSUInteger)supportedInterfaceOrientations
orientation = orientation | (supported & UIInterfaceOrientationMaskPortraitUpsideDown);
return orientation;
}

#endif

- (void)viewDidUnload
Expand Down Expand Up @@ -766,7 +764,7 @@ - (void)stopRecordingCleanup
BOOL isUIAccessibilityAnnouncementNotification = (&UIAccessibilityAnnouncementNotification != NULL);
if (isUIAccessibilityAnnouncementNotification) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 500ull * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
UIAccessibilityPostNotification (UIAccessibilityAnnouncementNotification, NSLocalizedString (@"timed recording complete", nil));
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, NSLocalizedString(@"timed recording complete", nil));
});
}
} else {
Expand Down
1 change: 0 additions & 1 deletion CordovaLib/Classes/CDVCommandDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

- (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.
Expand Down
22 changes: 8 additions & 14 deletions CordovaLib/Classes/CDVCommandDelegateImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ - (NSString*)pathForResource:(NSString*)resourcepath

- (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.");
}

[_commandQueue enqueCommandBatch:commandsJSON];
}
Expand All @@ -78,21 +82,16 @@ - (void)evalJsHelper:(NSString*)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]) {
if ([@"INVALID" isEqualToString : callbackId]) {
return;
}
int status = [result.status intValue];
BOOL keepCallback = [result.keepCallback boolValue];
id message = result.message == nil ? [NSNull null] : result.message;
NSString* argumentsAsJSON = [result argumentsAsJSON];

// Use an array to encode the message as JSON.
message = [NSArray arrayWithObject:message];
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)",
callbackId, status, encodedMessage, keepCallback];
NSString* js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeCallback('%@',%d,%@,%d)", callbackId, status, argumentsAsJSON, keepCallback];

[self evalJsHelper:js];
}
Expand Down Expand Up @@ -122,11 +121,6 @@ - (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);
Expand Down
8 changes: 1 addition & 7 deletions CordovaLib/Classes/CDVCommandQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@
@class CDVInvokedUrlCommand;
@class CDVViewController;

@interface CDVCommandQueue : NSObject {
@private
NSInteger _lastCommandQueueFlushRequestId;
__weak CDVViewController* _viewController;
NSMutableArray* _queue;
BOOL _currentlyExecuting;
}
@interface CDVCommandQueue : NSObject

@property (nonatomic, readonly) BOOL currentlyExecuting;

Expand Down
17 changes: 15 additions & 2 deletions CordovaLib/Classes/CDVCommandQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ Licensed to the Apache Software Foundation (ASF) under one
#import "CDVViewController.h"
#import "CDVCommandDelegateImpl.h"

@interface CDVCommandQueue () {
NSInteger _lastCommandQueueFlushRequestId;
__weak CDVViewController* _viewController;
NSMutableArray* _queue;
BOOL _currentlyExecuting;
}
@end

@implementation CDVCommandQueue

@synthesize currentlyExecuting = _currentlyExecuting;
Expand Down Expand Up @@ -74,6 +82,9 @@ - (void)fetchCommandsFromJs
@"cordova.require('cordova/exec').nativeFetchMessages()"];

[self enqueCommandBatch:queuedCommandsJSON];
if ([queuedCommandsJSON length] > 0) {
CDV_EXEC_LOG(@"Exec: Retrieved new exec messages by request.");
}
}

- (void)executePending
Expand All @@ -92,13 +103,15 @@ - (void)executePending
// 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;
[NSString stringWithFormat:@"%@[...]", [commandJson substringToIndex:maxLogLength]] :
commandJson;

DLog(@"FAILED pluginJSON = %@", commandString);
#endif
Expand Down
2 changes: 1 addition & 1 deletion CordovaLib/Classes/CDVConfigParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ - (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName names
} else if ([elementName isEqualToString:@"plugin"]) {
NSString* name = [attributeDict[@"name"] lowercaseString];
pluginsDict[name] = attributeDict[@"value"];
if ([@"true" isEqualToString:attributeDict[@"onload"]]) {
if ([@"true" isEqualToString : attributeDict[@"onload"]]) {
[self.startupPluginNames addObject:name];
}
} else if ([elementName isEqualToString:@"access"]) {
Expand Down
12 changes: 10 additions & 2 deletions CordovaLib/Classes/CDVConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ - (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability
return @"none";

case ReachableViaWWAN:
return @"2g"; // no generic default, so we use the lowest common denominator
// Return value of '2g' is deprecated as of 2.6.0 and will be replaced with 'cellular' in 3.0.0
return @"2g";

case ReachableViaWiFi:
return @"wifi";
Expand All @@ -66,7 +67,8 @@ - (BOOL)isCellularConnection:(NSString*)theConnectionType
{
return [theConnectionType isEqualToString:@"2g"] ||
[theConnectionType isEqualToString:@"3g"] ||
[theConnectionType isEqualToString:@"4g"];
[theConnectionType isEqualToString:@"4g"] ||
[theConnectionType isEqualToString:@"cellular"];
}

- (void)updateReachability:(CDVReachability*)reachability
Expand Down Expand Up @@ -111,6 +113,7 @@ - (CDVPlugin*)initWithWebView:(UIWebView*)theWebView
self.internetReach = [CDVReachability reachabilityForInternetConnection];
self.connectionType = [self w3cConnectionTypeFor:self.internetReach];
[self.internetReach startNotifier];
[self printDeprecationNotice];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateConnectionType:)
name:kReachabilityChangedNotification object:nil];
if (&UIApplicationDidEnterBackgroundNotification && &UIApplicationWillEnterForegroundNotification) {
Expand All @@ -121,4 +124,9 @@ - (CDVPlugin*)initWithWebView:(UIWebView*)theWebView
return self;
}

- (void)printDeprecationNotice
{
NSLog(@"DEPRECATION NOTICE: The Connection ReachableViaWWAN return value of '2g' is deprecated as of Cordova version 2.6.0 and will be changed to 'cellular' in a future release. ");
}

@end
Loading

0 comments on commit 3ff6dc5

Please sign in to comment.