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

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..3509118071ae112af0f8ac12079b261d8305d59e 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_(false) {
registrar_.Add(this,
content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
content::Source<content::WebContents>(web_contents));
@@ -206,14 +207,18 @@ void AutofillExternalDelegate::SetCurrentDataListValues(
void AutofillExternalDelegate::OnPopupShown(
content::KeyboardListener* listener) {
- if (web_contents_)
+ if (web_contents_ && !registered_keyboard_listener_) {
+ registered_keyboard_listener_ = true;
web_contents_->GetRenderViewHost()->AddKeyboardListener(listener);
+ }
}
void AutofillExternalDelegate::OnPopupHidden(
content::KeyboardListener* listener) {
- if (web_contents_)
+ if (web_contents_ && registered_keyboard_listener_) {
web_contents_->GetRenderViewHost()->RemoveKeyboardListener(listener);
+ registered_keyboard_listener_ = false;
+ }
}
void AutofillExternalDelegate::DidSelectSuggestion(int identifier) {
@@ -278,10 +283,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