Chromium Code Reviews| 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)) |
|
sky
2014/08/13 16:48:35
Fix indentation here.
| |
| 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 (ui::Clipboard::GetForCurrentThread()->IsFormatAvailable( | |
| 208 ui::Clipboard::GetUrlWFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE)) { | |
|
sky
2014/08/13 16:48:34
I think this path should convert to a BookmarkNode
| |
| 209 base::string16 url_text; | |
| 210 ui::Clipboard::GetForCurrentThread()->ReadText( | |
| 211 ui::CLIPBOARD_TYPE_COPY_PASTE, &url_text); | |
| 212 GURL url(url_text); | |
| 213 model->AddURL(parent, index, url_text, url); | |
| 214 } | |
| 205 } | 215 } |
| 206 | 216 |
| 207 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { | 217 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { |
| 208 if (!node || !model->client()->CanBeEditedByUser(node)) | 218 if (!node || !model->client()->CanBeEditedByUser(node)) |
| 209 return false; | 219 return false; |
| 210 return BookmarkNodeData::ClipboardContainsBookmarks(); | 220 return BookmarkNodeData::ClipboardContainsBookmarks() || |
| 221 ui::Clipboard::GetForCurrentThread()->IsFormatAvailable( | |
| 222 ui::Clipboard::GetUrlWFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE); | |
| 211 } | 223 } |
| 212 | 224 |
| 213 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( | 225 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( |
| 214 BookmarkModel* model, | 226 BookmarkModel* model, |
| 215 size_t max_count) { | 227 size_t max_count) { |
| 216 std::vector<const BookmarkNode*> nodes; | 228 std::vector<const BookmarkNode*> nodes; |
| 217 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node(), | 229 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node(), |
| 218 PruneInvisibleFolders); | 230 PruneInvisibleFolders); |
| 219 | 231 |
| 220 while (iterator.has_next()) { | 232 while (iterator.has_next()) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 } | 449 } |
| 438 return false; | 450 return false; |
| 439 } | 451 } |
| 440 | 452 |
| 441 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 453 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
| 442 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 454 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
| 443 return GetNodeByID(model->root_node(), id); | 455 return GetNodeByID(model->root_node(), id); |
| 444 } | 456 } |
| 445 | 457 |
| 446 } // namespace bookmarks | 458 } // namespace bookmarks |
| OLD | NEW |