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

Side by Side Diff: chrome/browser/bookmarks/bookmark_node_data.cc

Issue 8196001: content: Split web_drag_dest_gtk.cc into chrome/ and content/ parts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: :( Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/bookmarks/bookmark_node_data.h" 5 #include "chrome/browser/bookmarks/bookmark_node_data.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/bookmarks/bookmark_model.h" 13 #include "chrome/browser/bookmarks/bookmark_model.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "net/base/escape.h" 16 #include "net/base/escape.h"
17 #include "ui/base/clipboard/scoped_clipboard_writer.h" 17 #include "ui/base/clipboard/scoped_clipboard_writer.h"
18 #include "ui/base/dragdrop/bookmark_format.h"
18 19
19 #if defined(OS_MACOSX) 20 #if defined(OS_MACOSX)
20 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h" 21 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h"
21 #else 22 #else
22 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
23 #endif 24 #endif
24 25
25 const char* BookmarkNodeData::kClipboardFormatString =
26 "chromium/x-bookmark-entries";
27
28 BookmarkNodeData::Element::Element() : is_url(false), id_(0) { 26 BookmarkNodeData::Element::Element() : is_url(false), id_(0) {
29 } 27 }
30 28
31 BookmarkNodeData::Element::Element(const BookmarkNode* node) 29 BookmarkNodeData::Element::Element(const BookmarkNode* node)
32 : is_url(node->is_url()), 30 : is_url(node->is_url()),
33 url(node->url()), 31 url(node->url()),
34 title(node->GetTitle()), 32 title(node->GetTitle()),
35 id_(node->id()) { 33 id_(node->id()) {
36 for (int i = 0; i < node->child_count(); ++i) 34 for (int i = 0; i < node->child_count(); ++i)
37 children.push_back(Element(node->GetChild(i))); 35 children.push_back(Element(node->GetChild(i)));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 children.resize(children_count); 70 children.resize(children_count);
73 for (std::vector<Element>::iterator i = children.begin(); 71 for (std::vector<Element>::iterator i = children.begin();
74 i != children.end(); ++i) { 72 i != children.end(); ++i) {
75 if (!i->ReadFromPickle(pickle, iterator)) 73 if (!i->ReadFromPickle(pickle, iterator))
76 return false; 74 return false;
77 } 75 }
78 } 76 }
79 return true; 77 return true;
80 } 78 }
81 79
82 #if defined(TOOLKIT_VIEWS)
83 // static
84 ui::OSExchangeData::CustomFormat BookmarkNodeData::GetBookmarkCustomFormat() {
85 static ui::OSExchangeData::CustomFormat format;
86 static bool format_valid = false;
87
88 if (!format_valid) {
89 format_valid = true;
90 format = ui::OSExchangeData::RegisterCustomFormat(
91 BookmarkNodeData::kClipboardFormatString);
92 }
93 return format;
94 }
95 #endif
96
97 BookmarkNodeData::BookmarkNodeData() { 80 BookmarkNodeData::BookmarkNodeData() {
98 } 81 }
99 82
100 BookmarkNodeData::BookmarkNodeData(const BookmarkNode* node) { 83 BookmarkNodeData::BookmarkNodeData(const BookmarkNode* node) {
101 elements.push_back(Element(node)); 84 elements.push_back(Element(node));
102 } 85 }
103 86
104 BookmarkNodeData::BookmarkNodeData( 87 BookmarkNodeData::BookmarkNodeData(
105 const std::vector<const BookmarkNode*>& nodes) { 88 const std::vector<const BookmarkNode*>& nodes) {
106 ReadFromVector(nodes); 89 ReadFromVector(nodes);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // Also write the URL to the clipboard as text so that it can be pasted 137 // Also write the URL to the clipboard as text so that it can be pasted
155 // into text fields. We use WriteText instead of WriteURL because we don't 138 // into text fields. We use WriteText instead of WriteURL because we don't
156 // want to clobber the X clipboard when the user copies out of the omnibox 139 // want to clobber the X clipboard when the user copies out of the omnibox
157 // on Linux (on Windows and Mac, there is no difference between these 140 // on Linux (on Windows and Mac, there is no difference between these
158 // functions). 141 // functions).
159 scw.WriteText(UTF8ToUTF16(url)); 142 scw.WriteText(UTF8ToUTF16(url));
160 } 143 }
161 144
162 Pickle pickle; 145 Pickle pickle;
163 WriteToPickle(profile, &pickle); 146 WriteToPickle(profile, &pickle);
164 scw.WritePickledData(pickle, kClipboardFormatString); 147 scw.WritePickledData(pickle, ui::kClipboardFormatString);
165 } 148 }
166 149
167 bool BookmarkNodeData::ReadFromClipboard() { 150 bool BookmarkNodeData::ReadFromClipboard() {
168 std::string data; 151 std::string data;
169 ui::Clipboard* clipboard = g_browser_process->clipboard(); 152 ui::Clipboard* clipboard = g_browser_process->clipboard();
170 clipboard->ReadData(kClipboardFormatString, &data); 153 clipboard->ReadData(ui::kClipboardFormatString, &data);
171 154
172 if (!data.empty()) { 155 if (!data.empty()) {
173 Pickle pickle(data.data(), data.size()); 156 Pickle pickle(data.data(), data.size());
174 if (ReadFromPickle(&pickle)) 157 if (ReadFromPickle(&pickle))
175 return true; 158 return true;
176 } 159 }
177 160
178 string16 title; 161 string16 title;
179 std::string url; 162 std::string url;
180 clipboard->ReadBookmark(&title, &url); 163 clipboard->ReadBookmark(&title, &url);
(...skipping 12 matching lines...) Expand all
193 } 176 }
194 177
195 bool BookmarkNodeData::ClipboardContainsBookmarks() { 178 bool BookmarkNodeData::ClipboardContainsBookmarks() {
196 #if defined(TOUCH_UI) 179 #if defined(TOUCH_UI)
197 // Temporarily disabling clipboard due to bug 96448. 180 // Temporarily disabling clipboard due to bug 96448.
198 // TODO(wyck): Reenable when cause of message loop hang in 181 // TODO(wyck): Reenable when cause of message loop hang in
199 // gtk_clipboard_wait_for_contents is determined and fixed. 182 // gtk_clipboard_wait_for_contents is determined and fixed.
200 return false; 183 return false;
201 #else 184 #else
202 return g_browser_process->clipboard()->IsFormatAvailableByString( 185 return g_browser_process->clipboard()->IsFormatAvailableByString(
203 BookmarkNodeData::kClipboardFormatString, ui::Clipboard::BUFFER_STANDARD); 186 ui::kClipboardFormatString, ui::Clipboard::BUFFER_STANDARD);
204 #endif 187 #endif
205 } 188 }
206 #else 189 #else
207 void BookmarkNodeData::WriteToClipboard(Profile* profile) const { 190 void BookmarkNodeData::WriteToClipboard(Profile* profile) const {
208 bookmark_pasteboard_helper_mac::WriteToClipboard(elements, 191 bookmark_pasteboard_helper_mac::WriteToClipboard(elements,
209 profile_path_.value()); 192 profile_path_.value());
210 } 193 }
211 194
212 bool BookmarkNodeData::ReadFromClipboard() { 195 bool BookmarkNodeData::ReadFromClipboard() {
213 // TODO(evan): bookmark_pasteboard_helper_mac should just use FilePaths. 196 // TODO(evan): bookmark_pasteboard_helper_mac should just use FilePaths.
(...skipping 28 matching lines...) Expand all
242 if (elements[0].url.SchemeIs(chrome::kJavaScriptScheme)) { 225 if (elements[0].url.SchemeIs(chrome::kJavaScriptScheme)) {
243 data->SetString(UTF8ToUTF16(elements[0].url.spec())); 226 data->SetString(UTF8ToUTF16(elements[0].url.spec()));
244 } else { 227 } else {
245 data->SetURL(elements[0].url, elements[0].title); 228 data->SetURL(elements[0].url, elements[0].title);
246 } 229 }
247 } 230 }
248 231
249 Pickle data_pickle; 232 Pickle data_pickle;
250 WriteToPickle(profile, &data_pickle); 233 WriteToPickle(profile, &data_pickle);
251 234
252 data->SetPickledData(GetBookmarkCustomFormat(), data_pickle); 235 data->SetPickledData(ui::GetBookmarkCustomFormat(), data_pickle);
253 } 236 }
254 237
255 bool BookmarkNodeData::Read(const ui::OSExchangeData& data) { 238 bool BookmarkNodeData::Read(const ui::OSExchangeData& data) {
256 elements.clear(); 239 elements.clear();
257 240
258 profile_path_.clear(); 241 profile_path_.clear();
259 242
260 if (data.HasCustomFormat(GetBookmarkCustomFormat())) { 243 if (data.HasCustomFormat(ui::GetBookmarkCustomFormat())) {
261 Pickle drag_data_pickle; 244 Pickle drag_data_pickle;
262 if (data.GetPickledData(GetBookmarkCustomFormat(), &drag_data_pickle)) { 245 if (data.GetPickledData(ui::GetBookmarkCustomFormat(), &drag_data_pickle)) {
263 if (!ReadFromPickle(&drag_data_pickle)) 246 if (!ReadFromPickle(&drag_data_pickle))
264 return false; 247 return false;
265 } 248 }
266 } else { 249 } else {
267 // See if there is a URL on the clipboard. 250 // See if there is a URL on the clipboard.
268 Element element; 251 Element element;
269 GURL url; 252 GURL url;
270 string16 title; 253 string16 title;
271 if (data.GetURLAndTitle(&url, &title)) 254 if (data.GetURLAndTitle(&url, &title))
272 ReadFromTuple(url, title); 255 ReadFromTuple(url, title);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 DCHECK(profile_path_.empty()); 319 DCHECK(profile_path_.empty());
337 320
338 if (profile) 321 if (profile)
339 profile_path_ = profile->GetPath(); 322 profile_path_ = profile->GetPath();
340 } 323 }
341 324
342 bool BookmarkNodeData::IsFromProfile(Profile* profile) const { 325 bool BookmarkNodeData::IsFromProfile(Profile* profile) const {
343 // An empty path means the data is not associated with any profile. 326 // An empty path means the data is not associated with any profile.
344 return !profile_path_.empty() && profile_path_ == profile->GetPath(); 327 return !profile_path_.empty() && profile_path_ == profile->GetPath();
345 } 328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698