Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/browser/tab_contents/web_drag_bookmark_handler_gtk.cc

Issue 10945010: Switch BookmarkTabHelper to use WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_gtk.h" 5 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_gtk.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/gtk/bookmarks/bookmark_utils_gtk.h" 10 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.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 "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
15 #include "ui/base/dragdrop/gtk_dnd_util.h" 14 #include "ui/base/dragdrop/gtk_dnd_util.h"
16 15
17 using content::WebContents; 16 using content::WebContents;
18 17
19 WebDragBookmarkHandlerGtk::WebDragBookmarkHandlerGtk() 18 WebDragBookmarkHandlerGtk::WebDragBookmarkHandlerGtk()
20 : tab_(NULL) { 19 : bookmark_tab_helper_(NULL),
20 web_contents_(NULL) {
21 } 21 }
22 22
23 WebDragBookmarkHandlerGtk::~WebDragBookmarkHandlerGtk() {} 23 WebDragBookmarkHandlerGtk::~WebDragBookmarkHandlerGtk() {}
24 24
25 void WebDragBookmarkHandlerGtk::DragInitialize(WebContents* contents) { 25 void WebDragBookmarkHandlerGtk::DragInitialize(WebContents* contents) {
26 bookmark_drag_data_.Clear(); 26 bookmark_drag_data_.Clear();
27 27
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 WebDragDestGtk object is 29 // the constructor. We cannot do that as the WebDragDestGtk 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 GdkAtom WebDragBookmarkHandlerGtk::GetBookmarkTargetAtom() const { 37 GdkAtom WebDragBookmarkHandlerGtk::GetBookmarkTargetAtom() const {
38 // For GTK, bookmark drag data is encoded as pickle and associated with 38 // For GTK, bookmark drag data is encoded as pickle and associated with
39 // ui::CHROME_BOOKMARK_ITEM. See bookmark_utils::WriteBookmarksToSelection() 39 // ui::CHROME_BOOKMARK_ITEM. See bookmark_utils::WriteBookmarksToSelection()
40 // for details. 40 // for details.
41 return ui::GetAtomForTarget(ui::CHROME_BOOKMARK_ITEM); 41 return ui::GetAtomForTarget(ui::CHROME_BOOKMARK_ITEM);
42 } 42 }
43 43
44 void WebDragBookmarkHandlerGtk::OnReceiveDataFromGtk(GtkSelectionData* data) { 44 void WebDragBookmarkHandlerGtk::OnReceiveDataFromGtk(GtkSelectionData* data) {
45 if (tab_) { 45 Profile* profile =
46 Profile* profile = tab_->profile(); 46 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
47 bookmark_drag_data_.ReadFromVector( 47 bookmark_drag_data_.ReadFromVector(
48 bookmark_utils::GetNodesFromSelection( 48 bookmark_utils::GetNodesFromSelection(
49 NULL, data, 49 NULL, data,
50 ui::CHROME_BOOKMARK_ITEM, 50 ui::CHROME_BOOKMARK_ITEM,
51 profile, NULL, NULL)); 51 profile, NULL, NULL));
52 bookmark_drag_data_.SetOriginatingProfile(profile); 52 bookmark_drag_data_.SetOriginatingProfile(profile);
53 }
54 } 53 }
55 54
56 void WebDragBookmarkHandlerGtk::OnReceiveProcessedData(const GURL& url, 55 void WebDragBookmarkHandlerGtk::OnReceiveProcessedData(const GURL& url,
57 const string16& title) { 56 const string16& title) {
58 bookmark_drag_data_.ReadFromTuple(url, title); 57 bookmark_drag_data_.ReadFromTuple(url, title);
59 } 58 }
60 59
61 void WebDragBookmarkHandlerGtk::OnDragOver() { 60 void WebDragBookmarkHandlerGtk::OnDragOver() {
62 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { 61 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) {
63 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragOver( 62 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDragOver(
64 bookmark_drag_data_); 63 bookmark_drag_data_);
65 } 64 }
66 } 65 }
67 66
68 void WebDragBookmarkHandlerGtk::OnDragEnter() { 67 void WebDragBookmarkHandlerGtk::OnDragEnter() {
69 // This is non-null if tab_contents_ is showing an ExtensionWebUI with 68 // This is non-null if the web_contents_ is showing an ExtensionWebUI with
70 // support for (at the moment experimental) drag and drop extensions. 69 // support for (at the moment experimental) drag and drop extensions.
71 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { 70 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) {
72 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragEnter( 71 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDragEnter(
73 bookmark_drag_data_); 72 bookmark_drag_data_);
74 } 73 }
75 } 74 }
76 75
77 void WebDragBookmarkHandlerGtk::OnDrop() { 76 void WebDragBookmarkHandlerGtk::OnDrop() {
78 // This is non-null if tab_contents_ is showing an ExtensionWebUI with 77 // This is non-null if tab_contents_ is showing an ExtensionWebUI with
79 // support for (at the moment experimental) drag and drop extensions. 78 // support for (at the moment experimental) drag and drop extensions.
80 if (tab_) { 79 if (bookmark_tab_helper_) {
81 if (tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { 80 if (bookmark_tab_helper_->GetBookmarkDragDelegate()) {
82 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDrop( 81 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDrop(
83 bookmark_drag_data_); 82 bookmark_drag_data_);
84 } 83 }
85 84
86 // Focus the target browser. 85 // Focus the target browser.
87 Browser* browser = browser::FindBrowserWithWebContents( 86 Browser* browser = browser::FindBrowserWithWebContents(web_contents_);
88 tab_->web_contents());
89 if (browser) 87 if (browser)
90 browser->window()->Show(); 88 browser->window()->Show();
91 } 89 }
92 } 90 }
93 91
94 void WebDragBookmarkHandlerGtk::OnDragLeave() { 92 void WebDragBookmarkHandlerGtk::OnDragLeave() {
95 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { 93 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) {
96 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragLeave( 94 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDragLeave(
97 bookmark_drag_data_); 95 bookmark_drag_data_);
98 } 96 }
99 } 97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698