| 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/bookmarks/bookmark_extension_helpers.h" | 5 #include "chrome/browser/bookmarks/bookmark_extension_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_extension_api_constants.h" | 9 #include "chrome/browser/bookmarks/bookmark_extension_api_constants.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 11 | 11 |
| 12 namespace keys = bookmark_extension_api_constants; | 12 namespace keys = bookmark_extension_api_constants; |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 void AddNode(const BookmarkNode* node, | 16 void AddNode(const BookmarkNode* node, |
| 17 base::ListValue* list, | 17 base::ListValue* list, |
| 18 bool recurse, | 18 bool recurse, |
| 19 bool only_folders) { | 19 bool only_folders) { |
| 20 base::DictionaryValue* dict = bookmark_extension_helpers::GetNodeDictionary( | 20 if (node->IsVisible()) { |
| 21 node, recurse, only_folders); | 21 base::DictionaryValue* dict = bookmark_extension_helpers::GetNodeDictionary( |
| 22 list->Append(dict); | 22 node, recurse, only_folders); |
| 23 list->Append(dict); |
| 24 } |
| 23 } | 25 } |
| 24 | 26 |
| 25 } // namespace | 27 } // namespace |
| 26 | 28 |
| 27 namespace bookmark_extension_helpers { | 29 namespace bookmark_extension_helpers { |
| 28 | 30 |
| 29 base::DictionaryValue* GetNodeDictionary(const BookmarkNode* node, | 31 base::DictionaryValue* GetNodeDictionary(const BookmarkNode* node, |
| 30 bool recurse, | 32 bool recurse, |
| 31 bool only_folders) { | 33 bool only_folders) { |
| 32 base::DictionaryValue* dict = new base::DictionaryValue; | 34 base::DictionaryValue* dict = new base::DictionaryValue; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 52 if (!node->date_added().is_null()) { | 54 if (!node->date_added().is_null()) { |
| 53 // Javascript Date wants milliseconds since the epoch, ToDoubleT is seconds. | 55 // Javascript Date wants milliseconds since the epoch, ToDoubleT is seconds. |
| 54 dict->SetDouble(keys::kDateAddedKey, | 56 dict->SetDouble(keys::kDateAddedKey, |
| 55 floor(node->date_added().ToDoubleT() * 1000)); | 57 floor(node->date_added().ToDoubleT() * 1000)); |
| 56 } | 58 } |
| 57 | 59 |
| 58 if (recurse && node->is_folder()) { | 60 if (recurse && node->is_folder()) { |
| 59 base::ListValue* children = new base::ListValue; | 61 base::ListValue* children = new base::ListValue; |
| 60 for (int i = 0; i < node->child_count(); ++i) { | 62 for (int i = 0; i < node->child_count(); ++i) { |
| 61 const BookmarkNode* child = node->GetChild(i); | 63 const BookmarkNode* child = node->GetChild(i); |
| 62 if (!only_folders || child->is_folder()) { | 64 if (child->IsVisible() && (!only_folders || child->is_folder())) { |
| 63 DictionaryValue* dict = GetNodeDictionary(child, true, only_folders); | 65 DictionaryValue* dict = GetNodeDictionary(child, true, only_folders); |
| 64 children->Append(dict); | 66 children->Append(dict); |
| 65 } | 67 } |
| 66 } | 68 } |
| 67 dict->Set(keys::kChildrenKey, children); | 69 dict->Set(keys::kChildrenKey, children); |
| 68 } | 70 } |
| 69 return dict; | 71 return dict; |
| 70 } | 72 } |
| 71 | 73 |
| 72 void AddNode(const BookmarkNode* node, base::ListValue* list, bool recurse) { | 74 void AddNode(const BookmarkNode* node, base::ListValue* list, bool recurse) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 96 *error = keys::kFolderNotEmptyError; | 98 *error = keys::kFolderNotEmptyError; |
| 97 return false; | 99 return false; |
| 98 } | 100 } |
| 99 | 101 |
| 100 const BookmarkNode* parent = node->parent(); | 102 const BookmarkNode* parent = node->parent(); |
| 101 model->Remove(parent, parent->GetIndexOf(node)); | 103 model->Remove(parent, parent->GetIndexOf(node)); |
| 102 return true; | 104 return true; |
| 103 } | 105 } |
| 104 | 106 |
| 105 } // namespace bookmark_extension_helpers | 107 } // namespace bookmark_extension_helpers |
| OLD | NEW |