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

Unified Diff: ui/keyboard/keyboard_controller.cc

Issue 527153002: Fix the issue that GetFrameWindow() may change between AddObserver and RemoveObserver in KeyboardCo… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revised per comments. Created 6 years, 3 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
« no previous file with comments | « ui/keyboard/keyboard_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/keyboard/keyboard_controller.cc
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc
index ceef5941f7e424a9e912a7ad8ee0f8fe9ff73751..6c02069e7ff6e761199c30be5780802c71a78726 100644
--- a/ui/keyboard/keyboard_controller.cc
+++ b/ui/keyboard/keyboard_controller.cc
@@ -4,6 +4,8 @@
#include "ui/keyboard/keyboard_controller.h"
+#include <set>
+
#include "base/bind.h"
#include "base/command_line.h"
#include "content/public/browser/render_widget_host.h"
@@ -207,6 +209,12 @@ class WindowBoundsChangeObserver : public aura::WindowObserver {
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
+
+ void AddObservedWindow(aura::Window* window);
+ void RemoveAllObservedWindows();
+
+ private:
+ std::set<aura::Window*> observed_windows_;
};
void WindowBoundsChangeObserver::OnWindowBoundsChanged(aura::Window* window,
@@ -219,6 +227,21 @@ void WindowBoundsChangeObserver::OnWindowBoundsChanged(aura::Window* window,
void WindowBoundsChangeObserver::OnWindowDestroyed(aura::Window* window) {
if (window->HasObserver(this))
window->RemoveObserver(this);
+ observed_windows_.erase(window);
+}
+
+void WindowBoundsChangeObserver::AddObservedWindow(aura::Window* window) {
+ if (!window->HasObserver(this)) {
+ window->AddObserver(this);
+ observed_windows_.insert(window);
+ }
+}
+
+void WindowBoundsChangeObserver::RemoveAllObservedWindows() {
+ for (std::set<aura::Window*>::iterator it = observed_windows_.begin();
+ it != observed_windows_.end(); ++it)
+ (*it)->RemoveObserver(this);
+ observed_windows_.clear();
}
// static
@@ -533,12 +556,10 @@ void KeyboardController::ResetWindowInsets() {
content::RenderWidgetHost::GetRenderWidgetHosts());
while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
content::RenderWidgetHostView* view = widget->GetView();
- if (view) {
+ if (view)
view->SetInsets(insets);
- aura::Window *window = view->GetNativeView();
- RemoveBoundsChangedObserver(window);
- }
}
+ window_bounds_observer_->RemoveAllObservedWindows();
}
bool KeyboardController::WillHideKeyboard() const {
@@ -558,18 +579,8 @@ void KeyboardController::HideAnimationFinished() {
void KeyboardController::AddBoundsChangedObserver(aura::Window* window) {
aura::Window* target_window = GetFrameWindow(window);
- if (target_window &&
- !target_window->HasObserver(window_bounds_observer_.get())) {
- target_window->AddObserver(window_bounds_observer_.get());
- }
-}
-
-void KeyboardController::RemoveBoundsChangedObserver(aura::Window* window) {
- aura::Window* target_window = GetFrameWindow(window);
- if (target_window &&
- target_window->HasObserver(window_bounds_observer_.get())) {
- target_window->RemoveObserver(window_bounds_observer_.get());
- }
+ if (target_window)
+ window_bounds_observer_->AddObservedWindow(target_window);
}
} // namespace keyboard
« no previous file with comments | « ui/keyboard/keyboard_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698