• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_DRAG_WIN_H_
6 #define CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_DRAG_WIN_H_
7 #pragma once
8 
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/platform_thread.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h"
14 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
15 #include "ui/gfx/point.h"
16 
17 class DragDropThread;
18 class NativeTabContentsViewWin;
19 class WebDragSource;
20 struct WebDropData;
21 
22 // Windows-specific drag-and-drop handling in TabContentsView.
23 // If we are dragging a virtual file out of the browser, we use a background
24 // thread to do the drag-and-drop because we do not want to run nested
25 // message loop in the UI thread. For all other cases, the drag-and-drop happens
26 // in the UI thread.
27 class TabContentsDragWin
28     : public ui::DataObjectImpl::Observer,
29       public base::RefCountedThreadSafe<TabContentsDragWin> {
30  public:
31   explicit TabContentsDragWin(NativeTabContentsViewWin* view);
32   virtual ~TabContentsDragWin();
33 
34   // Called on UI thread.
35   void StartDragging(const WebDropData& drop_data,
36                      WebKit::WebDragOperationsMask ops,
37                      const SkBitmap& image,
38                      const gfx::Point& image_offset);
39   void CancelDrag();
40 
41   // DataObjectImpl::Observer implementation.
42   // Called on drag-and-drop thread.
43   virtual void OnWaitForData();
44   virtual void OnDataObjectDisposed();
45 
46  private:
47   // Called on either UI thread or drag-and-drop thread.
48   void PrepareDragForDownload(const WebDropData& drop_data,
49                               ui::OSExchangeData* data,
50                               const GURL& page_url,
51                               const std::string& page_encoding);
52   void PrepareDragForFileContents(const WebDropData& drop_data,
53                                   ui::OSExchangeData* data);
54   void PrepareDragForUrl(const WebDropData& drop_data,
55                          ui::OSExchangeData* data);
56   void DoDragging(const WebDropData& drop_data,
57                   WebKit::WebDragOperationsMask ops,
58                   const GURL& page_url,
59                   const std::string& page_encoding,
60                   const SkBitmap& image,
61                   const gfx::Point& image_offset);
62 
63   // Called on drag-and-drop thread.
64   void StartBackgroundDragging(const WebDropData& drop_data,
65                                WebKit::WebDragOperationsMask ops,
66                                const GURL& page_url,
67                                const std::string& page_encoding,
68                                const SkBitmap& image,
69                                const gfx::Point& image_offset);
70   // Called on UI thread.
71   void EndDragging(bool restore_suspended_state);
72   void CloseThread();
73 
74   // For debug check only. Access only on drag-and-drop thread.
75   base::PlatformThreadId drag_drop_thread_id_;
76 
77   // All the member variables below are accessed on UI thread.
78 
79   // Keep track of the TabContentsViewViews it is associated with.
80   NativeTabContentsViewWin* view_;
81 
82   // |drag_source_| is our callback interface passed to the system when we
83   // want to initiate a drag and drop operation.  We use it to tell if a
84   // drag operation is happening.
85   scoped_refptr<WebDragSource> drag_source_;
86 
87   // The thread used by the drag-out download. This is because we want to avoid
88   // running nested message loop in main UI thread.
89   scoped_ptr<DragDropThread> drag_drop_thread_;
90 
91   // The flag to guard that EndDragging is not called twice.
92   bool drag_ended_;
93 
94   // Keep track of the old suspended state of the drop target.
95   bool old_drop_target_suspended_state_;
96 
97   DISALLOW_COPY_AND_ASSIGN(TabContentsDragWin);
98 };
99 
100 
101 #endif  // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_DRAG_WIN_H_
102