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

Side by Side Diff: ash/wm/toplevel_window_event_handler.cc

Issue 2540143004: Prevent a crash if the window was deleted while in a drag runloop (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/toplevel_window_event_handler.h" 5 #include "ash/wm/toplevel_window_event_handler.h"
6 6
7 #include "ash/aura/wm_window_aura.h" 7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/wm/window_state.h" 8 #include "ash/common/wm/window_state.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/window_state_aura.h" 10 #include "ash/wm/window_state_aura.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "ui/aura/client/cursor_client.h" 13 #include "ui/aura/client/cursor_client.h"
14 #include "ui/aura/env.h" 14 #include "ui/aura/env.h"
15 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
16 #include "ui/aura/window_event_dispatcher.h" 16 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/aura/window_tracker.h"
17 #include "ui/aura/window_tree_host.h" 18 #include "ui/aura/window_tree_host.h"
18 #include "ui/base/cursor/cursor.h" 19 #include "ui/base/cursor/cursor.h"
19 #include "ui/base/hit_test.h" 20 #include "ui/base/hit_test.h"
20 #include "ui/events/event.h" 21 #include "ui/events/event.h"
21 #include "ui/events/event_utils.h" 22 #include "ui/events/event_utils.h"
22 #include "ui/events/gestures/gesture_recognizer.h" 23 #include "ui/events/gestures/gesture_recognizer.h"
23 24
24 namespace ash { 25 namespace ash {
25 26
26 ToplevelWindowEventHandler::ToplevelWindowEventHandler(WmShell* shell) 27 ToplevelWindowEventHandler::ToplevelWindowEventHandler(WmShell* shell)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 base::WeakPtr<ToplevelWindowEventHandler> weak_ptr( 88 base::WeakPtr<ToplevelWindowEventHandler> weak_ptr(
88 weak_factory_.GetWeakPtr()); 89 weak_factory_.GetWeakPtr());
89 base::MessageLoop* loop = base::MessageLoop::current(); 90 base::MessageLoop* loop = base::MessageLoop::current();
90 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); 91 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
91 92
92 // Disable window position auto management while dragging and restore it 93 // Disable window position auto management while dragging and restore it
93 // aftrewards. 94 // aftrewards.
94 wm::WindowState* window_state = wm::GetWindowState(source); 95 wm::WindowState* window_state = wm::GetWindowState(source);
95 const bool window_position_managed = window_state->window_position_managed(); 96 const bool window_position_managed = window_state->window_position_managed();
96 window_state->set_window_position_managed(false); 97 window_state->set_window_position_managed(false);
98 aura::WindowTracker tracker({source});
97 99
98 run_loop.Run(); 100 run_loop.Run();
99 101
100 if (!weak_ptr) 102 if (!weak_ptr)
101 return aura::client::MOVE_CANCELED; 103 return aura::client::MOVE_CANCELED;
102 104
103 window_state->set_window_position_managed(window_position_managed); 105 // Make sure the window hasn't been deleted.
106 if (tracker.Contains(source))
107 window_state->set_window_position_managed(window_position_managed);
104 108
105 in_move_loop_ = false; 109 in_move_loop_ = false;
106 return result == wm::WmToplevelWindowEventHandler::DragResult::SUCCESS 110 return result == wm::WmToplevelWindowEventHandler::DragResult::SUCCESS
107 ? aura::client::MOVE_SUCCESSFUL 111 ? aura::client::MOVE_SUCCESSFUL
108 : aura::client::MOVE_CANCELED; 112 : aura::client::MOVE_CANCELED;
109 } 113 }
110 114
111 void ToplevelWindowEventHandler::EndMoveLoop() { 115 void ToplevelWindowEventHandler::EndMoveLoop() {
112 if (in_move_loop_) 116 if (in_move_loop_)
113 wm_toplevel_window_event_handler_.RevertDrag(); 117 wm_toplevel_window_event_handler_.RevertDrag();
114 } 118 }
115 119
116 void ToplevelWindowEventHandler::OnDragCompleted( 120 void ToplevelWindowEventHandler::OnDragCompleted(
117 wm::WmToplevelWindowEventHandler::DragResult* result_return_value, 121 wm::WmToplevelWindowEventHandler::DragResult* result_return_value,
118 base::RunLoop* run_loop, 122 base::RunLoop* run_loop,
119 wm::WmToplevelWindowEventHandler::DragResult result) { 123 wm::WmToplevelWindowEventHandler::DragResult result) {
120 *result_return_value = result; 124 *result_return_value = result;
121 run_loop->Quit(); 125 run_loop->Quit();
122 } 126 }
123 127
124 } // namespace ash 128 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698