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 #include "components/autofill/content/browser/content_autofill_driver_factory.h" | 5 #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "components/autofill/content/browser/content_autofill_driver.h" | 12 #include "components/autofill/content/browser/content_autofill_driver.h" |
13 #include "components/autofill/core/browser/autofill_manager.h" | 13 #include "components/autofill/core/browser/autofill_manager.h" |
14 #include "content/public/browser/navigation_handle.h" | 14 #include "content/public/browser/navigation_handle.h" |
15 #include "content/public/browser/render_frame_host.h" | 15 #include "content/public/browser/render_frame_host.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 | 17 |
18 namespace autofill { | 18 namespace autofill { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 std::unique_ptr<AutofillDriver> CreateDriver( | 22 std::unique_ptr<AutofillDriver> CreateDriver( |
23 content::RenderFrameHost* render_frame_host, | 23 content::RenderFrameHost* render_frame_host, |
24 AutofillClient* client, | 24 AutofillClient* client, |
25 const std::string& app_locale, | 25 const std::string& app_locale, |
26 AutofillManager::AutofillDownloadManagerState enable_download_manager) { | 26 AutofillManager::AutofillDownloadManagerState enable_download_manager, |
| 27 AutofillProvider* provider) { |
27 return base::MakeUnique<ContentAutofillDriver>( | 28 return base::MakeUnique<ContentAutofillDriver>( |
28 render_frame_host, client, app_locale, enable_download_manager); | 29 render_frame_host, client, app_locale, enable_download_manager, provider); |
29 } | 30 } |
30 | 31 |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 const char ContentAutofillDriverFactory:: | 34 const char ContentAutofillDriverFactory:: |
34 kContentAutofillDriverFactoryWebContentsUserDataKey[] = | 35 kContentAutofillDriverFactoryWebContentsUserDataKey[] = |
35 "web_contents_autofill_driver_factory"; | 36 "web_contents_autofill_driver_factory"; |
36 | 37 |
37 ContentAutofillDriverFactory::~ContentAutofillDriverFactory() {} | 38 ContentAutofillDriverFactory::~ContentAutofillDriverFactory() {} |
38 | 39 |
39 // static | 40 // static |
40 void ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( | 41 void ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( |
41 content::WebContents* contents, | 42 content::WebContents* contents, |
42 AutofillClient* client, | 43 AutofillClient* client, |
43 const std::string& app_locale, | 44 const std::string& app_locale, |
44 AutofillManager::AutofillDownloadManagerState enable_download_manager) { | 45 AutofillManager::AutofillDownloadManagerState enable_download_manager) { |
| 46 CreateForWebContentsAndDelegate(contents, client, app_locale, |
| 47 enable_download_manager, nullptr); |
| 48 } |
| 49 |
| 50 void ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( |
| 51 content::WebContents* contents, |
| 52 AutofillClient* client, |
| 53 const std::string& app_locale, |
| 54 AutofillManager::AutofillDownloadManagerState enable_download_manager, |
| 55 AutofillProvider* provider) { |
45 if (FromWebContents(contents)) | 56 if (FromWebContents(contents)) |
46 return; | 57 return; |
47 | 58 |
48 auto new_factory = base::WrapUnique(new ContentAutofillDriverFactory( | 59 auto new_factory = base::WrapUnique(new ContentAutofillDriverFactory( |
49 contents, client, app_locale, enable_download_manager)); | 60 contents, client, app_locale, enable_download_manager, provider)); |
50 const std::vector<content::RenderFrameHost*> frames = | 61 const std::vector<content::RenderFrameHost*> frames = |
51 contents->GetAllFrames(); | 62 contents->GetAllFrames(); |
52 for (content::RenderFrameHost* frame : frames) { | 63 for (content::RenderFrameHost* frame : frames) { |
53 if (frame->IsRenderFrameLive()) | 64 if (frame->IsRenderFrameLive()) |
54 new_factory->RenderFrameCreated(frame); | 65 new_factory->RenderFrameCreated(frame); |
55 } | 66 } |
56 | 67 |
57 contents->SetUserData(kContentAutofillDriverFactoryWebContentsUserDataKey, | 68 contents->SetUserData(kContentAutofillDriverFactoryWebContentsUserDataKey, |
58 new_factory.release()); | 69 new_factory.release()); |
59 } | 70 } |
(...skipping 26 matching lines...) Expand all Loading... |
86 | 97 |
87 ContentAutofillDriver* driver = factory->DriverForFrame(render_frame_host); | 98 ContentAutofillDriver* driver = factory->DriverForFrame(render_frame_host); |
88 if (driver) | 99 if (driver) |
89 driver->BindRequest(std::move(request)); | 100 driver->BindRequest(std::move(request)); |
90 } | 101 } |
91 | 102 |
92 ContentAutofillDriverFactory::ContentAutofillDriverFactory( | 103 ContentAutofillDriverFactory::ContentAutofillDriverFactory( |
93 content::WebContents* web_contents, | 104 content::WebContents* web_contents, |
94 AutofillClient* client, | 105 AutofillClient* client, |
95 const std::string& app_locale, | 106 const std::string& app_locale, |
96 AutofillManager::AutofillDownloadManagerState enable_download_manager) | 107 AutofillManager::AutofillDownloadManagerState enable_download_manager, |
| 108 AutofillProvider* provider) |
97 : AutofillDriverFactory(client), | 109 : AutofillDriverFactory(client), |
98 content::WebContentsObserver(web_contents), | 110 content::WebContentsObserver(web_contents), |
99 app_locale_(app_locale), | 111 app_locale_(app_locale), |
100 enable_download_manager_(enable_download_manager) {} | 112 enable_download_manager_(enable_download_manager), |
| 113 provider_(provider) {} |
101 | 114 |
102 ContentAutofillDriver* ContentAutofillDriverFactory::DriverForFrame( | 115 ContentAutofillDriver* ContentAutofillDriverFactory::DriverForFrame( |
103 content::RenderFrameHost* render_frame_host) { | 116 content::RenderFrameHost* render_frame_host) { |
104 // This cast is safe because AutofillDriverFactory::AddForKey is protected | 117 // This cast is safe because AutofillDriverFactory::AddForKey is protected |
105 // and always called with ContentAutofillDriver instances within | 118 // and always called with ContentAutofillDriver instances within |
106 // ContentAutofillDriverFactory. | 119 // ContentAutofillDriverFactory. |
107 return static_cast<ContentAutofillDriver*>(DriverForKey(render_frame_host)); | 120 return static_cast<ContentAutofillDriver*>(DriverForKey(render_frame_host)); |
108 } | 121 } |
109 | 122 |
110 void ContentAutofillDriverFactory::RenderFrameCreated( | 123 void ContentAutofillDriverFactory::RenderFrameCreated( |
111 content::RenderFrameHost* render_frame_host) { | 124 content::RenderFrameHost* render_frame_host) { |
112 AddForKey(render_frame_host, | 125 AddForKey(render_frame_host, |
113 base::Bind(CreateDriver, render_frame_host, client(), app_locale_, | 126 base::Bind(CreateDriver, render_frame_host, client(), app_locale_, |
114 enable_download_manager_)); | 127 enable_download_manager_, provider_)); |
115 } | 128 } |
116 | 129 |
117 void ContentAutofillDriverFactory::RenderFrameDeleted( | 130 void ContentAutofillDriverFactory::RenderFrameDeleted( |
118 content::RenderFrameHost* render_frame_host) { | 131 content::RenderFrameHost* render_frame_host) { |
119 DeleteForKey(render_frame_host); | 132 DeleteForKey(render_frame_host); |
120 } | 133 } |
121 | 134 |
122 void ContentAutofillDriverFactory::DidFinishNavigation( | 135 void ContentAutofillDriverFactory::DidFinishNavigation( |
123 content::NavigationHandle* navigation_handle) { | 136 content::NavigationHandle* navigation_handle) { |
124 if (!navigation_handle->HasCommitted()) | 137 if (!navigation_handle->HasCommitted()) |
125 return; | 138 return; |
126 | 139 |
127 NavigationFinished(); | 140 NavigationFinished(); |
128 DriverForFrame(navigation_handle->GetRenderFrameHost()) | 141 DriverForFrame(navigation_handle->GetRenderFrameHost()) |
129 ->DidNavigateFrame(navigation_handle); | 142 ->DidNavigateFrame(navigation_handle); |
130 } | 143 } |
131 | 144 |
132 void ContentAutofillDriverFactory::WasHidden() { | 145 void ContentAutofillDriverFactory::WasHidden() { |
133 TabHidden(); | 146 TabHidden(); |
134 } | 147 } |
135 | 148 |
136 } // namespace autofill | 149 } // namespace autofill |
OLD | NEW |