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 
5 #ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_FORM_INPUT_ACCESSORY_FORM_INPUT_ACCESSORY_MEDIATOR_H_
6 #define IOS_CHROME_BROWSER_UI_AUTOFILL_FORM_INPUT_ACCESSORY_FORM_INPUT_ACCESSORY_MEDIATOR_H_
7 
8 #import <Foundation/Foundation.h>
9 
10 #include "components/password_manager/core/browser/password_store.h"
11 #import "ios/chrome/browser/autofill/form_input_navigator.h"
12 #import "ios/chrome/browser/autofill/form_suggestion_client.h"
13 #import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
14 #import "ios/web/public/web_state_observer_bridge.h"
15 
16 @class AppState;
17 @class ChromeCoordinator;
18 @protocol FormInputAccessoryConsumer;
19 @class FormInputAccessoryMediator;
20 @protocol FormInputSuggestionsProvider;
21 @class JsSuggestionManager;
22 @class ReauthenticationModule;
23 @protocol SecurityAlertCommands;
24 
25 namespace autofill {
26 class PersonalDataManager;
27 }
28 
29 namespace web {
30 class WebState;
31 }
32 
33 class WebStateList;
34 
35 // Delegate in charge of reacting to accessory mediator events.
36 @protocol FormInputAccessoryMediatorDelegate
37 
38 // The mediator detected that the keyboard was hidden and it is no longer
39 // present on the screen.
40 - (void)mediatorDidDetectKeyboardHide:(FormInputAccessoryMediator*)mediator;
41 
42 // The mediator detected that the keyboard was hidden and it is no longer
43 // present on the screen.
44 - (void)mediatorDidDetectMovingToBackground:
45     (FormInputAccessoryMediator*)mediator;
46 
47 @end
48 
49 // This class contains all the logic to get and provide keyboard input accessory
50 // views to its consumer. As well as telling the consumer when the default
51 // accessory view shoeuld be restored to the system default.
52 @interface FormInputAccessoryMediator : NSObject <FormSuggestionClient>
53 
54 // Returns a mediator observing the passed `WebStateList` and associated with
55 // the passed consumer. `webSateList` can be nullptr and `consumer` can be nil.
56 - (instancetype)
57           initWithConsumer:(id<FormInputAccessoryConsumer>)consumer
58                   delegate:(id<FormInputAccessoryMediatorDelegate>)delegate
59               webStateList:(WebStateList*)webStateList
60        personalDataManager:(autofill::PersonalDataManager*)personalDataManager
61              passwordStore:
62                  (scoped_refptr<password_manager::PasswordStore>)passwordStore
63                   appState:(AppState*)appState
64       securityAlertHandler:(id<SecurityAlertCommands>)securityAlertHandler
65     reauthenticationModule:(ReauthenticationModule*)reauthenticationModule;
66 
67 // Unavailable, use initWithConsumer:webStateList: instead.
68 - (instancetype)init NS_UNAVAILABLE;
69 
70 // Disables suggestions updates and asks the consumer to remove the current
71 // ones.
72 - (void)disableSuggestions;
73 
74 // Enables suggestions updates and sends the current ones, if any, to the
75 // consumer.
76 - (void)enableSuggestions;
77 
78 // Stops observing all objects.
79 - (void)disconnect;
80 
81 @end
82 
83 // Methods to allow injection in tests.
84 @interface FormInputAccessoryMediator (Tests)
85 
86 // The WebState this instance is observing. Can be null.
87 - (void)injectWebState:(web::WebState*)webState;
88 
89 // The JS manager for interacting with the underlying form.
90 - (void)injectSuggestionManager:(JsSuggestionManager*)JSSuggestionManager;
91 
92 // Replaces the object in charge of providing suggestions.
93 - (void)injectProvider:(id<FormInputSuggestionsProvider>)provider;
94 
95 @end
96 
97 #endif  // IOS_CHROME_BROWSER_UI_AUTOFILL_FORM_INPUT_ACCESSORY_FORM_INPUT_ACCESSORY_MEDIATOR_H_
98