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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_drag_drop_client_win.cc

Issue 795303002: Fix crash when the source browser window is deleted during a drag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@drag_drop_end_move_loop2
Patch Set: Created 6 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 | « ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h ('k') | ui/views/widget/widget.cc » ('j') | 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 "ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h" 5 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h"
6 6
7 #include "ui/base/dragdrop/drag_drop_types.h" 7 #include "ui/base/dragdrop/drag_drop_types.h"
8 #include "ui/base/dragdrop/drag_source_win.h" 8 #include "ui/base/dragdrop/drag_source_win.h"
9 #include "ui/base/dragdrop/drop_target_event.h" 9 #include "ui/base/dragdrop/drop_target_event.h"
10 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" 10 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
11 #include "ui/views/widget/desktop_aura/desktop_drop_target_win.h" 11 #include "ui/views/widget/desktop_aura/desktop_drop_target_win.h"
12 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" 12 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
13 13
14 namespace views { 14 namespace views {
15 15
16 DesktopDragDropClientWin::DesktopDragDropClientWin( 16 DesktopDragDropClientWin::DesktopDragDropClientWin(
17 aura::Window* root_window, 17 aura::Window* root_window,
18 HWND window) 18 HWND window)
19 : drag_drop_in_progress_(false), 19 : drag_drop_in_progress_(false),
20 drag_operation_(0) { 20 drag_operation_(0),
21 weak_factory_(this) {
21 drop_target_ = new DesktopDropTargetWin(root_window, window); 22 drop_target_ = new DesktopDropTargetWin(root_window, window);
22 } 23 }
23 24
24 DesktopDragDropClientWin::~DesktopDragDropClientWin() { 25 DesktopDragDropClientWin::~DesktopDragDropClientWin() {
26 DragCancel();
25 } 27 }
26 28
27 int DesktopDragDropClientWin::StartDragAndDrop( 29 int DesktopDragDropClientWin::StartDragAndDrop(
28 const ui::OSExchangeData& data, 30 const ui::OSExchangeData& data,
29 aura::Window* root_window, 31 aura::Window* root_window,
30 aura::Window* source_window, 32 aura::Window* source_window,
31 const gfx::Point& root_location, 33 const gfx::Point& root_location,
32 int operation, 34 int operation,
33 ui::DragDropTypes::DragEventSource source) { 35 ui::DragDropTypes::DragEventSource source) {
34 drag_drop_in_progress_ = true; 36 drag_drop_in_progress_ = true;
35 drag_operation_ = operation; 37 drag_operation_ = operation;
36 38
39 base::WeakPtr<DesktopDragDropClientWin> alive(weak_factory_.GetWeakPtr());
40
37 drag_source_ = new ui::DragSourceWin; 41 drag_source_ = new ui::DragSourceWin;
42 scoped_refptr<ui::DragSourceWin> drag_source_copy = drag_source_;
43
38 DWORD effect; 44 DWORD effect;
39 HRESULT result = DoDragDrop( 45 HRESULT result = DoDragDrop(
40 ui::OSExchangeDataProviderWin::GetIDataObject(data), drag_source_.get(), 46 ui::OSExchangeDataProviderWin::GetIDataObject(data), drag_source_.get(),
41 ui::DragDropTypes::DragOperationToDropEffect(operation), &effect); 47 ui::DragDropTypes::DragOperationToDropEffect(operation), &effect);
42 48
43 drag_drop_in_progress_ = false; 49 if (alive)
50 drag_drop_in_progress_ = false;
44 51
45 if (result != DRAGDROP_S_DROP) 52 if (result != DRAGDROP_S_DROP)
46 effect = DROPEFFECT_NONE; 53 effect = DROPEFFECT_NONE;
47 54
48 return ui::DragDropTypes::DropEffectToDragOperation(effect); 55 return ui::DragDropTypes::DropEffectToDragOperation(effect);
49 } 56 }
50 57
51 void DesktopDragDropClientWin::DragUpdate(aura::Window* target, 58 void DesktopDragDropClientWin::DragUpdate(aura::Window* target,
52 const ui::LocatedEvent& event) { 59 const ui::LocatedEvent& event) {
53 } 60 }
54 61
55 void DesktopDragDropClientWin::Drop(aura::Window* target, 62 void DesktopDragDropClientWin::Drop(aura::Window* target,
56 const ui::LocatedEvent& event) { 63 const ui::LocatedEvent& event) {
57 } 64 }
58 65
59 void DesktopDragDropClientWin::DragCancel() { 66 void DesktopDragDropClientWin::DragCancel() {
60 drag_source_->CancelDrag(); 67 if (drag_drop_in_progress_)
sky 2014/12/15 20:44:13 Should this be a DCHECK?
pkotwicz 2014/12/15 21:54:11 In patch set #2, I moved the check to the destruct
68 drag_source_->CancelDrag();
61 drag_operation_ = 0; 69 drag_operation_ = 0;
62 } 70 }
63 71
64 bool DesktopDragDropClientWin::IsDragDropInProgress() { 72 bool DesktopDragDropClientWin::IsDragDropInProgress() {
65 return drag_drop_in_progress_; 73 return drag_drop_in_progress_;
66 } 74 }
67 75
68 void DesktopDragDropClientWin::OnNativeWidgetDestroying(HWND window) { 76 void DesktopDragDropClientWin::OnNativeWidgetDestroying(HWND window) {
69 if (drop_target_.get()) { 77 if (drop_target_.get()) {
70 RevokeDragDrop(window); 78 RevokeDragDrop(window);
71 drop_target_ = NULL; 79 drop_target_ = NULL;
72 } 80 }
73 } 81 }
74 82
75 } // namespace views 83 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h ('k') | ui/views/widget/widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698