diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-09-26 01:35:13 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-09-26 01:35:13 +0200 |
| commit | 597fa051833ca3df6eb185c0143ff82e02dacba1 (patch) | |
| tree | cb25347477c57f82e955b054b70f4bb5359fb0d2 /StoneIsland/platforms/ios/CordovaLib/Classes | |
| parent | 6a9186aea6b85beef28e3eb765fbf2322a1c7890 (diff) | |
push plugin ugh
Diffstat (limited to 'StoneIsland/platforms/ios/CordovaLib/Classes')
9 files changed, 97 insertions, 14 deletions
diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m index bc8f7200..2b13849f 100644 --- a/StoneIsland/platforms/ios/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m +++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m @@ -118,7 +118,18 @@ // only allow-intent if it's a UIWebViewNavigationTypeLinkClicked (anchor tag) OR // it's a UIWebViewNavigationTypeOther, and it's an internal link if ([[self class] shouldOpenURLRequest:request navigationType:navigationType]){ +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 + // CB-11895; openURL with a single parameter is deprecated in iOS 10 + // see https://useyourloaf.com/blog/openurl-deprecated-in-ios10 + if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) { + [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; + } else { + [[UIApplication sharedApplication] openURL:url]; + } +#else + // fall back if on older SDK [[UIApplication sharedApplication] openURL:url]; +#endif } // consume the request (i.e. no error) if it wasn't handled above diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m index 6e316595..348c2845 100644 --- a/StoneIsland/platforms/ios/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m +++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m @@ -78,7 +78,7 @@ NSURL* errorUrl = vc.errorURL; if (errorUrl) { - errorUrl = [NSURL URLWithString:[NSString stringWithFormat:@"?error=%@", [message stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] relativeToURL:errorUrl]; + errorUrl = [NSURL URLWithString:[NSString stringWithFormat:@"?error=%@", [message stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLPathAllowedCharacterSet]] relativeToURL:errorUrl]; NSLog(@"%@", [errorUrl absoluteString]); [theWebView loadRequest:[NSURLRequest requestWithURL:errorUrl]]; } diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAppDelegate.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAppDelegate.m index 13c2e7bd..821b957e 100644 --- a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAppDelegate.m +++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAppDelegate.m @@ -85,9 +85,9 @@ return YES; } -#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 +#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 - (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window -#else +#else //CB-12098. Defaults to UIInterfaceOrientationMask for iOS 9+ - (UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window #endif { diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAvailability.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAvailability.h index 4e332412..38bdfd73 100644 --- a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAvailability.h +++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVAvailability.h @@ -66,6 +66,7 @@ #define __CORDOVA_4_2_1 40201 #define __CORDOVA_4_3_0 40300 #define __CORDOVA_4_3_1 40301 +#define __CORDOVA_4_4_0 40400 /* coho:next-version,insert-before */ #define __CORDOVA_NA 99999 /* not available */ @@ -78,7 +79,7 @@ */ #ifndef CORDOVA_VERSION_MIN_REQUIRED /* coho:next-version-min-required,replace-after */ - #define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_4_3_1 + #define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_4_4_0 #endif /* diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVScreenOrientationDelegate.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVScreenOrientationDelegate.h index 7226205a..519dd490 100644 --- a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVScreenOrientationDelegate.h +++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVScreenOrientationDelegate.h @@ -21,7 +21,12 @@ @protocol CDVScreenOrientationDelegate <NSObject> -- (NSUInteger)supportedInterfaceOrientations; +#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 +- (NSUInteger)supportedInterfaceOrientations; +#else +- (UIInterfaceOrientationMask)supportedInterfaceOrientations; +#endif + - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; - (BOOL)shouldAutorotate; diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVUserAgentUtil.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVUserAgentUtil.m index b589e1f3..b17107e1 100644 --- a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVUserAgentUtil.m +++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVUserAgentUtil.m @@ -90,7 +90,7 @@ static NSMutableArray* gPendingSetUserAgentBlocks = nil; + (void)releaseLock:(NSInteger*)lockToken { - if (*lockToken == 0) { + if (lockToken == nil || *lockToken == 0) { return; } NSAssert(gCurrentLockToken == *lockToken, @"Got token %ld, expected %ld", (long)*lockToken, (long)gCurrentLockToken); diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.h b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.h index 90d33d22..605dbbbf 100644 --- a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.h +++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.h @@ -79,6 +79,7 @@ - (NSString*)appURLScheme; - (NSURL*)errorURL; +- (UIColor*)colorFromColorString:(NSString*)colorString; - (NSArray*)parseInterfaceOrientations:(NSArray*)orientations; - (BOOL)supportsOrientation:(UIInterfaceOrientation)orientation; diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.m index 4019c204..d0c05865 100644 --- a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.m +++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVViewController.m @@ -27,6 +27,7 @@ #import "NSDictionary+CordovaPreferences.h" #import "CDVLocalStorage.h" #import "CDVCommandDelegateImpl.h" +#import <Foundation/NSCharacterSet.h> @interface CDVViewController () { NSInteger _userAgentLockToken; @@ -207,11 +208,11 @@ 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"]){ + } else if([self.wwwFolderName rangeOfString:@".bundle"].location != NSNotFound){ // 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"]){ + } else if([self.wwwFolderName rangeOfString:@".framework"].location != NSNotFound){ // www folder is actually a framework NSBundle* bundle = [NSBundle bundleWithPath:self.wwwFolderName]; appURL = [bundle URLForResource:self.startPage withExtension:nil]; @@ -319,10 +320,11 @@ // ///////////////// NSURL* appURL = [self appUrl]; + __weak __typeof__(self) weakSelf = self; [CDVUserAgentUtil acquireLock:^(NSInteger lockToken) { - _userAgentLockToken = lockToken; - [CDVUserAgentUtil setUserAgent:self.userAgent lockToken:lockToken]; + // Fix the memory leak caused by the strong reference. + [weakSelf setLockToken:lockToken]; if (appURL) { NSURLRequest* appReq = [NSURLRequest requestWithURL:appURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0]; [self.webViewEngine loadRequest:appReq]; @@ -332,7 +334,7 @@ NSURL* errorUrl = [self errorURL]; if (errorUrl) { - errorUrl = [NSURL URLWithString:[NSString stringWithFormat:@"?error=%@", [loadErr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] relativeToURL:errorUrl]; + errorUrl = [NSURL URLWithString:[NSString stringWithFormat:@"?error=%@", [loadErr stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLPathAllowedCharacterSet]] relativeToURL:errorUrl]; NSLog(@"%@", [errorUrl absoluteString]); [self.webViewEngine loadRequest:[NSURLRequest requestWithURL:errorUrl]]; } else { @@ -341,6 +343,18 @@ } } }]; + + // ///////////////// + + NSString* bgColorString = [self.settings cordovaSettingForKey:@"BackgroundColor"]; + UIColor* bgColor = [self colorFromColorString:bgColorString]; + [self.webView setBackgroundColor:bgColor]; +} + +- (void)setLockToken:(NSInteger)lockToken +{ + _userAgentLockToken = lockToken; + [CDVUserAgentUtil setUserAgent:self.userAgent lockToken:lockToken]; } -(void)viewWillAppear:(BOOL)animated @@ -385,6 +399,52 @@ [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVViewWillTransitionToSizeNotification object:[NSValue valueWithCGSize:size]]]; } +- (UIColor*)colorFromColorString:(NSString*)colorString +{ + // No value, nothing to do + if (!colorString) { + return nil; + } + + // Validate format + NSError* error = NULL; + NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"^(#[0-9A-F]{3}|(0x|#)([0-9A-F]{2})?[0-9A-F]{6})$" options:NSRegularExpressionCaseInsensitive error:&error]; + NSUInteger countMatches = [regex numberOfMatchesInString:colorString options:0 range:NSMakeRange(0, [colorString length])]; + + if (!countMatches) { + return nil; + } + + // #FAB to #FFAABB + if ([colorString hasPrefix:@"#"] && [colorString length] == 4) { + NSString* r = [colorString substringWithRange:NSMakeRange(1, 1)]; + NSString* g = [colorString substringWithRange:NSMakeRange(2, 1)]; + NSString* b = [colorString substringWithRange:NSMakeRange(3, 1)]; + colorString = [NSString stringWithFormat:@"#%@%@%@%@%@%@", r, r, g, g, b, b]; + } + + // #RRGGBB to 0xRRGGBB + colorString = [colorString stringByReplacingOccurrencesOfString:@"#" withString:@"0x"]; + + // 0xRRGGBB to 0xAARRGGBB + if ([colorString hasPrefix:@"0x"] && [colorString length] == 8) { + colorString = [@"0xFF" stringByAppendingString:[colorString substringFromIndex:2]]; + } + + // 0xAARRGGBB to int + unsigned colorValue = 0; + NSScanner *scanner = [NSScanner scannerWithString:colorString]; + if (![scanner scanHexInt:&colorValue]) { + return nil; + } + + // int to UIColor + return [UIColor colorWithRed:((float)((colorValue & 0x00FF0000) >> 16))/255.0 + green:((float)((colorValue & 0x0000FF00) >> 8))/255.0 + blue:((float)((colorValue & 0x000000FF) >> 0))/255.0 + alpha:((float)((colorValue & 0xFF000000) >> 24))/255.0]; +} + - (NSArray*)parseInterfaceOrientations:(NSArray*)orientations { NSMutableArray* result = [[NSMutableArray alloc] init]; @@ -419,7 +479,12 @@ return YES; } -- (NSUInteger)supportedInterfaceOrientations +// CB-12098 +#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 +- (NSUInteger)supportedInterfaceOrientations +#else +- (UIInterfaceOrientationMask)supportedInterfaceOrientations +#endif { NSUInteger ret = 0; @@ -493,7 +558,7 @@ _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]; + _userAgent = localBaseUserAgent; } return _userAgent; } diff --git a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWhitelist.m b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWhitelist.m index 552ea957..758f4d1e 100644 --- a/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWhitelist.m +++ b/StoneIsland/platforms/ios/CordovaLib/Classes/Public/CDVWhitelist.m @@ -256,7 +256,7 @@ NSString* const kCDVDefaultSchemeName = @"cdv-default-scheme"; // 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]]]; + NSURL* newUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@%@", kCDVDefaultSchemeName, [url host], [[url path] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLPathAllowedCharacterSet]]]; // 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; |
