From ce258fc495b1cd3ae21d80904bc579631ecbb65f Mon Sep 17 00:00:00 2001 From: Rad Azzouz Date: Mon, 13 Oct 2014 20:50:20 -0400 Subject: [PATCH 1/2] Fixed crash when the 1Password extension is shown before the web view is fully loaded. This should resolve #116 --- OnePasswordExtension.m | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/OnePasswordExtension.m b/OnePasswordExtension.m index c9f1349..9d61786 100644 --- a/OnePasswordExtension.m +++ b/OnePasswordExtension.m @@ -46,6 +46,7 @@ NSInteger const AppExtensionErrorCodeCollectFieldsScriptFailed = 4; NSInteger const AppExtensionErrorCodeFillFieldsScriptFailed = 5; NSInteger const AppExtensionErrorCodeUnexpectedData = 6; +NSInteger const AppExtensionErrorCodeFailedToGetURLStringFromWebView = 7; @implementation OnePasswordExtension @@ -356,6 +357,12 @@ + (NSError *)failedToLoadItemProviderDataErrorWithUnderlyingError:(NSError *)und return [[NSError alloc] initWithDomain:AppExtensionErrorDomain code:AppExtensionErrorCodeFailedToLoadItemProviderData userInfo:userInfo]; } ++ (NSError *)failedToGetURLStringFromWebViewError { + NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : NSLocalizedString(@"Failed to get URL String from web view. The web view must be loaded completely when calling the 1Password Extension", @"1Password Extension Error Message") }; + return [NSError errorWithDomain:AppExtensionErrorDomain code:AppExtensionErrorCodeFailedToGetURLStringFromWebView userInfo:userInfo]; +} + + #pragma mark - App Extension ItemProvider Callback #ifdef __IPHONE_8_0 @@ -436,8 +443,13 @@ - (void)fillLoginIntoUIWebView:(UIWebView *)webView webViewController:(UIViewCon }]; } -- (void)findLoginIn1PasswordWithURLString:URLString collectedPageDetails:(NSString *)collectedPageDetails forWebViewController:(UIViewController *)forViewController sender:(id)sender withWebView:(id)webView completion:(void (^)(BOOL success, NSError *error))completion -{ +- (void)findLoginIn1PasswordWithURLString:URLString collectedPageDetails:(NSString *)collectedPageDetails forWebViewController:(UIViewController *)forViewController sender:(id)sender withWebView:(id)webView completion:(void (^)(BOOL success, NSError *error))completion { + if ([URLString length] == 0) { + NSError *URLStringError = [OnePasswordExtension failedToGetURLStringFromWebViewError]; + NSLog(@"Failed to findLoginIn1PasswordWithURLString: %@", URLStringError); + completion(NO, URLStringError); + } + NSDictionary *item = @{ AppExtensionVersionNumberKey : VERSION_NUMBER, AppExtensionURLStringKey : URLString, AppExtensionWebViewPageDetails : collectedPageDetails }; __weak typeof (self) miniMe = self; @@ -484,8 +496,7 @@ - (void)findLoginIn1PasswordWithURLString:URLString collectedPageDetails:(NSStri [forViewController presentViewController:activityViewController animated:YES completion:nil]; } -- (void)executeFillScript:(NSString *)fillScript inWebView:(id)webView completion:(void (^)(BOOL success, NSError *error))completion -{ +- (void)executeFillScript:(NSString *)fillScript inWebView:(id)webView completion:(void (^)(BOOL success, NSError *error))completion { if (!fillScript) { NSLog(@"Failed to executeFillScript, fillScript is missing"); if (completion) { From 12a75f94f4c25fad30146a59d9c4edbb64475f11 Mon Sep 17 00:00:00 2001 From: Rad Azzouz Date: Tue, 28 Oct 2014 13:47:31 -0400 Subject: [PATCH 2/2] Replaced "Get" with "Obtain" --- OnePasswordExtension.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/OnePasswordExtension.m b/OnePasswordExtension.m index 259bf71..56573a1 100644 --- a/OnePasswordExtension.m +++ b/OnePasswordExtension.m @@ -46,7 +46,7 @@ NSInteger const AppExtensionErrorCodeCollectFieldsScriptFailed = 4; NSInteger const AppExtensionErrorCodeFillFieldsScriptFailed = 5; NSInteger const AppExtensionErrorCodeUnexpectedData = 6; -NSInteger const AppExtensionErrorCodeFailedToGetURLStringFromWebView = 7; +NSInteger const AppExtensionErrorCodeFailedToObtainURLStringFromWebView = 7; @implementation OnePasswordExtension @@ -353,9 +353,9 @@ + (NSError *)failedToLoadItemProviderDataErrorWithUnderlyingError:(NSError *)und return [[NSError alloc] initWithDomain:AppExtensionErrorDomain code:AppExtensionErrorCodeFailedToLoadItemProviderData userInfo:userInfo]; } -+ (NSError *)failedToGetURLStringFromWebViewError { - NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : NSLocalizedString(@"Failed to get URL String from web view. The web view must be loaded completely when calling the 1Password Extension", @"1Password Extension Error Message") }; - return [NSError errorWithDomain:AppExtensionErrorDomain code:AppExtensionErrorCodeFailedToGetURLStringFromWebView userInfo:userInfo]; ++ (NSError *)failedToObtainURLStringFromWebViewError { + NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : NSLocalizedString(@"Failed to obtain URL String from web view. The web view must be loaded completely when calling the 1Password Extension", @"1Password Extension Error Message") }; + return [NSError errorWithDomain:AppExtensionErrorDomain code:AppExtensionErrorCodeFailedToObtainURLStringFromWebView userInfo:userInfo]; } @@ -441,7 +441,7 @@ - (void)fillLoginIntoUIWebView:(UIWebView *)webView webViewController:(UIViewCon - (void)findLoginIn1PasswordWithURLString:URLString collectedPageDetails:(NSString *)collectedPageDetails forWebViewController:(UIViewController *)forViewController sender:(id)sender withWebView:(id)webView completion:(void (^)(BOOL success, NSError *error))completion { if ([URLString length] == 0) { - NSError *URLStringError = [OnePasswordExtension failedToGetURLStringFromWebViewError]; + NSError *URLStringError = [OnePasswordExtension failedToObtainURLStringFromWebViewError]; NSLog(@"Failed to findLoginIn1PasswordWithURLString: %@", URLStringError); completion(NO, URLStringError); }