summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/CordovaLib/Classes/Public
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-11-08 11:46:59 -0500
committerJules Laplace <jules@okfoc.us>2016-11-08 11:46:59 -0500
commit5fa81da81260d65113f57a293b6256d334fe8e2d (patch)
tree01d3dd7ab7a1febccd20de1756d0801a64ae64e9 /StoneIsland/platforms/ios/CordovaLib/Classes/Public
parente5652e9cd560ccda249819857c207643820b075f (diff)
parent7773d1d0686de69504e9b820efdb3e94d72eff04 (diff)
le build
Diffstat (limited to 'StoneIsland/platforms/ios/CordovaLib/Classes/Public')
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDV.h32
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAppDelegate.h28
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAppDelegate.m105
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAvailability.h105
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAvailabilityDeprecated.h26
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandDelegate.h51
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandDelegateImpl.h36
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandDelegateImpl.m186
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandQueue.h39
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandQueue.m194
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVConfigParser.h30
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVConfigParser.m81
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVInvokedUrlCommand.h52
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVInvokedUrlCommand.m116
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin+Resources.h39
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin+Resources.m38
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin.h83
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin.m169
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPluginResult.h66
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPluginResult.m186
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVScreenOrientationDelegate.h28
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVTimer.h27
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVTimer.m123
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVURLProtocol.h27
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVURLProtocol.m113
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVUserAgentUtil.h27
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVUserAgentUtil.m124
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.h91
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.m719
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWebViewEngineProtocol.h42
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWhitelist.h34
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWhitelist.m285
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSDictionary+CordovaPreferences.h35
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSDictionary+CordovaPreferences.m63
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSMutableArray+QueueAdditions.h29
-rw-r--r--StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSMutableArray+QueueAdditions.m58
36 files changed, 3487 insertions, 0 deletions
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDV.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDV.h
new file mode 100644
index 00000000..96d6efc8
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDV.h
@@ -0,0 +1,32 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVAvailability.h"
+#import "CDVAvailabilityDeprecated.h"
+#import "CDVAppDelegate.h"
+#import "CDVPlugin.h"
+#import "CDVPluginResult.h"
+#import "CDVViewController.h"
+#import "CDVCommandDelegate.h"
+#import "CDVURLProtocol.h"
+#import "CDVInvokedUrlCommand.h"
+#import "CDVWhitelist.h"
+#import "CDVScreenOrientationDelegate.h"
+#import "CDVTimer.h"
+#import "CDVUserAgentUtil.h"
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAppDelegate.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAppDelegate.h
new file mode 100644
index 00000000..de5b518f
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAppDelegate.h
@@ -0,0 +1,28 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+#import "CDVViewController.h"
+
+@interface CDVAppDelegate : NSObject <UIApplicationDelegate>{}
+
+@property (nonatomic, strong) IBOutlet UIWindow* window;
+@property (nonatomic, strong) IBOutlet CDVViewController* viewController;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAppDelegate.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAppDelegate.m
new file mode 100644
index 00000000..13c2e7bd
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAppDelegate.m
@@ -0,0 +1,105 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVAppDelegate.h"
+
+@implementation CDVAppDelegate
+
+@synthesize window, viewController;
+
+- (id)init
+{
+ /** If you need to do any extra app-specific initialization, you can do it here
+ * -jm
+ **/
+ NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
+
+ [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
+
+ int cacheSizeMemory = 8 * 1024 * 1024; // 8MB
+ int cacheSizeDisk = 32 * 1024 * 1024; // 32MB
+ NSURLCache* sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"];
+ [NSURLCache setSharedURLCache:sharedCache];
+
+ self = [super init];
+ return self;
+}
+
+#pragma mark UIApplicationDelegate implementation
+
+/**
+ * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
+ */
+- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
+{
+ CGRect screenBounds = [[UIScreen mainScreen] bounds];
+
+ self.window = [[UIWindow alloc] initWithFrame:screenBounds];
+ self.window.autoresizesSubviews = YES;
+
+ // only set if not already set in subclass
+ if (self.viewController == nil) {
+ self.viewController = [[CDVViewController alloc] init];
+ }
+
+ // Set your app's start page by setting the <content src='foo.html' /> tag in config.xml.
+ // If necessary, uncomment the line below to override it.
+ // self.viewController.startPage = @"index.html";
+
+ // NOTE: To customize the view's frame size (which defaults to full screen), override
+ // [self.viewController viewWillAppear:] in your view controller.
+
+ self.window.rootViewController = self.viewController;
+ [self.window makeKeyAndVisible];
+
+ return YES;
+}
+
+// this happens while we are running ( in the background, or from within our own app )
+// only valid if 40x-Info.plist specifies a protocol to handle
+- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
+{
+ if (!url) {
+ return NO;
+ }
+
+ // all plugins will get the notification, and their handlers will be called
+ [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
+
+ return YES;
+}
+
+#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
+- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
+#else
+- (UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
+#endif
+{
+ // iPhone doesn't support upside down by default, while the iPad does. Override to allow all orientations always, and let the root view controller decide what's allowed (the supported orientations mask gets intersected).
+ NSUInteger supportedInterfaceOrientations = (1 << UIInterfaceOrientationPortrait) | (1 << UIInterfaceOrientationLandscapeLeft) | (1 << UIInterfaceOrientationLandscapeRight) | (1 << UIInterfaceOrientationPortraitUpsideDown);
+
+ return supportedInterfaceOrientations;
+}
+
+- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application
+{
+ [[NSURLCache sharedURLCache] removeAllCachedResponses];
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAvailability.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAvailability.h
new file mode 100644
index 00000000..c9244327
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAvailability.h
@@ -0,0 +1,105 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVAvailabilityDeprecated.h"
+
+#define __CORDOVA_IOS__
+
+#define __CORDOVA_0_9_6 906
+#define __CORDOVA_1_0_0 10000
+#define __CORDOVA_1_1_0 10100
+#define __CORDOVA_1_2_0 10200
+#define __CORDOVA_1_3_0 10300
+#define __CORDOVA_1_4_0 10400
+#define __CORDOVA_1_4_1 10401
+#define __CORDOVA_1_5_0 10500
+#define __CORDOVA_1_6_0 10600
+#define __CORDOVA_1_6_1 10601
+#define __CORDOVA_1_7_0 10700
+#define __CORDOVA_1_8_0 10800
+#define __CORDOVA_1_8_1 10801
+#define __CORDOVA_1_9_0 10900
+#define __CORDOVA_2_0_0 20000
+#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_2_5_0 20500
+#define __CORDOVA_2_6_0 20600
+#define __CORDOVA_2_7_0 20700
+#define __CORDOVA_2_8_0 20800
+#define __CORDOVA_2_9_0 20900
+#define __CORDOVA_3_0_0 30000
+#define __CORDOVA_3_1_0 30100
+#define __CORDOVA_3_2_0 30200
+#define __CORDOVA_3_3_0 30300
+#define __CORDOVA_3_4_0 30400
+#define __CORDOVA_3_4_1 30401
+#define __CORDOVA_3_5_0 30500
+#define __CORDOVA_3_6_0 30600
+#define __CORDOVA_3_7_0 30700
+#define __CORDOVA_3_8_0 30800
+#define __CORDOVA_3_9_0 30900
+#define __CORDOVA_3_9_1 30901
+#define __CORDOVA_3_9_2 30902
+#define __CORDOVA_4_0_0 40000
+#define __CORDOVA_4_0_1 40001
+#define __CORDOVA_4_1_0 40100
+#define __CORDOVA_4_1_1 40101
+#define __CORDOVA_4_2_0 40200
+#define __CORDOVA_4_2_1 40201
+#define __CORDOVA_4_3_0 40300
+/* coho:next-version,insert-before */
+#define __CORDOVA_NA 99999 /* not available */
+
+/*
+ #if CORDOVA_VERSION_MIN_REQUIRED >= __CORDOVA_4_0_0
+ // do something when its at least 4.0.0
+ #else
+ // do something else (non 4.0.0)
+ #endif
+ */
+#ifndef CORDOVA_VERSION_MIN_REQUIRED
+ /* coho:next-version-min-required,replace-after */
+ #define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_4_3_0
+#endif
+
+/*
+ Returns YES if it is at least version specified as NSString(X)
+ Usage:
+ if (IsAtLeastiOSVersion(@"5.1")) {
+ // do something for iOS 5.1 or greater
+ }
+ */
+#define IsAtLeastiOSVersion(X) ([[[UIDevice currentDevice] systemVersion] compare:X options:NSNumericSearch] != NSOrderedAscending)
+
+/* 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]
+
+// 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
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAvailabilityDeprecated.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAvailabilityDeprecated.h
new file mode 100644
index 00000000..abf7a16a
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAvailabilityDeprecated.h
@@ -0,0 +1,26 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <UIKit/UIKit.h>
+
+#ifdef __clang__
+ #define CDV_DEPRECATED(version, msg) __attribute__((deprecated("Deprecated in Cordova " #version ". " msg)))
+#else
+ #define CDV_DEPRECATED(version, msg) __attribute__((deprecated()))
+#endif
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandDelegate.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandDelegate.h
new file mode 100644
index 00000000..3d9d90c9
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandDelegate.h
@@ -0,0 +1,51 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVAvailability.h"
+#import "CDVInvokedUrlCommand.h"
+
+@class CDVPlugin;
+@class CDVPluginResult;
+@class CDVWhitelist;
+
+typedef NSURL* (^ UrlTransformerBlock)(NSURL*);
+
+@protocol CDVCommandDelegate <NSObject>
+
+@property (nonatomic, readonly) NSDictionary* settings;
+@property (nonatomic, copy) UrlTransformerBlock urlTransformer;
+
+- (NSString*)pathForResource:(NSString*)resourcepath;
+- (id)getCommandInstance:(NSString*)pluginName;
+
+// Sends a plugin result to the JS. This is thread-safe.
+- (void)sendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId;
+// Evaluates the given JS. This is thread-safe.
+- (void)evalJs:(NSString*)js;
+// Can be used to evaluate JS right away instead of scheduling it on the run-loop.
+// This is required for dispatch resign and pause events, but should not be used
+// without reason. Without the run-loop delay, alerts used in JS callbacks may result
+// in dead-lock. This method must be called from the UI thread.
+- (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
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandDelegateImpl.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandDelegateImpl.h
new file mode 100644
index 00000000..05311343
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandDelegateImpl.h
@@ -0,0 +1,36 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <UIKit/UIKit.h>
+#import "CDVCommandDelegate.h"
+
+@class CDVViewController;
+@class CDVCommandQueue;
+
+@interface CDVCommandDelegateImpl : NSObject <CDVCommandDelegate>{
+ @private
+ __weak CDVViewController* _viewController;
+ NSRegularExpression* _callbackIdPattern;
+ @protected
+ __weak CDVCommandQueue* _commandQueue;
+ BOOL _delayResponses;
+}
+- (id)initWithViewController:(CDVViewController*)viewController;
+- (void)flushCommandQueueWithDelayedJs;
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandDelegateImpl.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandDelegateImpl.m
new file mode 100644
index 00000000..fd8b3e8d
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandDelegateImpl.m
@@ -0,0 +1,186 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVCommandDelegateImpl.h"
+#import "CDVJSON_private.h"
+#import "CDVCommandQueue.h"
+#import "CDVPluginResult.h"
+#import "CDVViewController.h"
+
+@implementation CDVCommandDelegateImpl
+
+@synthesize urlTransformer;
+
+- (id)initWithViewController:(CDVViewController*)viewController
+{
+ self = [super init];
+ if (self != nil) {
+ _viewController = viewController;
+ _commandQueue = _viewController.commandQueue;
+
+ NSError* err = nil;
+ _callbackIdPattern = [NSRegularExpression regularExpressionWithPattern:@"[^A-Za-z0-9._-]" options:0 error:&err];
+ if (err != nil) {
+ // Couldn't initialize Regex
+ NSLog(@"Error: Couldn't initialize regex");
+ _callbackIdPattern = nil;
+ }
+ }
+ return self;
+}
+
+- (NSString*)pathForResource:(NSString*)resourcepath
+{
+ NSBundle* mainBundle = [NSBundle mainBundle];
+ NSMutableArray* directoryParts = [NSMutableArray arrayWithArray:[resourcepath componentsSeparatedByString:@"/"]];
+ NSString* filename = [directoryParts lastObject];
+
+ [directoryParts removeLastObject];
+
+ NSString* directoryPartsJoined = [directoryParts componentsJoinedByString:@"/"];
+ NSString* directoryStr = _viewController.wwwFolderName;
+
+ if ([directoryPartsJoined length] > 0) {
+ directoryStr = [NSString stringWithFormat:@"%@/%@", _viewController.wwwFolderName, [directoryParts componentsJoinedByString:@"/"]];
+ }
+
+ return [mainBundle pathForResource:filename ofType:@"" inDirectory:directoryStr];
+}
+
+- (void)flushCommandQueueWithDelayedJs
+{
+ _delayResponses = YES;
+ [_commandQueue executePending];
+ _delayResponses = NO;
+}
+
+- (void)evalJsHelper2:(NSString*)js
+{
+ CDV_EXEC_LOG(@"Exec: evalling: %@", [js substringToIndex:MIN([js length], 160)]);
+ [_viewController.webViewEngine evaluateJavaScript:js completionHandler:^(id obj, NSError* error) {
+ // TODO: obj can be something other than string
+ if ([obj isKindOfClass:[NSString class]]) {
+ NSString* commandsJSON = (NSString*)obj;
+ if ([commandsJSON length] > 0) {
+ CDV_EXEC_LOG(@"Exec: Retrieved new exec messages by chaining.");
+ }
+
+ [_commandQueue enqueueCommandBatch:commandsJSON];
+ [_commandQueue executePending];
+ }
+ }];
+}
+
+- (void)evalJsHelper:(NSString*)js
+{
+ // Cycle the run-loop before executing the JS.
+ // For _delayResponses -
+ // This ensures that we don't eval JS during the middle of an existing JS
+ // function (possible since UIWebViewDelegate callbacks can be synchronous).
+ // For !isMainThread -
+ // It's a hard error to eval on the non-UI thread.
+ // For !_commandQueue.currentlyExecuting -
+ // This works around a bug where sometimes alerts() within callbacks can cause
+ // dead-lock.
+ // If the commandQueue is currently executing, then we know that it is safe to
+ // execute the callback immediately.
+ // Using (dispatch_get_main_queue()) does *not* fix deadlocks for some reason,
+ // but performSelectorOnMainThread: does.
+ if (_delayResponses || ![NSThread isMainThread] || !_commandQueue.currentlyExecuting) {
+ [self performSelectorOnMainThread:@selector(evalJsHelper2:) withObject:js waitUntilDone:NO];
+ } else {
+ [self evalJsHelper2:js];
+ }
+}
+
+- (BOOL)isValidCallbackId:(NSString*)callbackId
+{
+ if ((callbackId == nil) || (_callbackIdPattern == nil)) {
+ return NO;
+ }
+
+ // Disallow if too long or if any invalid characters were found.
+ if (([callbackId length] > 100) || [_callbackIdPattern firstMatchInString:callbackId options:0 range:NSMakeRange(0, [callbackId length])]) {
+ return NO;
+ }
+ return YES;
+}
+
+- (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]) {
+ return;
+ }
+ // This occurs when the callback id is malformed.
+ if (![self isValidCallbackId:callbackId]) {
+ NSLog(@"Invalid callback id received by sendPluginResult");
+ return;
+ }
+ int status = [result.status intValue];
+ BOOL keepCallback = [result.keepCallback boolValue];
+ NSString* argumentsAsJSON = [result argumentsAsJSON];
+ BOOL debug = NO;
+
+#ifdef DEBUG
+ debug = YES;
+#endif
+
+ NSString* js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeCallback('%@',%d,%@,%d, %d)", callbackId, status, argumentsAsJSON, keepCallback, debug];
+
+ [self evalJsHelper:js];
+}
+
+- (void)evalJs:(NSString*)js
+{
+ [self evalJs:js scheduledOnRunLoop:YES];
+}
+
+- (void)evalJs:(NSString*)js scheduledOnRunLoop:(BOOL)scheduledOnRunLoop
+{
+ js = [NSString stringWithFormat:@"try{cordova.require('cordova/exec').nativeEvalAndFetch(function(){%@})}catch(e){console.log('exception nativeEvalAndFetch : '+e);};", js];
+ if (scheduledOnRunLoop) {
+ [self evalJsHelper:js];
+ } else {
+ [self evalJsHelper2:js];
+ }
+}
+
+- (id)getCommandInstance:(NSString*)pluginName
+{
+ return [_viewController getCommandInstance:pluginName];
+}
+
+- (void)runInBackground:(void (^)())block
+{
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
+}
+
+- (NSString*)userAgent
+{
+ return [_viewController userAgent];
+}
+
+- (NSDictionary*)settings
+{
+ return _viewController.settings;
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandQueue.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandQueue.h
new file mode 100644
index 00000000..cb7bd6e4
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandQueue.h
@@ -0,0 +1,39 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+@class CDVInvokedUrlCommand;
+@class CDVViewController;
+
+@interface CDVCommandQueue : NSObject
+
+@property (nonatomic, readonly) BOOL currentlyExecuting;
+
+- (id)initWithViewController:(CDVViewController*)viewController;
+- (void)dispose;
+
+- (void)resetRequestId;
+- (void)enqueueCommandBatch:(NSString*)batchJSON;
+
+- (void)fetchCommandsFromJs;
+- (void)executePending;
+- (BOOL)execute:(CDVInvokedUrlCommand*)command;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandQueue.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandQueue.m
new file mode 100644
index 00000000..b78ed833
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVCommandQueue.m
@@ -0,0 +1,194 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#include <objc/message.h>
+#import "CDVCommandQueue.h"
+#import "CDVViewController.h"
+#import "CDVCommandDelegateImpl.h"
+#import "CDVJSON_private.h"
+#import "CDVDebug.h"
+
+// Parse JS on the main thread if it's shorter than this.
+static const NSInteger JSON_SIZE_FOR_MAIN_THREAD = 4 * 1024; // Chosen arbitrarily.
+// Execute multiple commands in one go until this many seconds have passed.
+static const double MAX_EXECUTION_TIME = .008; // Half of a 60fps frame.
+
+@interface CDVCommandQueue () {
+ NSInteger _lastCommandQueueFlushRequestId;
+ __weak CDVViewController* _viewController;
+ NSMutableArray* _queue;
+ NSTimeInterval _startExecutionTime;
+}
+@end
+
+@implementation CDVCommandQueue
+
+- (BOOL)currentlyExecuting
+{
+ return _startExecutionTime > 0;
+}
+
+- (id)initWithViewController:(CDVViewController*)viewController
+{
+ self = [super init];
+ if (self != nil) {
+ _viewController = viewController;
+ _queue = [[NSMutableArray alloc] init];
+ }
+ return self;
+}
+
+- (void)dispose
+{
+ // TODO(agrieve): Make this a zeroing weak ref once we drop support for 4.3.
+ _viewController = nil;
+}
+
+- (void)resetRequestId
+{
+ _lastCommandQueueFlushRequestId = 0;
+}
+
+- (void)enqueueCommandBatch:(NSString*)batchJSON
+{
+ if ([batchJSON length] > 0) {
+ NSMutableArray* commandBatchHolder = [[NSMutableArray alloc] init];
+ [_queue addObject:commandBatchHolder];
+ if ([batchJSON length] < JSON_SIZE_FOR_MAIN_THREAD) {
+ [commandBatchHolder addObject:[batchJSON cdv_JSONObject]];
+ } else {
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^() {
+ NSMutableArray* result = [batchJSON cdv_JSONObject];
+ @synchronized(commandBatchHolder) {
+ [commandBatchHolder addObject:result];
+ }
+ [self performSelectorOnMainThread:@selector(executePending) withObject:nil waitUntilDone:NO];
+ });
+ }
+ }
+}
+
+- (void)fetchCommandsFromJs
+{
+ __weak CDVCommandQueue* weakSelf = self;
+ NSString* js = @"cordova.require('cordova/exec').nativeFetchMessages()";
+
+ [_viewController.webViewEngine evaluateJavaScript:js
+ completionHandler:^(id obj, NSError* error) {
+ if ((error == nil) && [obj isKindOfClass:[NSString class]]) {
+ NSString* queuedCommandsJSON = (NSString*)obj;
+ CDV_EXEC_LOG(@"Exec: Flushed JS->native queue (hadCommands=%d).", [queuedCommandsJSON length] > 0);
+ [weakSelf enqueueCommandBatch:queuedCommandsJSON];
+ // this has to be called here now, because fetchCommandsFromJs is now async (previously: synchronous)
+ [self executePending];
+ }
+ }];
+}
+
+- (void)executePending
+{
+ // Make us re-entrant-safe.
+ if (_startExecutionTime > 0) {
+ return;
+ }
+ @try {
+ _startExecutionTime = [NSDate timeIntervalSinceReferenceDate];
+
+ while ([_queue count] > 0) {
+ NSMutableArray* commandBatchHolder = _queue[0];
+ NSMutableArray* commandBatch = nil;
+ @synchronized(commandBatchHolder) {
+ // If the next-up command is still being decoded, wait for it.
+ if ([commandBatchHolder count] == 0) {
+ break;
+ }
+ commandBatch = commandBatchHolder[0];
+ }
+
+ while ([commandBatch count] > 0) {
+ @autoreleasepool {
+ // Execute the commands one-at-a-time.
+ NSArray* jsonEntry = [commandBatch cdv_dequeue];
+ if ([commandBatch count] == 0) {
+ [_queue removeObjectAtIndex:0];
+ }
+ 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 cdv_JSONString];
+ static NSUInteger maxLogLength = 1024;
+ NSString* commandString = ([commandJson length] > maxLogLength) ?
+ [NSString stringWithFormat : @"%@[...]", [commandJson substringToIndex:maxLogLength]] :
+ commandJson;
+
+ DLog(@"FAILED pluginJSON = %@", commandString);
+#endif
+ }
+ }
+
+ // Yield if we're taking too long.
+ if (([_queue count] > 0) && ([NSDate timeIntervalSinceReferenceDate] - _startExecutionTime > MAX_EXECUTION_TIME)) {
+ [self performSelector:@selector(executePending) withObject:nil afterDelay:0];
+ return;
+ }
+ }
+ }
+ } @finally
+ {
+ _startExecutionTime = 0;
+ }
+}
+
+- (BOOL)execute:(CDVInvokedUrlCommand*)command
+{
+ if ((command.className == nil) || (command.methodName == nil)) {
+ NSLog(@"ERROR: Classname and/or methodName not found for command.");
+ return NO;
+ }
+
+ // Fetch an instance of this class
+ CDVPlugin* obj = [_viewController.commandDelegate getCommandInstance:command.className];
+
+ if (!([obj isKindOfClass:[CDVPlugin class]])) {
+ NSLog(@"ERROR: Plugin '%@' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.", command.className);
+ return NO;
+ }
+ BOOL retVal = YES;
+ double started = [[NSDate date] timeIntervalSince1970] * 1000.0;
+ // Find the proper selector to call.
+ NSString* methodName = [NSString stringWithFormat:@"%@:", command.methodName];
+ SEL normalSelector = NSSelectorFromString(methodName);
+ if ([obj respondsToSelector:normalSelector]) {
+ // [obj performSelector:normalSelector withObject:command];
+ ((void (*)(id, SEL, id))objc_msgSend)(obj, normalSelector, command);
+ } else {
+ // There's no method to call, so throw an error.
+ NSLog(@"ERROR: Method '%@' not defined in Plugin '%@'", methodName, command.className);
+ retVal = NO;
+ }
+ double elapsed = [[NSDate date] timeIntervalSince1970] * 1000.0 - started;
+ if (elapsed > 10) {
+ NSLog(@"THREAD WARNING: ['%@'] took '%f' ms. Plugin should use a background thread.", command.className, elapsed);
+ }
+ return retVal;
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVConfigParser.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVConfigParser.h
new file mode 100644
index 00000000..bae3d0f8
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVConfigParser.h
@@ -0,0 +1,30 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+@interface CDVConfigParser : NSObject <NSXMLParserDelegate>
+{
+ NSString* featureName;
+}
+
+@property (nonatomic, readonly, strong) NSMutableDictionary* pluginsDict;
+@property (nonatomic, readonly, strong) NSMutableDictionary* settings;
+@property (nonatomic, readonly, strong) NSMutableArray* startupPluginNames;
+@property (nonatomic, readonly, strong) NSString* startPage;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVConfigParser.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVConfigParser.m
new file mode 100644
index 00000000..ab32b4a7
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVConfigParser.m
@@ -0,0 +1,81 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVConfigParser.h"
+
+@interface CDVConfigParser ()
+
+@property (nonatomic, readwrite, strong) NSMutableDictionary* pluginsDict;
+@property (nonatomic, readwrite, strong) NSMutableDictionary* settings;
+@property (nonatomic, readwrite, strong) NSMutableArray* startupPluginNames;
+@property (nonatomic, readwrite, strong) NSString* startPage;
+
+@end
+
+@implementation CDVConfigParser
+
+@synthesize pluginsDict, settings, startPage, startupPluginNames;
+
+- (id)init
+{
+ self = [super init];
+ if (self != nil) {
+ self.pluginsDict = [[NSMutableDictionary alloc] initWithCapacity:30];
+ self.settings = [[NSMutableDictionary alloc] initWithCapacity:30];
+ self.startupPluginNames = [[NSMutableArray alloc] initWithCapacity:8];
+ featureName = nil;
+ }
+ return self;
+}
+
+- (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict
+{
+ if ([elementName isEqualToString:@"preference"]) {
+ settings[[attributeDict[@"name"] lowercaseString]] = attributeDict[@"value"];
+ } else if ([elementName isEqualToString:@"feature"]) { // store feature name to use with correct parameter set
+ featureName = [attributeDict[@"name"] lowercaseString];
+ } else if ((featureName != nil) && [elementName isEqualToString:@"param"]) {
+ NSString* paramName = [attributeDict[@"name"] lowercaseString];
+ id value = attributeDict[@"value"];
+ if ([paramName isEqualToString:@"ios-package"]) {
+ pluginsDict[featureName] = value;
+ }
+ BOOL paramIsOnload = ([paramName isEqualToString:@"onload"] && [@"true" isEqualToString : value]);
+ BOOL attribIsOnload = [@"true" isEqualToString :[attributeDict[@"onload"] lowercaseString]];
+ if (paramIsOnload || attribIsOnload) {
+ [self.startupPluginNames addObject:featureName];
+ }
+ } else if ([elementName isEqualToString:@"content"]) {
+ self.startPage = attributeDict[@"src"];
+ }
+}
+
+- (void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName
+{
+ if ([elementName isEqualToString:@"feature"]) { // no longer handling a feature so release
+ featureName = nil;
+ }
+}
+
+- (void)parser:(NSXMLParser*)parser parseErrorOccurred:(NSError*)parseError
+{
+ NSAssert(NO, @"config.xml parse error line %ld col %ld", (long)[parser lineNumber], (long)[parser columnNumber]);
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVInvokedUrlCommand.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVInvokedUrlCommand.h
new file mode 100644
index 00000000..993e0a28
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVInvokedUrlCommand.h
@@ -0,0 +1,52 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+@interface CDVInvokedUrlCommand : NSObject {
+ NSString* _callbackId;
+ NSString* _className;
+ NSString* _methodName;
+ NSArray* _arguments;
+}
+
+@property (nonatomic, readonly) NSArray* arguments;
+@property (nonatomic, readonly) NSString* callbackId;
+@property (nonatomic, readonly) NSString* className;
+@property (nonatomic, readonly) NSString* methodName;
+
++ (CDVInvokedUrlCommand*)commandFromJson:(NSArray*)jsonEntry;
+
+- (id)initWithArguments:(NSArray*)arguments
+ callbackId:(NSString*)callbackId
+ className:(NSString*)className
+ methodName:(NSString*)methodName;
+
+- (id)initFromJson:(NSArray*)jsonEntry;
+
+// Returns the argument at the given index.
+// If index >= the number of arguments, returns nil.
+// If the argument at the given index is NSNull, returns nil.
+- (id)argumentAtIndex:(NSUInteger)index;
+// Same as above, but returns defaultValue instead of nil.
+- (id)argumentAtIndex:(NSUInteger)index withDefault:(id)defaultValue;
+// Same as above, but returns defaultValue instead of nil, and if the argument is not of the expected class, returns defaultValue
+- (id)argumentAtIndex:(NSUInteger)index withDefault:(id)defaultValue andClass:(Class)aClass;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVInvokedUrlCommand.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVInvokedUrlCommand.m
new file mode 100644
index 00000000..5b4281df
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVInvokedUrlCommand.m
@@ -0,0 +1,116 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVInvokedUrlCommand.h"
+#import "CDVJSON_private.h"
+
+@implementation CDVInvokedUrlCommand
+
+@synthesize arguments = _arguments;
+@synthesize callbackId = _callbackId;
+@synthesize className = _className;
+@synthesize methodName = _methodName;
+
++ (CDVInvokedUrlCommand*)commandFromJson:(NSArray*)jsonEntry
+{
+ return [[CDVInvokedUrlCommand alloc] initFromJson:jsonEntry];
+}
+
+- (id)initFromJson:(NSArray*)jsonEntry
+{
+ id tmp = [jsonEntry objectAtIndex:0];
+ NSString* callbackId = tmp == [NSNull null] ? nil : tmp;
+ NSString* className = [jsonEntry objectAtIndex:1];
+ NSString* methodName = [jsonEntry objectAtIndex:2];
+ NSMutableArray* arguments = [jsonEntry objectAtIndex:3];
+
+ return [self initWithArguments:arguments
+ callbackId:callbackId
+ className:className
+ methodName:methodName];
+}
+
+- (id)initWithArguments:(NSArray*)arguments
+ callbackId:(NSString*)callbackId
+ className:(NSString*)className
+ methodName:(NSString*)methodName
+{
+ self = [super init];
+ if (self != nil) {
+ _arguments = arguments;
+ _callbackId = callbackId;
+ _className = className;
+ _methodName = methodName;
+ }
+ [self massageArguments];
+ return self;
+}
+
+- (void)massageArguments
+{
+ NSMutableArray* newArgs = nil;
+
+ for (NSUInteger i = 0, count = [_arguments count]; i < count; ++i) {
+ id arg = [_arguments objectAtIndex:i];
+ if (![arg isKindOfClass:[NSDictionary class]]) {
+ continue;
+ }
+ NSDictionary* dict = arg;
+ NSString* type = [dict objectForKey:@"CDVType"];
+ if (!type || ![type isEqualToString:@"ArrayBuffer"]) {
+ continue;
+ }
+ NSString* data = [dict objectForKey:@"data"];
+ if (!data) {
+ continue;
+ }
+ if (newArgs == nil) {
+ newArgs = [NSMutableArray arrayWithArray:_arguments];
+ _arguments = newArgs;
+ }
+ [newArgs replaceObjectAtIndex:i withObject:[[NSData alloc] initWithBase64EncodedString:data options:0]];
+ }
+}
+
+- (id)argumentAtIndex:(NSUInteger)index
+{
+ return [self argumentAtIndex:index withDefault:nil];
+}
+
+- (id)argumentAtIndex:(NSUInteger)index withDefault:(id)defaultValue
+{
+ return [self argumentAtIndex:index withDefault:defaultValue andClass:nil];
+}
+
+- (id)argumentAtIndex:(NSUInteger)index withDefault:(id)defaultValue andClass:(Class)aClass
+{
+ if (index >= [_arguments count]) {
+ return defaultValue;
+ }
+ id ret = [_arguments objectAtIndex:index];
+ if (ret == [NSNull null]) {
+ ret = defaultValue;
+ }
+ if ((aClass != nil) && ![ret isKindOfClass:aClass]) {
+ ret = defaultValue;
+ }
+ return ret;
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin+Resources.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin+Resources.h
new file mode 100644
index 00000000..cc43b16b
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin+Resources.h
@@ -0,0 +1,39 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <UIKit/UIKit.h>
+#import "CDVPlugin.h"
+
+@interface CDVPlugin (CDVPluginResources)
+
+/*
+ This will return the localized string for a key in a .bundle that is named the same as your class
+ For example, if your plugin class was called Foo, and you have a Spanish localized strings file, it will
+ try to load the desired key from Foo.bundle/es.lproj/Localizable.strings
+ */
+- (NSString*)pluginLocalizedString:(NSString*)key;
+
+/*
+ This will return the image for a name in a .bundle that is named the same as your class
+ For example, if your plugin class was called Foo, and you have an image called "bar",
+ it will try to load the image from Foo.bundle/bar.png (and appropriately named retina versions)
+ */
+- (UIImage*)pluginImageResource:(NSString*)name;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin+Resources.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin+Resources.m
new file mode 100644
index 00000000..56907385
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin+Resources.m
@@ -0,0 +1,38 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVPlugin+Resources.h"
+
+@implementation CDVPlugin (CDVPluginResources)
+
+- (NSString*)pluginLocalizedString:(NSString*)key
+{
+ NSBundle* bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:NSStringFromClass([self class]) ofType:@"bundle"]];
+
+ return [bundle localizedStringForKey:(key) value:nil table:nil];
+}
+
+- (UIImage*)pluginImageResource:(NSString*)name
+{
+ NSString* resourceIdentifier = [NSString stringWithFormat:@"%@.bundle/%@", NSStringFromClass([self class]), name];
+
+ return [UIImage imageNamed:resourceIdentifier];
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin.h
new file mode 100644
index 00000000..d59507ae
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin.h
@@ -0,0 +1,83 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+#import "CDVPluginResult.h"
+#import "NSMutableArray+QueueAdditions.h"
+#import "CDVCommandDelegate.h"
+#import "CDVWebViewEngineProtocol.h"
+
+@interface UIView (org_apache_cordova_UIView_Extension)
+
+@property (nonatomic, weak) UIScrollView* scrollView;
+
+@end
+
+extern NSString* const CDVPageDidLoadNotification;
+extern NSString* const CDVPluginHandleOpenURLNotification;
+extern NSString* const CDVPluginResetNotification;
+extern NSString* const CDVViewWillAppearNotification;
+extern NSString* const CDVViewDidAppearNotification;
+extern NSString* const CDVViewWillDisappearNotification;
+extern NSString* const CDVViewDidDisappearNotification;
+extern NSString* const CDVViewWillLayoutSubviewsNotification;
+extern NSString* const CDVViewDidLayoutSubviewsNotification;
+extern NSString* const CDVViewWillTransitionToSizeNotification;
+
+/*
+ * The local and remote push notification functionality has been removed from the core in cordova-ios 4.x,
+ * but these constants have unfortunately have not been removed, but will be removed in 5.x.
+ *
+ * To have the same functionality as 3.x, use a third-party plugin or the experimental
+ * https://github.com/apache/cordova-plugins/tree/master/notification-rebroadcast
+ */
+extern NSString* const CDVLocalNotification CDV_DEPRECATED(4.0, "Functionality removed in 4.0, constant will be removed in 5.0");
+extern NSString* const CDVRemoteNotification CDV_DEPRECATED(4.0, "Functionality removed in 4.0, constant will be removed in 5.0");
+extern NSString* const CDVRemoteNotificationError CDV_DEPRECATED(4.0, "Functionality removed in 4.0, constant will be removed in 5.0");
+
+@interface CDVPlugin : NSObject {}
+
+@property (nonatomic, readonly, weak) UIView* webView;
+@property (nonatomic, readonly, weak) id <CDVWebViewEngineProtocol> webViewEngine;
+
+@property (nonatomic, weak) UIViewController* viewController;
+@property (nonatomic, weak) id <CDVCommandDelegate> commandDelegate;
+
+@property (readonly, assign) BOOL hasPendingOperation;
+
+- (void)pluginInitialize;
+
+- (void)handleOpenURL:(NSNotification*)notification;
+- (void)onAppTerminate;
+- (void)onMemoryWarning;
+- (void)onReset;
+- (void)dispose;
+
+/*
+ // see initWithWebView implementation
+ - (void) onPause {}
+ - (void) onResume {}
+ - (void) onOrientationWillChange {}
+ - (void) onOrientationDidChange {}
+ */
+
+- (id)appDelegate;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin.m
new file mode 100644
index 00000000..f16f7fbe
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPlugin.m
@@ -0,0 +1,169 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVPlugin.h"
+#import "CDVPlugin+Private.h"
+#import "CDVPlugin+Resources.h"
+#import "CDVViewController.h"
+#include <objc/message.h>
+
+@implementation UIView (org_apache_cordova_UIView_Extension)
+
+@dynamic scrollView;
+
+- (UIScrollView*)scrollView
+{
+ SEL scrollViewSelector = NSSelectorFromString(@"scrollView");
+
+ if ([self respondsToSelector:scrollViewSelector]) {
+ return ((id (*)(id, SEL))objc_msgSend)(self, scrollViewSelector);
+ }
+
+ return nil;
+}
+
+@end
+
+NSString* const CDVPageDidLoadNotification = @"CDVPageDidLoadNotification";
+NSString* const CDVPluginHandleOpenURLNotification = @"CDVPluginHandleOpenURLNotification";
+NSString* const CDVPluginResetNotification = @"CDVPluginResetNotification";
+NSString* const CDVLocalNotification = @"CDVLocalNotification";
+NSString* const CDVRemoteNotification = @"CDVRemoteNotification";
+NSString* const CDVRemoteNotificationError = @"CDVRemoteNotificationError";
+NSString* const CDVViewWillAppearNotification = @"CDVViewWillAppearNotification";
+NSString* const CDVViewDidAppearNotification = @"CDVViewDidAppearNotification";
+NSString* const CDVViewWillDisappearNotification = @"CDVViewWillDisappearNotification";
+NSString* const CDVViewDidDisappearNotification = @"CDVViewDidDisappearNotification";
+NSString* const CDVViewWillLayoutSubviewsNotification = @"CDVViewWillLayoutSubviewsNotification";
+NSString* const CDVViewDidLayoutSubviewsNotification = @"CDVViewDidLayoutSubviewsNotification";
+NSString* const CDVViewWillTransitionToSizeNotification = @"CDVViewWillTransitionToSizeNotification";
+
+@interface CDVPlugin ()
+
+@property (readwrite, assign) BOOL hasPendingOperation;
+@property (nonatomic, readwrite, weak) id <CDVWebViewEngineProtocol> webViewEngine;
+
+@end
+
+@implementation CDVPlugin
+@synthesize webViewEngine, viewController, commandDelegate, hasPendingOperation;
+@dynamic webView;
+
+// Do not override these methods. Use pluginInitialize instead.
+- (instancetype)initWithWebViewEngine:(id <CDVWebViewEngineProtocol>)theWebViewEngine
+{
+ self = [super init];
+ if (self) {
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppTerminate) name:UIApplicationWillTerminateNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:CDVPluginHandleOpenURLNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReset) name:CDVPluginResetNotification object:theWebViewEngine.engineWebView];
+
+ self.webViewEngine = theWebViewEngine;
+ }
+ return self;
+}
+
+- (void)pluginInitialize
+{
+ // You can listen to more app notifications, see:
+ // http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006728-CH3-DontLinkElementID_4
+
+ // NOTE: if you want to use these, make sure you uncomment the corresponding notification handler
+
+ // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onPause) name:UIApplicationDidEnterBackgroundNotification object:nil];
+ // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResume) name:UIApplicationWillEnterForegroundNotification object:nil];
+ // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onOrientationWillChange) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
+ // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onOrientationDidChange) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
+
+ // Added in 2.5.0
+ // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pageDidLoad:) name:CDVPageDidLoadNotification object:self.webView];
+ //Added in 4.3.0
+ // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillAppear:) name:CDVViewWillAppearNotification object:nil];
+ // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidAppear:) name:CDVViewDidAppearNotification object:nil];
+ // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillDisappear:) name:CDVViewWillDisappearNotification object:nil];
+ // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidDisappear:) name:CDVViewDidDisappearNotification object:nil];
+ // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillLayoutSubviews:) name:CDVViewWillLayoutSubviewsNotification object:nil];
+ // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidLayoutSubviews:) name:CDVViewDidLayoutSubviewsNotification object:nil];
+ // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillTransitionToSize:) name:CDVViewWillTransitionToSizeNotification object:nil];
+}
+
+- (void)dispose
+{
+ viewController = nil;
+ commandDelegate = nil;
+}
+
+- (UIView*)webView
+{
+ if (self.webViewEngine != nil) {
+ return self.webViewEngine.engineWebView;
+ }
+
+ return nil;
+}
+
+/*
+// NOTE: for onPause and onResume, calls into JavaScript must not call or trigger any blocking UI, like alerts
+- (void) onPause {}
+- (void) onResume {}
+- (void) onOrientationWillChange {}
+- (void) onOrientationDidChange {}
+*/
+
+/* NOTE: calls into JavaScript must not call or trigger any blocking UI, like alerts */
+- (void)handleOpenURL:(NSNotification*)notification
+{
+ // override to handle urls sent to your app
+ // register your url schemes in your App-Info.plist
+
+ NSURL* url = [notification object];
+
+ if ([url isKindOfClass:[NSURL class]]) {
+ /* Do your thing! */
+ }
+}
+
+/* NOTE: calls into JavaScript must not call or trigger any blocking UI, like alerts */
+- (void)onAppTerminate
+{
+ // override this if you need to do any cleanup on app exit
+}
+
+- (void)onMemoryWarning
+{
+ // override to remove caches, etc
+}
+
+- (void)onReset
+{
+ // Override to cancel any long-running requests when the WebView navigates or refreshes.
+}
+
+- (void)dealloc
+{
+ [[NSNotificationCenter defaultCenter] removeObserver:self]; // this will remove all notifications unless added using addObserverForName:object:queue:usingBlock:
+}
+
+- (id)appDelegate
+{
+ return [[UIApplication sharedApplication] delegate];
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPluginResult.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPluginResult.h
new file mode 100644
index 00000000..56b8c232
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPluginResult.h
@@ -0,0 +1,66 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+#import "CDVAvailability.h"
+
+typedef enum {
+ CDVCommandStatus_NO_RESULT = 0,
+ CDVCommandStatus_OK,
+ CDVCommandStatus_CLASS_NOT_FOUND_EXCEPTION,
+ CDVCommandStatus_ILLEGAL_ACCESS_EXCEPTION,
+ CDVCommandStatus_INSTANTIATION_EXCEPTION,
+ CDVCommandStatus_MALFORMED_URL_EXCEPTION,
+ CDVCommandStatus_IO_EXCEPTION,
+ CDVCommandStatus_INVALID_ACTION,
+ CDVCommandStatus_JSON_EXCEPTION,
+ CDVCommandStatus_ERROR
+} CDVCommandStatus;
+
+@interface CDVPluginResult : NSObject {}
+
+@property (nonatomic, strong, readonly) NSNumber* status;
+@property (nonatomic, strong, readonly) id message;
+@property (nonatomic, strong) NSNumber* keepCallback;
+// This property can be used to scope the lifetime of another object. For example,
+// Use it to store the associated NSData when `message` is created using initWithBytesNoCopy.
+@property (nonatomic, strong) id associatedObject;
+
+- (CDVPluginResult*)init;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsString:(NSString*)theMessage;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsArray:(NSArray*)theMessage;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsInt:(int)theMessage;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsNSInteger:(NSInteger)theMessage;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsNSUInteger:(NSUInteger)theMessage;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsDouble:(double)theMessage;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsBool:(BOOL)theMessage;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsDictionary:(NSDictionary*)theMessage;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsArrayBuffer:(NSData*)theMessage;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsMultipart:(NSArray*)theMessages;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageToErrorObject:(int)errorCode;
+
++ (void)setVerbose:(BOOL)verbose;
++ (BOOL)isVerbose;
+
+- (void)setKeepCallbackAsBool:(BOOL)bKeepCallback;
+
+- (NSString*)argumentsAsJSON;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPluginResult.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPluginResult.m
new file mode 100644
index 00000000..3521e6d7
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVPluginResult.m
@@ -0,0 +1,186 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVPluginResult.h"
+#import "CDVJSON_private.h"
+#import "CDVDebug.h"
+
+@interface CDVPluginResult ()
+
+- (CDVPluginResult*)initWithStatus:(CDVCommandStatus)statusOrdinal message:(id)theMessage;
+
+@end
+
+@implementation CDVPluginResult
+@synthesize status, message, keepCallback, associatedObject;
+
+static NSArray* org_apache_cordova_CommandStatusMsgs;
+
+id messageFromArrayBuffer(NSData* data)
+{
+ return @{
+ @"CDVType" : @"ArrayBuffer",
+ @"data" :[data base64EncodedStringWithOptions:0]
+ };
+}
+
+id massageMessage(id message)
+{
+ if ([message isKindOfClass:[NSData class]]) {
+ return messageFromArrayBuffer(message);
+ }
+ return message;
+}
+
+id messageFromMultipart(NSArray* theMessages)
+{
+ NSMutableArray* messages = [NSMutableArray arrayWithArray:theMessages];
+
+ for (NSUInteger i = 0; i < messages.count; ++i) {
+ [messages replaceObjectAtIndex:i withObject:massageMessage([messages objectAtIndex:i])];
+ }
+
+ return @{
+ @"CDVType" : @"MultiPart",
+ @"messages" : messages
+ };
+}
+
++ (void)initialize
+{
+ org_apache_cordova_CommandStatusMsgs = [[NSArray alloc] initWithObjects:@"No result",
+ @"OK",
+ @"Class not found",
+ @"Illegal access",
+ @"Instantiation error",
+ @"Malformed url",
+ @"IO error",
+ @"Invalid action",
+ @"JSON error",
+ @"Error",
+ nil];
+}
+
+- (CDVPluginResult*)init
+{
+ return [self initWithStatus:CDVCommandStatus_NO_RESULT message:nil];
+}
+
+- (CDVPluginResult*)initWithStatus:(CDVCommandStatus)statusOrdinal message:(id)theMessage
+{
+ self = [super init];
+ if (self) {
+ status = [NSNumber numberWithInt:statusOrdinal];
+ message = theMessage;
+ keepCallback = [NSNumber numberWithBool:NO];
+ }
+ return self;
+}
+
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal
+{
+ return [[self alloc] initWithStatus:statusOrdinal message:nil];
+}
+
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsString:(NSString*)theMessage
+{
+ return [[self alloc] initWithStatus:statusOrdinal message:theMessage];
+}
+
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsArray:(NSArray*)theMessage
+{
+ return [[self alloc] initWithStatus:statusOrdinal message:theMessage];
+}
+
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsInt:(int)theMessage
+{
+ return [[self alloc] initWithStatus:statusOrdinal message:[NSNumber numberWithInt:theMessage]];
+}
+
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsNSInteger:(NSInteger)theMessage
+{
+ return [[self alloc] initWithStatus:statusOrdinal message:[NSNumber numberWithInteger:theMessage]];
+}
+
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsNSUInteger:(NSUInteger)theMessage
+{
+ return [[self alloc] initWithStatus:statusOrdinal message:[NSNumber numberWithUnsignedInteger:theMessage]];
+}
+
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsDouble:(double)theMessage
+{
+ return [[self alloc] initWithStatus:statusOrdinal message:[NSNumber numberWithDouble:theMessage]];
+}
+
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsBool:(BOOL)theMessage
+{
+ return [[self alloc] initWithStatus:statusOrdinal message:[NSNumber numberWithBool:theMessage]];
+}
+
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsDictionary:(NSDictionary*)theMessage
+{
+ return [[self alloc] initWithStatus:statusOrdinal message:theMessage];
+}
+
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsArrayBuffer:(NSData*)theMessage
+{
+ return [[self alloc] initWithStatus:statusOrdinal message:messageFromArrayBuffer(theMessage)];
+}
+
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsMultipart:(NSArray*)theMessages
+{
+ return [[self alloc] initWithStatus:statusOrdinal message:messageFromMultipart(theMessages)];
+}
+
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageToErrorObject:(int)errorCode
+{
+ NSDictionary* errDict = @{@"code" :[NSNumber numberWithInt:errorCode]};
+
+ return [[self alloc] initWithStatus:statusOrdinal message:errDict];
+}
+
+- (void)setKeepCallbackAsBool:(BOOL)bKeepCallback
+{
+ [self setKeepCallback:[NSNumber numberWithBool:bKeepCallback]];
+}
+
+- (NSString*)argumentsAsJSON
+{
+ id arguments = (self.message == nil ? [NSNull null] : self.message);
+ NSArray* argumentsWrappedInArray = [NSArray arrayWithObject:arguments];
+
+ NSString* argumentsJSON = [argumentsWrappedInArray cdv_JSONString];
+
+ argumentsJSON = [argumentsJSON substringWithRange:NSMakeRange(1, [argumentsJSON length] - 2)];
+
+ return argumentsJSON;
+}
+
+static BOOL gIsVerbose = NO;
++ (void)setVerbose:(BOOL)verbose
+{
+ gIsVerbose = verbose;
+}
+
++ (BOOL)isVerbose
+{
+ return gIsVerbose;
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVScreenOrientationDelegate.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVScreenOrientationDelegate.h
new file mode 100644
index 00000000..7226205a
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVScreenOrientationDelegate.h
@@ -0,0 +1,28 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+@protocol CDVScreenOrientationDelegate <NSObject>
+
+- (NSUInteger)supportedInterfaceOrientations;
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
+- (BOOL)shouldAutorotate;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVTimer.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVTimer.h
new file mode 100644
index 00000000..6d31593f
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVTimer.h
@@ -0,0 +1,27 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+@interface CDVTimer : NSObject
+
++ (void)start:(NSString*)name;
++ (void)stop:(NSString*)name;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVTimer.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVTimer.m
new file mode 100644
index 00000000..784e94d3
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVTimer.m
@@ -0,0 +1,123 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVTimer.h"
+
+#pragma mark CDVTimerItem
+
+@interface CDVTimerItem : NSObject
+
+@property (nonatomic, strong) NSString* name;
+@property (nonatomic, strong) NSDate* started;
+@property (nonatomic, strong) NSDate* ended;
+
+- (void)log;
+
+@end
+
+@implementation CDVTimerItem
+
+- (void)log
+{
+ NSLog(@"[CDVTimer][%@] %fms", self.name, [self.ended timeIntervalSinceDate:self.started] * 1000.0);
+}
+
+@end
+
+#pragma mark CDVTimer
+
+@interface CDVTimer ()
+
+@property (nonatomic, strong) NSMutableDictionary* items;
+
+@end
+
+@implementation CDVTimer
+
+#pragma mark object methods
+
+- (id)init
+{
+ if (self = [super init]) {
+ self.items = [NSMutableDictionary dictionaryWithCapacity:6];
+ }
+
+ return self;
+}
+
+- (void)add:(NSString*)name
+{
+ if ([self.items objectForKey:[name lowercaseString]] == nil) {
+ CDVTimerItem* item = [CDVTimerItem new];
+ item.name = name;
+ item.started = [NSDate new];
+ [self.items setObject:item forKey:[name lowercaseString]];
+ } else {
+ NSLog(@"Timer called '%@' already exists.", name);
+ }
+}
+
+- (void)remove:(NSString*)name
+{
+ CDVTimerItem* item = [self.items objectForKey:[name lowercaseString]];
+
+ if (item != nil) {
+ item.ended = [NSDate new];
+ [item log];
+ [self.items removeObjectForKey:[name lowercaseString]];
+ } else {
+ NSLog(@"Timer called '%@' does not exist.", name);
+ }
+}
+
+- (void)removeAll
+{
+ [self.items removeAllObjects];
+}
+
+#pragma mark class methods
+
++ (void)start:(NSString*)name
+{
+ [[CDVTimer sharedInstance] add:name];
+}
+
++ (void)stop:(NSString*)name
+{
+ [[CDVTimer sharedInstance] remove:name];
+}
+
++ (void)clearAll
+{
+ [[CDVTimer sharedInstance] removeAll];
+}
+
++ (CDVTimer*)sharedInstance
+{
+ static dispatch_once_t pred = 0;
+ __strong static CDVTimer* _sharedObject = nil;
+
+ dispatch_once(&pred, ^{
+ _sharedObject = [[self alloc] init];
+ });
+
+ return _sharedObject;
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVURLProtocol.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVURLProtocol.h
new file mode 100644
index 00000000..0561e04d
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVURLProtocol.h
@@ -0,0 +1,27 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+#import "CDVAvailability.h"
+
+@class CDVViewController;
+
+@interface CDVURLProtocol : NSURLProtocol {}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVURLProtocol.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVURLProtocol.m
new file mode 100644
index 00000000..7b2c5ce5
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVURLProtocol.m
@@ -0,0 +1,113 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <AssetsLibrary/ALAsset.h>
+#import <AssetsLibrary/ALAssetRepresentation.h>
+#import <AssetsLibrary/ALAssetsLibrary.h>
+#import <MobileCoreServices/MobileCoreServices.h>
+#import "CDVURLProtocol.h"
+#import "CDVCommandQueue.h"
+#import "CDVViewController.h"
+
+// Contains a set of NSNumbers of addresses of controllers. It doesn't store
+// the actual pointer to avoid retaining.
+static NSMutableSet* gRegisteredControllers = nil;
+
+NSString* const kCDVAssetsLibraryPrefixes = @"assets-library://";
+
+@implementation CDVURLProtocol
+
+
++ (BOOL)canInitWithRequest:(NSURLRequest*)theRequest
+{
+ NSURL* theUrl = [theRequest URL];
+
+ if ([[theUrl absoluteString] hasPrefix:kCDVAssetsLibraryPrefixes]) {
+ return YES;
+ }
+
+ return NO;
+}
+
++ (NSURLRequest*)canonicalRequestForRequest:(NSURLRequest*)request
+{
+ // NSLog(@"%@ received %@", self, NSStringFromSelector(_cmd));
+ return request;
+}
+
+- (void)startLoading
+{
+ // NSLog(@"%@ received %@ - start", self, NSStringFromSelector(_cmd));
+ NSURL* url = [[self request] URL];
+
+ if ([[url absoluteString] hasPrefix:kCDVAssetsLibraryPrefixes]) {
+ ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset* asset) {
+ if (asset) {
+ // We have the asset! Get the data and send it along.
+ ALAssetRepresentation* assetRepresentation = [asset defaultRepresentation];
+ NSString* MIMEType = (__bridge_transfer NSString*)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)[assetRepresentation UTI], kUTTagClassMIMEType);
+ Byte* buffer = (Byte*)malloc((unsigned long)[assetRepresentation size]);
+ NSUInteger bufferSize = [assetRepresentation getBytes:buffer fromOffset:0.0 length:(NSUInteger)[assetRepresentation size] error:nil];
+ NSData* data = [NSData dataWithBytesNoCopy:buffer length:bufferSize freeWhenDone:YES];
+ [self sendResponseWithResponseCode:200 data:data mimeType:MIMEType];
+ } else {
+ // Retrieving the asset failed for some reason. Send an error.
+ [self sendResponseWithResponseCode:404 data:nil mimeType:nil];
+ }
+ };
+ ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError* error) {
+ // Retrieving the asset failed for some reason. Send an error.
+ [self sendResponseWithResponseCode:401 data:nil mimeType:nil];
+ };
+
+ ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
+ [assetsLibrary assetForURL:url resultBlock:resultBlock failureBlock:failureBlock];
+ return;
+ }
+
+ NSString* body = [NSString stringWithFormat:@"Access not allowed to URL: %@", url];
+ [self sendResponseWithResponseCode:401 data:[body dataUsingEncoding:NSASCIIStringEncoding] mimeType:nil];
+}
+
+- (void)stopLoading
+{
+ // do any cleanup here
+}
+
++ (BOOL)requestIsCacheEquivalent:(NSURLRequest*)requestA toRequest:(NSURLRequest*)requestB
+{
+ return NO;
+}
+
+- (void)sendResponseWithResponseCode:(NSInteger)statusCode data:(NSData*)data mimeType:(NSString*)mimeType
+{
+ if (mimeType == nil) {
+ mimeType = @"text/plain";
+ }
+
+ NSHTTPURLResponse* response = [[NSHTTPURLResponse alloc] initWithURL:[[self request] URL] statusCode:statusCode HTTPVersion:@"HTTP/1.1" headerFields:@{@"Content-Type" : mimeType}];
+
+ [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
+ if (data != nil) {
+ [[self client] URLProtocol:self didLoadData:data];
+ }
+ [[self client] URLProtocolDidFinishLoading:self];
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVUserAgentUtil.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVUserAgentUtil.h
new file mode 100644
index 00000000..4de382f0
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVUserAgentUtil.h
@@ -0,0 +1,27 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+@interface CDVUserAgentUtil : NSObject
++ (NSString*)originalUserAgent;
++ (void)acquireLock:(void (^)(NSInteger lockToken))block;
++ (void)releaseLock:(NSInteger*)lockToken;
++ (void)setUserAgent:(NSString*)value lockToken:(NSInteger)lockToken;
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVUserAgentUtil.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVUserAgentUtil.m
new file mode 100644
index 00000000..b589e1f3
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVUserAgentUtil.m
@@ -0,0 +1,124 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVUserAgentUtil.h"
+
+#import <UIKit/UIKit.h>
+
+// #define VerboseLog NSLog
+#define VerboseLog(...) do {} while (0)
+
+static NSString* const kCdvUserAgentKey = @"Cordova-User-Agent";
+static NSString* const kCdvUserAgentVersionKey = @"Cordova-User-Agent-Version";
+
+static NSString* gOriginalUserAgent = nil;
+static NSInteger gNextLockToken = 0;
+static NSInteger gCurrentLockToken = 0;
+static NSMutableArray* gPendingSetUserAgentBlocks = nil;
+
+@implementation CDVUserAgentUtil
+
++ (NSString*)originalUserAgent
+{
+ if (gOriginalUserAgent == nil) {
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppLocaleDidChange:)
+ name:NSCurrentLocaleDidChangeNotification object:nil];
+
+ NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
+ NSString* systemVersion = [[UIDevice currentDevice] systemVersion];
+ NSString* localeStr = [[NSLocale currentLocale] localeIdentifier];
+ // Record the model since simulator can change it without re-install (CB-5420).
+ NSString* model = [UIDevice currentDevice].model;
+ // Record the version of the app so that we can bust the cache when it changes (CB-10078)
+ NSString* appVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];
+ NSString* systemAndLocale = [NSString stringWithFormat:@"%@ %@ %@ %@", appVersion, model, systemVersion, localeStr];
+
+ NSString* cordovaUserAgentVersion = [userDefaults stringForKey:kCdvUserAgentVersionKey];
+ gOriginalUserAgent = [userDefaults stringForKey:kCdvUserAgentKey];
+ BOOL cachedValueIsOld = ![systemAndLocale isEqualToString:cordovaUserAgentVersion];
+
+ if ((gOriginalUserAgent == nil) || cachedValueIsOld) {
+ UIWebView* sampleWebView = [[UIWebView alloc] initWithFrame:CGRectZero];
+ gOriginalUserAgent = [sampleWebView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
+
+ [userDefaults setObject:gOriginalUserAgent forKey:kCdvUserAgentKey];
+ [userDefaults setObject:systemAndLocale forKey:kCdvUserAgentVersionKey];
+
+ [userDefaults synchronize];
+ }
+ }
+ return gOriginalUserAgent;
+}
+
++ (void)onAppLocaleDidChange:(NSNotification*)notification
+{
+ // TODO: We should figure out how to update the user-agent of existing UIWebViews when this happens.
+ // Maybe use the PDF bug (noted in setUserAgent:).
+ gOriginalUserAgent = nil;
+}
+
++ (void)acquireLock:(void (^)(NSInteger lockToken))block
+{
+ if (gCurrentLockToken == 0) {
+ gCurrentLockToken = ++gNextLockToken;
+ VerboseLog(@"Gave lock %d", gCurrentLockToken);
+ block(gCurrentLockToken);
+ } else {
+ if (gPendingSetUserAgentBlocks == nil) {
+ gPendingSetUserAgentBlocks = [[NSMutableArray alloc] initWithCapacity:4];
+ }
+ VerboseLog(@"Waiting for lock");
+ [gPendingSetUserAgentBlocks addObject:block];
+ }
+}
+
++ (void)releaseLock:(NSInteger*)lockToken
+{
+ if (*lockToken == 0) {
+ return;
+ }
+ NSAssert(gCurrentLockToken == *lockToken, @"Got token %ld, expected %ld", (long)*lockToken, (long)gCurrentLockToken);
+
+ VerboseLog(@"Released lock %d", *lockToken);
+ if ([gPendingSetUserAgentBlocks count] > 0) {
+ void (^block)() = [gPendingSetUserAgentBlocks objectAtIndex:0];
+ [gPendingSetUserAgentBlocks removeObjectAtIndex:0];
+ gCurrentLockToken = ++gNextLockToken;
+ NSLog(@"Gave lock %ld", (long)gCurrentLockToken);
+ block(gCurrentLockToken);
+ } else {
+ gCurrentLockToken = 0;
+ }
+ *lockToken = 0;
+}
+
++ (void)setUserAgent:(NSString*)value lockToken:(NSInteger)lockToken
+{
+ NSAssert(gCurrentLockToken == lockToken, @"Got token %ld, expected %ld", (long)lockToken, (long)gCurrentLockToken);
+ VerboseLog(@"User-Agent set to: %@", value);
+
+ // Setting the UserAgent must occur before a UIWebView is instantiated.
+ // It is read per instantiation, so it does not affect previously created views.
+ // Except! When a PDF is loaded, all currently active UIWebViews reload their
+ // User-Agent from the NSUserDefaults some time after the DidFinishLoad of the PDF bah!
+ NSDictionary* dict = [[NSDictionary alloc] initWithObjectsAndKeys:value, @"UserAgent", nil];
+ [[NSUserDefaults standardUserDefaults] registerDefaults:dict];
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.h
new file mode 100644
index 00000000..90d33d22
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.h
@@ -0,0 +1,91 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <UIKit/UIKit.h>
+#import <Foundation/NSJSONSerialization.h>
+#import "CDVAvailability.h"
+#import "CDVInvokedUrlCommand.h"
+#import "CDVCommandDelegate.h"
+#import "CDVCommandQueue.h"
+#import "CDVScreenOrientationDelegate.h"
+#import "CDVPlugin.h"
+#import "CDVWebViewEngineProtocol.h"
+
+@interface CDVViewController : UIViewController <CDVScreenOrientationDelegate>{
+ @protected
+ id <CDVWebViewEngineProtocol> _webViewEngine;
+ @protected
+ id <CDVCommandDelegate> _commandDelegate;
+ @protected
+ CDVCommandQueue* _commandQueue;
+ NSString* _userAgent;
+}
+
+@property (nonatomic, readonly, weak) IBOutlet UIView* webView;
+
+@property (nonatomic, readonly, strong) NSMutableDictionary* pluginObjects;
+@property (nonatomic, readonly, strong) NSDictionary* pluginsMap;
+@property (nonatomic, readonly, strong) NSMutableDictionary* settings;
+@property (nonatomic, readonly, strong) NSXMLParser* configParser;
+
+@property (nonatomic, readwrite, copy) NSString* configFile;
+@property (nonatomic, readwrite, copy) NSString* wwwFolderName;
+@property (nonatomic, readwrite, copy) NSString* startPage;
+@property (nonatomic, readonly, strong) CDVCommandQueue* commandQueue;
+@property (nonatomic, readonly, strong) id <CDVWebViewEngineProtocol> webViewEngine;
+@property (nonatomic, readonly, strong) id <CDVCommandDelegate> commandDelegate;
+
+/**
+ The complete user agent that Cordova will use when sending web requests.
+ */
+@property (nonatomic, readonly) NSString* userAgent;
+
+/**
+ The base user agent data that Cordova will use to build its user agent. If this
+ property isn't set, Cordova will use the standard web view user agent as its
+ base.
+ */
+@property (nonatomic, readwrite, copy) NSString* baseUserAgent;
+
+/**
+ Takes/Gives an array of UIInterfaceOrientation (int) objects
+ ex. UIInterfaceOrientationPortrait
+*/
+@property (nonatomic, readwrite, strong) NSArray* supportedOrientations;
+
+/**
+ The address of the lock token used for controlling access to setting the user-agent
+ */
+@property (nonatomic, readonly) NSInteger* userAgentLockToken;
+
+- (UIView*)newCordovaViewWithFrame:(CGRect)bounds;
+
+- (NSString*)appURLScheme;
+- (NSURL*)errorURL;
+
+- (NSArray*)parseInterfaceOrientations:(NSArray*)orientations;
+- (BOOL)supportsOrientation:(UIInterfaceOrientation)orientation;
+
+- (id)getCommandInstance:(NSString*)pluginName;
+- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className;
+- (void)registerPlugin:(CDVPlugin*)plugin withPluginName:(NSString*)pluginName;
+
+- (void)parseSettingsWithParser:(NSObject <NSXMLParserDelegate>*)delegate;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.m
new file mode 100644
index 00000000..4019c204
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.m
@@ -0,0 +1,719 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <objc/message.h>
+#import "CDV.h"
+#import "CDVPlugin+Private.h"
+#import "CDVUIWebViewDelegate.h"
+#import "CDVConfigParser.h"
+#import "CDVUserAgentUtil.h"
+#import <AVFoundation/AVFoundation.h>
+#import "NSDictionary+CordovaPreferences.h"
+#import "CDVLocalStorage.h"
+#import "CDVCommandDelegateImpl.h"
+
+@interface CDVViewController () {
+ NSInteger _userAgentLockToken;
+}
+
+@property (nonatomic, readwrite, strong) NSXMLParser* configParser;
+@property (nonatomic, readwrite, strong) NSMutableDictionary* settings;
+@property (nonatomic, readwrite, strong) NSMutableDictionary* pluginObjects;
+@property (nonatomic, readwrite, strong) NSMutableArray* startupPluginNames;
+@property (nonatomic, readwrite, strong) NSDictionary* pluginsMap;
+@property (nonatomic, readwrite, strong) id <CDVWebViewEngineProtocol> webViewEngine;
+
+@property (readwrite, assign) BOOL initialized;
+
+@property (atomic, strong) NSURL* openURL;
+
+@end
+
+@implementation CDVViewController
+
+@synthesize supportedOrientations;
+@synthesize pluginObjects, pluginsMap, startupPluginNames;
+@synthesize configParser, settings;
+@synthesize wwwFolderName, startPage, initialized, openURL, baseUserAgent;
+@synthesize commandDelegate = _commandDelegate;
+@synthesize commandQueue = _commandQueue;
+@synthesize webViewEngine = _webViewEngine;
+@dynamic webView;
+
+- (void)__init
+{
+ if ((self != nil) && !self.initialized) {
+ _commandQueue = [[CDVCommandQueue alloc] initWithViewController:self];
+ _commandDelegate = [[CDVCommandDelegateImpl alloc] initWithViewController:self];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillTerminate:)
+ name:UIApplicationWillTerminateNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillResignActive:)
+ name:UIApplicationWillResignActiveNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidBecomeActive:)
+ name:UIApplicationDidBecomeActiveNotification object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillEnterForeground:)
+ name:UIApplicationWillEnterForegroundNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidEnterBackground:)
+ name:UIApplicationDidEnterBackgroundNotification object:nil];
+
+ // read from UISupportedInterfaceOrientations (or UISupportedInterfaceOrientations~iPad, if its iPad) from -Info.plist
+ self.supportedOrientations = [self parseInterfaceOrientations:
+ [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"]];
+
+ [self printVersion];
+ [self printMultitaskingInfo];
+ [self printPlatformVersionWarning];
+ self.initialized = YES;
+ }
+}
+
+- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
+{
+ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+ [self __init];
+ return self;
+}
+
+- (id)initWithCoder:(NSCoder*)aDecoder
+{
+ self = [super initWithCoder:aDecoder];
+ [self __init];
+ return self;
+}
+
+- (id)init
+{
+ self = [super init];
+ [self __init];
+ return self;
+}
+
+- (void)printVersion
+{
+ NSLog(@"Apache Cordova native platform version %@ is starting.", CDV_VERSION);
+}
+
+- (void)printPlatformVersionWarning
+{
+ if (!IsAtLeastiOSVersion(@"8.0")) {
+ NSLog(@"CRITICAL: For Cordova 4.0.0 and above, you will need to upgrade to at least iOS 8.0 or greater. Your current version of iOS is %@.",
+ [[UIDevice currentDevice] systemVersion]
+ );
+ }
+}
+
+- (void)printMultitaskingInfo
+{
+ UIDevice* device = [UIDevice currentDevice];
+ BOOL backgroundSupported = NO;
+
+ if ([device respondsToSelector:@selector(isMultitaskingSupported)]) {
+ backgroundSupported = device.multitaskingSupported;
+ }
+
+ NSNumber* exitsOnSuspend = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIApplicationExitsOnSuspend"];
+ if (exitsOnSuspend == nil) { // if it's missing, it should be NO (i.e. multi-tasking on by default)
+ exitsOnSuspend = [NSNumber numberWithBool:NO];
+ }
+
+ NSLog(@"Multi-tasking -> Device: %@, App: %@", (backgroundSupported ? @"YES" : @"NO"), (![exitsOnSuspend intValue]) ? @"YES" : @"NO");
+}
+
+-(NSString*)configFilePath{
+ NSString* path = self.configFile ?: @"config.xml";
+
+ // if path is relative, resolve it against the main bundle
+ if(![path isAbsolutePath]){
+ NSString* absolutePath = [[NSBundle mainBundle] pathForResource:path ofType:nil];
+ if(!absolutePath){
+ NSAssert(NO, @"ERROR: %@ not found in the main bundle!", path);
+ }
+ path = absolutePath;
+ }
+
+ // Assert file exists
+ if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
+ NSAssert(NO, @"ERROR: %@ does not exist. Please run cordova-ios/bin/cordova_plist_to_config_xml path/to/project.", path);
+ return nil;
+ }
+
+ return path;
+}
+
+- (void)parseSettingsWithParser:(NSObject <NSXMLParserDelegate>*)delegate
+{
+ // read from config.xml in the app bundle
+ NSString* path = [self configFilePath];
+
+ NSURL* url = [NSURL fileURLWithPath:path];
+
+ self.configParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
+ if (self.configParser == nil) {
+ NSLog(@"Failed to initialize XML parser.");
+ return;
+ }
+ [self.configParser setDelegate:((id < NSXMLParserDelegate >)delegate)];
+ [self.configParser parse];
+}
+
+- (void)loadSettings
+{
+ CDVConfigParser* delegate = [[CDVConfigParser alloc] init];
+
+ [self parseSettingsWithParser:delegate];
+
+ // Get the plugin dictionary, whitelist and settings from the delegate.
+ self.pluginsMap = delegate.pluginsDict;
+ self.startupPluginNames = delegate.startupPluginNames;
+ self.settings = delegate.settings;
+
+ // And the start folder/page.
+ if(self.wwwFolderName == nil){
+ self.wwwFolderName = @"www";
+ }
+ if(delegate.startPage && self.startPage == nil){
+ self.startPage = delegate.startPage;
+ }
+ if (self.startPage == nil) {
+ self.startPage = @"index.html";
+ }
+
+ // Initialize the plugin objects dict.
+ self.pluginObjects = [[NSMutableDictionary alloc] initWithCapacity:20];
+}
+
+- (NSURL*)appUrl
+{
+ NSURL* appURL = nil;
+
+ if ([self.startPage rangeOfString:@"://"].location != NSNotFound) {
+ appURL = [NSURL URLWithString:self.startPage];
+ } else if ([self.wwwFolderName rangeOfString:@"://"].location != NSNotFound) {
+ appURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", self.wwwFolderName, self.startPage]];
+ } else if([self.wwwFolderName hasSuffix:@".bundle"]){
+ // www folder is actually a bundle
+ NSBundle* bundle = [NSBundle bundleWithPath:self.wwwFolderName];
+ appURL = [bundle URLForResource:self.startPage withExtension:nil];
+ } else if([self.wwwFolderName hasSuffix:@".framework"]){
+ // www folder is actually a framework
+ NSBundle* bundle = [NSBundle bundleWithPath:self.wwwFolderName];
+ appURL = [bundle URLForResource:self.startPage withExtension:nil];
+ } else {
+ // CB-3005 strip parameters from start page to check if page exists in resources
+ NSURL* startURL = [NSURL URLWithString:self.startPage];
+ NSString* startFilePath = [self.commandDelegate pathForResource:[startURL path]];
+
+ if (startFilePath == nil) {
+ appURL = nil;
+ } else {
+ appURL = [NSURL fileURLWithPath:startFilePath];
+ // CB-3005 Add on the query params or fragment.
+ NSString* startPageNoParentDirs = self.startPage;
+ NSRange r = [startPageNoParentDirs rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"?#"] options:0];
+ if (r.location != NSNotFound) {
+ NSString* queryAndOrFragment = [self.startPage substringFromIndex:r.location];
+ appURL = [NSURL URLWithString:queryAndOrFragment relativeToURL:appURL];
+ }
+ }
+ }
+
+ return appURL;
+}
+
+- (NSURL*)errorURL
+{
+ NSURL* errorUrl = nil;
+
+ id setting = [self.settings cordovaSettingForKey:@"ErrorUrl"];
+
+ if (setting) {
+ NSString* errorUrlString = (NSString*)setting;
+ if ([errorUrlString rangeOfString:@"://"].location != NSNotFound) {
+ errorUrl = [NSURL URLWithString:errorUrlString];
+ } else {
+ NSURL* url = [NSURL URLWithString:(NSString*)setting];
+ NSString* errorFilePath = [self.commandDelegate pathForResource:[url path]];
+ if (errorFilePath) {
+ errorUrl = [NSURL fileURLWithPath:errorFilePath];
+ }
+ }
+ }
+
+ return errorUrl;
+}
+
+- (UIView*)webView
+{
+ if (self.webViewEngine != nil) {
+ return self.webViewEngine.engineWebView;
+ }
+
+ return nil;
+}
+
+// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+
+ // Load settings
+ [self loadSettings];
+
+ NSString* backupWebStorageType = @"cloud"; // default value
+
+ id backupWebStorage = [self.settings cordovaSettingForKey:@"BackupWebStorage"];
+ if ([backupWebStorage isKindOfClass:[NSString class]]) {
+ backupWebStorageType = backupWebStorage;
+ }
+ [self.settings setCordovaSetting:backupWebStorageType forKey:@"BackupWebStorage"];
+
+ [CDVLocalStorage __fixupDatabaseLocationsWithBackupType:backupWebStorageType];
+
+ // // Instantiate the WebView ///////////////
+
+ if (!self.webView) {
+ [self createGapView];
+ }
+
+ // /////////////////
+
+ /*
+ * Fire up CDVLocalStorage to work-around WebKit storage limitations: on all iOS 5.1+ versions for local-only backups, but only needed on iOS 5.1 for cloud backup.
+ With minimum iOS 7/8 supported, only first clause applies.
+ */
+ if ([backupWebStorageType isEqualToString:@"local"]) {
+ NSString* localStorageFeatureName = @"localstorage";
+ if ([self.pluginsMap objectForKey:localStorageFeatureName]) { // plugin specified in config
+ [self.startupPluginNames addObject:localStorageFeatureName];
+ }
+ }
+
+ if ([self.startupPluginNames count] > 0) {
+ [CDVTimer start:@"TotalPluginStartup"];
+
+ for (NSString* pluginName in self.startupPluginNames) {
+ [CDVTimer start:pluginName];
+ [self getCommandInstance:pluginName];
+ [CDVTimer stop:pluginName];
+ }
+
+ [CDVTimer stop:@"TotalPluginStartup"];
+ }
+
+ // /////////////////
+ NSURL* appURL = [self appUrl];
+
+ [CDVUserAgentUtil acquireLock:^(NSInteger lockToken) {
+ _userAgentLockToken = lockToken;
+ [CDVUserAgentUtil setUserAgent:self.userAgent lockToken:lockToken];
+ if (appURL) {
+ NSURLRequest* appReq = [NSURLRequest requestWithURL:appURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
+ [self.webViewEngine loadRequest:appReq];
+ } else {
+ NSString* loadErr = [NSString stringWithFormat:@"ERROR: Start Page at '%@/%@' was not found.", self.wwwFolderName, self.startPage];
+ NSLog(@"%@", loadErr);
+
+ NSURL* errorUrl = [self errorURL];
+ if (errorUrl) {
+ errorUrl = [NSURL URLWithString:[NSString stringWithFormat:@"?error=%@", [loadErr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] relativeToURL:errorUrl];
+ NSLog(@"%@", [errorUrl absoluteString]);
+ [self.webViewEngine loadRequest:[NSURLRequest requestWithURL:errorUrl]];
+ } else {
+ NSString* html = [NSString stringWithFormat:@"<html><body> %@ </body></html>", loadErr];
+ [self.webViewEngine loadHTMLString:html baseURL:nil];
+ }
+ }
+ }];
+}
+
+-(void)viewWillAppear:(BOOL)animated
+{
+ [super viewWillAppear:animated];
+ [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVViewWillAppearNotification object:nil]];
+}
+
+-(void)viewDidAppear:(BOOL)animated
+{
+ [super viewDidAppear:animated];
+ [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVViewDidAppearNotification object:nil]];
+}
+
+-(void)viewWillDisappear:(BOOL)animated
+{
+ [super viewWillDisappear:animated];
+ [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVViewWillDisappearNotification object:nil]];
+}
+
+-(void)viewDidDisappear:(BOOL)animated
+{
+ [super viewDidDisappear:animated];
+ [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVViewDidDisappearNotification object:nil]];
+}
+
+-(void)viewWillLayoutSubviews
+{
+ [super viewWillLayoutSubviews];
+ [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVViewWillLayoutSubviewsNotification object:nil]];
+}
+
+-(void)viewDidLayoutSubviews
+{
+ [super viewDidLayoutSubviews];
+ [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVViewDidLayoutSubviewsNotification object:nil]];
+}
+
+-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
+{
+ [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
+ [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVViewWillTransitionToSizeNotification object:[NSValue valueWithCGSize:size]]];
+}
+
+- (NSArray*)parseInterfaceOrientations:(NSArray*)orientations
+{
+ NSMutableArray* result = [[NSMutableArray alloc] init];
+
+ if (orientations != nil) {
+ NSEnumerator* enumerator = [orientations objectEnumerator];
+ NSString* orientationString;
+
+ while (orientationString = [enumerator nextObject]) {
+ if ([orientationString isEqualToString:@"UIInterfaceOrientationPortrait"]) {
+ [result addObject:[NSNumber numberWithInt:UIInterfaceOrientationPortrait]];
+ } else if ([orientationString isEqualToString:@"UIInterfaceOrientationPortraitUpsideDown"]) {
+ [result addObject:[NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown]];
+ } else if ([orientationString isEqualToString:@"UIInterfaceOrientationLandscapeLeft"]) {
+ [result addObject:[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]];
+ } else if ([orientationString isEqualToString:@"UIInterfaceOrientationLandscapeRight"]) {
+ [result addObject:[NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]];
+ }
+ }
+ }
+
+ // default
+ if ([result count] == 0) {
+ [result addObject:[NSNumber numberWithInt:UIInterfaceOrientationPortrait]];
+ }
+
+ return result;
+}
+
+- (BOOL)shouldAutorotate
+{
+ return YES;
+}
+
+- (NSUInteger)supportedInterfaceOrientations
+{
+ NSUInteger ret = 0;
+
+ if ([self supportsOrientation:UIInterfaceOrientationPortrait]) {
+ ret = ret | (1 << UIInterfaceOrientationPortrait);
+ }
+ if ([self supportsOrientation:UIInterfaceOrientationPortraitUpsideDown]) {
+ ret = ret | (1 << UIInterfaceOrientationPortraitUpsideDown);
+ }
+ if ([self supportsOrientation:UIInterfaceOrientationLandscapeRight]) {
+ ret = ret | (1 << UIInterfaceOrientationLandscapeRight);
+ }
+ if ([self supportsOrientation:UIInterfaceOrientationLandscapeLeft]) {
+ ret = ret | (1 << UIInterfaceOrientationLandscapeLeft);
+ }
+
+ return ret;
+}
+
+- (BOOL)supportsOrientation:(UIInterfaceOrientation)orientation
+{
+ return [self.supportedOrientations containsObject:[NSNumber numberWithInt:orientation]];
+}
+
+- (UIView*)newCordovaViewWithFrame:(CGRect)bounds
+{
+ NSString* defaultWebViewEngineClass = [self.settings cordovaSettingForKey:@"CordovaDefaultWebViewEngine"];
+ NSString* webViewEngineClass = [self.settings cordovaSettingForKey:@"CordovaWebViewEngine"];
+
+ if (!defaultWebViewEngineClass) {
+ defaultWebViewEngineClass = @"CDVUIWebViewEngine";
+ }
+ if (!webViewEngineClass) {
+ webViewEngineClass = defaultWebViewEngineClass;
+ }
+
+ // Find webViewEngine
+ if (NSClassFromString(webViewEngineClass)) {
+ self.webViewEngine = [[NSClassFromString(webViewEngineClass) alloc] initWithFrame:bounds];
+ // if a webView engine returns nil (not supported by the current iOS version) or doesn't conform to the protocol, or can't load the request, we use UIWebView
+ if (!self.webViewEngine || ![self.webViewEngine conformsToProtocol:@protocol(CDVWebViewEngineProtocol)] || ![self.webViewEngine canLoadRequest:[NSURLRequest requestWithURL:self.appUrl]]) {
+ self.webViewEngine = [[NSClassFromString(defaultWebViewEngineClass) alloc] initWithFrame:bounds];
+ }
+ } else {
+ self.webViewEngine = [[NSClassFromString(defaultWebViewEngineClass) alloc] initWithFrame:bounds];
+ }
+
+ if ([self.webViewEngine isKindOfClass:[CDVPlugin class]]) {
+ [self registerPlugin:(CDVPlugin*)self.webViewEngine withClassName:webViewEngineClass];
+ }
+
+ return self.webViewEngine.engineWebView;
+}
+
+- (NSString*)userAgent
+{
+ if (_userAgent != nil) {
+ return _userAgent;
+ }
+
+ NSString* localBaseUserAgent;
+ if (self.baseUserAgent != nil) {
+ localBaseUserAgent = self.baseUserAgent;
+ } else if ([self.settings cordovaSettingForKey:@"OverrideUserAgent"] != nil) {
+ localBaseUserAgent = [self.settings cordovaSettingForKey:@"OverrideUserAgent"];
+ } else {
+ localBaseUserAgent = [CDVUserAgentUtil originalUserAgent];
+ }
+ NSString* appendUserAgent = [self.settings cordovaSettingForKey:@"AppendUserAgent"];
+ if (appendUserAgent) {
+ _userAgent = [NSString stringWithFormat:@"%@ %@", localBaseUserAgent, appendUserAgent];
+ } else {
+ // Use our address as a unique number to append to the User-Agent.
+ _userAgent = [NSString stringWithFormat:@"%@ (%lld)", localBaseUserAgent, (long long)self];
+ }
+ return _userAgent;
+}
+
+- (void)createGapView
+{
+ CGRect webViewBounds = self.view.bounds;
+
+ webViewBounds.origin = self.view.bounds.origin;
+
+ UIView* view = [self newCordovaViewWithFrame:webViewBounds];
+
+ view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
+ [self.view addSubview:view];
+ [self.view sendSubviewToBack:view];
+}
+
+- (void)didReceiveMemoryWarning
+{
+ // iterate through all the plugin objects, and call hasPendingOperation
+ // if at least one has a pending operation, we don't call [super didReceiveMemoryWarning]
+
+ NSEnumerator* enumerator = [self.pluginObjects objectEnumerator];
+ CDVPlugin* plugin;
+
+ BOOL doPurge = YES;
+
+ while ((plugin = [enumerator nextObject])) {
+ if (plugin.hasPendingOperation) {
+ NSLog(@"Plugin '%@' has a pending operation, memory purge is delayed for didReceiveMemoryWarning.", NSStringFromClass([plugin class]));
+ doPurge = NO;
+ }
+ }
+
+ if (doPurge) {
+ // Releases the view if it doesn't have a superview.
+ [super didReceiveMemoryWarning];
+ }
+
+ // Release any cached data, images, etc. that aren't in use.
+}
+
+- (void)viewDidUnload
+{
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+
+ [CDVUserAgentUtil releaseLock:&_userAgentLockToken];
+
+ [super viewDidUnload];
+}
+
+#pragma mark CordovaCommands
+
+- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className
+{
+ if ([plugin respondsToSelector:@selector(setViewController:)]) {
+ [plugin setViewController:self];
+ }
+
+ if ([plugin respondsToSelector:@selector(setCommandDelegate:)]) {
+ [plugin setCommandDelegate:_commandDelegate];
+ }
+
+ [self.pluginObjects setObject:plugin forKey:className];
+ [plugin pluginInitialize];
+}
+
+- (void)registerPlugin:(CDVPlugin*)plugin withPluginName:(NSString*)pluginName
+{
+ if ([plugin respondsToSelector:@selector(setViewController:)]) {
+ [plugin setViewController:self];
+ }
+
+ if ([plugin respondsToSelector:@selector(setCommandDelegate:)]) {
+ [plugin setCommandDelegate:_commandDelegate];
+ }
+
+ NSString* className = NSStringFromClass([plugin class]);
+ [self.pluginObjects setObject:plugin forKey:className];
+ [self.pluginsMap setValue:className forKey:[pluginName lowercaseString]];
+ [plugin pluginInitialize];
+}
+
+/**
+ Returns an instance of a CordovaCommand object, based on its name. If one exists already, it is returned.
+ */
+- (id)getCommandInstance:(NSString*)pluginName
+{
+ // first, we try to find the pluginName in the pluginsMap
+ // (acts as a whitelist as well) if it does not exist, we return nil
+ // NOTE: plugin names are matched as lowercase to avoid problems - however, a
+ // possible issue is there can be duplicates possible if you had:
+ // "org.apache.cordova.Foo" and "org.apache.cordova.foo" - only the lower-cased entry will match
+ NSString* className = [self.pluginsMap objectForKey:[pluginName lowercaseString]];
+
+ if (className == nil) {
+ return nil;
+ }
+
+ id obj = [self.pluginObjects objectForKey:className];
+ if (!obj) {
+ obj = [[NSClassFromString(className)alloc] initWithWebViewEngine:_webViewEngine];
+
+ if (obj != nil) {
+ [self registerPlugin:obj withClassName:className];
+ } else {
+ NSLog(@"CDVPlugin class %@ (pluginName: %@) does not exist.", className, pluginName);
+ }
+ }
+ return obj;
+}
+
+#pragma mark -
+
+- (NSString*)appURLScheme
+{
+ NSString* URLScheme = nil;
+
+ NSArray* URLTypes = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleURLTypes"];
+
+ if (URLTypes != nil) {
+ NSDictionary* dict = [URLTypes objectAtIndex:0];
+ if (dict != nil) {
+ NSArray* URLSchemes = [dict objectForKey:@"CFBundleURLSchemes"];
+ if (URLSchemes != nil) {
+ URLScheme = [URLSchemes objectAtIndex:0];
+ }
+ }
+ }
+
+ return URLScheme;
+}
+
+#pragma mark -
+#pragma mark UIApplicationDelegate impl
+
+/*
+ This method lets your application know that it is about to be terminated and purged from memory entirely
+ */
+- (void)onAppWillTerminate:(NSNotification*)notification
+{
+ // empty the tmp directory
+ NSFileManager* fileMgr = [[NSFileManager alloc] init];
+ NSError* __autoreleasing err = nil;
+
+ // clear contents of NSTemporaryDirectory
+ NSString* tempDirectoryPath = NSTemporaryDirectory();
+ NSDirectoryEnumerator* directoryEnumerator = [fileMgr enumeratorAtPath:tempDirectoryPath];
+ NSString* fileName = nil;
+ BOOL result;
+
+ while ((fileName = [directoryEnumerator nextObject])) {
+ NSString* filePath = [tempDirectoryPath stringByAppendingPathComponent:fileName];
+ result = [fileMgr removeItemAtPath:filePath error:&err];
+ if (!result && err) {
+ NSLog(@"Failed to delete: %@ (error: %@)", filePath, err);
+ }
+ }
+}
+
+/*
+ This method is called to let your application know that it is about to move from the active to inactive state.
+ You should use this method to pause ongoing tasks, disable timer, ...
+ */
+- (void)onAppWillResignActive:(NSNotification*)notification
+{
+ // NSLog(@"%@",@"applicationWillResignActive");
+ [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('resign');" scheduledOnRunLoop:NO];
+}
+
+/*
+ In iOS 4.0 and later, this method is called as part of the transition from the background to the inactive state.
+ You can use this method to undo many of the changes you made to your application upon entering the background.
+ invariably followed by applicationDidBecomeActive
+ */
+- (void)onAppWillEnterForeground:(NSNotification*)notification
+{
+ // NSLog(@"%@",@"applicationWillEnterForeground");
+ [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('resume');"];
+
+ /** Clipboard fix **/
+ UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
+ NSString* string = pasteboard.string;
+ if (string) {
+ [pasteboard setValue:string forPasteboardType:@"public.text"];
+ }
+}
+
+// This method is called to let your application know that it moved from the inactive to active state.
+- (void)onAppDidBecomeActive:(NSNotification*)notification
+{
+ // NSLog(@"%@",@"applicationDidBecomeActive");
+ [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('active');"];
+}
+
+/*
+ In iOS 4.0 and later, this method is called instead of the applicationWillTerminate: method
+ when the user quits an application that supports background execution.
+ */
+- (void)onAppDidEnterBackground:(NSNotification*)notification
+{
+ // NSLog(@"%@",@"applicationDidEnterBackground");
+ [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('pause', null, true);" scheduledOnRunLoop:NO];
+}
+
+// ///////////////////////
+
+- (void)dealloc
+{
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+
+ [CDVUserAgentUtil releaseLock:&_userAgentLockToken];
+ [_commandQueue dispose];
+ [[self.pluginObjects allValues] makeObjectsPerformSelector:@selector(dispose)];
+}
+
+- (NSInteger*)userAgentLockToken
+{
+ return &_userAgentLockToken;
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWebViewEngineProtocol.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWebViewEngineProtocol.h
new file mode 100644
index 00000000..34d07f3d
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWebViewEngineProtocol.h
@@ -0,0 +1,42 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <UIKit/UIKit.h>
+
+#define kCDVWebViewEngineScriptMessageHandlers @"kCDVWebViewEngineScriptMessageHandlers"
+#define kCDVWebViewEngineUIWebViewDelegate @"kCDVWebViewEngineUIWebViewDelegate"
+#define kCDVWebViewEngineWKNavigationDelegate @"kCDVWebViewEngineWKNavigationDelegate"
+#define kCDVWebViewEngineWKUIDelegate @"kCDVWebViewEngineWKUIDelegate"
+#define kCDVWebViewEngineWebViewPreferences @"kCDVWebViewEngineWebViewPreferences"
+
+@protocol CDVWebViewEngineProtocol <NSObject>
+
+@property (nonatomic, strong, readonly) UIView* engineWebView;
+
+- (id)loadRequest:(NSURLRequest*)request;
+- (id)loadHTMLString:(NSString*)string baseURL:(NSURL*)baseURL;
+- (void)evaluateJavaScript:(NSString*)javaScriptString completionHandler:(void (^)(id, NSError*))completionHandler;
+
+- (NSURL*)URL;
+- (BOOL)canLoadRequest:(NSURLRequest*)request;
+
+- (instancetype)initWithFrame:(CGRect)frame;
+- (void)updateWithInfo:(NSDictionary*)info;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWhitelist.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWhitelist.h
new file mode 100644
index 00000000..91650970
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWhitelist.h
@@ -0,0 +1,34 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+extern NSString* const kCDVDefaultWhitelistRejectionString;
+
+@interface CDVWhitelist : NSObject
+
+@property (nonatomic, copy) NSString* whitelistRejectionFormatString;
+
+- (id)initWithArray:(NSArray*)array;
+- (BOOL)schemeIsAllowed:(NSString*)scheme;
+- (BOOL)URLIsAllowed:(NSURL*)url;
+- (BOOL)URLIsAllowed:(NSURL*)url logFailure:(BOOL)logFailure;
+- (NSString*)errorStringForURL:(NSURL*)url;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWhitelist.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWhitelist.m
new file mode 100644
index 00000000..552ea957
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWhitelist.m
@@ -0,0 +1,285 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVWhitelist.h"
+
+NSString* const kCDVDefaultWhitelistRejectionString = @"ERROR whitelist rejection: url='%@'";
+NSString* const kCDVDefaultSchemeName = @"cdv-default-scheme";
+
+@interface CDVWhitelistPattern : NSObject {
+ @private
+ NSRegularExpression* _scheme;
+ NSRegularExpression* _host;
+ NSNumber* _port;
+ NSRegularExpression* _path;
+}
+
++ (NSString*)regexFromPattern:(NSString*)pattern allowWildcards:(bool)allowWildcards;
+- (id)initWithScheme:(NSString*)scheme host:(NSString*)host port:(NSString*)port path:(NSString*)path;
+- (bool)matches:(NSURL*)url;
+
+@end
+
+@implementation CDVWhitelistPattern
+
++ (NSString*)regexFromPattern:(NSString*)pattern allowWildcards:(bool)allowWildcards
+{
+ NSString* regex = [NSRegularExpression escapedPatternForString:pattern];
+
+ if (allowWildcards) {
+ regex = [regex stringByReplacingOccurrencesOfString:@"\\*" withString:@".*"];
+
+ /* [NSURL path] has the peculiarity that a trailing slash at the end of a path
+ * will be omitted. This regex tweak compensates for that.
+ */
+ if ([regex hasSuffix:@"\\/.*"]) {
+ regex = [NSString stringWithFormat:@"%@(\\/.*)?", [regex substringToIndex:([regex length] - 4)]];
+ }
+ }
+ return [NSString stringWithFormat:@"%@$", regex];
+}
+
+- (id)initWithScheme:(NSString*)scheme host:(NSString*)host port:(NSString*)port path:(NSString*)path
+{
+ self = [super init]; // Potentially change "self"
+ if (self) {
+ if ((scheme == nil) || [scheme isEqualToString:@"*"]) {
+ _scheme = nil;
+ } else {
+ _scheme = [NSRegularExpression regularExpressionWithPattern:[CDVWhitelistPattern regexFromPattern:scheme allowWildcards:NO] options:NSRegularExpressionCaseInsensitive error:nil];
+ }
+ if ([host isEqualToString:@"*"] || host == nil) {
+ _host = nil;
+ } else if ([host hasPrefix:@"*."]) {
+ _host = [NSRegularExpression regularExpressionWithPattern:[NSString stringWithFormat:@"([a-z0-9.-]*\\.)?%@", [CDVWhitelistPattern regexFromPattern:[host substringFromIndex:2] allowWildcards:false]] options:NSRegularExpressionCaseInsensitive error:nil];
+ } else {
+ _host = [NSRegularExpression regularExpressionWithPattern:[CDVWhitelistPattern regexFromPattern:host allowWildcards:NO] options:NSRegularExpressionCaseInsensitive error:nil];
+ }
+ if ((port == nil) || [port isEqualToString:@"*"]) {
+ _port = nil;
+ } else {
+ _port = [[NSNumber alloc] initWithInteger:[port integerValue]];
+ }
+ if ((path == nil) || [path isEqualToString:@"/*"]) {
+ _path = nil;
+ } else {
+ _path = [NSRegularExpression regularExpressionWithPattern:[CDVWhitelistPattern regexFromPattern:path allowWildcards:YES] options:0 error:nil];
+ }
+ }
+ return self;
+}
+
+- (bool)matches:(NSURL*)url
+{
+ return (_scheme == nil || [_scheme numberOfMatchesInString:[url scheme] options:NSMatchingAnchored range:NSMakeRange(0, [[url scheme] length])]) &&
+ (_host == nil || ([url host] != nil && [_host numberOfMatchesInString:[url host] options:NSMatchingAnchored range:NSMakeRange(0, [[url host] length])])) &&
+ (_port == nil || [[url port] isEqualToNumber:_port]) &&
+ (_path == nil || [_path numberOfMatchesInString:[url path] options:NSMatchingAnchored range:NSMakeRange(0, [[url path] length])])
+ ;
+}
+
+@end
+
+@interface CDVWhitelist ()
+
+@property (nonatomic, readwrite, strong) NSMutableArray* whitelist;
+@property (nonatomic, readwrite, strong) NSMutableSet* permittedSchemes;
+
+- (void)addWhiteListEntry:(NSString*)pattern;
+
+@end
+
+@implementation CDVWhitelist
+
+@synthesize whitelist, permittedSchemes, whitelistRejectionFormatString;
+
+- (id)initWithArray:(NSArray*)array
+{
+ self = [super init];
+ if (self) {
+ self.whitelist = [[NSMutableArray alloc] init];
+ self.permittedSchemes = [[NSMutableSet alloc] init];
+ self.whitelistRejectionFormatString = kCDVDefaultWhitelistRejectionString;
+
+ for (NSString* pattern in array) {
+ [self addWhiteListEntry:pattern];
+ }
+ }
+ return self;
+}
+
+- (BOOL)isIPv4Address:(NSString*)externalHost
+{
+ // an IPv4 address has 4 octets b.b.b.b where b is a number between 0 and 255.
+ // for our purposes, b can also be the wildcard character '*'
+
+ // we could use a regex to solve this problem but then I would have two problems
+ // anyways, this is much clearer and maintainable
+ NSArray* octets = [externalHost componentsSeparatedByString:@"."];
+ NSUInteger num_octets = [octets count];
+
+ // quick check
+ if (num_octets != 4) {
+ return NO;
+ }
+
+ // restrict number parsing to 0-255
+ NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
+ [numberFormatter setMinimum:[NSNumber numberWithUnsignedInteger:0]];
+ [numberFormatter setMaximum:[NSNumber numberWithUnsignedInteger:255]];
+
+ // iterate through each octet, and test for a number between 0-255 or if it equals '*'
+ for (NSUInteger i = 0; i < num_octets; ++i) {
+ NSString* octet = [octets objectAtIndex:i];
+
+ if ([octet isEqualToString:@"*"]) { // passes - check next octet
+ continue;
+ } else if ([numberFormatter numberFromString:octet] == nil) { // fails - not a number and not within our range, return
+ return NO;
+ }
+ }
+
+ return YES;
+}
+
+- (void)addWhiteListEntry:(NSString*)origin
+{
+ if (self.whitelist == nil) {
+ return;
+ }
+
+ if ([origin isEqualToString:@"*"]) {
+ NSLog(@"Unlimited access to network resources");
+ self.whitelist = nil;
+ self.permittedSchemes = nil;
+ } else { // specific access
+ NSRegularExpression* parts = [NSRegularExpression regularExpressionWithPattern:@"^((\\*|[A-Za-z-]+):/?/?)?(((\\*\\.)?[^*/:]+)|\\*)?(:(\\d+))?(/.*)?" options:0 error:nil];
+ NSTextCheckingResult* m = [parts firstMatchInString:origin options:NSMatchingAnchored range:NSMakeRange(0, [origin length])];
+ if (m != nil) {
+ NSRange r;
+ NSString* scheme = nil;
+ r = [m rangeAtIndex:2];
+ if (r.location != NSNotFound) {
+ scheme = [origin substringWithRange:r];
+ }
+
+ NSString* host = nil;
+ r = [m rangeAtIndex:3];
+ if (r.location != NSNotFound) {
+ host = [origin substringWithRange:r];
+ }
+
+ // Special case for two urls which are allowed to have empty hosts
+ if (([scheme isEqualToString:@"file"] || [scheme isEqualToString:@"content"]) && (host == nil)) {
+ host = @"*";
+ }
+
+ NSString* port = nil;
+ r = [m rangeAtIndex:7];
+ if (r.location != NSNotFound) {
+ port = [origin substringWithRange:r];
+ }
+
+ NSString* path = nil;
+ r = [m rangeAtIndex:8];
+ if (r.location != NSNotFound) {
+ path = [origin substringWithRange:r];
+ }
+
+ if (scheme == nil) {
+ // XXX making it stupid friendly for people who forget to include protocol/SSL
+ [self.whitelist addObject:[[CDVWhitelistPattern alloc] initWithScheme:@"http" host:host port:port path:path]];
+ [self.whitelist addObject:[[CDVWhitelistPattern alloc] initWithScheme:@"https" host:host port:port path:path]];
+ } else {
+ [self.whitelist addObject:[[CDVWhitelistPattern alloc] initWithScheme:scheme host:host port:port path:path]];
+ }
+
+ if (self.permittedSchemes != nil) {
+ if ([scheme isEqualToString:@"*"]) {
+ self.permittedSchemes = nil;
+ } else if (scheme != nil) {
+ [self.permittedSchemes addObject:scheme];
+ }
+ }
+ }
+ }
+}
+
+- (BOOL)schemeIsAllowed:(NSString*)scheme
+{
+ if ([scheme isEqualToString:@"http"] ||
+ [scheme isEqualToString:@"https"] ||
+ [scheme isEqualToString:@"ftp"] ||
+ [scheme isEqualToString:@"ftps"]) {
+ return YES;
+ }
+
+ return (self.permittedSchemes == nil) || [self.permittedSchemes containsObject:scheme];
+}
+
+- (BOOL)URLIsAllowed:(NSURL*)url
+{
+ return [self URLIsAllowed:url logFailure:YES];
+}
+
+- (BOOL)URLIsAllowed:(NSURL*)url logFailure:(BOOL)logFailure
+{
+ // Shortcut acceptance: Are all urls whitelisted ("*" in whitelist)?
+ if (whitelist == nil) {
+ return YES;
+ }
+
+ // Shortcut rejection: Check that the scheme is supported
+ NSString* scheme = [[url scheme] lowercaseString];
+ if (![self schemeIsAllowed:scheme]) {
+ if (logFailure) {
+ NSLog(@"%@", [self errorStringForURL:url]);
+ }
+ return NO;
+ }
+
+ // http[s] and ftp[s] should also validate against the common set in the kCDVDefaultSchemeName list
+ if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString:@"ftp"] || [scheme isEqualToString:@"ftps"]) {
+ NSURL* newUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@%@", kCDVDefaultSchemeName, [url host], [[url path] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
+ // If it is allowed, we are done. If not, continue to check for the actual scheme-specific list
+ if ([self URLIsAllowed:newUrl logFailure:NO]) {
+ return YES;
+ }
+ }
+
+ // Check the url against patterns in the whitelist
+ for (CDVWhitelistPattern* p in self.whitelist) {
+ if ([p matches:url]) {
+ return YES;
+ }
+ }
+
+ if (logFailure) {
+ NSLog(@"%@", [self errorStringForURL:url]);
+ }
+ // if we got here, the url host is not in the white-list, do nothing
+ return NO;
+}
+
+- (NSString*)errorStringForURL:(NSURL*)url
+{
+ return [NSString stringWithFormat:self.whitelistRejectionFormatString, [url absoluteString]];
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSDictionary+CordovaPreferences.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSDictionary+CordovaPreferences.h
new file mode 100644
index 00000000..9be2be2d
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSDictionary+CordovaPreferences.h
@@ -0,0 +1,35 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+
+@interface NSDictionary (CordovaPreferences)
+
+- (id)cordovaSettingForKey:(NSString*)key;
+- (BOOL)cordovaBoolSettingForKey:(NSString*)key defaultValue:(BOOL)defaultValue;
+- (CGFloat)cordovaFloatSettingForKey:(NSString*)key defaultValue:(CGFloat)defaultValue;
+
+@end
+
+@interface NSMutableDictionary (CordovaPreferences)
+
+- (void)setCordovaSetting:(id)value forKey:(NSString*)key;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSDictionary+CordovaPreferences.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSDictionary+CordovaPreferences.m
new file mode 100644
index 00000000..dcac40f1
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSDictionary+CordovaPreferences.m
@@ -0,0 +1,63 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "NSDictionary+CordovaPreferences.h"
+#import <Foundation/Foundation.h>
+
+@implementation NSDictionary (CordovaPreferences)
+
+- (id)cordovaSettingForKey:(NSString*)key
+{
+ return [self objectForKey:[key lowercaseString]];
+}
+
+- (BOOL)cordovaBoolSettingForKey:(NSString*)key defaultValue:(BOOL)defaultValue
+{
+ BOOL value = defaultValue;
+ id prefObj = [self cordovaSettingForKey:key];
+
+ if (prefObj != nil) {
+ value = [(NSNumber*)prefObj boolValue];
+ }
+
+ return value;
+}
+
+- (CGFloat)cordovaFloatSettingForKey:(NSString*)key defaultValue:(CGFloat)defaultValue
+{
+ CGFloat value = defaultValue;
+ id prefObj = [self cordovaSettingForKey:key];
+
+ if (prefObj != nil) {
+ value = [prefObj floatValue];
+ }
+
+ return value;
+}
+
+@end
+
+@implementation NSMutableDictionary (CordovaPreferences)
+
+- (void)setCordovaSetting:(id)value forKey:(NSString*)key
+{
+ [self setObject:value forKey:[key lowercaseString]];
+}
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSMutableArray+QueueAdditions.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSMutableArray+QueueAdditions.h
new file mode 100644
index 00000000..79e65164
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSMutableArray+QueueAdditions.h
@@ -0,0 +1,29 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+@interface NSMutableArray (QueueAdditions)
+
+- (id)cdv_pop;
+- (id)cdv_queueHead;
+- (id)cdv_dequeue;
+- (void)cdv_enqueue:(id)obj;
+
+@end
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSMutableArray+QueueAdditions.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSMutableArray+QueueAdditions.m
new file mode 100644
index 00000000..2b3acdc0
--- /dev/null
+++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/NSMutableArray+QueueAdditions.m
@@ -0,0 +1,58 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "NSMutableArray+QueueAdditions.h"
+
+@implementation NSMutableArray (QueueAdditions)
+
+- (id)cdv_queueHead
+{
+ if ([self count] == 0) {
+ return nil;
+ }
+
+ return [self objectAtIndex:0];
+}
+
+- (__autoreleasing id)cdv_dequeue
+{
+ if ([self count] == 0) {
+ return nil;
+ }
+
+ id head = [self objectAtIndex:0];
+ if (head != nil) {
+ // [[head retain] autorelease]; ARC - the __autoreleasing on the return value should so the same thing
+ [self removeObjectAtIndex:0];
+ }
+
+ return head;
+}
+
+- (id)cdv_pop
+{
+ return [self cdv_dequeue];
+}
+
+- (void)cdv_enqueue:(id)object
+{
+ [self addObject:object];
+}
+
+@end