Commit afba6145 authored by shuchen's avatar shuchen Committed by Commit bot

Fix the issue that GetFrameWindow() may change between AddObserver and...

Fix the issue that GetFrameWindow() may change between AddObserver and RemoveObserver in KeyboardController.

BUG=408995
TEST=Verified on linux_chromeos.

Review URL: https://codereview.chromium.org/527153002

Cr-Commit-Position: refs/heads/master@{#292949}
parent 045e90a0
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ui/keyboard/keyboard_controller.h" #include "ui/keyboard/keyboard_controller.h"
#include <set>
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_widget_host.h"
...@@ -207,6 +209,12 @@ class WindowBoundsChangeObserver : public aura::WindowObserver { ...@@ -207,6 +209,12 @@ class WindowBoundsChangeObserver : public aura::WindowObserver {
const gfx::Rect& old_bounds, const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE; const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnWindowDestroyed(aura::Window* window) 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, void WindowBoundsChangeObserver::OnWindowBoundsChanged(aura::Window* window,
...@@ -219,6 +227,21 @@ void WindowBoundsChangeObserver::OnWindowBoundsChanged(aura::Window* window, ...@@ -219,6 +227,21 @@ void WindowBoundsChangeObserver::OnWindowBoundsChanged(aura::Window* window,
void WindowBoundsChangeObserver::OnWindowDestroyed(aura::Window* window) { void WindowBoundsChangeObserver::OnWindowDestroyed(aura::Window* window) {
if (window->HasObserver(this)) if (window->HasObserver(this))
window->RemoveObserver(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 // static
...@@ -533,12 +556,10 @@ void KeyboardController::ResetWindowInsets() { ...@@ -533,12 +556,10 @@ void KeyboardController::ResetWindowInsets() {
content::RenderWidgetHost::GetRenderWidgetHosts()); content::RenderWidgetHost::GetRenderWidgetHosts());
while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
content::RenderWidgetHostView* view = widget->GetView(); content::RenderWidgetHostView* view = widget->GetView();
if (view) { if (view)
view->SetInsets(insets); view->SetInsets(insets);
aura::Window *window = view->GetNativeView();
RemoveBoundsChangedObserver(window);
}
} }
window_bounds_observer_->RemoveAllObservedWindows();
} }
bool KeyboardController::WillHideKeyboard() const { bool KeyboardController::WillHideKeyboard() const {
...@@ -558,18 +579,8 @@ void KeyboardController::HideAnimationFinished() { ...@@ -558,18 +579,8 @@ void KeyboardController::HideAnimationFinished() {
void KeyboardController::AddBoundsChangedObserver(aura::Window* window) { void KeyboardController::AddBoundsChangedObserver(aura::Window* window) {
aura::Window* target_window = GetFrameWindow(window); aura::Window* target_window = GetFrameWindow(window);
if (target_window && if (target_window)
!target_window->HasObserver(window_bounds_observer_.get())) { window_bounds_observer_->AddObservedWindow(target_window);
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());
}
} }
} // namespace keyboard } // namespace keyboard
...@@ -139,11 +139,10 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver, ...@@ -139,11 +139,10 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
void ShowAnimationFinished(); void ShowAnimationFinished();
void HideAnimationFinished(); void HideAnimationFinished();
// Adds or removes an observer for tracking changes to a window size or // Adds an observer for tracking changes to a window size or
// position while the keyboard is displayed. Any window repositioning // position while the keyboard is displayed. Any window repositioning
// invalidates insets for overscrolling. // invalidates insets for overscrolling.
void AddBoundsChangedObserver(aura::Window* window); void AddBoundsChangedObserver(aura::Window* window);
void RemoveBoundsChangedObserver(aura::Window* window);
scoped_ptr<KeyboardControllerProxy> proxy_; scoped_ptr<KeyboardControllerProxy> proxy_;
scoped_ptr<aura::Window> container_; scoped_ptr<aura::Window> container_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment