OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/bookmarks/browser/bookmark_node_data.h" | 5 #include "components/bookmarks/browser/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" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // Don't call scw.WriteHyperlink() here, since some rich text editors will | 170 // Don't call scw.WriteHyperlink() here, since some rich text editors will |
171 // change fonts when such data is pasted in; besides, most such editors | 171 // change fonts when such data is pasted in; besides, most such editors |
172 // auto-linkify at some point anyway. | 172 // auto-linkify at some point anyway. |
173 | 173 |
174 // Also write the URL to the clipboard as text so that it can be pasted | 174 // Also write the URL to the clipboard as text so that it can be pasted |
175 // into text fields. We use WriteText instead of WriteURL because we don't | 175 // into text fields. We use WriteText instead of WriteURL because we don't |
176 // want to clobber the X clipboard when the user copies out of the omnibox | 176 // want to clobber the X clipboard when the user copies out of the omnibox |
177 // on Linux (on Windows and Mac, there is no difference between these | 177 // on Linux (on Windows and Mac, there is no difference between these |
178 // functions). | 178 // functions). |
179 scw.WriteText(base::UTF8ToUTF16(url)); | 179 scw.WriteText(base::UTF8ToUTF16(url)); |
| 180 } else { |
| 181 // We have either more than one URL, a folder, or a combination of URLs |
| 182 // and folders. |
| 183 base::string16 text; |
| 184 for (size_t i = 0; i < elements.size(); i++) { |
| 185 if (!elements[i].is_url) { |
| 186 // Then it's a folder. Only copy the name of the folder. |
| 187 const base::string16 title = elements[i].title; |
| 188 text += i == 0 ? title : base::ASCIIToUTF16("\n") + title; |
| 189 } else { |
| 190 const base::string16 url = base::UTF8ToUTF16(elements[i].url.spec()); |
| 191 text += i == 0 ? url : base::ASCIIToUTF16("\n") + url; |
| 192 } |
| 193 } |
| 194 scw.WriteText(text); |
180 } | 195 } |
181 | 196 |
182 Pickle pickle; | 197 Pickle pickle; |
183 WriteToPickle(base::FilePath(), &pickle); | 198 WriteToPickle(base::FilePath(), &pickle); |
184 scw.WritePickledData(pickle, | 199 scw.WritePickledData(pickle, |
185 ui::Clipboard::GetFormatType(kClipboardFormatString)); | 200 ui::Clipboard::GetFormatType(kClipboardFormatString)); |
186 } | 201 } |
187 | 202 |
188 bool BookmarkNodeData::ReadFromClipboard(ui::ClipboardType type) { | 203 bool BookmarkNodeData::ReadFromClipboard(ui::ClipboardType type) { |
189 DCHECK_EQ(type, ui::CLIPBOARD_TYPE_COPY_PASTE); | 204 DCHECK_EQ(type, ui::CLIPBOARD_TYPE_COPY_PASTE); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 profile_path_ = profile_path; | 295 profile_path_ = profile_path; |
281 } | 296 } |
282 | 297 |
283 bool BookmarkNodeData::IsFromProfilePath( | 298 bool BookmarkNodeData::IsFromProfilePath( |
284 const base::FilePath& profile_path) const { | 299 const base::FilePath& profile_path) const { |
285 // An empty path means the data is not associated with any profile. | 300 // An empty path means the data is not associated with any profile. |
286 return !profile_path_.empty() && profile_path_ == profile_path; | 301 return !profile_path_.empty() && profile_path_ == profile_path; |
287 } | 302 } |
288 | 303 |
289 } // namespace bookmarks | 304 } // namespace bookmarks |
OLD | NEW |