electron_autofill_driver_factory.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (c) 2019 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_FACTORY_H_
  5. #define ELECTRON_SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_FACTORY_H_
  6. #include <memory>
  7. #include "base/functional/callback_forward.h"
  8. #include "content/public/browser/web_contents_observer.h"
  9. #include "content/public/browser/web_contents_user_data.h"
  10. #include "shell/common/api/api.mojom.h"
  11. #include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
  12. namespace electron {
  13. class AutofillDriver;
  14. class AutofillDriverFactory
  15. : private content::WebContentsObserver,
  16. public content::WebContentsUserData<AutofillDriverFactory> {
  17. public:
  18. typedef base::OnceCallback<std::unique_ptr<AutofillDriver>()>
  19. CreationCallback;
  20. ~AutofillDriverFactory() override;
  21. static void BindAutofillDriver(
  22. mojo::PendingAssociatedReceiver<mojom::ElectronAutofillDriver>
  23. pending_receiver,
  24. content::RenderFrameHost* render_frame_host);
  25. AutofillDriver* DriverForFrame(content::RenderFrameHost* render_frame_host);
  26. void AddDriverForFrame(content::RenderFrameHost* render_frame_host,
  27. CreationCallback factory_method);
  28. void DeleteDriverForFrame(content::RenderFrameHost* render_frame_host);
  29. void CloseAllPopups();
  30. WEB_CONTENTS_USER_DATA_KEY_DECL();
  31. private:
  32. // content::WebContentsObserver:
  33. void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
  34. void DidFinishNavigation(
  35. content::NavigationHandle* navigation_handle) override;
  36. explicit AutofillDriverFactory(content::WebContents* web_contents);
  37. friend class content::WebContentsUserData<AutofillDriverFactory>;
  38. absl::flat_hash_map<content::RenderFrameHost*,
  39. std::unique_ptr<AutofillDriver>>
  40. driver_map_;
  41. };
  42. } // namespace electron
  43. #endif // ELECTRON_SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_FACTORY_H_