| 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_utils.h" | 5 #include "components/bookmarks/browser/bookmark_utils.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 void PasteFromClipboard(BookmarkModel* model, | 191 void PasteFromClipboard(BookmarkModel* model, |
| 192 const BookmarkNode* parent, | 192 const BookmarkNode* parent, |
| 193 int index) { | 193 int index) { |
| 194 if (!parent) | 194 if (!parent) |
| 195 return; | 195 return; |
| 196 | 196 |
| 197 BookmarkNodeData bookmark_data; | 197 if (BookmarkNodeData::ClipboardContainsBookmarks()) { |
| 198 BookmarkNodeData bookmark_data; |
| 198 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) | 199 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) |
| 199 return; | 200 return; |
| 200 | 201 |
| 201 if (index == -1) | 202 if (index == -1) |
| 202 index = parent->child_count(); | 203 index = parent->child_count(); |
| 203 ScopedGroupBookmarkActions group_paste(model); | 204 ScopedGroupBookmarkActions group_paste(model); |
| 204 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); | 205 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); |
| 206 } |
| 207 if (BookmarkNodeData::ClipboardContainsUrls()) { |
| 208 base::string16 url_text; |
| 209 ui::Clipboard::GetForCurrentThread()->ReadText( |
| 210 ui::CLIPBOARD_TYPE_COPY_PASTE, &url_text); |
| 211 GURL url(url_text); |
| 212 model->AddURL(parent, index, url_text, url); |
| 213 } |
| 205 } | 214 } |
| 206 | 215 |
| 207 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { | 216 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { |
| 208 if (!node || !model->client()->CanBeEditedByUser(node)) | 217 if (!node || !model->client()->CanBeEditedByUser(node)) |
| 209 return false; | 218 return false; |
| 210 return BookmarkNodeData::ClipboardContainsBookmarks(); | 219 return BookmarkNodeData::ClipboardContainsBookmarks() || |
| 220 BookmarkNodeData::ClipboardContainsUrls(); |
| 211 } | 221 } |
| 212 | 222 |
| 213 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( | 223 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( |
| 214 BookmarkModel* model, | 224 BookmarkModel* model, |
| 215 size_t max_count) { | 225 size_t max_count) { |
| 216 std::vector<const BookmarkNode*> nodes; | 226 std::vector<const BookmarkNode*> nodes; |
| 217 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node(), | 227 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node(), |
| 218 PruneInvisibleFolders); | 228 PruneInvisibleFolders); |
| 219 | 229 |
| 220 while (iterator.has_next()) { | 230 while (iterator.has_next()) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 } | 447 } |
| 438 return false; | 448 return false; |
| 439 } | 449 } |
| 440 | 450 |
| 441 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 451 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
| 442 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 452 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
| 443 return GetNodeByID(model->root_node(), id); | 453 return GetNodeByID(model->root_node(), id); |
| 444 } | 454 } |
| 445 | 455 |
| 446 } // namespace bookmarks | 456 } // namespace bookmarks |
| OLD | NEW |