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(
// if the provider can provide an accessory view for the specified form/field
// and NO otherwise.
NSMutableArray* findProviderBlocks = [[NSMutableArray alloc] init];
for (NSUInteger i = 0; i < [_providers count]; i++) {
passwords::PipelineBlock block =
^(void (^completion)(BOOL success)) {
// Access all the providers through |self| to guarantee that both
// |self| and all the providers exist when the block is executed.
// |_providers| is immutable, so the subscripting is always valid.
FormInputAccessoryViewController* strongSelf = weakSelf;
if (!strongSelf)
return;
id<FormInputAccessoryViewProvider> provider =
strongSelf->_providers[i];
[provider checkIfAccessoryViewIsAvailableForForm:strongParams
webState:webState
completionHandler:completion];
};
for (id<FormInputAccessoryViewProvider> provider in _providers) {
passwords::PipelineBlock block = ^(void (^completion)(BOOL success)) {
AccessoryViewReadyCompletion accessoryViewReadyCompletion =
^(UIView* view, id<FormInputAccessoryViewProvider> provider) {
if (!view) {
// View is nil, tell the pipeline to continue searching.
completion(NO);
return;
}
// Once the view is retrieved, tell the pipeline to stop and
// update the UI.
completion(YES);
FormInputAccessoryViewController* strongSelf = weakSelf;
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];
}
// 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
// completion with YES. The first one to do so will be passed to
// |onProviderFound|.
passwords::RunSearchPipeline(findProviderBlocks, onProviderFound);
passwords::RunSearchPipeline(findProviderBlocks, ^(NSUInteger providerIndex) {
// If no view was retrieved, reset self.
if (providerIndex == NSNotFound) {
[weakSelf reset];
}
});
}
- (UIView*)getKeyboardView {
......
......@@ -16,11 +16,6 @@ class WebState;
#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.
typedef void (^AccessoryViewReadyCompletion)(
UIView* view,
......@@ -33,16 +28,9 @@ typedef void (^AccessoryViewReadyCompletion)(
@property(nonatomic, assign) id<FormInputAccessoryViewDelegate>
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
// 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
webState:(web::WebState*)webState
accessoryViewUpdateBlock:
......
......@@ -6,11 +6,13 @@
#include <memory>
#include "base/feature_list.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_block.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.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_provider.h"
#import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h"
......@@ -143,9 +145,6 @@ AutofillSuggestionState::AutofillSuggestionState(
}
}
- (void)onNoSuggestionsAvailable {
}
- (void)detachFromWebState {
if (_webState) {
_webState->RemoveObserver(_webStateObserverBridge.get());
......@@ -264,6 +263,17 @@ AutofillSuggestionState::AutofillSuggestionState(
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
provider:(id<FormSuggestionProvider>)provider {
// TODO(ios): crbug.com/249916. If we can also pass in the form/field for
......@@ -357,23 +367,14 @@ AutofillSuggestionState::AutofillSuggestionState(
_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
webState:(web::WebState*)webState
accessoryViewUpdateBlock:
(AccessoryViewReadyCompletion)accessoryViewUpdateBlock {
[self processPage:webState];
_suggestionState.reset(
new AutofillSuggestionState(params.form_name, params.field_name,
params.field_identifier, params.value));
accessoryViewUpdateBlock([self suggestionViewWithSuggestions:@[]], self);
accessoryViewUpdateBlock_ = [accessoryViewUpdateBlock copy];
[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