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

Unified Diff: components/autofill/content/browser/key_press_handler_manager.cc

Issue 2762233004: Fix autofill popup controller key press callback registration (Closed)
Patch Set: Fix typo Created 3 years, 8 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: components/autofill/content/browser/key_press_handler_manager.cc
diff --git a/components/autofill/content/browser/key_press_handler_manager.cc b/components/autofill/content/browser/key_press_handler_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..96b463bc5d4e1b6dc277540e96fdc4e67fcad5e7
--- /dev/null
+++ b/components/autofill/content/browser/key_press_handler_manager.cc
@@ -0,0 +1,37 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/autofill/content/browser/key_press_handler_manager.h"
+
+namespace autofill {
+
+KeyPressHandlerManager::KeyPressHandlerManager(Delegate* delegate)
+ : delegate_(delegate) {}
+
+KeyPressHandlerManager::~KeyPressHandlerManager() = default;
+
+void KeyPressHandlerManager::RegisterKeyPressHandler(
+ const content::RenderWidgetHost::KeyPressEventCallback& handler) {
+ // It would have been nice to be able to tell if two callbacks are just the
+ // same function with the same bound arguments. That's not what Equals() does
+ // (they have to have the same BindState), but it's the closest approximation
+ // available.
+ if (handler.is_null() || handler.Equals(handler_))
+ return;
+
+ if (!handler_.is_null())
+ delegate_->RemoveHandler(handler_);
+ handler_ = handler;
+ delegate_->AddHandler(handler_);
+}
+
+void KeyPressHandlerManager::RemoveKeyPressHandler() {
+ if (handler_.is_null())
+ return;
+
+ delegate_->RemoveHandler(handler_);
+ handler_.Reset();
+}
+
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698