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/ui/webui/ntp/bookmarks_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/bookmarks_handler.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_bookmark_helpers.h" | 10 #include "chrome/browser/extensions/extension_bookmark_helpers.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // We wish to merge the root node with the bookmarks bar node. | 70 // We wish to merge the root node with the bookmarks bar node. |
71 if (model->is_root_node(node)) | 71 if (model->is_root_node(node)) |
72 node = model->bookmark_bar_node(); | 72 node = model->bookmark_bar_node(); |
73 | 73 |
74 base::ListValue* items = new base::ListValue(); | 74 base::ListValue* items = new base::ListValue(); |
75 int child_count = node->child_count(); | 75 int child_count = node->child_count(); |
76 for (int i = 0; i < child_count; ++i) { | 76 for (int i = 0; i < child_count; ++i) { |
77 const BookmarkNode* child = node->GetChild(i); | 77 const BookmarkNode* child = node->GetChild(i); |
78 extension_bookmark_helpers::AddNode(child, items, false); | 78 extension_bookmark_helpers::AddNode(child, items, false); |
79 } | 79 } |
80 if (node == model->bookmark_bar_node()) | 80 if (node == model->bookmark_bar_node() && model->other_node()->child_count()) |
81 extension_bookmark_helpers::AddNode(model->other_node(), items, false); | 81 extension_bookmark_helpers::AddNode(model->other_node(), items, false); |
82 | 82 |
83 base::ListValue* navigation_items = new base::ListValue(); | 83 base::ListValue* navigation_items = new base::ListValue(); |
84 while (node) { | 84 while (node) { |
85 if (node != model->bookmark_bar_node()) | 85 if (node != model->bookmark_bar_node()) |
86 extension_bookmark_helpers::AddNode(node, navigation_items, false); | 86 extension_bookmark_helpers::AddNode(node, navigation_items, false); |
87 node = node->parent(); | 87 node = node->parent(); |
88 } | 88 } |
89 | 89 |
90 base::DictionaryValue bookmarksData; | 90 base::DictionaryValue bookmarksData; |
91 bookmarksData.Set("items", items); | 91 bookmarksData.Set("items", items); |
92 bookmarksData.Set("navigationItems", navigation_items); | 92 bookmarksData.Set("navigationItems", navigation_items); |
93 web_ui_->CallJavascriptFunction("ntp4.setBookmarksData", bookmarksData); | 93 web_ui_->CallJavascriptFunction("ntp4.setBookmarksData", bookmarksData); |
94 } | 94 } |
95 | 95 |
96 // static | 96 // static |
97 void BookmarksHandler::RegisterUserPrefs(PrefService* prefs) { | 97 void BookmarksHandler::RegisterUserPrefs(PrefService* prefs) { |
98 // Default folder is the root node. | 98 // Default folder is the root node. |
99 // TODO(csilv): Should we default to the Bookmarks bar? | 99 // TODO(csilv): Should we default to the Bookmarks bar? |
100 // TODO(csilv): Should we sync this preference? | 100 // TODO(csilv): Should we sync this preference? |
101 prefs->RegisterInt64Pref(prefs::kNTPShownBookmarksFolder, 0, | 101 prefs->RegisterInt64Pref(prefs::kNTPShownBookmarksFolder, 0, |
102 PrefService::UNSYNCABLE_PREF); | 102 PrefService::UNSYNCABLE_PREF); |
103 } | 103 } |
OLD | NEW |