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..db4c2387685363b43c4fcf1a66f32505758637ee |
--- /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 Equals() does (they |
Mathieu
2017/04/05 18:58:21
*what Equals() does
vabr (Chromium)
2017/04/06 05:39:58
Done.
|
+ // 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 |