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

Side by Side Diff: chrome/browser/ui/webui/ntp/android/bookmarks_handler.h

Issue 10829326: Add the webui handler for Android's bookmark section on the NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_BOOKMARKS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_BOOKMARKS_HANDLER_H_
7
8 #include "base/values.h"
9 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
10 #include "chrome/browser/cancelable_request.h"
11 #include "chrome/browser/favicon/favicon_service.h"
12 #include "chrome/browser/ui/webui/ntp/android/partner_bookmarks_shim.h"
13 #include "content/public/browser/web_ui_message_handler.h"
14
15 // The handler for Javascript messages related to the bookmarks.
16 //
17 // In Javascript if getBookmarks() is called without any parameter, the 'Other
18 // Bookmark' folder and bookmark bar's bookmarks and folders are returned.
19 // If getBookmarks() is called with a valid bookmark folder id, the given
20 // folder's bookmarks and sub folders of are returned.
21 //
22 // All bookmarks and subfolder is returned by bookmarks() javascript callback
23 // function.
24 // The returned field 'folder' indicates whether the data is a folder. The
25 // returned field 'root' indicates whether or not the bookmark list that was
26 // returned is the root list or not. Besides these fields, a folder has id
27 // and title fields; A bookmark has url and title fields.
28 //
29 // A sample result looks like:
30 // {
31 // title: 'Bookmark Bar',
32 // id: '1',
33 // root: true,
34 // bookmarks: [
35 // {
36 // title: 'Cake',
37 // url: 'http://www.google.com',
38 // folder: false
39 // },
40 // {
41 // title: 'Puppies',
42 // folder: true,
43 // id: '2'
44 // }
45 // ]
46 // }
47 class BookmarksHandler : public content::WebUIMessageHandler,
48 public BaseBookmarkModelObserver,
49 public PartnerBookmarksShim::Observer {
50 public:
51 BookmarksHandler();
52 virtual ~BookmarksHandler();
53
54 // WebUIMessageHandler override and implementation.
55 virtual void RegisterMessages() OVERRIDE;
56
57 // Callback for the "getBookmarks" message.
58 void HandleGetBookmarks(const ListValue* args);
59 // Callback for the "deleteBookmark" message.
60 void HandleDeleteBookmark(const ListValue* args);
61 // Callback for the "createHomeScreenBookmarkShortcut" message. Used when
62 // creating a shortcut on the home screen that should open the bookmark
63 // specified in |args|.
64 void HandleCreateHomeScreenBookmarkShortcut(const base::ListValue* args);
65
66 // Notify the UI that a change occurred to the bookmark model.
67 virtual void NotifyModelChanged(const DictionaryValue& status);
68
69 // Override the methods of BookmarkModelObserver
70 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE;
71 virtual void BookmarkModelChanged() OVERRIDE;
72 virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE;
73 virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) OVERRIDE;
74 virtual void BookmarkNodeRemoved(BookmarkModel* model,
75 const BookmarkNode* parent,
76 int old_index,
77 const BookmarkNode* node) OVERRIDE;
78 virtual void BookmarkNodeAdded(BookmarkModel* model,
79 const BookmarkNode* parent,
80 int index) OVERRIDE;
81 virtual void BookmarkNodeChanged(BookmarkModel* model,
82 const BookmarkNode* node) OVERRIDE;
83
84 // Override the methods of PartnerBookmarksShim::Observer
85 virtual void PartnerShimLoaded(PartnerBookmarksShim* shim) OVERRIDE;
86 virtual void ShimBeingDeleted(PartnerBookmarksShim* shim) OVERRIDE;
87
88 private:
89 // The bookmark model being observed (if it has been attached).
90 BookmarkModel* bookmark_model_;
91
92 // Information about the Partner bookmarks (must check for IsLoaded())
93 PartnerBookmarksShim* partner_bookmarks_shim_;
94
95 // Whether the bookmark data has been requested by the UI yet.
96 bool bookmark_data_requested_;
97
98 // Indicates that extensive changes to the BookmarkModel is on-going.
99 bool extensive_changes_;
100
101 // Used for loading bookmark node.
102 CancelableRequestConsumerTSimple<const BookmarkNode*> cancelable_consumer_;
103
104 // Generates the string encoded ID to be used by the NTP.
105 std::string GetBookmarkIdForNtp(const BookmarkNode* node);
106
107 // Sets the necessary parent information in the response object to be sent
108 // to the UI renderer.
109 void SetParentInBookmarksResult(const BookmarkNode* parent,
110 DictionaryValue* result);
111
112 // Convert the given bookmark |node| into a dictionary format to be returned
113 // to JavaScript.
114 void PopulateBookmark(const BookmarkNode* node, ListValue* result);
115
116 // Given a bookmark folder node, |folder|, populate the |result| with the
117 // structured JavaScript-formatted data regarding the folder.
118 void PopulateBookmarksInFolder(const BookmarkNode* folder,
119 DictionaryValue* result);
120
121 // Sends all bookmarks and sub folders in the given folder back to the NTP.
122 void QueryBookmarkFolder(const int64& id, bool is_partner_bookmark);
123
124 // Sends bookmark bar's bookmarks and sub folders and other folders back to
125 // NTP.
126 void QueryInitialBookmarks();
127
128 // Sends the result back to Javascript
129 void SendResult(const DictionaryValue& result);
130
131 // Called once the favicon is loaded during creation of the bookmark shortcuts
132 // and is available for use.
133 void OnShortcutFaviconDataAvailable(FaviconService::Handle handle,
134 history::FaviconData favicon);
135
136 DISALLOW_COPY_AND_ASSIGN(BookmarksHandler);
137 };
138
139 #endif // CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_BOOKMARKS_HANDLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp_android/ntp_android.js ('k') | chrome/browser/ui/webui/ntp/android/bookmarks_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698