| 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_mac.h" | 5 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_finder.h" | 8 #include "chrome/browser/ui/browser_finder.h" |
| 9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 10 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 12 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 13 | 12 |
| 14 using content::WebContents; | 13 using content::WebContents; |
| 15 | 14 |
| 16 WebDragBookmarkHandlerMac::WebDragBookmarkHandlerMac() | 15 WebDragBookmarkHandlerMac::WebDragBookmarkHandlerMac() |
| 17 : tab_(NULL) { | 16 : bookmark_tab_helper_(NULL), |
| 17 web_contents_(NULL) { |
| 18 } | 18 } |
| 19 | 19 |
| 20 WebDragBookmarkHandlerMac::~WebDragBookmarkHandlerMac() {} | 20 WebDragBookmarkHandlerMac::~WebDragBookmarkHandlerMac() {} |
| 21 | 21 |
| 22 void WebDragBookmarkHandlerMac::DragInitialize(WebContents* contents) { | 22 void WebDragBookmarkHandlerMac::DragInitialize(WebContents* contents) { |
| 23 DCHECK(tab_ ? (tab_->web_contents() == contents) : true); | 23 web_contents_ = contents; |
| 24 if (!tab_) | 24 if (!bookmark_tab_helper_) |
| 25 tab_ = TabContents::FromWebContents(contents); | 25 bookmark_tab_helper_ = BookmarkTabHelper::FromWebContents(contents); |
| 26 | 26 |
| 27 bookmark_drag_data_.ReadFromDragClipboard(); | 27 bookmark_drag_data_.ReadFromDragClipboard(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void WebDragBookmarkHandlerMac::OnDragOver() { | 30 void WebDragBookmarkHandlerMac::OnDragOver() { |
| 31 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { | 31 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) { |
| 32 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragOver( | 32 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDragOver( |
| 33 bookmark_drag_data_); | 33 bookmark_drag_data_); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 void WebDragBookmarkHandlerMac::OnDragEnter() { | 37 void WebDragBookmarkHandlerMac::OnDragEnter() { |
| 38 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { | 38 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) { |
| 39 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragEnter( | 39 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDragEnter( |
| 40 bookmark_drag_data_); | 40 bookmark_drag_data_); |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 void WebDragBookmarkHandlerMac::OnDrop() { | 44 void WebDragBookmarkHandlerMac::OnDrop() { |
| 45 // This is non-null if tab_contents_ is showing an ExtensionWebUI with | 45 // This is non-null if the web_contents_ is showing an ExtensionWebUI with |
| 46 // support for (at the moment experimental) drag and drop extensions. | 46 // support for (at the moment experimental) drag and drop extensions. |
| 47 if (tab_) { | 47 if (bookmark_tab_helper_) { |
| 48 if (tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { | 48 if (bookmark_tab_helper_->GetBookmarkDragDelegate()) { |
| 49 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDrop( | 49 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDrop( |
| 50 bookmark_drag_data_); | 50 bookmark_drag_data_); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Focus the target browser. | 53 // Focus the target browser. |
| 54 Browser* browser = browser::FindBrowserWithWebContents( | 54 Browser* browser = browser::FindBrowserWithWebContents(web_contents_); |
| 55 tab_->web_contents()); | |
| 56 if (browser) | 55 if (browser) |
| 57 browser->window()->Show(); | 56 browser->window()->Show(); |
| 58 } | 57 } |
| 59 } | 58 } |
| 60 | 59 |
| 61 void WebDragBookmarkHandlerMac::OnDragLeave() { | 60 void WebDragBookmarkHandlerMac::OnDragLeave() { |
| 62 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { | 61 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) { |
| 63 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragLeave( | 62 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDragLeave( |
| 64 bookmark_drag_data_); | 63 bookmark_drag_data_); |
| 65 } | 64 } |
| 66 } | 65 } |
| OLD | NEW |