#ifndef COMPONENTS_AUTOFILL_IOS_BROWSER_AUTOFILL_DRIVER_IOS_FACTORY_H_
#define COMPONENTS_AUTOFILL_IOS_BROWSER_AUTOFILL_DRIVER_IOS_FACTORY_H_
#import <map>
#import <memory>
#import <string>
#import "base/memory/raw_ptr.h"
#import "components/autofill/core/browser/foundations/autofill_client.h"
#import "components/autofill/core/browser/foundations/autofill_driver_factory.h"
#import "components/autofill/core/browser/foundations/autofill_driver_router.h"
#import "components/autofill/ios/browser/autofill_driver_ios_bridge.h"
#import "ios/web/public/js_messaging/web_frames_manager.h"
#import "ios/web/public/web_state_observer.h"
namespace web {
class WebFrame;
class WebState;
}
namespace autofill {
class AutofillClientIOS;
class AutofillDriverIOS;
class AutofillDriverIOSFactory final
: public AutofillDriverFactory,
public web::WebStateObserver,
public web::WebFramesManager::Observer {
public:
class Observer : public AutofillDriverFactory::Observer {
public:
virtual void OnAutofillDriverIOSFactoryDestroyed(
AutofillDriverIOSFactory& factory) {}
virtual void OnAutofillDriverIOSCreated(AutofillDriverIOSFactory& factory,
AutofillDriverIOS& driver) {}
virtual void OnAutofillDriverIOSStateChanged(
AutofillDriverIOSFactory& factory,
AutofillDriverIOS& driver,
AutofillDriver::LifecycleState old_state,
AutofillDriver::LifecycleState new_state) {}
void OnAutofillDriverFactoryDestroyed(AutofillDriverFactory& factory) final;
void OnAutofillDriverCreated(AutofillDriverFactory& factory,
AutofillDriver& driver) final;
void OnAutofillDriverStateChanged(AutofillDriverFactory& factory,
AutofillDriver& driver,
LifecycleState old_state,
LifecycleState new_state) final;
};
AutofillDriverIOSFactory(AutofillClientIOS* client,
id<AutofillDriverIOSBridge> bridge);
~AutofillDriverIOSFactory() override;
AutofillDriverIOS* DriverForFrame(web::WebFrame* web_frame);
AutofillDriverRouter& router() { return router_; }
std::vector<AutofillDriver*> GetExistingDrivers() override;
private:
friend class AutofillDriverIOSFactoryTestApi;
void WebStateDestroyed(web::WebState* web_state) override;
void WebFrameBecameAvailable(web::WebFramesManager* web_frames_manager,
web::WebFrame* web_frame) override;
void WebFrameBecameUnavailable(web::WebFramesManager* web_frames_manager,
const std::string& frame_id) override;
web::WebFramesManager& GetWebFramesManager();
web::WebState* web_state();
raw_ref<AutofillClientIOS> client_;
AutofillDriverRouter router_;
id<AutofillDriverIOSBridge> bridge_ = nil;
bool web_state_destroyed_ = false;
std::map<std::string, std::unique_ptr<AutofillDriverIOS>> driver_map_;
size_t max_drivers_ = 0;
};
}
#endif