| OLD | NEW |
| 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 "chrome/browser/tab_contents/web_drag_bookmark_handler_aura.h" | 5 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_aura.h" |
| 6 | 6 |
| 7 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 7 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 11 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 13 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 14 #include "ui/base/dragdrop/os_exchange_data.h" | 13 #include "ui/base/dragdrop/os_exchange_data.h" |
| 15 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" | 14 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" |
| 16 #include "webkit/glue/webdropdata.h" | 15 #include "webkit/glue/webdropdata.h" |
| 17 | 16 |
| 18 using content::WebContents; | 17 using content::WebContents; |
| 19 | 18 |
| 20 WebDragBookmarkHandlerAura::WebDragBookmarkHandlerAura() | 19 WebDragBookmarkHandlerAura::WebDragBookmarkHandlerAura() |
| 21 : tab_(NULL) { | 20 : bookmark_tab_helper_(NULL), |
| 21 web_contents_(NULL) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 WebDragBookmarkHandlerAura::~WebDragBookmarkHandlerAura() { | 24 WebDragBookmarkHandlerAura::~WebDragBookmarkHandlerAura() { |
| 25 } | 25 } |
| 26 | 26 |
| 27 void WebDragBookmarkHandlerAura::DragInitialize(WebContents* contents) { | 27 void WebDragBookmarkHandlerAura::DragInitialize(WebContents* contents) { |
| 28 // Ideally we would want to initialize the the TabContents member in | 28 // Ideally we would want to initialize the the BookmarkTabHelper member in |
| 29 // the constructor. We cannot do that as the WebDragDest object is | 29 // the constructor. We cannot do that as the WebDragDest object is |
| 30 // created during the construction of the WebContents object. The | 30 // created during the construction of the WebContents object. The |
| 31 // TabContents is created much later. | 31 // BookmarkTabHelper is created much later. |
| 32 DCHECK(tab_ ? (tab_->web_contents() == contents) : true); | 32 web_contents_ = contents; |
| 33 if (!tab_) | 33 if (!bookmark_tab_helper_) |
| 34 tab_ = TabContents::FromWebContents(contents); | 34 bookmark_tab_helper_ = BookmarkTabHelper::FromWebContents(contents); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void WebDragBookmarkHandlerAura::OnDragOver() { | 37 void WebDragBookmarkHandlerAura::OnDragOver() { |
| 38 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { | 38 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) { |
| 39 if (bookmark_drag_data_.is_valid()) | 39 if (bookmark_drag_data_.is_valid()) |
| 40 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragOver( | 40 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDragOver( |
| 41 bookmark_drag_data_); | 41 bookmark_drag_data_); |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 void WebDragBookmarkHandlerAura::OnReceiveDragData( | 45 void WebDragBookmarkHandlerAura::OnReceiveDragData( |
| 46 const ui::OSExchangeData& data) { | 46 const ui::OSExchangeData& data) { |
| 47 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { | 47 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) { |
| 48 // Read the bookmark drag data and save it for use in later events in this | 48 // Read the bookmark drag data and save it for use in later events in this |
| 49 // drag. | 49 // drag. |
| 50 bookmark_drag_data_.Read(data); | 50 bookmark_drag_data_.Read(data); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 void WebDragBookmarkHandlerAura::OnDragEnter() { | 54 void WebDragBookmarkHandlerAura::OnDragEnter() { |
| 55 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { | 55 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) { |
| 56 if (bookmark_drag_data_.is_valid()) | 56 if (bookmark_drag_data_.is_valid()) |
| 57 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragEnter( | 57 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDragEnter( |
| 58 bookmark_drag_data_); | 58 bookmark_drag_data_); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 void WebDragBookmarkHandlerAura::OnDrop() { | 62 void WebDragBookmarkHandlerAura::OnDrop() { |
| 63 if (tab_) { | 63 if (bookmark_tab_helper_) { |
| 64 if (tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { | 64 if (bookmark_tab_helper_->GetBookmarkDragDelegate()) { |
| 65 if (bookmark_drag_data_.is_valid()) { | 65 if (bookmark_drag_data_.is_valid()) { |
| 66 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDrop( | 66 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDrop( |
| 67 bookmark_drag_data_); | 67 bookmark_drag_data_); |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Focus the target browser. | 71 // Focus the target browser. |
| 72 Browser* browser = browser::FindBrowserWithWebContents( | 72 Browser* browser = browser::FindBrowserWithWebContents(web_contents_); |
| 73 tab_->web_contents()); | |
| 74 if (browser) | 73 if (browser) |
| 75 browser->window()->Show(); | 74 browser->window()->Show(); |
| 76 } | 75 } |
| 77 | 76 |
| 78 bookmark_drag_data_.Clear(); | 77 bookmark_drag_data_.Clear(); |
| 79 } | 78 } |
| 80 | 79 |
| 81 void WebDragBookmarkHandlerAura::OnDragLeave() { | 80 void WebDragBookmarkHandlerAura::OnDragLeave() { |
| 82 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { | 81 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) { |
| 83 if (bookmark_drag_data_.is_valid()) | 82 if (bookmark_drag_data_.is_valid()) |
| 84 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragLeave( | 83 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDragLeave( |
| 85 bookmark_drag_data_); | 84 bookmark_drag_data_); |
| 86 } | 85 } |
| 87 | 86 |
| 88 bookmark_drag_data_.Clear(); | 87 bookmark_drag_data_.Clear(); |
| 89 } | 88 } |
| OLD | NEW |