You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/01/14 20:57:49 UTC

[1/2] ios commit: Added a native uri option to DestinationType.

Added a native uri option to DestinationType.

Also added accompanying "not supported" errors.


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/256c6b92
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/256c6b92
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/256c6b92

Branch: refs/heads/master
Commit: 256c6b929251dc0879f018fc2efb319bcbc1d856
Parents: 5183183
Author: mwoghiren <ma...@gmail.com>
Authored: Mon Jan 14 12:08:10 2013 -0500
Committer: mwoghiren <ma...@gmail.com>
Committed: Mon Jan 14 12:43:07 2013 -0500

----------------------------------------------------------------------
 CordovaLib/Classes/CDVCamera.h       |    3 +-
 CordovaLib/Classes/CDVCamera.m       |    3 +
 CordovaLib/Classes/CDVFile.h         |    2 +
 CordovaLib/Classes/CDVFile.m         |   94 +++++++++++++++++++++++++++++
 CordovaLib/Classes/CDVFileTransfer.m |   17 +++++
 5 files changed, 118 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/256c6b92/CordovaLib/Classes/CDVCamera.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.h b/CordovaLib/Classes/CDVCamera.h
index 2905a8a..e32da7d 100644
--- a/CordovaLib/Classes/CDVCamera.h
+++ b/CordovaLib/Classes/CDVCamera.h
@@ -22,7 +22,8 @@
 
 enum CDVDestinationType {
     DestinationTypeDataUrl = 0,
-    DestinationTypeFileUri
+    DestinationTypeFileUri,
+    DestinationTypeNativeUri
 };
 typedef NSUInteger CDVDestinationType;
 

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/256c6b92/CordovaLib/Classes/CDVCamera.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.m b/CordovaLib/Classes/CDVCamera.m
index cfbf415..4cf5c82 100644
--- a/CordovaLib/Classes/CDVCamera.m
+++ b/CordovaLib/Classes/CDVCamera.m
@@ -287,6 +287,9 @@ static NSSet* org_apache_cordova_validArrowDirections;
             } 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]];
         }

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/256c6b92/CordovaLib/Classes/CDVFile.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFile.h b/CordovaLib/Classes/CDVFile.h
index 204c9f0..919fdef 100644
--- a/CordovaLib/Classes/CDVFile.h
+++ b/CordovaLib/Classes/CDVFile.h
@@ -42,6 +42,8 @@ enum CDVFileSystemType {
 };
 typedef int CDVFileSystemType;
 
+extern NSString* const kAssetsLibraryPrefix;
+
 @interface CDVFile : CDVPlugin {
     NSString* appDocsPath;
     NSString* appLibraryPath;

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/256c6b92/CordovaLib/Classes/CDVFile.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFile.m b/CordovaLib/Classes/CDVFile.m
index 348d717..b7900ec 100644
--- a/CordovaLib/Classes/CDVFile.m
+++ b/CordovaLib/Classes/CDVFile.m
@@ -32,6 +32,8 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     NSString* const NSURLIsExcludedFromBackupKey = @"NSURLIsExcludedFromBackupKey";
 #endif
 
+NSString* const kAssetsLibraryPrefix = @"assets-library://";
+
 @implementation CDVFile
 
 @synthesize appDocsPath, appLibraryPath, appTempPath, persistentPath, temporaryPath, userHasAllowed;
@@ -329,6 +331,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     NSString* requestedPath = [command.arguments objectAtIndex:1];
     NSDictionary* options = [command.arguments objectAtIndex:2 withDefault:nil];
 
+    // return unsupported result for assets-library URLs
+    if ([fullPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"getFile not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     CDVPluginResult* result = nil;
     BOOL bDirRequest = NO;
     BOOL create = NO;
@@ -425,6 +434,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     // arguments are URL encoded
     NSString* fullPath = [command.arguments objectAtIndex:0];
 
+    // return unsupported result for assets-library URLs
+    if ([fullPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"remove not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     CDVPluginResult* result = nil;
     NSString* newPath = nil;
 
@@ -461,6 +477,14 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
 {
     // arguments
     NSString* argPath = [command.arguments objectAtIndex:0];
+
+    // return unsupported result for assets-library URLs
+    if ([argPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"getMetadata not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     NSString* testPath = argPath; // [self getFullPath: argPath];
 
     NSFileManager* fileMgr = [[NSFileManager alloc] init];
@@ -501,6 +525,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     NSString* filePath = [command.arguments objectAtIndex:0];
     NSDictionary* options = [command.arguments objectAtIndex:1 withDefault:nil];
 
+    // return unsupported result for assets-library URLs
+    if ([filePath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"setMetadata not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     CDVPluginResult* result = nil;
     BOOL ok = NO;
 
@@ -547,6 +578,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     // arguments
     NSString* fullPath = [command.arguments objectAtIndex:0];
 
+    // return unsupported result for assets-library URLs
+    if ([fullPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"remove not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     CDVPluginResult* result = nil;
     CDVFileError errorCode = 0;  // !! 0 not currently defined
 
@@ -587,6 +625,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     // arguments
     NSString* fullPath = [command.arguments objectAtIndex:0];
 
+    // return unsupported result for assets-library URLs
+    if ([fullPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"removeRecursively not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     CDVPluginResult* result = nil;
 
     // error if try to remove top level (documents or tmp) dir
@@ -693,6 +738,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     // optional argument
     NSString* newName = ([arguments count] > 2) ? [arguments objectAtIndex:2] : [srcFullPath lastPathComponent];          // use last component from appPath if new name not provided
 
+    // return unsupported result for assets-library URLs
+    if ([srcFullPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"moveTo/copyTo not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     CDVPluginResult* result = nil;
     CDVFileError errCode = 0;  // !! Currently 0 is not defined, use this to signal error !!
 
@@ -838,6 +890,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     // arguments
     NSString* argPath = [command.arguments objectAtIndex:0];
 
+    // return unsupported result for assets-library URLs
+    if ([argPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"getFileMetadata not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     CDVPluginResult* result = nil;
 
     NSString* fullPath = argPath; // [self getFullPath: argPath];
@@ -875,6 +934,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     // arguments
     NSString* fullPath = [command.arguments objectAtIndex:0];
 
+    // return unsupported result for assets-library URLs
+    if ([fullPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"readEntries not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     CDVPluginResult* result = nil;
 
     NSFileManager* fileMgr = [[NSFileManager alloc] init];
@@ -925,6 +991,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
         end = [[command.arguments objectAtIndex:3] integerValue];
     }
 
+    // return unsupported result for assets-library URLs
+    if ([argPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"readAsText not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     // NSString* encoding = [command.arguments objectAtIndex:2];   // not currently used
     CDVPluginResult* result = nil;
 
@@ -981,6 +1054,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
         end = [[command.arguments objectAtIndex:2] integerValue];
     }
 
+    // return unsupported result for assets-library URLs
+    if ([argPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"readAsDataURL not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     CDVFileError errCode = ABORT_ERR;
     CDVPluginResult* result = nil;
 
@@ -1054,6 +1134,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     NSString* argPath = [command.arguments objectAtIndex:0];
     unsigned long long pos = (unsigned long long)[[command.arguments objectAtIndex:1] longLongValue];
 
+    // return unsupported result for assets-library URLs
+    if ([argPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"truncate not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     NSString* appFile = argPath; // [self getFullPath:argPath];
 
     unsigned long long newPos = [self truncateFile:appFile atPosition:pos];
@@ -1094,6 +1181,13 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
     NSString* argData = [arguments objectAtIndex:1];
     unsigned long long pos = (unsigned long long)[[arguments objectAtIndex:2] longLongValue];
 
+    // return unsupported result for assets-library URLs
+    if ([argPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"write not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     NSString* fullPath = argPath; // [self getFullPath:argPath];
 
     [self truncateFile:fullPath atPosition:pos];

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/256c6b92/CordovaLib/Classes/CDVFileTransfer.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFileTransfer.m b/CordovaLib/Classes/CDVFileTransfer.m
index 6a81245..24d013f 100644
--- a/CordovaLib/Classes/CDVFileTransfer.m
+++ b/CordovaLib/Classes/CDVFileTransfer.m
@@ -269,6 +269,15 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
 
 - (void)upload:(CDVInvokedUrlCommand*)command
 {
+    NSString* argPath = [command.arguments objectAtIndex:0];
+
+    // return unsupported result for assets-library URLs
+    if ([argPath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"upload not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     // fileData and req are split into helper functions to ease the unit testing of delegateForUpload.
     NSData* fileData = [self fileDataForUploadCommand:command];
     NSURLRequest* req = [self requestForUploadCommand:command fileData:fileData];
@@ -312,6 +321,14 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
     NSString* filePath = [command.arguments objectAtIndex:1];
     //  NSString* trustAllHosts = (NSString*)[arguments objectAtIndex:6]; // allow self-signed certs
     NSString* objectId = [command.arguments objectAtIndex:3];
+
+    // return unsupported result for assets-library URLs
+    if ([filePath hasPrefix:kAssetsLibraryPrefix]) {
+        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"download not supported for assets-library URLs."];
+        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+        return;
+    }
+
     CDVPluginResult* result = nil;
     CDVFileTransferError errorCode = 0;