OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "chrome/browser/autofill/autofill_external_delegate.h" | 6 #include "chrome/browser/autofill/autofill_external_delegate.h" |
7 #include "chrome/browser/autofill/autofill_manager.h" | 7 #include "chrome/browser/autofill/autofill_manager.h" |
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
9 #include "chrome/common/autofill_messages.h" | 9 #include "chrome/common/autofill_messages.h" |
10 #include "chrome/common/chrome_constants.h" | 10 #include "chrome/common/chrome_constants.h" |
11 #include "content/browser/renderer_host/render_view_host.h" | 11 #include "content/browser/renderer_host/render_view_host.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "grit/chromium_strings.h" | 13 #include "grit/chromium_strings.h" |
14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
16 | 16 |
17 AutofillExternalDelegate::~AutofillExternalDelegate() { | 17 AutofillExternalDelegate::~AutofillExternalDelegate() { |
18 } | 18 } |
19 | 19 |
20 AutofillExternalDelegate::AutofillExternalDelegate( | 20 AutofillExternalDelegate::AutofillExternalDelegate( |
21 TabContentsWrapper* tab_contents_wrapper, | 21 TabContentsWrapper* tab_contents_wrapper, |
22 AutofillManager* autofill_manager) | 22 AutofillManager* autofill_manager) |
23 : tab_contents_wrapper_(tab_contents_wrapper), | 23 : tab_contents_wrapper_(tab_contents_wrapper), |
24 autofill_manager_(autofill_manager), | 24 autofill_manager_(autofill_manager), |
| 25 password_autofill_manager_(tab_contents_wrapper), |
25 autofill_query_id_(0), | 26 autofill_query_id_(0), |
26 display_warning_if_disabled_(false), | 27 display_warning_if_disabled_(false), |
27 has_shown_autofill_popup_for_current_edit_(false), | 28 has_shown_autofill_popup_for_current_edit_(false), |
28 suggestions_clear_index_(-1), | 29 suggestions_clear_index_(-1), |
29 suggestions_options_index_(-1) { | 30 suggestions_options_index_(-1) { |
30 } | 31 } |
31 | 32 |
32 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, | 33 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, |
33 int list_index) { | 34 int list_index) { |
| 35 if (password_autofill_manager_.DidSelectAutofillSuggestion( |
| 36 autofill_query_field_)) |
| 37 return; |
| 38 |
34 if (list_index == suggestions_options_index_ || | 39 if (list_index == suggestions_options_index_ || |
35 list_index == suggestions_clear_index_ || | 40 list_index == suggestions_clear_index_ || |
36 unique_id == -1) | 41 unique_id == -1) |
37 return; | 42 return; |
38 | 43 |
39 FillAutofillFormData(unique_id, true); | 44 FillAutofillFormData(unique_id, true); |
40 } | 45 } |
41 | 46 |
42 void AutofillExternalDelegate::OnQuery(int query_id, | 47 void AutofillExternalDelegate::OnQuery(int query_id, |
43 const webkit::forms::FormData& form, | 48 const webkit::forms::FormData& form, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 144 } |
140 | 145 |
141 void AutofillExternalDelegate::DidAcceptAutofillSuggestions( | 146 void AutofillExternalDelegate::DidAcceptAutofillSuggestions( |
142 const string16& value, | 147 const string16& value, |
143 int unique_id, | 148 int unique_id, |
144 unsigned index) { | 149 unsigned index) { |
145 // If the selected element is a warning we don't want to do anything. | 150 // If the selected element is a warning we don't want to do anything. |
146 if (unique_id < 0) | 151 if (unique_id < 0) |
147 return; | 152 return; |
148 | 153 |
149 // TODO(csharp): Add the password autofill manager. | 154 if (password_autofill_manager_.DidAcceptAutofillSuggestion( |
150 // if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) | 155 autofill_query_field_, value)) { |
151 // return; | 156 // Accepting has been handled by the password manager. Just make sure |
| 157 // to hide the popup. |
| 158 HideAutofillPopup(); |
| 159 return; |
| 160 } |
152 | 161 |
153 if (suggestions_options_index_ != -1 && | 162 if (suggestions_options_index_ != -1 && |
154 index == static_cast<unsigned>(suggestions_options_index_)) { | 163 index == static_cast<unsigned>(suggestions_options_index_)) { |
155 // User selected 'Autofill Options'. | 164 // User selected 'Autofill Options'. |
156 autofill_manager_->OnShowAutofillDialog(); | 165 autofill_manager_->OnShowAutofillDialog(); |
157 } else if (suggestions_clear_index_ != -1 && | 166 } else if (suggestions_clear_index_ != -1 && |
158 index == static_cast<unsigned>(suggestions_clear_index_)) { | 167 index == static_cast<unsigned>(suggestions_clear_index_)) { |
159 // User selected 'Clear form'. | 168 // User selected 'Clear form'. |
160 RenderViewHost* host = | 169 RenderViewHost* host = |
161 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | 170 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
162 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); | 171 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); |
163 } else if (!unique_id) { | 172 } else if (!unique_id) { |
164 // User selected an Autocomplete entry, so we fill directly. | 173 // User selected an Autocomplete entry, so we fill directly. |
165 RenderViewHost* host = | 174 RenderViewHost* host = |
166 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | 175 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
167 host->Send(new AutofillMsg_SetNodeText( | 176 host->Send(new AutofillMsg_SetNodeText( |
168 host->GetRoutingID(), | 177 host->GetRoutingID(), |
169 value)); | 178 value)); |
170 } else { | 179 } else { |
171 FillAutofillFormData(unique_id, false); | 180 FillAutofillFormData(unique_id, false); |
172 } | 181 } |
173 | 182 |
174 HideAutofillPopup(); | 183 HideAutofillPopup(); |
175 } | 184 } |
176 | 185 |
177 void AutofillExternalDelegate::ClearPreviewedForm() { | 186 void AutofillExternalDelegate::ClearPreviewedForm() { |
| 187 if (password_autofill_manager_.DidClearAutofillSelection( |
| 188 autofill_query_field_)) |
| 189 return; |
| 190 |
178 RenderViewHost* host = | 191 RenderViewHost* host = |
179 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | 192 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
180 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); | 193 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); |
181 } | 194 } |
182 | 195 |
183 void AutofillExternalDelegate::HideAutofillPopup() { | 196 void AutofillExternalDelegate::HideAutofillPopup() { |
184 suggestions_clear_index_ = -1; | 197 suggestions_clear_index_ = -1; |
185 suggestions_options_index_ = -1; | 198 suggestions_options_index_ = -1; |
186 | 199 |
187 HideAutofillPopupInternal(); | 200 HideAutofillPopupInternal(); |
188 } | 201 } |
189 | 202 |
| 203 void AutofillExternalDelegate::FrameClosing(int frame_id) { |
| 204 password_autofill_manager_.FrameClosing(frame_id); |
| 205 } |
| 206 |
| 207 void AutofillExternalDelegate::FillPasswordForm( |
| 208 const webkit::forms::FormField& form, |
| 209 const webkit::forms::PasswordFormFillData& fill_data, |
| 210 int frame_id) { |
| 211 password_autofill_manager_.FillPasswordForm(form, fill_data, frame_id); |
| 212 } |
| 213 |
190 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, | 214 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, |
191 bool is_preview) { | 215 bool is_preview) { |
192 RenderViewHost* host = | 216 RenderViewHost* host = |
193 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | 217 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
194 | 218 |
195 if (is_preview) { | 219 if (is_preview) { |
196 host->Send(new AutofillMsg_SetAutofillActionPreview( | 220 host->Send(new AutofillMsg_SetAutofillActionPreview( |
197 host->GetRoutingID())); | 221 host->GetRoutingID())); |
198 } else { | 222 } else { |
199 host->Send(new AutofillMsg_SetAutofillActionFill( | 223 host->Send(new AutofillMsg_SetAutofillActionFill( |
(...skipping 12 matching lines...) Expand all Loading... |
212 // none, so all platforms use the default. | 236 // none, so all platforms use the default. |
213 | 237 |
214 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) | 238 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) |
215 | 239 |
216 AutofillExternalDelegate* AutofillExternalDelegate::Create( | 240 AutofillExternalDelegate* AutofillExternalDelegate::Create( |
217 TabContentsWrapper*, AutofillManager*) { | 241 TabContentsWrapper*, AutofillManager*) { |
218 return NULL; | 242 return NULL; |
219 } | 243 } |
220 | 244 |
221 #endif | 245 #endif |
OLD | NEW |