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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 model->Remove(filtered_nodes[i]->parent(), index); | 186 model->Remove(filtered_nodes[i]->parent(), index); |
| 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 | |
| 197 BookmarkNodeData bookmark_data; | 196 BookmarkNodeData bookmark_data; |
| 198 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) | 197 if (BookmarkNodeData::ClipboardContainsBookmarks()) { |
| 198 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) | |
| 199 return; | 199 return; |
|
sky
2014/08/15 18:24:55
spacing is off.
But I think this would be clearer
ankit
2014/08/16 07:43:57
Please correct if my understanding is not correct.
| |
| 200 | 200 } else if (ui::Clipboard::GetForCurrentThread()->IsFormatAvailable( |
| 201 ui::Clipboard::GetUrlWFormatType(), | |
| 202 ui::CLIPBOARD_TYPE_COPY_PASTE)) { | |
| 203 base::string16 url_text; | |
| 204 ui::Clipboard::GetForCurrentThread()->ReadText( | |
| 205 ui::CLIPBOARD_TYPE_COPY_PASTE, &url_text); | |
| 206 GURL url(url_text); | |
| 207 if (!url.is_valid()) | |
| 208 return; | |
| 209 BookmarkNode node(url); | |
| 210 node.SetTitle(url_text); | |
| 211 BookmarkNodeData bookmark(&node); | |
| 212 bookmark_data = bookmark; | |
| 213 } | |
| 201 if (index == -1) | 214 if (index == -1) |
| 202 index = parent->child_count(); | 215 index = parent->child_count(); |
| 203 ScopedGroupBookmarkActions group_paste(model); | 216 ScopedGroupBookmarkActions group_paste(model); |
| 204 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); | 217 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); |
| 205 } | 218 } |
| 206 | 219 |
| 207 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { | 220 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { |
| 208 if (!node || !model->client()->CanBeEditedByUser(node)) | 221 if (!node || !model->client()->CanBeEditedByUser(node)) |
| 209 return false; | 222 return false; |
| 210 return BookmarkNodeData::ClipboardContainsBookmarks(); | 223 if (BookmarkNodeData::ClipboardContainsBookmarks()) |
| 224 return true; | |
| 225 if (ui::Clipboard::GetForCurrentThread()->IsFormatAvailable( | |
|
sky
2014/08/15 18:24:55
223-233 is nearly identical to 200-208, refactor t
| |
| 226 ui::Clipboard::GetUrlWFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE)) { | |
| 227 base::string16 url_text; | |
| 228 ui::Clipboard::GetForCurrentThread()->ReadText( | |
| 229 ui::CLIPBOARD_TYPE_COPY_PASTE, &url_text); | |
| 230 GURL url(url_text); | |
| 231 if (url.is_valid()) | |
| 232 return true; | |
| 233 } | |
| 234 return false; | |
| 211 } | 235 } |
| 212 | 236 |
| 213 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( | 237 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( |
| 214 BookmarkModel* model, | 238 BookmarkModel* model, |
| 215 size_t max_count) { | 239 size_t max_count) { |
| 216 std::vector<const BookmarkNode*> nodes; | 240 std::vector<const BookmarkNode*> nodes; |
| 217 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node(), | 241 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node(), |
| 218 PruneInvisibleFolders); | 242 PruneInvisibleFolders); |
| 219 | 243 |
| 220 while (iterator.has_next()) { | 244 while (iterator.has_next()) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 } | 461 } |
| 438 return false; | 462 return false; |
| 439 } | 463 } |
| 440 | 464 |
| 441 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 465 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
| 442 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 466 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
| 443 return GetNodeByID(model->root_node(), id); | 467 return GetNodeByID(model->root_node(), id); |
| 444 } | 468 } |
| 445 | 469 |
| 446 } // namespace bookmarks | 470 } // namespace bookmarks |
| OLD | NEW |