Commit 5097771c authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Only send autofill JS on visible webStates.

When autofilling credit card, the CVC prompt View disables
the webState.
JS processing may be different when view is not visible. This
makes some sites like walgreens.com flaky.
This CL queue the JS if the webState is not visible and executes
it after |webStateWasShown| is called.

Bug: 728606
Change-Id: I7a9ffd5e15d403a7faf9f7f4f4151371474676d5
Reviewed-on: https://chromium-review.googlesource.com/817277
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524354}
parent 79ff0353
...@@ -149,6 +149,10 @@ void GetFormAndField(autofill::FormData* form, ...@@ -149,6 +149,10 @@ void GetFormAndField(autofill::FormData* form,
// key/value suggestions if the user hasn't started typing. // key/value suggestions if the user hasn't started typing.
- (NSArray*)processSuggestions:(NSArray*)suggestions; - (NSArray*)processSuggestions:(NSArray*)suggestions;
// Sends the the |formData| to the JavaScript manager of |webState_| to actually
// fill the data.
- (void)sendDataToWebState:(NSString*)formData;
@end @end
@implementation AutofillAgent { @implementation AutofillAgent {
...@@ -192,6 +196,8 @@ void GetFormAndField(autofill::FormData* form, ...@@ -192,6 +196,8 @@ void GetFormAndField(autofill::FormData* form,
// The reference is weak because a weak pointer is sent to our // The reference is weak because a weak pointer is sent to our
// AutofillManagerDelegate. // AutofillManagerDelegate.
base::WeakPtr<autofill::AutofillPopupDelegate> popupDelegate_; base::WeakPtr<autofill::AutofillPopupDelegate> popupDelegate_;
// The autofill data that needs to be send when the |webState_| is shown.
NSString* pendingFormData_;
} }
- (instancetype)initWithPrefService:(PrefService*)prefService - (instancetype)initWithPrefService:(PrefService*)prefService
...@@ -651,6 +657,14 @@ void GetFormAndField(autofill::FormData* form, ...@@ -651,6 +657,14 @@ void GetFormAndField(autofill::FormData* form,
[self detachFromWebState]; [self detachFromWebState];
} }
- (void)webStateWasShown:(web::WebState*)webState {
DCHECK_EQ(webState_, webState);
if (pendingFormData_) {
[self sendDataToWebState:pendingFormData_];
}
pendingFormData_ = nil;
}
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
didSubmitDocumentWithFormNamed:(const std::string&)formName didSubmitDocumentWithFormNamed:(const std::string&)formName
userInitiated:(BOOL)userInitiated userInitiated:(BOOL)userInitiated
...@@ -877,14 +891,24 @@ void GetFormAndField(autofill::FormData* form, ...@@ -877,14 +891,24 @@ void GetFormAndField(autofill::FormData* form,
// Stringify the JSON data and send it to the UIWebView-side fillForm method. // Stringify the JSON data and send it to the UIWebView-side fillForm method.
std::string dataString; std::string dataString;
base::JSONWriter::Write(*formData.get(), &dataString); base::JSONWriter::Write(*formData.get(), &dataString);
NSString* nsDataString = base::SysUTF8ToNSString(dataString);
if (!webState_->IsVisible()) {
pendingFormData_ = nsDataString;
return;
}
[self sendDataToWebState:nsDataString];
}
- (void)sendDataToWebState:(NSString*)formData {
DCHECK(webState_->IsVisible());
// It is possible that the fill was not initiated by selecting a suggestion. // It is possible that the fill was not initiated by selecting a suggestion.
// In this case we provide an empty callback. // In this case we provide an empty callback.
if (!suggestionHandledCompletion_) if (!suggestionHandledCompletion_)
suggestionHandledCompletion_ = [^{ suggestionHandledCompletion_ = [^{
} copy]; } copy];
[jsAutofillManager_ [jsAutofillManager_
fillForm:base::SysUTF8ToNSString(dataString) fillForm:formData
forceFillFieldName:base::SysUTF16ToNSString(pendingAutocompleteField_) forceFillFieldName:base::SysUTF16ToNSString(pendingAutocompleteField_)
completionHandler:suggestionHandledCompletion_]; completionHandler:suggestionHandledCompletion_];
suggestionHandledCompletion_ = nil; suggestionHandledCompletion_ = nil;
......
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