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.h" | 5 #include "components/autofill/content/browser/content_autofill_driver.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
9 #include "components/autofill/content/common/autofill_messages.h" | 9 #include "components/autofill/content/common/autofill_messages.h" |
10 #include "components/autofill/core/browser/autofill_client.h" | 10 #include "components/autofill/core/browser/autofill_client.h" |
11 #include "components/autofill/core/browser/autofill_external_delegate.h" | 11 #include "components/autofill/core/browser/autofill_external_delegate.h" |
12 #include "components/autofill/core/browser/autofill_manager.h" | 12 #include "components/autofill/core/browser/autofill_manager.h" |
13 #include "components/autofill/core/browser/form_structure.h" | 13 #include "components/autofill/core/browser/form_structure.h" |
14 #include "components/autofill/core/common/autofill_switches.h" | 14 #include "components/autofill/core/common/autofill_switches.h" |
| 15 #include "components/password_manager/content/browser/content_password_manager_d
river.h" |
15 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/navigation_details.h" | 19 #include "content/public/browser/navigation_details.h" |
| 20 #include "content/public/browser/render_frame_host.h" |
19 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/site_instance.h" |
21 #include "content/public/common/frame_navigate_params.h" | |
22 #include "ipc/ipc_message_macros.h" | 23 #include "ipc/ipc_message_macros.h" |
23 | 24 |
24 namespace autofill { | 25 namespace autofill { |
25 | 26 |
26 namespace { | |
27 | |
28 const char kContentAutofillDriverWebContentsUserDataKey[] = | |
29 "web_contents_autofill_driver_impl"; | |
30 | |
31 } // namespace | |
32 | |
33 // static | |
34 void ContentAutofillDriver::CreateForWebContentsAndDelegate( | |
35 content::WebContents* contents, | |
36 AutofillClient* client, | |
37 const std::string& app_locale, | |
38 AutofillManager::AutofillDownloadManagerState enable_download_manager) { | |
39 if (FromWebContents(contents)) | |
40 return; | |
41 | |
42 contents->SetUserData( | |
43 kContentAutofillDriverWebContentsUserDataKey, | |
44 new ContentAutofillDriver( | |
45 contents, client, app_locale, enable_download_manager)); | |
46 } | |
47 | |
48 // static | |
49 ContentAutofillDriver* ContentAutofillDriver::FromWebContents( | |
50 content::WebContents* contents) { | |
51 return static_cast<ContentAutofillDriver*>( | |
52 contents->GetUserData(kContentAutofillDriverWebContentsUserDataKey)); | |
53 } | |
54 | |
55 ContentAutofillDriver::ContentAutofillDriver( | 27 ContentAutofillDriver::ContentAutofillDriver( |
56 content::WebContents* web_contents, | 28 content::RenderFrameHost* render_frame_host, |
57 AutofillClient* client, | 29 AutofillClient* client, |
58 const std::string& app_locale, | 30 const std::string& app_locale, |
59 AutofillManager::AutofillDownloadManagerState enable_download_manager) | 31 AutofillManager::AutofillDownloadManagerState enable_download_manager) |
60 : content::WebContentsObserver(web_contents), | 32 : render_frame_host_(render_frame_host), |
61 autofill_manager_(new AutofillManager(this, | 33 autofill_manager_(new AutofillManager(this, |
62 client, | 34 client, |
63 app_locale, | 35 app_locale, |
64 enable_download_manager)), | 36 enable_download_manager)), |
65 autofill_external_delegate_(autofill_manager_.get(), this), | 37 autofill_external_delegate_(autofill_manager_.get(), this), |
66 request_autocomplete_manager_(this) { | 38 request_autocomplete_manager_(this) { |
67 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_); | 39 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_); |
68 } | 40 } |
69 | 41 |
70 ContentAutofillDriver::~ContentAutofillDriver() {} | 42 ContentAutofillDriver::~ContentAutofillDriver() {} |
71 | 43 |
72 bool ContentAutofillDriver::IsOffTheRecord() const { | 44 bool ContentAutofillDriver::IsOffTheRecord() const { |
73 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 45 return render_frame_host_->GetSiteInstance() |
| 46 ->GetBrowserContext() |
| 47 ->IsOffTheRecord(); |
74 } | 48 } |
75 | 49 |
76 net::URLRequestContextGetter* ContentAutofillDriver::GetURLRequestContext() { | 50 net::URLRequestContextGetter* ContentAutofillDriver::GetURLRequestContext() { |
77 return web_contents()->GetBrowserContext()->GetRequestContext(); | 51 return render_frame_host_->GetSiteInstance() |
| 52 ->GetBrowserContext() |
| 53 ->GetRequestContext(); |
78 } | 54 } |
79 | 55 |
80 base::SequencedWorkerPool* ContentAutofillDriver::GetBlockingPool() { | 56 base::SequencedWorkerPool* ContentAutofillDriver::GetBlockingPool() { |
81 return content::BrowserThread::GetBlockingPool(); | 57 return content::BrowserThread::GetBlockingPool(); |
82 } | 58 } |
83 | 59 |
84 bool ContentAutofillDriver::RendererIsAvailable() { | 60 bool ContentAutofillDriver::RendererIsAvailable() { |
85 return (web_contents()->GetRenderViewHost() != NULL); | 61 return render_frame_host_->GetRenderViewHost() != NULL; |
86 } | 62 } |
87 | 63 |
88 void ContentAutofillDriver::SendFormDataToRenderer( | 64 void ContentAutofillDriver::SendFormDataToRenderer( |
89 int query_id, | 65 int query_id, |
90 RendererFormDataAction action, | 66 RendererFormDataAction action, |
91 const FormData& data) { | 67 const FormData& data) { |
92 if (!RendererIsAvailable()) | 68 if (!RendererIsAvailable()) |
93 return; | 69 return; |
94 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | |
95 switch (action) { | 70 switch (action) { |
96 case FORM_DATA_ACTION_FILL: | 71 case FORM_DATA_ACTION_FILL: |
97 host->Send( | 72 render_frame_host_->Send(new AutofillMsg_FillForm( |
98 new AutofillMsg_FillForm(host->GetRoutingID(), query_id, data)); | 73 render_frame_host_->GetRoutingID(), query_id, data)); |
99 break; | 74 break; |
100 case FORM_DATA_ACTION_PREVIEW: | 75 case FORM_DATA_ACTION_PREVIEW: |
101 host->Send( | 76 render_frame_host_->Send(new AutofillMsg_PreviewForm( |
102 new AutofillMsg_PreviewForm(host->GetRoutingID(), query_id, data)); | 77 render_frame_host_->GetRoutingID(), query_id, data)); |
103 break; | 78 break; |
104 } | 79 } |
105 } | 80 } |
106 | 81 |
107 void ContentAutofillDriver::PingRenderer() { | 82 void ContentAutofillDriver::PingRenderer() { |
108 if (!RendererIsAvailable()) | 83 if (!RendererIsAvailable()) |
109 return; | 84 return; |
110 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 85 render_frame_host_->Send( |
111 host->Send(new AutofillMsg_Ping(host->GetRoutingID())); | 86 new AutofillMsg_Ping(render_frame_host_->GetRoutingID())); |
| 87 } |
| 88 |
| 89 void ContentAutofillDriver::DetectAccountCreationForms( |
| 90 const std::vector<FormStructure*>& forms) { |
| 91 password_manager::ContentPasswordManagerDriver::GetForRenderFrameHost( |
| 92 render_frame_host_) |
| 93 ->GetPasswordGenerationManager() |
| 94 ->DetectAccountCreationForms(forms); |
112 } | 95 } |
113 | 96 |
114 void ContentAutofillDriver::SendAutofillTypePredictionsToRenderer( | 97 void ContentAutofillDriver::SendAutofillTypePredictionsToRenderer( |
115 const std::vector<FormStructure*>& forms) { | 98 const std::vector<FormStructure*>& forms) { |
116 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 99 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
117 switches::kShowAutofillTypePredictions)) | 100 switches::kShowAutofillTypePredictions)) |
118 return; | 101 return; |
119 | 102 |
120 if (!RendererIsAvailable()) | 103 if (!RendererIsAvailable()) |
121 return; | 104 return; |
122 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | |
123 | 105 |
124 std::vector<FormDataPredictions> type_predictions; | 106 std::vector<FormDataPredictions> type_predictions; |
125 FormStructure::GetFieldTypePredictions(forms, &type_predictions); | 107 FormStructure::GetFieldTypePredictions(forms, &type_predictions); |
126 host->Send(new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(), | 108 render_frame_host_->Send(new AutofillMsg_FieldTypePredictionsAvailable( |
127 type_predictions)); | 109 render_frame_host_->GetRoutingID(), type_predictions)); |
128 } | 110 } |
129 | 111 |
130 void ContentAutofillDriver::RendererShouldAcceptDataListSuggestion( | 112 void ContentAutofillDriver::RendererShouldAcceptDataListSuggestion( |
131 const base::string16& value) { | 113 const base::string16& value) { |
132 if (!RendererIsAvailable()) | 114 if (!RendererIsAvailable()) |
133 return; | 115 return; |
134 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 116 render_frame_host_->Send(new AutofillMsg_AcceptDataListSuggestion( |
135 host->Send( | 117 render_frame_host_->GetRoutingID(), value)); |
136 new AutofillMsg_AcceptDataListSuggestion(host->GetRoutingID(), value)); | |
137 } | 118 } |
138 | 119 |
139 void ContentAutofillDriver::RendererShouldClearFilledForm() { | 120 void ContentAutofillDriver::RendererShouldClearFilledForm() { |
140 if (!RendererIsAvailable()) | 121 if (!RendererIsAvailable()) |
141 return; | 122 return; |
142 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 123 render_frame_host_->Send( |
143 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); | 124 new AutofillMsg_ClearForm(render_frame_host_->GetRoutingID())); |
144 } | 125 } |
145 | 126 |
146 void ContentAutofillDriver::RendererShouldClearPreviewedForm() { | 127 void ContentAutofillDriver::RendererShouldClearPreviewedForm() { |
147 if (!RendererIsAvailable()) | 128 if (!RendererIsAvailable()) |
148 return; | 129 return; |
149 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 130 render_frame_host_->Send( |
150 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); | 131 new AutofillMsg_ClearPreviewedForm(render_frame_host_->GetRoutingID())); |
151 } | 132 } |
152 | 133 |
153 void ContentAutofillDriver::RendererShouldFillFieldWithValue( | 134 void ContentAutofillDriver::RendererShouldFillFieldWithValue( |
154 const base::string16& value) { | 135 const base::string16& value) { |
155 if (!RendererIsAvailable()) | 136 if (!RendererIsAvailable()) |
156 return; | 137 return; |
157 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 138 render_frame_host_->Send(new AutofillMsg_FillFieldWithValue( |
158 host->Send(new AutofillMsg_FillFieldWithValue(host->GetRoutingID(), value)); | 139 render_frame_host_->GetRoutingID(), value)); |
159 } | 140 } |
| 141 |
160 void ContentAutofillDriver::RendererShouldPreviewFieldWithValue( | 142 void ContentAutofillDriver::RendererShouldPreviewFieldWithValue( |
161 const base::string16& value) { | 143 const base::string16& value) { |
162 if (!RendererIsAvailable()) | 144 if (!RendererIsAvailable()) |
163 return; | 145 return; |
164 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 146 render_frame_host_->Send(new AutofillMsg_PreviewFieldWithValue( |
165 host->Send(new AutofillMsg_PreviewFieldWithValue(host->GetRoutingID(), | 147 render_frame_host_->GetRoutingID(), value)); |
166 value)); | |
167 } | 148 } |
168 | 149 |
169 bool ContentAutofillDriver::OnMessageReceived(const IPC::Message& message) { | 150 bool ContentAutofillDriver::HandleMessage(const IPC::Message& message) { |
170 bool handled = true; | 151 bool handled = true; |
171 IPC_BEGIN_MESSAGE_MAP(ContentAutofillDriver, message) | 152 IPC_BEGIN_MESSAGE_MAP(ContentAutofillDriver, message) |
172 IPC_MESSAGE_FORWARD(AutofillHostMsg_FormsSeen, | 153 IPC_MESSAGE_FORWARD(AutofillHostMsg_FormsSeen, |
173 autofill_manager_.get(), | 154 autofill_manager_.get(), |
174 AutofillManager::OnFormsSeen) | 155 AutofillManager::OnFormsSeen) |
175 IPC_MESSAGE_FORWARD(AutofillHostMsg_FormSubmitted, | 156 IPC_MESSAGE_FORWARD(AutofillHostMsg_FormSubmitted, |
176 autofill_manager_.get(), | 157 autofill_manager_.get(), |
177 AutofillManager::OnFormSubmitted) | 158 AutofillManager::OnFormSubmitted) |
178 IPC_MESSAGE_FORWARD(AutofillHostMsg_TextFieldDidChange, | 159 IPC_MESSAGE_FORWARD(AutofillHostMsg_TextFieldDidChange, |
179 autofill_manager_.get(), | 160 autofill_manager_.get(), |
(...skipping 23 matching lines...) Expand all Loading... |
203 &request_autocomplete_manager_, | 184 &request_autocomplete_manager_, |
204 RequestAutocompleteManager::OnRequestAutocomplete) | 185 RequestAutocompleteManager::OnRequestAutocomplete) |
205 IPC_MESSAGE_FORWARD(AutofillHostMsg_CancelRequestAutocomplete, | 186 IPC_MESSAGE_FORWARD(AutofillHostMsg_CancelRequestAutocomplete, |
206 &request_autocomplete_manager_, | 187 &request_autocomplete_manager_, |
207 RequestAutocompleteManager::OnCancelRequestAutocomplete) | 188 RequestAutocompleteManager::OnCancelRequestAutocomplete) |
208 IPC_MESSAGE_UNHANDLED(handled = false) | 189 IPC_MESSAGE_UNHANDLED(handled = false) |
209 IPC_END_MESSAGE_MAP() | 190 IPC_END_MESSAGE_MAP() |
210 return handled; | 191 return handled; |
211 } | 192 } |
212 | 193 |
213 void ContentAutofillDriver::DidNavigateMainFrame( | 194 void ContentAutofillDriver::DidNavigateFrame( |
214 const content::LoadCommittedDetails& details, | 195 const content::LoadCommittedDetails& details, |
215 const content::FrameNavigateParams& params) { | 196 const content::FrameNavigateParams& params) { |
216 if (details.is_navigation_to_different_page()) | 197 if (details.is_navigation_to_different_page()) |
217 autofill_manager_->Reset(); | 198 autofill_manager_->Reset(); |
218 } | 199 } |
219 | 200 |
220 void ContentAutofillDriver::SetAutofillManager( | 201 void ContentAutofillDriver::SetAutofillManager( |
221 scoped_ptr<AutofillManager> manager) { | 202 scoped_ptr<AutofillManager> manager) { |
222 autofill_manager_ = manager.Pass(); | 203 autofill_manager_ = manager.Pass(); |
223 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_); | 204 autofill_manager_->SetExternalDelegate(&autofill_external_delegate_); |
224 } | 205 } |
225 | 206 |
226 void ContentAutofillDriver::NavigationEntryCommitted( | |
227 const content::LoadCommittedDetails& load_details) { | |
228 autofill_manager_->client()->HideAutofillPopup(); | |
229 } | |
230 | |
231 void ContentAutofillDriver::WasHidden() { | |
232 autofill_manager_->client()->HideAutofillPopup(); | |
233 } | |
234 | |
235 } // namespace autofill | 207 } // namespace autofill |
OLD | NEW |