-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alexbassy
authored and
alexbassy
committed
Oct 11, 2013
0 parents
commit 2321142
Showing
183 changed files
with
29,481 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.mode1v3 | ||
*.perspectivev3 | ||
*.pbxuser | ||
.DS_Store | ||
build | ||
www/phonegap.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
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 "CDVPlugin.h" | ||
#import "CDVViewController.h" | ||
#import "CDVCommandDelegate.h" | ||
#import "CDVURLProtocol.h" | ||
#import "CDVInvokedUrlCommand.h" | ||
|
||
#import "CDVDebug.h" | ||
#import "CDVPluginResult.h" | ||
#import "CDVWhitelist.h" | ||
#import "CDVLocalStorage.h" | ||
#import "CDVScreenOrientationDelegate.h" | ||
#import "CDVTimer.h" | ||
|
||
#import "NSArray+Comparisons.h" | ||
#import "NSData+Base64.h" | ||
#import "NSDictionary+Extensions.h" | ||
#import "NSMutableArray+QueueAdditions.h" | ||
#import "UIDevice+Extensions.h" | ||
|
||
#import "CDVJSON.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
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. | ||
*/ | ||
|
||
#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_NA 99999 /* not available */ | ||
|
||
/* | ||
#if CORDOVA_VERSION_MIN_REQUIRED >= __CORDOVA_1_7_0 | ||
// do something when its at least 1.7.0 | ||
#else | ||
// do something else (non 1.7.0) | ||
#endif | ||
*/ | ||
#ifndef CORDOVA_VERSION_MIN_REQUIRED | ||
#define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_3_1_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) | ||
|
||
#define CDV_IsIPad() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] && ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)) | ||
|
||
#define CDV_IsIPhone5() ([[UIScreen mainScreen] bounds].size.height == 568 && [[UIScreen mainScreen] bounds].size.width == 320) | ||
|
||
/* 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] | ||
|
||
#ifdef __clang__ | ||
#define CDV_DEPRECATED(version, msg) __attribute__((deprecated("Deprecated in Cordova " #version ". " msg))) | ||
#else | ||
#define CDV_DEPRECATED(version, msg) __attribute__((deprecated())) | ||
#endif | ||
|
||
// Enable this to log all exec() calls. | ||
#define CDV_ENABLE_EXEC_LOGGING 0 | ||
#if CDV_ENABLE_EXEC_LOGGING | ||
#define CDV_EXEC_LOG NSLog | ||
#else | ||
#define CDV_EXEC_LOG(...) do {} while (NO) | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
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; | ||
|
||
@protocol CDVCommandDelegate <NSObject> | ||
|
||
@property (nonatomic, readonly) NSDictionary* settings; | ||
|
||
- (NSString*)pathForResource:(NSString*)resourcepath; | ||
- (id)getCommandInstance:(NSString*)pluginName; | ||
|
||
// Plugins should not be using this interface to call other plugins since it | ||
// will result in bogus callbacks being made. | ||
- (BOOL)execute:(CDVInvokedUrlCommand*)command CDV_DEPRECATED(2.2, "Use direct method calls instead."); | ||
|
||
// 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; | ||
// Returns whether the given URL passes the white-list. | ||
- (BOOL)URLIsWhitelisted:(NSURL*)url; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
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; | ||
@protected | ||
__weak CDVCommandQueue* _commandQueue; | ||
} | ||
- (id)initWithViewController:(CDVViewController*)viewController; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
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.h" | ||
#import "CDVCommandQueue.h" | ||
#import "CDVPluginResult.h" | ||
#import "CDVViewController.h" | ||
|
||
@implementation CDVCommandDelegateImpl | ||
|
||
- (id)initWithViewController:(CDVViewController*)viewController | ||
{ | ||
self = [super init]; | ||
if (self != nil) { | ||
_viewController = viewController; | ||
_commandQueue = _viewController.commandQueue; | ||
} | ||
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)evalJsHelper2:(NSString*)js | ||
{ | ||
CDV_EXEC_LOG(@"Exec: evalling: %@", [js substringToIndex:MIN([js length], 160)]); | ||
NSString* commandsJSON = [_viewController.webView stringByEvaluatingJavaScriptFromString:js]; | ||
if ([commandsJSON length] > 0) { | ||
CDV_EXEC_LOG(@"Exec: Retrieved new exec messages by chaining."); | ||
} | ||
|
||
[_commandQueue enqueCommandBatch:commandsJSON]; | ||
} | ||
|
||
- (void)evalJsHelper:(NSString*)js | ||
{ | ||
// Cycle the run-loop before executing the JS. | ||
// 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 reaon, | ||
// but performSelectorOnMainThread: does. | ||
if (![NSThread isMainThread] || !_commandQueue.currentlyExecuting) { | ||
[self performSelectorOnMainThread:@selector(evalJsHelper2:) withObject:js waitUntilDone:NO]; | ||
} else { | ||
[self evalJsHelper2:js]; | ||
} | ||
} | ||
|
||
- (void)sendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId | ||
{ | ||
CDV_EXEC_LOG(@"Exec(%@): Sending result. Status=%@", callbackId, result.status); | ||
// This occurs when there is are no win/fail callbacks for the call. | ||
if ([@"INVALID" isEqualToString : callbackId]) { | ||
return; | ||
} | ||
int status = [result.status intValue]; | ||
BOOL keepCallback = [result.keepCallback boolValue]; | ||
NSString* argumentsAsJSON = [result argumentsAsJSON]; | ||
|
||
NSString* js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeCallback('%@',%d,%@,%d)", callbackId, status, argumentsAsJSON, keepCallback]; | ||
|
||
[self evalJsHelper:js]; | ||
} | ||
|
||
- (void)evalJs:(NSString*)js | ||
{ | ||
[self evalJs:js scheduledOnRunLoop:YES]; | ||
} | ||
|
||
- (void)evalJs:(NSString*)js scheduledOnRunLoop:(BOOL)scheduledOnRunLoop | ||
{ | ||
js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeEvalAndFetch(function(){%@})", js]; | ||
if (scheduledOnRunLoop) { | ||
[self evalJsHelper:js]; | ||
} else { | ||
[self evalJsHelper2:js]; | ||
} | ||
} | ||
|
||
- (BOOL)execute:(CDVInvokedUrlCommand*)command | ||
{ | ||
return [_commandQueue execute:command]; | ||
} | ||
|
||
- (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]; | ||
} | ||
|
||
- (BOOL)URLIsWhitelisted:(NSURL*)url | ||
{ | ||
return ![_viewController.whitelist schemeIsAllowed:[url scheme]] || | ||
[_viewController.whitelist URLIsAllowed:url]; | ||
} | ||
|
||
- (NSDictionary*)settings | ||
{ | ||
return _viewController.settings; | ||
} | ||
|
||
@end |
Oops, something went wrong.