Chromium Code Reviews| Index: chrome/browser/ui/webui/ntp/bookmarks_handler.cc |
| =================================================================== |
| --- chrome/browser/ui/webui/ntp/bookmarks_handler.cc (revision 96479) |
| +++ chrome/browser/ui/webui/ntp/bookmarks_handler.cc (working copy) |
| @@ -4,18 +4,73 @@ |
| #include "chrome/browser/ui/webui/ntp/bookmarks_handler.h" |
| +#include "base/string_number_conversions.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/bookmarks/bookmark_model.h" |
| +#include "chrome/browser/extensions/extension_bookmark_helpers.h" |
| +#include "chrome/browser/prefs/pref_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/sync/profile_sync_service.h" |
| #include "chrome/common/chrome_notification_types.h" |
| +#include "chrome/common/pref_names.h" |
| #include "content/common/notification_service.h" |
| BookmarksHandler::BookmarksHandler() { |
| + // TODO(csilv): Register for bookmark model change notifications. |
| } |
| BookmarksHandler::~BookmarksHandler() {} |
| void BookmarksHandler::RegisterMessages() { |
| + web_ui_->RegisterMessageCallback("getBookmarksData", |
| + NewCallback(this, &BookmarksHandler::HandleGetBookmarksData)); |
| } |
| void BookmarksHandler::Observe(int type, |
| const NotificationSource& source, |
| const NotificationDetails& details) { |
| + // TODO(csilv): Update UI based on changes to bookmark notifications. |
| } |
| + |
| +void BookmarksHandler::HandleGetBookmarksData(const base::ListValue* args) { |
| + int64 id; |
| + std::string id_string; |
| + PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); |
| + if (args->GetString(0, &id_string) && base::StringToInt64(id_string, &id)) { |
| + // A folder ID was requested, so persist this value. |
| + prefs->SetInt64(prefs::kNTPShownBookmarksFolder, id); |
| + } else { |
| + // No folder ID was requested, so get the default (persisted) value. |
| + id = prefs->GetInt64(prefs::kNTPShownBookmarksFolder); |
| + } |
| + |
| + BookmarkModel* model = Profile::FromWebUI(web_ui_)->GetBookmarkModel(); |
| + const BookmarkNode* node = model->GetNodeByID(id); |
| + if (!node) |
| + return; |
| + |
| + base::ListValue* items = new base::ListValue(); |
| + int child_count = node->child_count(); |
| + for (int i = 0; i < child_count; ++i) { |
| + const BookmarkNode* child = node->GetChild(i); |
| + extension_bookmark_helpers::AddNode(child, items, false); |
| + } |
| + |
| + base::ListValue* navigation_items = new base::ListValue(); |
| + while (node) { |
| + extension_bookmark_helpers::AddNode(node, navigation_items, false); |
| + node = node->parent(); |
| + } |
| + |
| + base::DictionaryValue bookmarksData; |
| + bookmarksData.Set("items", items); |
| + bookmarksData.Set("navigationItems", navigation_items); |
| + web_ui_->CallJavascriptFunction("ntp4.setBookmarksData", bookmarksData); |
| +} |
| + |
| +// static |
| +void BookmarksHandler::RegisterUserPrefs(PrefService* prefs) { |
| + // TODO(csilv): show we sync this preference? |
| + prefs->RegisterInt64Pref(prefs::kNTPShownBookmarksFolder, 0, |
|
arv (Not doing code reviews)
2011/08/15 17:46:30
Add a comment that 0 is the ID of the bookmark roo
csilv
2011/08/15 18:24:28
Added a comment. Bookmarks bar may be the logical
|
| + PrefService::UNSYNCABLE_PREF); |
| +} |