added whitelist support, and more complete interface with readonly props

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

Branch: refs/heads/master
Commit: b808ee9d89306265a946f18bfdaae9a3d413148a
Parents: e4e75dc
Author: Jesse <jesse.macfad...@nitobi.com>
Authored: Thu Jan 5 17:02:14 2012 -0800
Committer: shazron <shaz...@gmail.com>
Committed: Fri Jan 6 10:50:09 2012 -0800

----------------------------------------------------------------------
 PhoneGapLib/Classes/PGViewController.h            |    5 +-
 PhoneGapLib/Classes/PGViewController.m            |   69 +++++++++++++---
 PhoneGapLib/PhoneGapLib.xcodeproj/project.pbxproj |   28 ++++++
 3 files changed, 90 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/b808ee9d/PhoneGapLib/Classes/PGViewController.h
----------------------------------------------------------------------
diff --git a/PhoneGapLib/Classes/PGViewController.h 
b/PhoneGapLib/Classes/PGViewController.h
index c7cc1e3..5c41c35 100644
--- a/PhoneGapLib/Classes/PGViewController.h
+++ b/PhoneGapLib/Classes/PGViewController.h
@@ -10,7 +10,8 @@
 
 #import "JSONKit.h"
 #import "InvokedUrlCommand.h"
-@class PGWhitelist;
+
+#import "PGWhitelist.h"
 
 @interface PGViewController : UIViewController<UIWebViewDelegate> {
        
@@ -26,6 +27,8 @@
 @property (nonatomic, readonly, retain) NSDictionary *settings;
 @property (nonatomic, readonly, retain) PGWhitelist* whitelist; // readonly 
for public
 
+@property (nonatomic, retain)  NSArray* supportedOrientations;
+
 + (NSDictionary*)getBundlePlist:(NSString *)plistName;
 + (NSString*) wwwFolderName;
 + (NSString*) pathForResource:(NSString*)resourcepath;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/b808ee9d/PhoneGapLib/Classes/PGViewController.m
----------------------------------------------------------------------
diff --git a/PhoneGapLib/Classes/PGViewController.m 
b/PhoneGapLib/Classes/PGViewController.m
index a76d1da..48e51b1 100644
--- a/PhoneGapLib/Classes/PGViewController.m
+++ b/PhoneGapLib/Classes/PGViewController.m
@@ -16,25 +16,31 @@
 
 @property (nonatomic, readwrite, retain) NSDictionary *settings;
 @property (nonatomic, readwrite, retain) PGWhitelist* whitelist; 
+@property (nonatomic, readwrite, retain) NSMutableDictionary *pluginObjects;
+@property (nonatomic, readwrite, retain) NSDictionary *pluginsMap;
 
 @end
 
 
 @implementation PGViewController
 
-@synthesize webView;
+@synthesize webView, supportedOrientations;
 @synthesize pluginObjects, pluginsMap, whitelist;
 @synthesize activityView, imageView, settings;
 
 
+
+
+
 // Implement viewDidLoad to do additional setup after loading the view, 
typically from a nib.
 - (void)viewDidLoad 
 {
     [super viewDidLoad];
        
-       
+    self.pluginObjects = [[[NSMutableDictionary alloc] initWithCapacity:4] 
autorelease];
+    
        // read from UISupportedInterfaceOrientations (or 
UISupportedInterfaceOrientations~iPad, if its iPad) from -Info.plist
-    NSArray* supportedOrientations = [self parseInterfaceOrientations:
+    self.supportedOrientations = [self parseInterfaceOrientations:
                                                                          
[[[NSBundle mainBundle] infoDictionary] 
objectForKey:@"UISupportedInterfaceOrientations"]];
     
     // read from PhoneGap.plist in the app bundle
@@ -57,8 +63,10 @@
     // set the whitelist
     self.whitelist = [[[PGWhitelist alloc] initWithArray:[self.settings 
objectForKey:@"ExternalHosts"]] autorelease];
        
+    
        
-       
+    self.pluginsMap = [pluginsDict dictionaryWithLowercaseKeys];
+    
        NSString* path = [PGViewController pathForResource:@"index.html"];
        NSURL *appURL  = [NSURL fileURLWithPath:path];//[NSURL 
URLWithString:path];
        //[NSURL fileURLWithPath:path];
@@ -104,6 +112,52 @@
     return result;
 }
 
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) 
interfaceOrientation 
+{
+       // First ask the webview via JS if it wants to support the new 
orientation -jm
+       int i = 0;
+       
+       switch (interfaceOrientation){
+            
+               case UIInterfaceOrientationPortraitUpsideDown:
+                       i = 180;
+                       break;
+               case UIInterfaceOrientationLandscapeLeft:
+                       i = -90;
+                       break;
+               case UIInterfaceOrientationLandscapeRight:
+                       i = 90;
+                       break;
+               default:
+               case UIInterfaceOrientationPortrait:
+                       // noop
+                       break;
+       }
+       
+       NSString* jsCall = [ NSString 
stringWithFormat:@"shouldRotateToOrientation(%d);",i];
+       NSString* res = [webView stringByEvaluatingJavaScriptFromString:jsCall];
+       
+       if([res length] > 0)
+       {
+               return [res boolValue];
+       }
+       
+       // if js did not handle the new orientation ( no return value ) we will 
look it up in the plist -jm
+       
+       BOOL autoRotate = [self.supportedOrientations count] > 0; // autorotate 
if only more than 1 orientation supported
+       if (autoRotate)
+       {
+               if ([self.supportedOrientations containsObject:
+                        [NSNumber numberWithInt:interfaceOrientation]]) {
+                       return YES;
+               }
+    }
+       
+       // default return value is NO! -jm
+       
+       return NO;
+}
+
 
 -(void)createGapView
 {
@@ -140,13 +194,6 @@
 }
 
 
