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/extensions/api/bookmarks/bookmark_api_helpers.h" | 5 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h" |
6 | 6 |
7 #include <math.h> // For floor() | 7 #include <math.h> // For floor() |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 bookmark_tree_node->title = base::UTF16ToUTF8(node->GetTitle()); | 72 bookmark_tree_node->title = base::UTF16ToUTF8(node->GetTitle()); |
73 if (!node->date_added().is_null()) { | 73 if (!node->date_added().is_null()) { |
74 // Javascript Date wants milliseconds since the epoch, ToDoubleT is seconds. | 74 // Javascript Date wants milliseconds since the epoch, ToDoubleT is seconds. |
75 bookmark_tree_node->date_added.reset( | 75 bookmark_tree_node->date_added.reset( |
76 new double(floor(node->date_added().ToDoubleT() * 1000))); | 76 new double(floor(node->date_added().ToDoubleT() * 1000))); |
77 } | 77 } |
78 | 78 |
79 if (client->IsDescendantOfManagedNode(node)) | 79 if (bookmarks::IsDescendantOf(node, client->managed_node()) || |
| 80 bookmarks::IsDescendantOf(node, client->supervised_node())) { |
80 bookmark_tree_node->unmodifiable = BookmarkTreeNode::UNMODIFIABLE_MANAGED; | 81 bookmark_tree_node->unmodifiable = BookmarkTreeNode::UNMODIFIABLE_MANAGED; |
| 82 } |
81 | 83 |
82 if (recurse && node->is_folder()) { | 84 if (recurse && node->is_folder()) { |
83 std::vector<linked_ptr<BookmarkTreeNode> > children; | 85 std::vector<linked_ptr<BookmarkTreeNode> > children; |
84 for (int i = 0; i < node->child_count(); ++i) { | 86 for (int i = 0; i < node->child_count(); ++i) { |
85 const BookmarkNode* child = node->GetChild(i); | 87 const BookmarkNode* child = node->GetChild(i); |
86 if (child->IsVisible() && (!only_folders || child->is_folder())) { | 88 if (child->IsVisible() && (!only_folders || child->is_folder())) { |
87 linked_ptr<BookmarkTreeNode> child_node( | 89 linked_ptr<BookmarkTreeNode> child_node( |
88 GetBookmarkTreeNode(client, child, true, only_folders)); | 90 GetBookmarkTreeNode(client, child, true, only_folders)); |
89 children.push_back(child_node); | 91 children.push_back(child_node); |
90 } | 92 } |
(...skipping 25 matching lines...) Expand all Loading... |
116 std::string* error) { | 118 std::string* error) { |
117 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID(model, id); | 119 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID(model, id); |
118 if (!node) { | 120 if (!node) { |
119 *error = keys::kNoNodeError; | 121 *error = keys::kNoNodeError; |
120 return false; | 122 return false; |
121 } | 123 } |
122 if (model->is_permanent_node(node)) { | 124 if (model->is_permanent_node(node)) { |
123 *error = keys::kModifySpecialError; | 125 *error = keys::kModifySpecialError; |
124 return false; | 126 return false; |
125 } | 127 } |
126 if (client->IsDescendantOfManagedNode(node)) { | 128 if (bookmarks::IsDescendantOf(node, client->managed_node()) || |
| 129 bookmarks::IsDescendantOf(node, client->supervised_node())) { |
127 *error = keys::kModifyManagedError; | 130 *error = keys::kModifyManagedError; |
128 return false; | 131 return false; |
129 } | 132 } |
130 if (node->is_folder() && !node->empty() && !recursive) { | 133 if (node->is_folder() && !node->empty() && !recursive) { |
131 *error = keys::kFolderNotEmptyError; | 134 *error = keys::kFolderNotEmptyError; |
132 return false; | 135 return false; |
133 } | 136 } |
134 | 137 |
135 const BookmarkNode* parent = node->parent(); | 138 const BookmarkNode* parent = node->parent(); |
136 model->Remove(parent, parent->GetIndexOf(node)); | 139 model->Remove(parent, parent->GetIndexOf(node)); |
(...skipping 17 matching lines...) Expand all Loading... |
154 | 157 |
155 if (node.is_folder()) { | 158 if (node.is_folder()) { |
156 for (int i = 0; i < node.child_count(); ++i) { | 159 for (int i = 0; i < node.child_count(); ++i) { |
157 GetMetaInfo(*(node.GetChild(i)), id_to_meta_info_map); | 160 GetMetaInfo(*(node.GetChild(i)), id_to_meta_info_map); |
158 } | 161 } |
159 } | 162 } |
160 } | 163 } |
161 | 164 |
162 } // namespace bookmark_api_helpers | 165 } // namespace bookmark_api_helpers |
163 } // namespace extensions | 166 } // namespace extensions |
OLD | NEW |