| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/gtk/tab_contents/web_drag_bookmark_handler_gtk.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/browser.h" | |
| 8 #include "chrome/browser/ui/browser_finder.h" | |
| 9 #include "chrome/browser/ui/browser_window.h" | |
| 10 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" | |
| 11 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "content/public/browser/web_contents.h" | |
| 14 #include "ui/base/dragdrop/gtk_dnd_util.h" | |
| 15 | |
| 16 using content::WebContents; | |
| 17 | |
| 18 WebDragBookmarkHandlerGtk::WebDragBookmarkHandlerGtk() | |
| 19 : bookmark_tab_helper_(NULL), | |
| 20 web_contents_(NULL) { | |
| 21 } | |
| 22 | |
| 23 WebDragBookmarkHandlerGtk::~WebDragBookmarkHandlerGtk() {} | |
| 24 | |
| 25 void WebDragBookmarkHandlerGtk::DragInitialize(WebContents* contents) { | |
| 26 bookmark_drag_data_.Clear(); | |
| 27 | |
| 28 // Ideally we would want to initialize the the BookmarkTabHelper member in | |
| 29 // the constructor. We cannot do that as the WebDragDestGtk object is | |
| 30 // created during the construction of the WebContents object. The | |
| 31 // BookmarkTabHelper is created much later. | |
| 32 web_contents_ = contents; | |
| 33 if (!bookmark_tab_helper_) | |
| 34 bookmark_tab_helper_ = BookmarkTabHelper::FromWebContents(contents); | |
| 35 } | |
| 36 | |
| 37 GdkAtom WebDragBookmarkHandlerGtk::GetBookmarkTargetAtom() const { | |
| 38 // For GTK, bookmark drag data is encoded as pickle and associated with | |
| 39 // ui::CHROME_BOOKMARK_ITEM. See WriteBookmarksToSelection() for details. | |
| 40 return ui::GetAtomForTarget(ui::CHROME_BOOKMARK_ITEM); | |
| 41 } | |
| 42 | |
| 43 void WebDragBookmarkHandlerGtk::OnReceiveDataFromGtk(GtkSelectionData* data) { | |
| 44 Profile* profile = | |
| 45 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
| 46 bookmark_drag_data_.ReadFromVector(GetNodesFromSelection( | |
| 47 NULL, data, ui::CHROME_BOOKMARK_ITEM, profile, NULL, NULL)); | |
| 48 bookmark_drag_data_.SetOriginatingProfile(profile); | |
| 49 } | |
| 50 | |
| 51 void WebDragBookmarkHandlerGtk::OnReceiveProcessedData( | |
| 52 const GURL& url, | |
| 53 const base::string16& title) { | |
| 54 bookmark_drag_data_.ReadFromTuple(url, title); | |
| 55 } | |
| 56 | |
| 57 void WebDragBookmarkHandlerGtk::OnDragOver() { | |
| 58 if (bookmark_tab_helper_ && bookmark_tab_helper_->bookmark_drag_delegate()) { | |
| 59 bookmark_tab_helper_->bookmark_drag_delegate()->OnDragOver( | |
| 60 bookmark_drag_data_); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void WebDragBookmarkHandlerGtk::OnDragEnter() { | |
| 65 // This is non-null if the web_contents_ is showing an ExtensionWebUI with | |
| 66 // support for (at the moment experimental) drag and drop extensions. | |
| 67 if (bookmark_tab_helper_ && bookmark_tab_helper_->bookmark_drag_delegate()) { | |
| 68 bookmark_tab_helper_->bookmark_drag_delegate()->OnDragEnter( | |
| 69 bookmark_drag_data_); | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 void WebDragBookmarkHandlerGtk::OnDrop() { | |
| 74 // This is non-null if web_contents_ is showing an ExtensionWebUI with | |
| 75 // support for (at the moment experimental) drag and drop extensions. | |
| 76 if (bookmark_tab_helper_) { | |
| 77 if (bookmark_tab_helper_->bookmark_drag_delegate()) { | |
| 78 bookmark_tab_helper_->bookmark_drag_delegate()->OnDrop( | |
| 79 bookmark_drag_data_); | |
| 80 } | |
| 81 | |
| 82 // Focus the target browser. | |
| 83 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | |
| 84 if (browser) | |
| 85 browser->window()->Show(); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 void WebDragBookmarkHandlerGtk::OnDragLeave() { | |
| 90 if (bookmark_tab_helper_ && bookmark_tab_helper_->bookmark_drag_delegate()) { | |
| 91 bookmark_tab_helper_->bookmark_drag_delegate()->OnDragLeave( | |
| 92 bookmark_drag_data_); | |
| 93 } | |
| 94 } | |
| OLD | NEW |