Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Unified Diff: chrome/browser/autofill/autofill_external_delegate.cc

Issue 12223106: Properly Remove Autofill Keyboard Listener. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/autofill_external_delegate.cc
diff --git a/chrome/browser/autofill/autofill_external_delegate.cc b/chrome/browser/autofill/autofill_external_delegate.cc
index 1bc339d51f0588471dff640281d1a76654b9a9bd..0f635a4a04cf8c980f8112b812999b7c76b475c0 100644
--- a/chrome/browser/autofill/autofill_external_delegate.cc
+++ b/chrome/browser/autofill/autofill_external_delegate.cc
@@ -49,7 +49,8 @@ AutofillExternalDelegate::AutofillExternalDelegate(
password_autofill_manager_(web_contents),
autofill_query_id_(0),
display_warning_if_disabled_(false),
- has_shown_autofill_popup_for_current_edit_(false) {
+ has_shown_autofill_popup_for_current_edit_(false),
+ registered_keyboard_listener_with_(NULL) {
registrar_.Add(this,
content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
content::Source<content::WebContents>(web_contents));
@@ -206,14 +207,19 @@ void AutofillExternalDelegate::SetCurrentDataListValues(
void AutofillExternalDelegate::OnPopupShown(
content::KeyboardListener* listener) {
- if (web_contents_)
- web_contents_->GetRenderViewHost()->AddKeyboardListener(listener);
+ if (web_contents_ && !registered_keyboard_listener_with_) {
+ registered_keyboard_listener_with_ = web_contents_->GetRenderViewHost();
+ registered_keyboard_listener_with_->AddKeyboardListener(listener);
+ }
}
void AutofillExternalDelegate::OnPopupHidden(
content::KeyboardListener* listener) {
- if (web_contents_)
+ if (web_contents_ && registered_keyboard_listener_with_ ==
+ web_contents_->GetRenderViewHost())
web_contents_->GetRenderViewHost()->RemoveKeyboardListener(listener);
+
+ registered_keyboard_listener_with_ = NULL;
}
void AutofillExternalDelegate::DidSelectSuggestion(int identifier) {
@@ -278,10 +284,8 @@ void AutofillExternalDelegate::ClearPreviewedForm() {
}
void AutofillExternalDelegate::HideAutofillPopup() {
- if (controller_) {
+ if (controller_)
controller_->Hide();
- OnPopupHidden(controller_.get());
- }
}
void AutofillExternalDelegate::Reset() {

Powered by Google App Engine
This is Rietveld 408576698