Commit 8ccb2226 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][Autofill] Returns NO if no suggestions available

Right now `checkIfAccessoryViewIsAvailableForForm` always return YES in the block. This
CL actually checks with the providers, and returns NO, if none has suggestions. This means
That no accessory will be provided by the form suggestion if no suggestion exists.
Gated to the AutofillManualFallback feature flag.

Bug: 845472
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Id36c0e8280555dc87829b78e7b1d6a9ed6df88b7
Reviewed-on: https://chromium-review.googlesource.com/1136550
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577729}
parent 264209c0
...@@ -562,60 +562,46 @@ NSArray* FindDescendantToolbarItemsForActionName( ...@@ -562,60 +562,46 @@ NSArray* FindDescendantToolbarItemsForActionName(
// if the provider can provide an accessory view for the specified form/field // if the provider can provide an accessory view for the specified form/field
// and NO otherwise. // and NO otherwise.
NSMutableArray* findProviderBlocks = [[NSMutableArray alloc] init]; NSMutableArray* findProviderBlocks = [[NSMutableArray alloc] init];
for (NSUInteger i = 0; i < [_providers count]; i++) { for (id<FormInputAccessoryViewProvider> provider in _providers) {
passwords::PipelineBlock block = passwords::PipelineBlock block = ^(void (^completion)(BOOL success)) {
^(void (^completion)(BOOL success)) { AccessoryViewReadyCompletion accessoryViewReadyCompletion =
// Access all the providers through |self| to guarantee that both ^(UIView* view, id<FormInputAccessoryViewProvider> provider) {
// |self| and all the providers exist when the block is executed. if (!view) {
// |_providers| is immutable, so the subscripting is always valid. // View is nil, tell the pipeline to continue searching.
FormInputAccessoryViewController* strongSelf = weakSelf; completion(NO);
if (!strongSelf) return;
return; }
id<FormInputAccessoryViewProvider> provider = // Once the view is retrieved, tell the pipeline to stop and
strongSelf->_providers[i]; // update the UI.
[provider checkIfAccessoryViewIsAvailableForForm:strongParams completion(YES);
webState:webState FormInputAccessoryViewController* strongSelf = weakSelf;
completionHandler:completion]; if (!strongSelf) {
}; return;
}
if (strongSelf->_currentProvider != provider) {
[strongSelf->_currentProvider
inputAccessoryViewControllerDidReset:strongSelf];
}
strongSelf->_currentProvider = provider;
[provider setAccessoryViewDelegate:strongSelf];
[strongSelf showCustomInputAccessoryView:view];
};
[provider retrieveAccessoryViewForForm:strongParams
webState:webState
accessoryViewUpdateBlock:accessoryViewReadyCompletion];
};
[findProviderBlocks addObject:block]; [findProviderBlocks addObject:block];
} }
// Once the view is retrieved, update the UI.
AccessoryViewReadyCompletion readyCompletion =
^(UIView* accessoryView, id<FormInputAccessoryViewProvider> provider) {
FormInputAccessoryViewController* strongSelf = weakSelf;
if (!strongSelf || !strongSelf->_currentProvider)
return;
DCHECK_EQ(strongSelf->_currentProvider, provider);
[provider setAccessoryViewDelegate:strongSelf];
[strongSelf showCustomInputAccessoryView:accessoryView];
};
// Once a provider is found, use it to retrieve the accessory view.
passwords::PipelineCompletionBlock onProviderFound =
^(NSUInteger providerIndex) {
if (providerIndex == NSNotFound) {
[weakSelf reset];
return;
}
FormInputAccessoryViewController* strongSelf = weakSelf;
if (!strongSelf || !strongSelf->_webState)
return;
id<FormInputAccessoryViewProvider> provider =
strongSelf->_providers[providerIndex];
[strongSelf->_currentProvider
inputAccessoryViewControllerDidReset:self];
strongSelf->_currentProvider = provider;
[strongSelf->_currentProvider
retrieveAccessoryViewForForm:strongParams
webState:webState
accessoryViewUpdateBlock:readyCompletion];
};
// Run all the blocks in |findProviderBlocks| until one invokes its // Run all the blocks in |findProviderBlocks| until one invokes its
// completion with YES. The first one to do so will be passed to // completion with YES. The first one to do so will be passed to
// |onProviderFound|. // |onProviderFound|.
passwords::RunSearchPipeline(findProviderBlocks, onProviderFound); passwords::RunSearchPipeline(findProviderBlocks, ^(NSUInteger providerIndex) {
// If no view was retrieved, reset self.
if (providerIndex == NSNotFound) {
[weakSelf reset];
}
});
} }
- (UIView*)getKeyboardView { - (UIView*)getKeyboardView {
......
...@@ -16,11 +16,6 @@ class WebState; ...@@ -16,11 +16,6 @@ class WebState;
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
// Block type to indicate that a FormInputAccessoryViewProvider has an accessory
// view to provide.
typedef void (^AccessoryViewAvailableCompletion)(
BOOL inputAccessoryViewAvailable);
// Block type to provide an accessory view asynchronously. // Block type to provide an accessory view asynchronously.
typedef void (^AccessoryViewReadyCompletion)( typedef void (^AccessoryViewReadyCompletion)(
UIView* view, UIView* view,
...@@ -33,16 +28,9 @@ typedef void (^AccessoryViewReadyCompletion)( ...@@ -33,16 +28,9 @@ typedef void (^AccessoryViewReadyCompletion)(
@property(nonatomic, assign) id<FormInputAccessoryViewDelegate> @property(nonatomic, assign) id<FormInputAccessoryViewDelegate>
accessoryViewDelegate; accessoryViewDelegate;
// Determines asynchronously if this provider has a view available for the
// specified form/field and invokes |completionHandler| with the answer.
- (void)
checkIfAccessoryViewIsAvailableForForm:(const web::FormActivityParams&)params
webState:(web::WebState*)webState
completionHandler:
(AccessoryViewAvailableCompletion)completionHandler;
// Asynchronously retrieves an accessory view from this provider for the // Asynchronously retrieves an accessory view from this provider for the
// specified form/field and returns it via |accessoryViewUpdateBlock|. // specified form/field and returns it via |accessoryViewUpdateBlock|. View
// will be nil if no accessories are available from this provider.
- (void)retrieveAccessoryViewForForm:(const web::FormActivityParams&)params - (void)retrieveAccessoryViewForForm:(const web::FormActivityParams&)params
webState:(web::WebState*)webState webState:(web::WebState*)webState
accessoryViewUpdateBlock: accessoryViewUpdateBlock:
......
...@@ -6,11 +6,13 @@ ...@@ -6,11 +6,13 @@
#include <memory> #include <memory>
#include "base/feature_list.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/mac/scoped_block.h" #include "base/mac/scoped_block.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_popup_delegate.h" #include "components/autofill/core/browser/autofill_popup_delegate.h"
#include "components/autofill/core/common/autofill_features.h"
#import "components/autofill/ios/browser/form_suggestion.h" #import "components/autofill/ios/browser/form_suggestion.h"
#import "components/autofill/ios/browser/form_suggestion_provider.h" #import "components/autofill/ios/browser/form_suggestion_provider.h"
#import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h"
...@@ -143,9 +145,6 @@ AutofillSuggestionState::AutofillSuggestionState( ...@@ -143,9 +145,6 @@ AutofillSuggestionState::AutofillSuggestionState(
} }
} }
- (void)onNoSuggestionsAvailable {
}
- (void)detachFromWebState { - (void)detachFromWebState {
if (_webState) { if (_webState) {
_webState->RemoveObserver(_webStateObserverBridge.get()); _webState->RemoveObserver(_webStateObserverBridge.get());
...@@ -264,6 +263,17 @@ AutofillSuggestionState::AutofillSuggestionState( ...@@ -264,6 +263,17 @@ AutofillSuggestionState::AutofillSuggestionState(
passwords::RunSearchPipeline(findProviderBlocks, completion); passwords::RunSearchPipeline(findProviderBlocks, completion);
} }
- (void)onNoSuggestionsAvailable {
DCHECK(accessoryViewUpdateBlock_);
BOOL isManualFillEnabled =
base::FeatureList::IsEnabled(autofill::features::kAutofillManualFallback);
if (isManualFillEnabled) {
accessoryViewUpdateBlock_(nil, self);
} else {
accessoryViewUpdateBlock_([self suggestionViewWithSuggestions:@[]], self);
}
}
- (void)onSuggestionsReady:(NSArray<FormSuggestion*>*)suggestions - (void)onSuggestionsReady:(NSArray<FormSuggestion*>*)suggestions
provider:(id<FormSuggestionProvider>)provider { provider:(id<FormSuggestionProvider>)provider {
// TODO(ios): crbug.com/249916. If we can also pass in the form/field for // TODO(ios): crbug.com/249916. If we can also pass in the form/field for
...@@ -357,23 +367,14 @@ AutofillSuggestionState::AutofillSuggestionState( ...@@ -357,23 +367,14 @@ AutofillSuggestionState::AutofillSuggestionState(
_delegate = delegate; _delegate = delegate;
} }
- (void)
checkIfAccessoryViewIsAvailableForForm:(const web::FormActivityParams&)params
webState:(web::WebState*)webState
completionHandler:
(AccessoryViewAvailableCompletion)completionHandler {
[self processPage:webState];
completionHandler(YES);
}
- (void)retrieveAccessoryViewForForm:(const web::FormActivityParams&)params - (void)retrieveAccessoryViewForForm:(const web::FormActivityParams&)params
webState:(web::WebState*)webState webState:(web::WebState*)webState
accessoryViewUpdateBlock: accessoryViewUpdateBlock:
(AccessoryViewReadyCompletion)accessoryViewUpdateBlock { (AccessoryViewReadyCompletion)accessoryViewUpdateBlock {
[self processPage:webState];
_suggestionState.reset( _suggestionState.reset(
new AutofillSuggestionState(params.form_name, params.field_name, new AutofillSuggestionState(params.form_name, params.field_name,
params.field_identifier, params.value)); params.field_identifier, params.value));
accessoryViewUpdateBlock([self suggestionViewWithSuggestions:@[]], self);
accessoryViewUpdateBlock_ = [accessoryViewUpdateBlock copy]; accessoryViewUpdateBlock_ = [accessoryViewUpdateBlock copy];
[self retrieveSuggestionsForForm:params webState:webState]; [self retrieveSuggestionsForForm:params webState:webState];
} }
......
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