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

Side by Side Diff: chrome/browser/tab_contents/web_drag_bookmark_handler_win.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_win.h" 5 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_win.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 "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
15 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
16 #include "ui/base/dragdrop/os_exchange_data.h" 15 #include "ui/base/dragdrop/os_exchange_data.h"
17 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" 16 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
18 #include "webkit/glue/webdropdata.h" 17 #include "webkit/glue/webdropdata.h"
19 18
20 using content::WebContents; 19 using content::WebContents;
21 20
22 WebDragBookmarkHandlerWin::WebDragBookmarkHandlerWin() 21 WebDragBookmarkHandlerWin::WebDragBookmarkHandlerWin()
23 : tab_(NULL) { 22 : bookmark_tab_helper_(NULL),
23 web_contents_(NULL) {
24 } 24 }
25 25
26 WebDragBookmarkHandlerWin::~WebDragBookmarkHandlerWin() { 26 WebDragBookmarkHandlerWin::~WebDragBookmarkHandlerWin() {
27 } 27 }
28 28
29 void WebDragBookmarkHandlerWin::DragInitialize(WebContents* contents) { 29 void WebDragBookmarkHandlerWin::DragInitialize(WebContents* contents) {
30 // Ideally we would want to initialize the the TabContents member in 30 // Ideally we would want to initialize the the BookmarkTabHelper member in
31 // the constructor. We cannot do that as the WebDragTargetWin object is 31 // the constructor. We cannot do that as the WebDragTargetWin object is
32 // created during the construction of the WebContents object. The 32 // created during the construction of the WebContents object. The
33 // TabContents is created much later. 33 // BookmarkTabHelper is created much later.
34 DCHECK(tab_ ? (tab_->web_contents() == contents) : true); 34 web_contents_ = contents;
35 if (!tab_) 35 if (!bookmark_tab_helper_)
36 tab_ = TabContents::FromWebContents(contents); 36 bookmark_tab_helper_ = BookmarkTabHelper::FromWebContents(contents);
37 } 37 }
38 38
39 void WebDragBookmarkHandlerWin::OnDragOver(IDataObject* data_object) { 39 void WebDragBookmarkHandlerWin::OnDragOver(IDataObject* data_object) {
40 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { 40 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) {
41 ui::OSExchangeData os_exchange_data( 41 ui::OSExchangeData os_exchange_data(
42 new ui::OSExchangeDataProviderWin(data_object)); 42 new ui::OSExchangeDataProviderWin(data_object));
43 BookmarkNodeData bookmark_drag_data; 43 BookmarkNodeData bookmark_drag_data;
44 if (bookmark_drag_data.Read(os_exchange_data)) 44 if (bookmark_drag_data.Read(os_exchange_data))
45 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragOver( 45 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDragOver(
46 bookmark_drag_data); 46 bookmark_drag_data);
47 } 47 }
48 } 48 }
49 49
50 void WebDragBookmarkHandlerWin::OnDragEnter(IDataObject* data_object) { 50 void WebDragBookmarkHandlerWin::OnDragEnter(IDataObject* data_object) {
51 // This is non-null if web_contents_ is showing an ExtensionWebUI with 51 // This is non-null if the web_contents_ is showing an ExtensionWebUI with
52 // support for (at the moment experimental) drag and drop extensions. 52 // support for (at the moment experimental) drag and drop extensions.
53 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { 53 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) {
54 ui::OSExchangeData os_exchange_data( 54 ui::OSExchangeData os_exchange_data(
55 new ui::OSExchangeDataProviderWin(data_object)); 55 new ui::OSExchangeDataProviderWin(data_object));
56 BookmarkNodeData bookmark_drag_data; 56 BookmarkNodeData bookmark_drag_data;
57 if (bookmark_drag_data.Read(os_exchange_data)) 57 if (bookmark_drag_data.Read(os_exchange_data))
58 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragEnter( 58 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDragEnter(
59 bookmark_drag_data); 59 bookmark_drag_data);
60 } 60 }
61 } 61 }
62 62
63 void WebDragBookmarkHandlerWin::OnDrop(IDataObject* data_object) { 63 void WebDragBookmarkHandlerWin::OnDrop(IDataObject* data_object) {
64 // This is non-null if tab_contents_ is showing an ExtensionWebUI with 64 // This is non-null if the web_contents_ is showing an ExtensionWebUI with
65 // support for (at the moment experimental) drag and drop extensions. 65 // support for (at the moment experimental) drag and drop extensions.
66 if (tab_) { 66 if (bookmark_tab_helper_) {
67 if (tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { 67 if (bookmark_tab_helper_->GetBookmarkDragDelegate()) {
68 ui::OSExchangeData os_exchange_data( 68 ui::OSExchangeData os_exchange_data(
69 new ui::OSExchangeDataProviderWin(data_object)); 69 new ui::OSExchangeDataProviderWin(data_object));
70 BookmarkNodeData bookmark_drag_data; 70 BookmarkNodeData bookmark_drag_data;
71 if (bookmark_drag_data.Read(os_exchange_data)) { 71 if (bookmark_drag_data.Read(os_exchange_data)) {
72 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDrop( 72 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDrop(
73 bookmark_drag_data); 73 bookmark_drag_data);
74 } 74 }
75 } 75 }
76 76
77 // Focus the target browser. 77 // Focus the target browser.
78 Browser* browser = browser::FindBrowserWithWebContents( 78 Browser* browser = browser::FindBrowserWithWebContents(web_contents_);
79 tab_->web_contents());
80 if (browser) 79 if (browser)
81 browser->window()->Show(); 80 browser->window()->Show();
82 } 81 }
83 } 82 }
84 83
85 void WebDragBookmarkHandlerWin::OnDragLeave(IDataObject* data_object) { 84 void WebDragBookmarkHandlerWin::OnDragLeave(IDataObject* data_object) {
86 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { 85 if (bookmark_tab_helper_ && bookmark_tab_helper_->GetBookmarkDragDelegate()) {
87 ui::OSExchangeData os_exchange_data( 86 ui::OSExchangeData os_exchange_data(
88 new ui::OSExchangeDataProviderWin(data_object)); 87 new ui::OSExchangeDataProviderWin(data_object));
89 BookmarkNodeData bookmark_drag_data; 88 BookmarkNodeData bookmark_drag_data;
90 if (bookmark_drag_data.Read(os_exchange_data)) 89 if (bookmark_drag_data.Read(os_exchange_data))
91 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragLeave( 90 bookmark_tab_helper_->GetBookmarkDragDelegate()->OnDragLeave(
92 bookmark_drag_data); 91 bookmark_drag_data);
93 } 92 }
94 } 93 }
95 94
96 bool WebDragBookmarkHandlerWin::AddDragData(const WebDropData& drop_data, 95 bool WebDragBookmarkHandlerWin::AddDragData(const WebDropData& drop_data,
97 ui::OSExchangeData* data) { 96 ui::OSExchangeData* data) {
98 if (!drop_data.url.SchemeIs(chrome::kJavaScriptScheme)) 97 if (!drop_data.url.SchemeIs(chrome::kJavaScriptScheme))
99 return false; 98 return false;
100 99
101 // We don't want to allow javascript URLs to be dragged to the desktop, 100 // We don't want to allow javascript URLs to be dragged to the desktop,
102 // but we do want to allow them to be added to the bookmarks bar 101 // but we do want to allow them to be added to the bookmarks bar
103 // (bookmarklets). So we create a fake bookmark entry (BookmarkNodeData 102 // (bookmarklets). So we create a fake bookmark entry (BookmarkNodeData
104 // object) which explorer.exe cannot handle, and write the entry to data. 103 // object) which explorer.exe cannot handle, and write the entry to data.
105 BookmarkNodeData::Element bm_elt; 104 BookmarkNodeData::Element bm_elt;
106 bm_elt.is_url = true; 105 bm_elt.is_url = true;
107 bm_elt.url = drop_data.url; 106 bm_elt.url = drop_data.url;
108 bm_elt.title = drop_data.url_title; 107 bm_elt.title = drop_data.url_title;
109 108
110 BookmarkNodeData bm_drag_data; 109 BookmarkNodeData bm_drag_data;
111 bm_drag_data.elements.push_back(bm_elt); 110 bm_drag_data.elements.push_back(bm_elt);
112 111
113 // Pass in NULL as the profile so that the bookmark always adds the url 112 // Pass in NULL as the profile so that the bookmark always adds the url
114 // rather than trying to move an existing url. 113 // rather than trying to move an existing url.
115 bm_drag_data.Write(NULL, data); 114 bm_drag_data.Write(NULL, data);
116 115
117 return true; 116 return true;
118 } 117 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/web_drag_bookmark_handler_win.h ('k') | chrome/browser/ui/bookmarks/bookmark_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698