| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_FACTORY_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_FACTORY_H_ |
| 6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_FACTORY_H_ | 6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_FACTORY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" |
| 12 #include "base/supports_user_data.h" | 13 #include "base/supports_user_data.h" |
| 13 #include "components/autofill/content/common/autofill_driver.mojom.h" | 14 #include "components/autofill/content/common/autofill_driver.mojom.h" |
| 14 #include "components/autofill/core/browser/autofill_manager.h" | 15 #include "components/autofill/core/browser/autofill_manager.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 class RenderFrameHost; | 19 class RenderFrameHost; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace autofill { | 22 namespace autofill { |
| 22 | 23 |
| 23 class ContentAutofillDriver; | 24 class AutofillDriver; |
| 24 | 25 |
| 25 // Manages lifetime of ContentAutofillDriver. One Factory per WebContents | 26 // Manages lifetime of ContentAutofillDriver. One Factory per WebContents |
| 26 // creates one Driver per RenderFrame. | 27 // creates one Driver per RenderFrame. |
| 27 class ContentAutofillDriverFactory : public content::WebContentsObserver, | 28 class ContentAutofillDriverFactory : public content::WebContentsObserver, |
| 28 public base::SupportsUserData::Data { | 29 public base::SupportsUserData::Data { |
| 29 public: | 30 public: |
| 31 using DriverCreator = base::Callback<std::unique_ptr<AutofillDriver>( |
| 32 content::RenderFrameHost*, |
| 33 AutofillClient*, |
| 34 const std::string&, |
| 35 AutofillManager::AutofillDownloadManagerState)>; |
| 36 |
| 30 ~ContentAutofillDriverFactory() override; | 37 ~ContentAutofillDriverFactory() override; |
| 31 | 38 |
| 32 static void CreateForWebContentsAndDelegate( | 39 static void CreateForWebContentsAndDelegate( |
| 33 content::WebContents* contents, | 40 content::WebContents* contents, |
| 34 AutofillClient* client, | 41 AutofillClient* client, |
| 35 const std::string& app_locale, | 42 const std::string& app_locale, |
| 36 AutofillManager::AutofillDownloadManagerState enable_download_manager); | 43 AutofillManager::AutofillDownloadManagerState enable_download_manager); |
| 37 static ContentAutofillDriverFactory* FromWebContents( | 44 static ContentAutofillDriverFactory* FromWebContents( |
| 38 content::WebContents* contents); | 45 content::WebContents* contents); |
| 39 static void BindAutofillDriver(content::RenderFrameHost* render_frame_host, | 46 static void BindAutofillDriver(content::RenderFrameHost* render_frame_host, |
| 40 mojom::AutofillDriverRequest request); | 47 mojom::AutofillDriverRequest request); |
| 41 | 48 |
| 42 // Gets the |ContentAutofillDriver| associated with |render_frame_host|. | 49 // Gets the |AutofillDriver| associated with |render_frame_host|. |
| 43 // |render_frame_host| must be owned by |web_contents()|. | 50 // |render_frame_host| must be owned by |web_contents()|. |
| 44 ContentAutofillDriver* DriverForFrame( | 51 AutofillDriver* DriverForFrame(content::RenderFrameHost* render_frame_host); |
| 45 content::RenderFrameHost* render_frame_host); | |
| 46 | 52 |
| 47 // content::WebContentsObserver: | 53 // content::WebContentsObserver: |
| 48 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; | 54 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
| 49 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 55 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
| 50 void DidNavigateAnyFrame( | 56 void DidNavigateAnyFrame( |
| 51 content::RenderFrameHost* render_frame_host, | 57 content::RenderFrameHost* render_frame_host, |
| 52 const content::LoadCommittedDetails& details, | 58 const content::LoadCommittedDetails& details, |
| 53 const content::FrameNavigateParams& params) override; | 59 const content::FrameNavigateParams& params) override; |
| 54 void DidFinishNavigation( | 60 void DidFinishNavigation( |
| 55 content::NavigationHandle* navigation_handle) override; | 61 content::NavigationHandle* navigation_handle) override; |
| 56 void WasHidden() override; | 62 void WasHidden() override; |
| 57 | 63 |
| 58 static const char kContentAutofillDriverFactoryWebContentsUserDataKey[]; | 64 static const char kContentAutofillDriverFactoryWebContentsUserDataKey[]; |
| 59 | 65 |
| 60 protected: | 66 protected: |
| 67 // Accessible for tests. |
| 61 ContentAutofillDriverFactory( | 68 ContentAutofillDriverFactory( |
| 62 content::WebContents* web_contents, | 69 content::WebContents* web_contents, |
| 63 AutofillClient* client, | 70 AutofillClient* client, |
| 64 const std::string& app_locale, | 71 const std::string& app_locale, |
| 65 AutofillManager::AutofillDownloadManagerState enable_download_manager); | 72 AutofillManager::AutofillDownloadManagerState enable_download_manager, |
| 73 DriverCreator driver_creator); |
| 66 | 74 |
| 67 private: | 75 private: |
| 68 AutofillClient* client_; | 76 AutofillClient* client_; |
| 69 std::string app_locale_; | 77 std::string app_locale_; |
| 70 AutofillManager::AutofillDownloadManagerState enable_download_manager_; | 78 AutofillManager::AutofillDownloadManagerState enable_download_manager_; |
| 79 const DriverCreator driver_creator_; |
| 71 | 80 |
| 72 std::map<content::RenderFrameHost*, std::unique_ptr<ContentAutofillDriver>> | 81 std::map<content::RenderFrameHost*, std::unique_ptr<AutofillDriver>> |
| 73 frame_driver_map_; | 82 frame_driver_map_; |
| 74 }; | 83 }; |
| 75 | 84 |
| 76 } // namespace autofill | 85 } // namespace autofill |
| 77 | 86 |
| 78 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_FACTORY_H
_ | 87 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_FACTORY_H
_ |
| OLD | NEW |