-
-// Override to allow orientations other than the default portrait orientation.
-- 
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
-       // Return YES for supported orientations.
-       return (interfaceOrientation == UIInterfaceOrientationPortrait);
-}
-
 #pragma mark UIWebViewDelegate
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/b808ee9d/PhoneGapLib/PhoneGapLib.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/PhoneGapLib/PhoneGapLib.xcodeproj/project.pbxproj 
b/PhoneGapLib/PhoneGapLib.xcodeproj/project.pbxproj
index 36d2def..8d5e01d 100644
--- a/PhoneGapLib/PhoneGapLib.xcodeproj/project.pbxproj
+++ b/PhoneGapLib/PhoneGapLib.xcodeproj/project.pbxproj
@@ -124,6 +124,16 @@
                68A32D7D141030E4006B237C /* CoreGraphics.framework in 
Frameworks */ = {isa = PBXBuildFile; fileRef = 686357AE141002F100DF4CF2 /* 
CoreGraphics.framework */; };
                68A32D7E141030EB006B237C /* UIKit.framework in Frameworks */ = 
{isa = PBXBuildFile; fileRef = 686357AA141002F100DF4CF2 /* UIKit.framework */; 
};
                68A32D7F141030F3006B237C /* Foundation.framework in Frameworks 
*/ = {isa = PBXBuildFile; fileRef = 686357AC141002F100DF4CF2 /* 
Foundation.framework */; };
+               8852C43A14B65FD800F0E735 /* PGViewController.h in Headers */ = 
{isa = PBXBuildFile; fileRef = 8852C43614B65FD800F0E735 /* PGViewController.h 
*/; };
+               8852C43B14B65FD800F0E735 /* PGViewController.h in Headers */ = 
{isa = PBXBuildFile; fileRef = 8852C43614B65FD800F0E735 /* PGViewController.h 
*/; };
+               8852C43C14B65FD800F0E735 /* PGViewController.m in Sources */ = 
{isa = PBXBuildFile; fileRef = 8852C43714B65FD800F0E735 /* PGViewController.m 
*/; };
+               8852C43D14B65FD800F0E735 /* PGViewController.m in Sources */ = 
{isa = PBXBuildFile; fileRef = 8852C43714B65FD800F0E735 /* PGViewController.m 
*/; };
+               8852C43E14B65FD800F0E735 /* PGViewController.m in Sources */ = 
{isa = PBXBuildFile; fileRef = 8852C43714B65FD800F0E735 /* PGViewController.m 
*/; };
+               8852C43F14B65FD800F0E735 /* UIGapView.h in Headers */ = {isa = 
PBXBuildFile; fileRef = 8852C43814B65FD800F0E735 /* UIGapView.h */; };
+               8852C44014B65FD800F0E735 /* UIGapView.h in Headers */ = {isa = 
PBXBuildFile; fileRef = 8852C43814B65FD800F0E735 /* UIGapView.h */; };
+               8852C44114B65FD800F0E735 /* UIGapView.m in Sources */ = {isa = 
PBXBuildFile; fileRef = 8852C43914B65FD800F0E735 /* UIGapView.m */; };
+               8852C44214B65FD800F0E735 /* UIGapView.m in Sources */ = {isa = 
PBXBuildFile; fileRef = 8852C43914B65FD800F0E735 /* UIGapView.m */; };
+               8852C44314B65FD800F0E735 /* UIGapView.m in Sources */ = {isa = 
PBXBuildFile; fileRef = 8852C43914B65FD800F0E735 /* UIGapView.m */; };
                8887FD661090FBE7009987E8 /* Camera.h in Headers */ = {isa = 
PBXBuildFile; fileRef = 8887FD261090FBE7009987E8 /* Camera.h */; };
                8887FD671090FBE7009987E8 /* Camera.m in Sources */ = {isa = 
PBXBuildFile; fileRef = 8887FD271090FBE7009987E8 /* Camera.m */; };
                8887FD681090FBE7009987E8 /* Categories.h in Headers */ = {isa = 
PBXBuildFile; fileRef = 8887FD281090FBE7009987E8 /* Categories.h */; };
@@ -218,6 +228,10 @@
                686357DC14100B1600DF4CF2 /* CoreMedia.framework */ = {isa = 
PBXFileReference; lastKnownFileType = wrapper.framework; name = 
CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; 
sourceTree = SDKROOT; };
                68A32D7114102E1C006B237C /* libPhoneGap.a */ = {isa = 
PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = 
libPhoneGap.a; sourceTree = BUILT_PRODUCTS_DIR; };
                68A32D7414103017006B237C /* AddressBook.framework */ = {isa = 
PBXFileReference; lastKnownFileType = wrapper.framework; name = 
AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; 
sourceTree = SDKROOT; };
+               8852C43614B65FD800F0E735 /* PGViewController.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = 
PGViewController.h; path = Classes/PGViewController.h; sourceTree = "<group>"; 
};
+               8852C43714B65FD800F0E735 /* PGViewController.m */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name 
= PGViewController.m; path = Classes/PGViewController.m; sourceTree = 
"<group>"; };
+               8852C43814B65FD800F0E735 /* UIGapView.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = 
UIGapView.h; path = Classes/UIGapView.h; sourceTree = "<group>"; };
+               8852C43914B65FD800F0E735 /* UIGapView.m */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name 
= UIGapView.m; path = Classes/UIGapView.m; sourceTree = "<group>"; };
                8887FD261090FBE7009987E8 /* Camera.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = 
Camera.h; path = Classes/Camera.h; sourceTree = "<group>"; };
                8887FD271090FBE7009987E8 /* Camera.m */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name 
