Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_bookmark_helpers.h" | 5 #include "chrome/browser/extensions/extension_bookmark_helpers.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" | 10 #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 // seconds. | 43 // seconds. |
| 44 dict->SetDouble(keys::kDateAddedKey, | 44 dict->SetDouble(keys::kDateAddedKey, |
| 45 floor(node->date_added().ToDoubleT() * 1000)); | 45 floor(node->date_added().ToDoubleT() * 1000)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 if (recurse && node->is_folder()) { | 48 if (recurse && node->is_folder()) { |
| 49 int childCount = node->child_count(); | 49 int childCount = node->child_count(); |
| 50 ListValue* children = new ListValue(); | 50 ListValue* children = new ListValue(); |
| 51 for (int i = 0; i < childCount; ++i) { | 51 for (int i = 0; i < childCount; ++i) { |
| 52 const BookmarkNode* child = node->GetChild(i); | 52 const BookmarkNode* child = node->GetChild(i); |
| 53 if (!only_folders || child->is_folder()) { | 53 if (child->IsVisible() && (!only_folders || child->is_folder())) { |
| 54 DictionaryValue* dict = GetNodeDictionary(child, true, only_folders); | 54 DictionaryValue* dict = GetNodeDictionary(child, true, only_folders); |
| 55 children->Append(dict); | 55 children->Append(dict); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 dict->Set(keys::kChildrenKey, children); | 58 dict->Set(keys::kChildrenKey, children); |
| 59 } | 59 } |
| 60 return dict; | 60 return dict; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void AddNode(const BookmarkNode* node, | 63 void AddNode(const BookmarkNode* node, |
| 64 ListValue* list, | 64 ListValue* list, |
| 65 bool recurse, | 65 bool recurse, |
| 66 bool only_folders) { | 66 bool only_folders) { |
| 67 DictionaryValue* dict = GetNodeDictionary(node, recurse, only_folders); | 67 if (node->IsVisible()) { |
| 68 list->Append(dict); | 68 DictionaryValue* dict = GetNodeDictionary(node, recurse, only_folders); |
| 69 list->Append(dict); | |
| 70 } | |
| 69 } | 71 } |
| 70 | 72 |
| 71 // Add a JSON representation of |node| to the JSON |list|. | 73 // Add a JSON representation of |node| to the JSON |list|. |
| 72 void AddNode(const BookmarkNode* node, | 74 void AddNode(const BookmarkNode* node, |
| 73 ListValue* list, | 75 ListValue* list, |
| 74 bool recurse) { | 76 bool recurse) { |
| 75 return AddNode(node, list, recurse, false); | 77 return AddNode(node, list, recurse, false); |
| 76 } | 78 } |
| 77 | 79 |
| 78 void AddNodeFoldersOnly(const BookmarkNode* node, | 80 void AddNodeFoldersOnly(const BookmarkNode* node, |
| 79 ListValue* list, | 81 ListValue* list, |
| 80 bool recurse) { | 82 bool recurse) { |
| 81 return AddNode(node, list, recurse, true); | 83 return AddNode(node, list, recurse, true); |
| 82 } | 84 } |
| 83 | 85 |
| 84 bool RemoveNode(BookmarkModel* model, | 86 bool RemoveNode(BookmarkModel* model, |
| 85 int64 id, | 87 int64 id, |
| 86 bool recursive, | 88 bool recursive, |
| 87 std::string* error) { | 89 std::string* error) { |
| 88 const BookmarkNode* node = model->GetNodeByID(id); | 90 const BookmarkNode* node = model->GetNodeByID(id); |
| 89 if (!node) { | 91 if (!node) { |
| 90 *error = keys::kNoNodeError; | 92 *error = keys::kNoNodeError; |
| 91 return false; | 93 return false; |
| 92 } | 94 } |
| 93 if (node == model->root_node() || | 95 if (node == model->root_node() || |
|
sky
2011/05/17 15:59:08
is_permanent_node
| |
| 94 node == model->other_node() || | 96 node == model->other_node() || |
| 97 node == model->synced_node() || | |
| 95 node == model->GetBookmarkBarNode()) { | 98 node == model->GetBookmarkBarNode()) { |
| 96 *error = keys::kModifySpecialError; | 99 *error = keys::kModifySpecialError; |
| 97 return false; | 100 return false; |
| 98 } | 101 } |
| 99 if (node->is_folder() && node->child_count() > 0 && !recursive) { | 102 if (node->is_folder() && node->child_count() > 0 && !recursive) { |
| 100 *error = keys::kFolderNotEmptyError; | 103 *error = keys::kFolderNotEmptyError; |
| 101 return false; | 104 return false; |
| 102 } | 105 } |
| 103 | 106 |
| 104 const BookmarkNode* parent = node->parent(); | 107 const BookmarkNode* parent = node->parent(); |
| 105 int index = parent->GetIndexOf(node); | 108 int index = parent->GetIndexOf(node); |
| 106 model->Remove(parent, index); | 109 model->Remove(parent, index); |
| 107 return true; | 110 return true; |
| 108 } | 111 } |
| 109 | 112 |
| 110 } | 113 } |
| OLD | NEW |