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/02/15 20:09:31 UTC
ios commit: [CB-1693] Allow plugins to be loaded on start-up.
Updated Branches:
refs/heads/master b55609eff -> 45de64893
[CB-1693] Allow plugins to be loaded on start-up.
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/45de6489
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/45de6489
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/45de6489
Branch: refs/heads/master
Commit: 45de64893b7b2123b9447fa3de4e810e4eaea1af
Parents: b55609e
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Feb 14 14:03:11 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Feb 15 13:48:50 2013 -0500
----------------------------------------------------------------------
CordovaLib/Classes/CDVConfigParser.h | 3 +-
CordovaLib/Classes/CDVConfigParser.m | 31 ++++++++++++--------------
CordovaLib/Classes/CDVViewController.m | 17 +++++++++++---
3 files changed, 28 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/45de6489/CordovaLib/Classes/CDVConfigParser.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVConfigParser.h b/CordovaLib/Classes/CDVConfigParser.h
index 0f4fa4c..7392580 100644
--- a/CordovaLib/Classes/CDVConfigParser.h
+++ b/CordovaLib/Classes/CDVConfigParser.h
@@ -22,8 +22,7 @@
@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;
-- (NSString*)getStartPage;
-
@end
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/45de6489/CordovaLib/Classes/CDVConfigParser.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVConfigParser.m b/CordovaLib/Classes/CDVConfigParser.m
index 3938b3e..6fd5913 100644
--- a/CordovaLib/Classes/CDVConfigParser.m
+++ b/CordovaLib/Classes/CDVConfigParser.m
@@ -24,21 +24,23 @@
@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;
+@synthesize pluginsDict, settings, whitelistHosts, startPage, startupPluginNames;
- (id)init
{
self = [super init];
if (self != nil) {
- self.pluginsDict = [[NSMutableDictionary alloc] initWithCapacity:4];
- self.settings = [[NSMutableDictionary alloc] initWithCapacity:4];
- self.whitelistHosts = [[NSMutableArray alloc] initWithCapacity:1];
+ 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;
}
@@ -46,13 +48,17 @@
- (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict
{
if ([elementName isEqualToString:@"preference"]) {
- [settings setObject:[attributeDict objectForKey:@"value"] forKey:[attributeDict objectForKey:@"name"]];
+ settings[attributeDict[@"name"]] = attributeDict[@"value"];
} else if ([elementName isEqualToString:@"plugin"]) {
- [pluginsDict setObject:[attributeDict objectForKey:@"value"] forKey:[attributeDict objectForKey:@"name"]];
+ 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 objectForKey:@"origin"]];
+ [whitelistHosts addObject:attributeDict[@"origin"]];
} else if ([elementName isEqualToString:@"content"]) {
- self.startPage = [attributeDict objectForKey:@"src"];
+ self.startPage = attributeDict[@"src"];
}
}
@@ -61,13 +67,4 @@
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
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/45de6489/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m
index 79fb43c..41d98d2 100644
--- a/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/Classes/CDVViewController.m
@@ -42,6 +42,7 @@
@property (nonatomic, readwrite, strong) NSMutableDictionary* settings;
@property (nonatomic, readwrite, strong) CDVWhitelist* whitelist;
@property (nonatomic, readwrite, strong) NSMutableDictionary* pluginObjects;
+@property (nonatomic, readwrite, strong) NSArray* startupPluginNames;
@property (nonatomic, readwrite, strong) NSDictionary* pluginsMap;
@property (nonatomic, readwrite, strong) NSArray* supportedOrientations;
@property (nonatomic, readwrite, assign) BOOL loadFromString;
@@ -57,7 +58,7 @@
@implementation CDVViewController
@synthesize webView, supportedOrientations;
-@synthesize pluginObjects, pluginsMap, whitelist;
+@synthesize pluginObjects, pluginsMap, whitelist, startupPluginNames;
@synthesize configParser, settings, loadFromString;
@synthesize imageView, activityView, useSplashScreen;
@synthesize wwwFolderName, startPage, initialized, openURL;
@@ -170,16 +171,20 @@
[configParser parse];
// Get the plugin dictionary, whitelist and settings from the delegate.
- self.pluginsMap = [delegate.pluginsDict dictionaryWithLowercaseKeys];
+ self.pluginsMap = delegate.pluginsDict;
+ self.startupPluginNames = delegate.startupPluginNames;
self.whitelist = [[CDVWhitelist alloc] initWithArray:delegate.whitelistHosts];
self.settings = delegate.settings;
// And the start folder/page.
self.wwwFolderName = @"www";
- self.startPage = [delegate getStartPage];
+ self.startPage = delegate.startPage;
+ if (self.startPage == nil) {
+ self.startPage = @"index.html";
+ }
// Initialize the plugin objects dict.
- self.pluginObjects = [[NSMutableDictionary alloc] initWithCapacity:4];
+ self.pluginObjects = [[NSMutableDictionary alloc] initWithCapacity:20];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
@@ -312,6 +317,10 @@
}
}
+ for (NSString* pluginName in self.startupPluginNames) {
+ [self getCommandInstance:pluginName];
+ }
+
// /////////////////
[CDVUserAgentUtil acquireLock:^(NSInteger lockToken) {
_userAgentLockToken = lockToken;