OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/scoped_clipboard_writer.h" | 9 #include "base/scoped_clipboard_writer.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "chrome/browser/bookmarks/bookmark_model.h" | 11 #include "chrome/browser/bookmarks/bookmark_model.h" |
12 #include "chrome/browser/profile.h" | 12 #include "chrome/browser/profile.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "net/base/escape.h" |
15 | 16 |
16 const char* BookmarkDragData::kClipboardFormatString = | 17 const char* BookmarkDragData::kClipboardFormatString = |
17 "chromium/x-bookmark-entries"; | 18 "chromium/x-bookmark-entries"; |
18 | 19 |
19 BookmarkDragData::Element::Element(const BookmarkNode* node) | 20 BookmarkDragData::Element::Element(const BookmarkNode* node) |
20 : is_url(node->is_url()), | 21 : is_url(node->is_url()), |
21 url(node->GetURL()), | 22 url(node->GetURL()), |
22 title(node->GetTitle()), | 23 title(node->GetTitle()), |
23 id_(node->id()) { | 24 id_(node->id()) { |
24 for (int i = 0; i < node->GetChildCount(); ++i) | 25 for (int i = 0; i < node->GetChildCount(); ++i) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 elements.push_back(Element(nodes[i])); | 90 elements.push_back(Element(nodes[i])); |
90 } | 91 } |
91 | 92 |
92 #if !defined(OS_MACOSX) | 93 #if !defined(OS_MACOSX) |
93 void BookmarkDragData::WriteToClipboard(Profile* profile) const { | 94 void BookmarkDragData::WriteToClipboard(Profile* profile) const { |
94 ScopedClipboardWriter scw(g_browser_process->clipboard()); | 95 ScopedClipboardWriter scw(g_browser_process->clipboard()); |
95 | 96 |
96 // If there is only one element and it is a URL, write the URL to the | 97 // If there is only one element and it is a URL, write the URL to the |
97 // clipboard. | 98 // clipboard. |
98 if (elements.size() == 1 && elements[0].is_url) { | 99 if (elements.size() == 1 && elements[0].is_url) { |
99 scw.WriteBookmark(WideToUTF16Hack(elements[0].title), | 100 string16 title = WideToUTF16Hack(elements[0].title); |
100 elements[0].url.spec()); | 101 std::string url = elements[0].url.spec(); |
| 102 |
| 103 scw.WriteBookmark(title, url); |
| 104 scw.WriteHyperlink(EscapeForHTML(UTF16ToUTF8(title)), url); |
101 } | 105 } |
102 | 106 |
103 Pickle pickle; | 107 Pickle pickle; |
104 WriteToPickle(profile, &pickle); | 108 WriteToPickle(profile, &pickle); |
105 scw.WritePickledData(pickle, kClipboardFormatString); | 109 scw.WritePickledData(pickle, kClipboardFormatString); |
106 } | 110 } |
107 | 111 |
108 bool BookmarkDragData::ReadFromClipboard() { | 112 bool BookmarkDragData::ReadFromClipboard() { |
109 std::string data; | 113 std::string data; |
110 Clipboard* clipboard = g_browser_process->clipboard(); | 114 Clipboard* clipboard = g_browser_process->clipboard(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 251 |
248 bool BookmarkDragData::IsFromProfile(Profile* profile) const { | 252 bool BookmarkDragData::IsFromProfile(Profile* profile) const { |
249 // An empty path means the data is not associated with any profile. | 253 // An empty path means the data is not associated with any profile. |
250 return (!profile_path_.empty() && | 254 return (!profile_path_.empty() && |
251 #if defined(WCHAR_T_IS_UTF16) | 255 #if defined(WCHAR_T_IS_UTF16) |
252 profile->GetPath().ToWStringHack() == profile_path_); | 256 profile->GetPath().ToWStringHack() == profile_path_); |
253 #elif defined(WCHAR_T_IS_UTF32) | 257 #elif defined(WCHAR_T_IS_UTF32) |
254 profile->GetPath().value() == profile_path_); | 258 profile->GetPath().value() == profile_path_); |
255 #endif | 259 #endif |
256 } | 260 } |
OLD | NEW |