Commit 98ac45f3 authored by Maria Kazinova's avatar Maria Kazinova Committed by Commit Bot

[iOS] Fixing a crash in AutofillAgent blocks.

Adding a check for _suggestionHandledCompletion in a block prior to
calling it.

Bug: 1134005
Change-Id: I8a8fae7abe4567925514bd98841d5866f70c2dab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2445010Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Commit-Queue: Maria Kazinova <kazinova@google.com>
Cr-Commit-Position: refs/heads/master@{#813255}
parent ce6a6887
...@@ -429,6 +429,7 @@ autofillManagerFromWebState:(web::WebState*)webState ...@@ -429,6 +429,7 @@ autofillManagerFromWebState:(web::WebState*)webState
frameID:(NSString*)frameID frameID:(NSString*)frameID
completionHandler:(SuggestionHandledCompletion)completion { completionHandler:(SuggestionHandledCompletion)completion {
[[UIDevice currentDevice] playInputClick]; [[UIDevice currentDevice] playInputClick];
DCHECK(completion);
_suggestionHandledCompletion = [completion copy]; _suggestionHandledCompletion = [completion copy];
if (suggestion.identifier > 0) { if (suggestion.identifier > 0) {
...@@ -453,6 +454,9 @@ autofillManagerFromWebState:(web::WebState*)webState ...@@ -453,6 +454,9 @@ autofillManagerFromWebState:(web::WebState*)webState
web::WebFrame* frame = web::WebFrame* frame =
web::GetWebFrameWithId(_webState, SysNSStringToUTF8(frameID)); web::GetWebFrameWithId(_webState, SysNSStringToUTF8(frameID));
__weak AutofillAgent* weakSelf = self; __weak AutofillAgent* weakSelf = self;
SuggestionHandledCompletion suggestionHandledCompletionCopy =
[_suggestionHandledCompletion copy];
_suggestionHandledCompletion = nil;
[_jsAutofillManager [_jsAutofillManager
clearAutofilledFieldsForFormName:formName clearAutofilledFieldsForFormName:formName
formUniqueID:uniqueFormID formUniqueID:uniqueFormID
...@@ -465,8 +469,7 @@ autofillManagerFromWebState:(web::WebState*)webState ...@@ -465,8 +469,7 @@ autofillManagerFromWebState:(web::WebState*)webState
return; return;
UpdateFieldManagerForClearedIDs( UpdateFieldManagerForClearedIDs(
strongSelf->_fieldDataManager, jsonString); strongSelf->_fieldDataManager, jsonString);
strongSelf->_suggestionHandledCompletion(); suggestionHandledCompletionCopy();
strongSelf->_suggestionHandledCompletion = nil;
}]; }];
} else if (suggestion.identifier == } else if (suggestion.identifier ==
...@@ -915,6 +918,9 @@ autofillManagerFromWebState:(web::WebState*)webState ...@@ -915,6 +918,9 @@ autofillManagerFromWebState:(web::WebState*)webState
DCHECK(_suggestionHandledCompletion); DCHECK(_suggestionHandledCompletion);
__weak AutofillAgent* weakSelf = self; __weak AutofillAgent* weakSelf = self;
SuggestionHandledCompletion suggestionHandledCompletionCopy =
[_suggestionHandledCompletion copy];
_suggestionHandledCompletion = nil;
[_jsAutofillManager [_jsAutofillManager
fillActiveFormField:std::move(data) fillActiveFormField:std::move(data)
inFrame:frame inFrame:frame
...@@ -926,8 +932,7 @@ autofillManagerFromWebState:(web::WebState*)webState ...@@ -926,8 +932,7 @@ autofillManagerFromWebState:(web::WebState*)webState
strongSelf->_fieldDataManager->UpdateFieldDataWithAutofilledValue( strongSelf->_fieldDataManager->UpdateFieldDataWithAutofilledValue(
uniqueFieldID, value, kAutofilledOnUserTrigger); uniqueFieldID, value, kAutofilledOnUserTrigger);
} }
strongSelf->_suggestionHandledCompletion(); suggestionHandledCompletionCopy();
strongSelf->_suggestionHandledCompletion = nil;
}]; }];
} }
...@@ -935,12 +940,10 @@ autofillManagerFromWebState:(web::WebState*)webState ...@@ -935,12 +940,10 @@ autofillManagerFromWebState:(web::WebState*)webState
- (void)sendData:(std::unique_ptr<base::Value>)data - (void)sendData:(std::unique_ptr<base::Value>)data
toFrame:(web::WebFrame*)frame { toFrame:(web::WebFrame*)frame {
DCHECK(_webState->IsVisible()); DCHECK(_webState->IsVisible());
// It is possible that the fill was not initiated by selecting a suggestion.
// In this case we provide an empty callback.
if (!_suggestionHandledCompletion)
_suggestionHandledCompletion = [^{
} copy];
__weak AutofillAgent* weakSelf = self; __weak AutofillAgent* weakSelf = self;
SuggestionHandledCompletion suggestionHandledCompletionCopy =
[_suggestionHandledCompletion copy];
_suggestionHandledCompletion = nil;
[_jsAutofillManager fillForm:std::move(data) [_jsAutofillManager fillForm:std::move(data)
forceFillFieldIdentifier:SysUTF16ToNSString(_pendingAutocompleteField) forceFillFieldIdentifier:SysUTF16ToNSString(_pendingAutocompleteField)
forceFillFieldUniqueID:_pendingAutocompleteFieldID forceFillFieldUniqueID:_pendingAutocompleteFieldID
...@@ -951,8 +954,10 @@ autofillManagerFromWebState:(web::WebState*)webState ...@@ -951,8 +954,10 @@ autofillManagerFromWebState:(web::WebState*)webState
return; return;
UpdateFieldManagerWithFillingResults( UpdateFieldManagerWithFillingResults(
strongSelf->_fieldDataManager, jsonString); strongSelf->_fieldDataManager, jsonString);
strongSelf->_suggestionHandledCompletion(); // It is possible that the fill was not initiated by selecting
strongSelf->_suggestionHandledCompletion = nil; // a suggestion in this case the callback is nil.
if (suggestionHandledCompletionCopy)
suggestionHandledCompletionCopy();
}]; }];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment