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

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

Issue 819793002: Reland: Fix crash when the source browser window is deleted during a drag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 "base/tracked_objects.h" 7 #include "base/tracked_objects.h"
8 #include "ui/base/dragdrop/drag_drop_types.h" 8 #include "ui/base/dragdrop/drag_drop_types.h"
9 #include "ui/base/dragdrop/drag_source_win.h" 9 #include "ui/base/dragdrop/drag_source_win.h"
10 #include "ui/base/dragdrop/drop_target_event.h" 10 #include "ui/base/dragdrop/drop_target_event.h"
11 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" 11 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
12 #include "ui/views/widget/desktop_aura/desktop_drop_target_win.h" 12 #include "ui/views/widget/desktop_aura/desktop_drop_target_win.h"
13 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" 13 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
14 14
15 namespace views { 15 namespace views {
16 16
17 DesktopDragDropClientWin::DesktopDragDropClientWin( 17 DesktopDragDropClientWin::DesktopDragDropClientWin(
18 aura::Window* root_window, 18 aura::Window* root_window,
19 HWND window) 19 HWND window)
20 : drag_drop_in_progress_(false), 20 : drag_drop_in_progress_(false),
21 drag_operation_(0) { 21 drag_operation_(0),
22 weak_factory_(this) {
22 drop_target_ = new DesktopDropTargetWin(root_window, window); 23 drop_target_ = new DesktopDropTargetWin(root_window, window);
23 } 24 }
24 25
25 DesktopDragDropClientWin::~DesktopDragDropClientWin() { 26 DesktopDragDropClientWin::~DesktopDragDropClientWin() {
27 if (drag_drop_in_progress_)
28 DragCancel();
26 } 29 }
27 30
28 int DesktopDragDropClientWin::StartDragAndDrop( 31 int DesktopDragDropClientWin::StartDragAndDrop(
29 const ui::OSExchangeData& data, 32 const ui::OSExchangeData& data,
30 aura::Window* root_window, 33 aura::Window* root_window,
31 aura::Window* source_window, 34 aura::Window* source_window,
32 const gfx::Point& root_location, 35 const gfx::Point& root_location,
33 int operation, 36 int operation,
34 ui::DragDropTypes::DragEventSource source) { 37 ui::DragDropTypes::DragEventSource source) {
35 drag_drop_in_progress_ = true; 38 drag_drop_in_progress_ = true;
36 drag_operation_ = operation; 39 drag_operation_ = operation;
37 40
41 base::WeakPtr<DesktopDragDropClientWin> alive(weak_factory_.GetWeakPtr());
42
38 drag_source_ = new ui::DragSourceWin; 43 drag_source_ = new ui::DragSourceWin;
44 scoped_refptr<ui::DragSourceWin> drag_source_copy = drag_source_;
45
39 DWORD effect; 46 DWORD effect;
40 47
41 // Use task stopwatch to exclude the drag-drop time current task, if any. 48 // Use task stopwatch to exclude the drag-drop time current task, if any.
42 tracked_objects::TaskStopwatch stopwatch; 49 tracked_objects::TaskStopwatch stopwatch;
43 stopwatch.Start(); 50 stopwatch.Start();
44 HRESULT result = DoDragDrop( 51 HRESULT result = DoDragDrop(
45 ui::OSExchangeDataProviderWin::GetIDataObject(data), drag_source_.get(), 52 ui::OSExchangeDataProviderWin::GetIDataObject(data), drag_source_.get(),
46 ui::DragDropTypes::DragOperationToDropEffect(operation), &effect); 53 ui::DragDropTypes::DragOperationToDropEffect(operation), &effect);
47 stopwatch.Stop(); 54 stopwatch.Stop();
48 55
49 drag_drop_in_progress_ = false; 56 if (alive)
57 drag_drop_in_progress_ = false;
50 58
51 if (result != DRAGDROP_S_DROP) 59 if (result != DRAGDROP_S_DROP)
52 effect = DROPEFFECT_NONE; 60 effect = DROPEFFECT_NONE;
53 61
54 return ui::DragDropTypes::DropEffectToDragOperation(effect); 62 return ui::DragDropTypes::DropEffectToDragOperation(effect);
55 } 63 }
56 64
57 void DesktopDragDropClientWin::DragUpdate(aura::Window* target, 65 void DesktopDragDropClientWin::DragUpdate(aura::Window* target,
58 const ui::LocatedEvent& event) { 66 const ui::LocatedEvent& event) {
59 } 67 }
(...skipping 12 matching lines...) Expand all
72 } 80 }
73 81
74 void DesktopDragDropClientWin::OnNativeWidgetDestroying(HWND window) { 82 void DesktopDragDropClientWin::OnNativeWidgetDestroying(HWND window) {
75 if (drop_target_.get()) { 83 if (drop_target_.get()) {
76 RevokeDragDrop(window); 84 RevokeDragDrop(window);
77 drop_target_ = NULL; 85 drop_target_ = NULL;
78 } 86 }
79 } 87 }
80 88
81 } // namespace views 89 } // 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