password_suggestion_helper.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_PASSWORD_MANAGER_IOS_PASSWORD_SUGGESTION_HELPER_H_
  5. #define COMPONENTS_PASSWORD_MANAGER_IOS_PASSWORD_SUGGESTION_HELPER_H_
  6. #import <Foundation/Foundation.h>
  7. #include <memory>
  8. #include "components/autofill/core/common/unique_ids.h"
  9. #import "components/autofill/ios/browser/form_suggestion_provider.h"
  10. NS_ASSUME_NONNULL_BEGIN
  11. @class FormSuggestion;
  12. @class PasswordSuggestionHelper;
  13. namespace autofill {
  14. struct PasswordFormFillData;
  15. } // namespace autofill
  16. namespace password_manager {
  17. struct FillData;
  18. } // namespace password_manager
  19. namespace web {
  20. class WebState;
  21. } // namespace web
  22. // A protocol implemented by a delegate of PasswordSuggestionHelper.
  23. @protocol PasswordSuggestionHelperDelegate<NSObject>
  24. // Called when form extraction is required for checking suggestion availability.
  25. // The caller must trigger the form extraction in this method.
  26. - (void)suggestionHelperShouldTriggerFormExtraction:
  27. (PasswordSuggestionHelper*)suggestionHelper;
  28. @end
  29. // Provides common logic of password autofill suggestions for both ios/chrome
  30. // and ios/web_view.
  31. // TODO(crbug.com/1097353): Consider folding this class into
  32. // SharedPasswordController.
  33. @interface PasswordSuggestionHelper : NSObject
  34. // Delegate to receive callbacks.
  35. @property(nonatomic, weak) id<PasswordSuggestionHelperDelegate> delegate;
  36. // Retrieves suggestions as username and realm pairs
  37. // (defined in |password_manager::UsernameAndRealm|) and converts
  38. // them into objective C representations. In the returned |FormSuggestion|
  39. // items, |value| field will be the username and |displayDescription| will be
  40. // the realm.
  41. - (NSArray<FormSuggestion*>*)
  42. retrieveSuggestionsWithFormID:(autofill::FormRendererId)formIdentifier
  43. fieldIdentifier:(autofill::FieldRendererId)fieldIdentifier
  44. fieldType:(NSString*)fieldType;
  45. // Checks if suggestions are available for the field.
  46. // |completion| will be called when the check is completed, with boolean
  47. // parameter indicating whether suggestions are available or not.
  48. // See //components/autofill/ios/form_util/form_activity_params.h for definition
  49. // of other parameters.
  50. - (void)checkIfSuggestionsAvailableForForm:
  51. (FormSuggestionProviderQuery*)formQuery
  52. isMainFrame:(BOOL)isMainFrame
  53. webState:(web::WebState*)webState
  54. completionHandler:
  55. (SuggestionsAvailableCompletion)completion;
  56. // Retrieves password form fill data for |username| for use in
  57. // |PasswordFormHelper|'s
  58. // -fillPasswordFormWithFillData:completionHandler:.
  59. - (std::unique_ptr<password_manager::FillData>)passwordFillDataForUsername:
  60. (NSString*)username;
  61. // The following methods should be called to maintain the correct state along
  62. // with password forms.
  63. // Resets fill data, callbacks and state flags for new page. This method should
  64. // be called in password controller's -webState:didFinishNavigation:.
  65. - (void)resetForNewPage;
  66. // Prepares fill data with given password form data. Triggers callback for
  67. // -checkIfSuggestionsAvailableForForm... if needed.
  68. // This method should be called in password controller's
  69. // -fillPasswordForm:completionHandler:.
  70. - (void)processWithPasswordFormFillData:
  71. (const autofill::PasswordFormFillData&)formData;
  72. // Processes field for which no saved credentials are available.
  73. // Triggers callback for -checkIfSuggestionsAvailableForForm... if needed.
  74. // This method should be called in password controller's
  75. // -onNoSavedCredentials.
  76. - (void)processWithNoSavedCredentials;
  77. // Updates the state for password form extraction state.
  78. // This method should be called in password controller's
  79. // -didFinishPasswordFormExtraction:, when the extracted forms are not empty.
  80. - (void)updateStateOnPasswordFormExtracted;
  81. @end
  82. NS_ASSUME_NONNULL_END
  83. #endif // COMPONENTS_PASSWORD_MANAGER_IOS_PASSWORD_SUGGESTION_HELPER_H_