| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_utils.h" | 5 #include "chrome/browser/bookmarks/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" |
| 11 #include "base/i18n/case_conversion.h" | 11 #include "base/i18n/case_conversion.h" |
| 12 #include "base/i18n/string_search.h" | 12 #include "base/i18n/string_search.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_model.h" | 17 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | |
| 19 #include "chrome/browser/bookmarks/scoped_group_bookmark_actions.h" | |
| 20 #include "chrome/browser/history/query_parser.h" | 18 #include "chrome/browser/history/query_parser.h" |
| 21 #include "chrome/browser/undo/bookmark_undo_service.h" | 19 #include "chrome/browser/undo/bookmark_undo_service.h" |
| 22 #include "chrome/browser/undo/bookmark_undo_service_factory.h" | 20 #include "chrome/browser/undo/bookmark_undo_service_factory.h" |
| 21 #include "chrome/browser/undo/bookmark_undo_utils.h" |
| 23 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 24 #include "components/user_prefs/pref_registry_syncable.h" | 23 #include "components/user_prefs/pref_registry_syncable.h" |
| 25 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 26 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
| 27 #include "ui/base/models/tree_node_iterator.h" | 26 #include "ui/base/models/tree_node_iterator.h" |
| 28 | 27 |
| 29 using base::Time; | 28 using base::Time; |
| 30 | 29 |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 std::vector<const BookmarkNode*> filtered_nodes; | 142 std::vector<const BookmarkNode*> filtered_nodes; |
| 144 for (size_t i = 0; i < nodes.size(); ++i) | 143 for (size_t i = 0; i < nodes.size(); ++i) |
| 145 if (!HasSelectedAncestor(model, nodes, nodes[i]->parent())) | 144 if (!HasSelectedAncestor(model, nodes, nodes[i]->parent())) |
| 146 filtered_nodes.push_back(nodes[i]); | 145 filtered_nodes.push_back(nodes[i]); |
| 147 | 146 |
| 148 BookmarkNodeData(filtered_nodes). | 147 BookmarkNodeData(filtered_nodes). |
| 149 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); | 148 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 150 | 149 |
| 151 if (remove_nodes) { | 150 if (remove_nodes) { |
| 152 #if !defined(OS_ANDROID) | 151 #if !defined(OS_ANDROID) |
| 153 ScopedGroupBookmarkActions group_cut(model); | 152 ScopedGroupBookmarkActions group_cut(model->profile()); |
| 154 #endif | 153 #endif |
| 155 for (size_t i = 0; i < filtered_nodes.size(); ++i) { | 154 for (size_t i = 0; i < filtered_nodes.size(); ++i) { |
| 156 int index = filtered_nodes[i]->parent()->GetIndexOf(filtered_nodes[i]); | 155 int index = filtered_nodes[i]->parent()->GetIndexOf(filtered_nodes[i]); |
| 157 if (index > -1) | 156 if (index > -1) |
| 158 model->Remove(filtered_nodes[i]->parent(), index); | 157 model->Remove(filtered_nodes[i]->parent(), index); |
| 159 } | 158 } |
| 160 } | 159 } |
| 161 } | 160 } |
| 162 | 161 |
| 163 void PasteFromClipboard(BookmarkModel* model, | 162 void PasteFromClipboard(BookmarkModel* model, |
| 164 const BookmarkNode* parent, | 163 const BookmarkNode* parent, |
| 165 int index) { | 164 int index) { |
| 166 if (!parent) | 165 if (!parent) |
| 167 return; | 166 return; |
| 168 | 167 |
| 169 BookmarkNodeData bookmark_data; | 168 BookmarkNodeData bookmark_data; |
| 170 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) | 169 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) |
| 171 return; | 170 return; |
| 172 | 171 |
| 173 if (index == -1) | 172 if (index == -1) |
| 174 index = parent->child_count(); | 173 index = parent->child_count(); |
| 175 #if !defined(OS_ANDROID) | 174 #if !defined(OS_ANDROID) |
| 176 ScopedGroupBookmarkActions group_paste(model); | 175 ScopedGroupBookmarkActions group_paste(model->profile()); |
| 177 #endif | 176 #endif |
| 178 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); | 177 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); |
| 179 } | 178 } |
| 180 | 179 |
| 181 bool CanPasteFromClipboard(const BookmarkNode* node) { | 180 bool CanPasteFromClipboard(const BookmarkNode* node) { |
| 182 if (!node) | 181 if (!node) |
| 183 return false; | 182 return false; |
| 184 return BookmarkNodeData::ClipboardContainsBookmarks(); | 183 return BookmarkNodeData::ClipboardContainsBookmarks(); |
| 185 } | 184 } |
| 186 | 185 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 // Remove all the bookmarks. | 367 // Remove all the bookmarks. |
| 369 for (size_t i = 0; i < bookmarks.size(); ++i) { | 368 for (size_t i = 0; i < bookmarks.size(); ++i) { |
| 370 const BookmarkNode* node = bookmarks[i]; | 369 const BookmarkNode* node = bookmarks[i]; |
| 371 int index = node->parent()->GetIndexOf(node); | 370 int index = node->parent()->GetIndexOf(node); |
| 372 if (index > -1) | 371 if (index > -1) |
| 373 model->Remove(node->parent(), index); | 372 model->Remove(node->parent(), index); |
| 374 } | 373 } |
| 375 } | 374 } |
| 376 | 375 |
| 377 } // namespace bookmark_utils | 376 } // namespace bookmark_utils |
| OLD | NEW |