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
frameID:(NSString*)frameID
completionHandler:(SuggestionHandledCompletion)completion {
[[UIDevice currentDevice] playInputClick];
DCHECK(completion);
_suggestionHandledCompletion = [completion copy];
if (suggestion.identifier > 0) {
......@@ -453,6 +454,9 @@ autofillManagerFromWebState:(web::WebState*)webState
web::WebFrame* frame =
web::GetWebFrameWithId(_webState, SysNSStringToUTF8(frameID));
__weak AutofillAgent* weakSelf = self;
SuggestionHandledCompletion suggestionHandledCompletionCopy =
[_suggestionHandledCompletion copy];
_suggestionHandledCompletion = nil;
[_jsAutofillManager
clearAutofilledFieldsForFormName:formName
formUniqueID:uniqueFormID
......@@ -465,8 +469,7 @@ autofillManagerFromWebState:(web::WebState*)webState
return;
UpdateFieldManagerForClearedIDs(
strongSelf->_fieldDataManager, jsonString);
strongSelf->_suggestionHandledCompletion();
strongSelf->_suggestionHandledCompletion = nil;
suggestionHandledCompletionCopy();
}];
} else if (suggestion.identifier ==
......@@ -915,6 +918,9 @@ autofillManagerFromWebState:(web::WebState*)webState
DCHECK(_suggestionHandledCompletion);
__weak AutofillAgent* weakSelf = self;
SuggestionHandledCompletion suggestionHandledCompletionCopy =
[_suggestionHandledCompletion copy];
_suggestionHandledCompletion = nil;
[_jsAutofillManager
fillActiveFormField:std::move(data)
inFrame:frame
......@@ -926,8 +932,7 @@ autofillManagerFromWebState:(web::WebState*)webState
strongSelf->_fieldDataManager->UpdateFieldDataWithAutofilledValue(
uniqueFieldID, value, kAutofilledOnUserTrigger);
}
strongSelf->_suggestionHandledCompletion();
strongSelf->_suggestionHandledCompletion = nil;
suggestionHandledCompletionCopy();
}];
}
......@@ -935,12 +940,10 @@ autofillManagerFromWebState:(web::WebState*)webState
- (void)sendData:(std::unique_ptr<base::Value>)data
toFrame:(web::WebFrame*)frame {
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;
SuggestionHandledCompletion suggestionHandledCompletionCopy =
[_suggestionHandledCompletion copy];
_suggestionHandledCompletion = nil;
[_jsAutofillManager fillForm:std::move(data)
forceFillFieldIdentifier:SysUTF16ToNSString(_pendingAutocompleteField)
forceFillFieldUniqueID:_pendingAutocompleteFieldID
......@@ -951,8 +954,10 @@ autofillManagerFromWebState:(web::WebState*)webState
return;
UpdateFieldManagerWithFillingResults(
strongSelf->_fieldDataManager, jsonString);
strongSelf->_suggestionHandledCompletion();
strongSelf->_suggestionHandledCompletion = nil;
// It is possible that the fill was not initiated by selecting
// 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