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/autocomplete_history_manager.h" | 6 #include "chrome/browser/autofill/autocomplete_history_manager.h" |
7 #include "chrome/browser/autofill/autofill_external_delegate.h" | 7 #include "chrome/browser/autofill/autofill_external_delegate.h" |
8 #include "chrome/browser/autofill/autofill_manager.h" | 8 #include "chrome/browser/autofill/autofill_manager.h" |
9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" | 9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
10 #include "chrome/common/autofill_messages.h" | 10 #include "chrome/common/autofill_messages.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 content::Source<content::NavigationController>( | 61 content::Source<content::NavigationController>( |
62 &(web_contents->GetController()))); | 62 &(web_contents->GetController()))); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 AutofillExternalDelegate::~AutofillExternalDelegate() { | 66 AutofillExternalDelegate::~AutofillExternalDelegate() { |
67 if (controller_) | 67 if (controller_) |
68 controller_->Hide(); | 68 controller_->Hide(); |
69 } | 69 } |
70 | 70 |
71 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id) { | |
72 ClearPreviewedForm(); | |
73 | |
74 // Only preview the data if it is a profile. | |
75 if (unique_id > 0) | |
76 FillAutofillFormData(unique_id, true); | |
77 } | |
78 | |
79 void AutofillExternalDelegate::OnQuery(int query_id, | 71 void AutofillExternalDelegate::OnQuery(int query_id, |
80 const FormData& form, | 72 const FormData& form, |
81 const FormFieldData& field, | 73 const FormFieldData& field, |
82 const gfx::Rect& element_bounds, | 74 const gfx::Rect& element_bounds, |
83 bool display_warning_if_disabled) { | 75 bool display_warning_if_disabled) { |
84 autofill_query_form_ = form; | 76 autofill_query_form_ = form; |
85 autofill_query_field_ = field; | 77 autofill_query_field_ = field; |
86 display_warning_if_disabled_ = display_warning_if_disabled; | 78 display_warning_if_disabled_ = display_warning_if_disabled; |
87 autofill_query_id_ = query_id; | 79 autofill_query_id_ = query_id; |
88 | 80 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 const std::vector<string16>& data_list_values, | 190 const std::vector<string16>& data_list_values, |
199 const std::vector<string16>& data_list_labels, | 191 const std::vector<string16>& data_list_labels, |
200 const std::vector<string16>& data_list_icons, | 192 const std::vector<string16>& data_list_icons, |
201 const std::vector<int>& data_list_unique_ids) { | 193 const std::vector<int>& data_list_unique_ids) { |
202 data_list_values_ = data_list_values; | 194 data_list_values_ = data_list_values; |
203 data_list_labels_ = data_list_labels; | 195 data_list_labels_ = data_list_labels; |
204 data_list_icons_ = data_list_icons; | 196 data_list_icons_ = data_list_icons; |
205 data_list_unique_ids_ = data_list_unique_ids; | 197 data_list_unique_ids_ = data_list_unique_ids; |
206 } | 198 } |
207 | 199 |
200 void AutofillExternalDelegate::DidSelectSuggestion(int identifier) { | |
201 ClearPreviewedForm(); | |
202 | |
203 // Only preview the data if it is a profile. | |
204 if (identifier > 0) | |
205 FillAutofillFormData(identifier, true); | |
206 } | |
207 | |
208 void AutofillExternalDelegate::DidAcceptSuggestion(const string16& value, | |
209 int identifier) { | |
210 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
211 | |
212 if (identifier == WebAutofillClient::MenuItemIDAutofillOptions) { | |
213 // User selected 'Autofill Options'. | |
214 autofill_manager_->OnShowAutofillDialog(); | |
215 } else if (identifier == WebAutofillClient::MenuItemIDClearForm) { | |
216 // User selected 'Clear form'. | |
217 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); | |
218 } else if (identifier == WebAutofillClient::MenuItemIDPasswordEntry && | |
219 password_autofill_manager_.DidAcceptAutofillSuggestion( | |
220 autofill_query_field_, value)) { | |
221 // DidAcceptAutofillSuggestion has already handled the work to fill in | |
222 // the page as required. | |
223 } else if (identifier == WebAutofillClient::MenuItemIDDataListEntry) { | |
224 host->Send(new AutofillMsg_AcceptDataListSuggestion(host->GetRoutingID(), | |
225 value)); | |
226 } else if (identifier == WebAutofillClient::MenuItemIDAutocompleteEntry) { | |
227 // User selected an Autocomplete, so we fill directly. | |
228 host->Send(new AutofillMsg_SetNodeText( | |
229 host->GetRoutingID(), | |
230 value)); | |
231 } else { | |
232 FillAutofillFormData(identifier, false); | |
233 } | |
234 | |
235 HideAutofillPopup(); | |
236 } | |
237 | |
238 void AutofillExternalDelegate::RemoveSuggestion(int identifier) { | |
239 autofill_manager_->RemoveAutofillProfileOrCreditCard(identifier); | |
240 } | |
241 | |
208 void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) { | 242 void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) { |
209 if (web_contents_) { | 243 if (web_contents_) { |
Ilya Sherman
2012/12/20 21:57:42
Hmm, why is it relevant whether we have a WebConte
| |
210 autofill_manager_->RemoveAutocompleteEntry( | 244 autofill_manager_->RemoveAutocompleteEntry( |
211 autofill_query_field_.name, value); | 245 autofill_query_field_.name, value); |
212 } | 246 } |
213 } | 247 } |
214 | 248 |
215 void AutofillExternalDelegate::RemoveAutofillProfileOrCreditCard( | |
216 int unique_id) { | |
217 autofill_manager_->RemoveAutofillProfileOrCreditCard(unique_id); | |
218 } | |
219 | |
220 void AutofillExternalDelegate::DidEndTextFieldEditing() { | 249 void AutofillExternalDelegate::DidEndTextFieldEditing() { |
221 HideAutofillPopup(); | 250 HideAutofillPopup(); |
222 | 251 |
223 has_shown_autofill_popup_for_current_edit_ = false; | 252 has_shown_autofill_popup_for_current_edit_ = false; |
224 } | 253 } |
225 | 254 |
226 bool AutofillExternalDelegate::DidAcceptAutofillSuggestion( | |
227 const string16& value, | |
228 int unique_id, | |
229 unsigned index) { | |
230 // If the selected element is a warning we don't want to do anything. | |
231 if (unique_id == WebAutofillClient::MenuItemIDWarningMessage) | |
232 return false; | |
233 | |
234 RenderViewHost* host = web_contents_->GetRenderViewHost(); | |
235 | |
236 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions) { | |
237 // User selected 'Autofill Options'. | |
238 autofill_manager_->OnShowAutofillDialog(); | |
239 } else if (unique_id == WebAutofillClient::MenuItemIDClearForm) { | |
240 // User selected 'Clear form'. | |
241 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); | |
242 } else if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry && | |
243 password_autofill_manager_.DidAcceptAutofillSuggestion( | |
244 autofill_query_field_, value)) { | |
245 // DidAcceptAutofillSuggestion has already handled the work to fill in | |
246 // the page as required. | |
247 } else if (unique_id == WebAutofillClient::MenuItemIDDataListEntry) { | |
248 host->Send(new AutofillMsg_AcceptDataListSuggestion(host->GetRoutingID(), | |
249 value)); | |
250 } else if (unique_id == WebAutofillClient::MenuItemIDAutocompleteEntry) { | |
251 // User selected an Autocomplete, so we fill directly. | |
252 host->Send(new AutofillMsg_SetNodeText( | |
253 host->GetRoutingID(), | |
254 value)); | |
255 } else { | |
256 FillAutofillFormData(unique_id, false); | |
257 } | |
258 | |
259 HideAutofillPopup(); | |
260 | |
261 return true; | |
262 } | |
263 | |
264 void AutofillExternalDelegate::ClearPreviewedForm() { | 255 void AutofillExternalDelegate::ClearPreviewedForm() { |
265 if (web_contents_) { | 256 if (web_contents_) { |
266 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 257 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
267 | 258 |
268 if (host) | 259 if (host) |
269 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); | 260 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); |
270 } | 261 } |
271 } | 262 } |
272 | 263 |
273 void AutofillExternalDelegate::ControllerDestroyed() { | 264 void AutofillExternalDelegate::ControllerDestroyed() { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 if (!*content::Details<bool>(details).ptr()) | 406 if (!*content::Details<bool>(details).ptr()) |
416 HideAutofillPopup(); | 407 HideAutofillPopup(); |
417 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { | 408 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
418 HideAutofillPopup(); | 409 HideAutofillPopup(); |
419 } else { | 410 } else { |
420 NOTREACHED(); | 411 NOTREACHED(); |
421 } | 412 } |
422 } | 413 } |
423 | 414 |
424 | 415 |
OLD | NEW |