diff options
author | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-26 19:28:45 +0000 |
---|---|---|
committer | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-26 19:28:45 +0000 |
commit | 4b1501ed72f5a90e3b90cd95fd222fbb9c4ad0a2 (patch) | |
tree | d43d7753b98f7d842151877e2228b595a62ee404 /ui | |
parent | 302322a3e242d9e2093fdab344b2020c0ff087b0 (diff) | |
download | chromium_src-4b1501ed72f5a90e3b90cd95fd222fbb9c4ad0a2.zip chromium_src-4b1501ed72f5a90e3b90cd95fd222fbb9c4ad0a2.tar.gz chromium_src-4b1501ed72f5a90e3b90cd95fd222fbb9c4ad0a2.tar.bz2 |
[Aura] Fix NativeViewHostAura::RemovedFromWidget crash.
Make NativeViewHostAura detach the native view when notified OnWindowDestroyed.
BUG=101526
TEST=Verify closing a window with DOMView inside (e.g. AppList window) does not crash per 101526.
Review URL: http://codereview.chromium.org/8390052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/window.cc | 2 | ||||
-rw-r--r-- | ui/aura/window_observer.h | 3 | ||||
-rw-r--r-- | ui/aura/window_unittest.cc | 33 |
3 files changed, 37 insertions, 1 deletions
diff --git a/ui/aura/window.cc b/ui/aura/window.cc index d7ee967..409454c 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -68,6 +68,8 @@ Window::~Window() { delegate_->OnWindowDestroyed(); if (parent_) parent_->RemoveChild(this); + + FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroyed(this)); } void Window::Init(ui::Layer::LayerType layer_type) { diff --git a/ui/aura/window_observer.h b/ui/aura/window_observer.h index f3ecabc..4d048c0 100644 --- a/ui/aura/window_observer.h +++ b/ui/aura/window_observer.h @@ -25,6 +25,9 @@ class AURA_EXPORT WindowObserver { // may still return false. See description in Window::IsVisible() for details. virtual void OnWindowVisibilityChanged(Window* window, bool visible) {} + // Invoked when the Window has been destroyed (i.e. from its destructor). + virtual void OnWindowDestroyed(Window* window) {} + protected: virtual ~WindowObserver() {} }; diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index 0e4507b..a6474c8 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -1144,7 +1144,11 @@ class WindowObserverTest : public WindowTest, bool visible_param; }; - WindowObserverTest() : added_count_(0), removed_count_(0) {} + WindowObserverTest() + : added_count_(0), + removed_count_(0), + destroyed_count_(0) { + } virtual ~WindowObserverTest() {} @@ -1165,6 +1169,12 @@ class WindowObserverTest : public WindowTest, return result; } + int DestroyedCountAndClear() { + int result = destroyed_count_; + destroyed_count_ = 0; + return result; + } + private: virtual void OnWindowAdded(Window* new_window) OVERRIDE { added_count_++; @@ -1181,8 +1191,13 @@ class WindowObserverTest : public WindowTest, visibility_info_->visible_param = visible; } + virtual void OnWindowDestroyed(Window* window) OVERRIDE { + destroyed_count_++; + } + int added_count_; int removed_count_; + int destroyed_count_; scoped_ptr<VisibilityInfo> visibility_info_; DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); @@ -1254,6 +1269,22 @@ TEST_F(WindowObserverTest, WindowVisibility) { EXPECT_TRUE(GetVisibilityInfo()->visible_param); } +// Test if OnWindowDestroyed is invoked as expected. +TEST_F(WindowObserverTest, WindowDestroyed) { + // Delete a window should fire a destroyed notification. + scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); + w1->AddObserver(this); + w1.reset(); + EXPECT_EQ(1, DestroyedCountAndClear()); + + // Observe on child and delete parent window should fire a notification. + scoped_ptr<Window> parent(CreateTestWindowWithId(1, NULL)); + Window* child = CreateTestWindowWithId(1, parent.get()); // owned by parent + child->AddObserver(this); + parent.reset(); + EXPECT_EQ(1, DestroyedCountAndClear()); +} + class DesktopObserverTest : public WindowTest, public DesktopObserver { public: |