= Camera.m; path = Classes/Camera.m; sourceTree = "<group>"; };
                8887FD281090FBE7009987E8 /* Categories.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = 
Categories.h; path = Classes/Categories.h; sourceTree = "<group>"; };
@@ -436,6 +450,10 @@
                8887FD101090FB43009987E8 /* Classes */ = {
                        isa = PBXGroup;
                        children = (
+                               8852C43614B65FD800F0E735 /* PGViewController.h 
*/,
+                               8852C43714B65FD800F0E735 /* PGViewController.m 
*/,
+                               8852C43814B65FD800F0E735 /* UIGapView.h */,
+                               8852C43914B65FD800F0E735 /* UIGapView.m */,
                                888700D710922F56009987E8 /* Commands */,
                                8887FD361090FBE7009987E8 /* JSON */,
                                888700D910923009009987E8 /* Util */,
@@ -493,6 +511,8 @@
                                30C684811406CB38004C1A8E /* PGWhitelist.h in 
Headers */,
                                30B39EC013D0268B0009682A /* PGSplashScreen.h in 
Headers */,
                                30E563D113E217EC00C949AA /* 
NSMutableArray+QueueAdditions.h in Headers */,
+                               8852C43B14B65FD800F0E735 /* PGViewController.h 
in Headers */,
+                               8852C44014B65FD800F0E735 /* UIGapView.h in 
Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
@@ -529,6 +549,8 @@
                                30C684941407044B004C1A8E /* PGURLProtocol.h in 
Headers */,
                                30356214141049E1006C2D43 /* PGWhitelistTests.h 
in Headers */,
                                30A90B9114588697006178D3 /* JSONKit.h in 
Headers */,
+                               8852C43A14B65FD800F0E735 /* PGViewController.h 
in Headers */,
+                               8852C43F14B65FD800F0E735 /* UIGapView.h in 
Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
@@ -737,6 +759,8 @@
                                30C684831406CB38004C1A8E /* PGWhitelist.m in 
Sources */,
                                30C684971407044B004C1A8E /* PGURLProtocol.m in 
Sources */,
                                30A90B9414588697006178D3 /* JSONKit.m in 
Sources */,
+                               8852C43D14B65FD800F0E735 /* PGViewController.m 
in Sources */,
+                               8852C44214B65FD800F0E735 /* UIGapView.m in 
Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
@@ -748,6 +772,8 @@
                                686357BA141002F200DF4CF2 /* 
PluginResultJSONSerializationTests.m in Sources */,
                                30AE4E8D1419532F005A9C9A /* PGContactsTests.m 
in Sources */,
                                30AE4E97141953C7005A9C9A /* MockUIWebview.m in 
Sources */,
+                               8852C43E14B65FD800F0E735 /* PGViewController.m 
in Sources */,
+                               8852C44314B65FD800F0E735 /* UIGapView.m in 
Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
@@ -782,6 +808,8 @@
                                30C684821406CB38004C1A8E /* PGWhitelist.m in 
Sources */,
                                30C684961407044B004C1A8E /* PGURLProtocol.m in 
Sources */,
                                30A90B9314588697006178D3 /* JSONKit.m in 
Sources */,
+                               8852C43C14B65FD800F0E735 /* PGViewController.m 
in Sources */,
+                               8852C44114B65FD800F0E735 /* UIGapView.m in 
Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };

Reply via email to