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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 AutofillExternalDelegate::AutofillExternalDelegate( | 44 AutofillExternalDelegate::AutofillExternalDelegate( |
45 content::WebContents* web_contents, | 45 content::WebContents* web_contents, |
46 AutofillManager* autofill_manager) | 46 AutofillManager* autofill_manager) |
47 : web_contents_(web_contents), | 47 : web_contents_(web_contents), |
48 autofill_manager_(autofill_manager), | 48 autofill_manager_(autofill_manager), |
49 password_autofill_manager_(web_contents), | 49 password_autofill_manager_(web_contents), |
50 autofill_query_id_(0), | 50 autofill_query_id_(0), |
51 display_warning_if_disabled_(false), | 51 display_warning_if_disabled_(false), |
52 has_shown_autofill_popup_for_current_edit_(false) { | 52 has_shown_autofill_popup_for_current_edit_(false), |
| 53 registered_keyboard_listener_(false) { |
53 registrar_.Add(this, | 54 registrar_.Add(this, |
54 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 55 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
55 content::Source<content::WebContents>(web_contents)); | 56 content::Source<content::WebContents>(web_contents)); |
56 if (web_contents) { | 57 if (web_contents) { |
57 registrar_.Add( | 58 registrar_.Add( |
58 this, | 59 this, |
59 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 60 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
60 content::Source<content::NavigationController>( | 61 content::Source<content::NavigationController>( |
61 &(web_contents->GetController()))); | 62 &(web_contents->GetController()))); |
62 } | 63 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 const std::vector<string16>& data_list_icons, | 200 const std::vector<string16>& data_list_icons, |
200 const std::vector<int>& data_list_unique_ids) { | 201 const std::vector<int>& data_list_unique_ids) { |
201 data_list_values_ = data_list_values; | 202 data_list_values_ = data_list_values; |
202 data_list_labels_ = data_list_labels; | 203 data_list_labels_ = data_list_labels; |
203 data_list_icons_ = data_list_icons; | 204 data_list_icons_ = data_list_icons; |
204 data_list_unique_ids_ = data_list_unique_ids; | 205 data_list_unique_ids_ = data_list_unique_ids; |
205 } | 206 } |
206 | 207 |
207 void AutofillExternalDelegate::OnPopupShown( | 208 void AutofillExternalDelegate::OnPopupShown( |
208 content::KeyboardListener* listener) { | 209 content::KeyboardListener* listener) { |
209 if (web_contents_) | 210 if (web_contents_ && !registered_keyboard_listener_) { |
| 211 registered_keyboard_listener_ = true; |
210 web_contents_->GetRenderViewHost()->AddKeyboardListener(listener); | 212 web_contents_->GetRenderViewHost()->AddKeyboardListener(listener); |
| 213 } |
211 } | 214 } |
212 | 215 |
213 void AutofillExternalDelegate::OnPopupHidden( | 216 void AutofillExternalDelegate::OnPopupHidden( |
214 content::KeyboardListener* listener) { | 217 content::KeyboardListener* listener) { |
215 if (web_contents_) | 218 if (web_contents_ && registered_keyboard_listener_) { |
216 web_contents_->GetRenderViewHost()->RemoveKeyboardListener(listener); | 219 web_contents_->GetRenderViewHost()->RemoveKeyboardListener(listener); |
| 220 registered_keyboard_listener_ = false; |
| 221 } |
217 } | 222 } |
218 | 223 |
219 void AutofillExternalDelegate::DidSelectSuggestion(int identifier) { | 224 void AutofillExternalDelegate::DidSelectSuggestion(int identifier) { |
220 ClearPreviewedForm(); | 225 ClearPreviewedForm(); |
221 | 226 |
222 // Only preview the data if it is a profile. | 227 // Only preview the data if it is a profile. |
223 if (identifier > 0) | 228 if (identifier > 0) |
224 FillAutofillFormData(identifier, true); | 229 FillAutofillFormData(identifier, true); |
225 } | 230 } |
226 | 231 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 void AutofillExternalDelegate::ClearPreviewedForm() { | 276 void AutofillExternalDelegate::ClearPreviewedForm() { |
272 if (web_contents_) { | 277 if (web_contents_) { |
273 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 278 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
274 | 279 |
275 if (host) | 280 if (host) |
276 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); | 281 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); |
277 } | 282 } |
278 } | 283 } |
279 | 284 |
280 void AutofillExternalDelegate::HideAutofillPopup() { | 285 void AutofillExternalDelegate::HideAutofillPopup() { |
281 if (controller_) { | 286 if (controller_) |
282 controller_->Hide(); | 287 controller_->Hide(); |
283 OnPopupHidden(controller_.get()); | |
284 } | |
285 } | 288 } |
286 | 289 |
287 void AutofillExternalDelegate::Reset() { | 290 void AutofillExternalDelegate::Reset() { |
288 HideAutofillPopup(); | 291 HideAutofillPopup(); |
289 | 292 |
290 password_autofill_manager_.Reset(); | 293 password_autofill_manager_.Reset(); |
291 } | 294 } |
292 | 295 |
293 void AutofillExternalDelegate::AddPasswordFormMapping( | 296 void AutofillExternalDelegate::AddPasswordFormMapping( |
294 const FormFieldData& form, | 297 const FormFieldData& form, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 const content::NotificationDetails& details) { | 419 const content::NotificationDetails& details) { |
417 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { | 420 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { |
418 if (!*content::Details<bool>(details).ptr()) | 421 if (!*content::Details<bool>(details).ptr()) |
419 HideAutofillPopup(); | 422 HideAutofillPopup(); |
420 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { | 423 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
421 HideAutofillPopup(); | 424 HideAutofillPopup(); |
422 } else { | 425 } else { |
423 NOTREACHED(); | 426 NOTREACHED(); |
424 } | 427 } |
425 } | 428 } |
OLD | NEW |