Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1443)

Unified Diff: chrome/browser/ui/webui/ntp/bookmarks_handler.cc

Issue 7610014: [ntp4] Bookmarks page implementation, first-pass. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Code tweak for rebase. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,58 @@
#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/profiles/profile.h"
#include "chrome/common/chrome_notification_types.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;
+ CHECK(args->GetString(0, &id_string));
+ if (!base::StringToInt64(id_string, &id))
+ return;
+
+ BookmarkModel* model = Profile::FromWebUI(web_ui_)->GetBookmarkModel();
+ const BookmarkNode* node = model->GetNodeByID(id);
+ if (!node)
+ return;
+
+ base::ListValue* items = new 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 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);
+}
« chrome/browser/resources/ntp4/tile_page.js ('K') | « chrome/browser/ui/webui/ntp/bookmarks_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698