| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_drag_data.h" | 5 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
| 6 | 6 |
| 7 #include "app/clipboard/scoped_clipboard_writer.h" | 7 #include "app/clipboard/scoped_clipboard_writer.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 if (nodes.empty()) | 99 if (nodes.empty()) |
| 100 return false; | 100 return false; |
| 101 | 101 |
| 102 for (size_t i = 0; i < nodes.size(); ++i) | 102 for (size_t i = 0; i < nodes.size(); ++i) |
| 103 elements.push_back(Element(nodes[i])); | 103 elements.push_back(Element(nodes[i])); |
| 104 | 104 |
| 105 return true; | 105 return true; |
| 106 } | 106 } |
| 107 | 107 |
| 108 bool BookmarkDragData::ReadFromTuple(const GURL& url, const string16& title) { |
| 109 Clear(); |
| 110 |
| 111 if (!url.is_valid()) |
| 112 return false; |
| 113 |
| 114 Element element; |
| 115 element.title = title; |
| 116 element.url = url; |
| 117 element.is_url = true; |
| 118 |
| 119 elements.push_back(element); |
| 120 } |
| 121 |
| 108 #if !defined(OS_MACOSX) | 122 #if !defined(OS_MACOSX) |
| 109 void BookmarkDragData::WriteToClipboard(Profile* profile) const { | 123 void BookmarkDragData::WriteToClipboard(Profile* profile) const { |
| 110 ScopedClipboardWriter scw(g_browser_process->clipboard()); | 124 ScopedClipboardWriter scw(g_browser_process->clipboard()); |
| 111 | 125 |
| 112 // If there is only one element and it is a URL, write the URL to the | 126 // If there is only one element and it is a URL, write the URL to the |
| 113 // clipboard. | 127 // clipboard. |
| 114 if (elements.size() == 1 && elements[0].is_url) { | 128 if (elements.size() == 1 && elements[0].is_url) { |
| 115 const string16& title = elements[0].title; | 129 const string16& title = elements[0].title; |
| 116 std::string url = elements[0].url.spec(); | 130 std::string url = elements[0].url.spec(); |
| 117 | 131 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 221 |
| 208 if (data.HasCustomFormat(GetBookmarkCustomFormat())) { | 222 if (data.HasCustomFormat(GetBookmarkCustomFormat())) { |
| 209 Pickle drag_data_pickle; | 223 Pickle drag_data_pickle; |
| 210 if (data.GetPickledData(GetBookmarkCustomFormat(), &drag_data_pickle)) { | 224 if (data.GetPickledData(GetBookmarkCustomFormat(), &drag_data_pickle)) { |
| 211 if (!ReadFromPickle(&drag_data_pickle)) | 225 if (!ReadFromPickle(&drag_data_pickle)) |
| 212 return false; | 226 return false; |
| 213 } | 227 } |
| 214 } else { | 228 } else { |
| 215 // See if there is a URL on the clipboard. | 229 // See if there is a URL on the clipboard. |
| 216 Element element; | 230 Element element; |
| 231 GURL url; |
| 217 std::wstring title; | 232 std::wstring title; |
| 218 if (data.GetURLAndTitle(&element.url, &title) && | 233 if (data.GetURLAndTitle(&url, &title)) |
| 219 element.url.is_valid()) { | 234 ReadFromTuple(url, WideToUTF16(title)); |
| 220 element.title = WideToUTF16(title); | 235 } |
| 221 element.is_url = true; | |
| 222 elements.push_back(element); | |
| 223 } | |
| 224 } | |
| 225 | 236 |
| 226 return is_valid(); | 237 return is_valid(); |
| 227 } | 238 } |
| 228 #endif | 239 #endif |
| 229 | 240 |
| 230 void BookmarkDragData::WriteToPickle(Profile* profile, Pickle* pickle) const { | 241 void BookmarkDragData::WriteToPickle(Profile* profile, Pickle* pickle) const { |
| 231 FilePath path = profile ? profile->GetPath() : FilePath(); | 242 FilePath path = profile ? profile->GetPath() : FilePath(); |
| 232 FilePath::WriteStringTypeToPickle(pickle, path.value()); | 243 FilePath::WriteStringTypeToPickle(pickle, path.value()); |
| 233 pickle->WriteSize(elements.size()); | 244 pickle->WriteSize(elements.size()); |
| 234 | 245 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 DCHECK(profile_path_.empty()); | 299 DCHECK(profile_path_.empty()); |
| 289 | 300 |
| 290 if (profile) | 301 if (profile) |
| 291 profile_path_ = profile->GetPath().value(); | 302 profile_path_ = profile->GetPath().value(); |
| 292 } | 303 } |
| 293 | 304 |
| 294 bool BookmarkDragData::IsFromProfile(Profile* profile) const { | 305 bool BookmarkDragData::IsFromProfile(Profile* profile) const { |
| 295 // An empty path means the data is not associated with any profile. | 306 // An empty path means the data is not associated with any profile. |
| 296 return !profile_path_.empty() && profile_path_ == profile->GetPath().value(); | 307 return !profile_path_.empty() && profile_path_ == profile->GetPath().value(); |
| 297 } | 308 } |
| OLD | NEW |