OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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_VIEWS_TAB_CONTENTS_TAB_CONTENTS_DRAG_WIN_H_ |
| 6 #define CHROME_BROWSER_VIEWS_TAB_CONTENTS_TAB_CONTENTS_DRAG_WIN_H_ |
| 7 |
| 8 #include "app/os_exchange_data_provider_win.h" |
| 9 #include "base/platform_thread.h" |
| 10 #include "base/ref_counted.h" |
| 11 #include "base/scoped_ptr.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" |
| 13 |
| 14 class DragDropThread; |
| 15 class TabContentsViewWin; |
| 16 class WebDragSource; |
| 17 struct WebDropData; |
| 18 |
| 19 // Windows-specific drag-and-drop handling in TabContentsView. |
| 20 // If we are dragging a virtual file out of the browser, we use a background |
| 21 // thread to do the drag-and-drop because we do not want to run nested |
| 22 // message loop in the UI thread. For all other cases, the drag-and-drop happens |
| 23 // in the UI thread. |
| 24 class TabContentsDragWin |
| 25 : public DataObjectImpl::Observer, |
| 26 public base::RefCountedThreadSafe<TabContentsDragWin> { |
| 27 public: |
| 28 explicit TabContentsDragWin(TabContentsViewWin* view); |
| 29 virtual ~TabContentsDragWin(); |
| 30 |
| 31 // Called on UI thread. |
| 32 void StartDragging(const WebDropData& drop_data, |
| 33 WebKit::WebDragOperationsMask ops); |
| 34 void CancelDrag(); |
| 35 |
| 36 // DataObjectImpl::Observer implementation. |
| 37 // Called on drag-and-drop thread. |
| 38 virtual void OnWaitForData(); |
| 39 virtual void OnDataObjectDisposed(); |
| 40 |
| 41 private: |
| 42 // Called on either UI thread or drag-and-drop thread. |
| 43 void PrepareDragForDownload(const WebDropData& drop_data, |
| 44 OSExchangeData* data, |
| 45 const GURL& page_url, |
| 46 const std::string& page_encoding); |
| 47 void PrepareDragForFileContents(const WebDropData& drop_data, |
| 48 OSExchangeData* data); |
| 49 void PrepareDragForUrl(const WebDropData& drop_data, OSExchangeData* data); |
| 50 void DoDragging(const WebDropData& drop_data, |
| 51 WebKit::WebDragOperationsMask ops, |
| 52 const GURL& page_url, |
| 53 const std::string& page_encoding); |
| 54 |
| 55 // Called on drag-and-drop thread. |
| 56 void StartBackgroundDragging(const WebDropData& drop_data, |
| 57 WebKit::WebDragOperationsMask ops, |
| 58 const GURL& page_url, |
| 59 const std::string& page_encoding); |
| 60 // Called on UI thread. |
| 61 void EndDragging(bool restore_suspended_state); |
| 62 void CloseThread(); |
| 63 |
| 64 // For debug check only. Access only on drag-and-drop thread. |
| 65 #ifndef NDEBUG |
| 66 PlatformThreadId drag_drop_thread_id_; |
| 67 #endif |
| 68 |
| 69 // All the member variables below are accessed on UI thread. |
| 70 |
| 71 // Keep track of the TabContentsViewWin it is associated with. |
| 72 TabContentsViewWin* view_; |
| 73 |
| 74 // |drag_source_| is our callback interface passed to the system when we |
| 75 // want to initiate a drag and drop operation. We use it to tell if a |
| 76 // drag operation is happening. |
| 77 scoped_refptr<WebDragSource> drag_source_; |
| 78 |
| 79 // The thread used by the drag-out download. This is because we want to avoid |
| 80 // running nested message loop in main UI thread. |
| 81 scoped_ptr<DragDropThread> drag_drop_thread_; |
| 82 |
| 83 // The flag to guard that EndDragging is not called twice. |
| 84 bool drag_ended_; |
| 85 |
| 86 // Keep track of the old suspended state of the drop target. |
| 87 bool old_drop_target_suspended_state_; |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(TabContentsDragWin); |
| 90 }; |
| 91 |
| 92 |
| 93 #endif // CHROME_BROWSER_VIEWS_TAB_CONTENTS_TAB_CONTENTS_DRAG_WIN_H_ |
OLD | NEW |