OLD | NEW |
---|---|
(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/memory/scoped_ptr.h" | |
9 #include "base/values.h" | |
10 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" | |
11 #include "chrome/browser/cancelable_request.h" | |
12 #include "chrome/browser/favicon/favicon_service.h" | |
13 #include "chrome/browser/ui/webui/ntp/android/partner_bookmarks_shim.h" | |
14 #include "content/public/browser/web_ui_message_handler.h" | |
15 | |
16 // The handler for Javascript messages related to the bookmarks. | |
17 // | |
18 // In Javascript if getBookmarks() is called without any parameter, the 'Other | |
19 // Bookmark' folder and bookmark bar's bookmarks and folders are returned. | |
20 // If getBookmarks() is called with a valid bookmark folder id, the given | |
21 // folder's bookmarks and sub folders of are returned. | |
22 // | |
23 // All bookmarks and subfolder is returned by bookmarks() javascript callback | |
24 // function. | |
25 // The returned field 'folder' indicates whether the data is a folder. The | |
26 // returned field 'root' indicates whether or not the bookmark list that was | |
27 // returned is the root list or not. Besides these fields, a folder has id | |
28 // and title fields; A bookmark has url and title fields. | |
29 // | |
30 // A sample result looks like: | |
31 // { | |
32 // title: 'Bookmark Bar', | |
33 // id: '1', | |
34 // root: true, | |
35 // bookmarks: [ | |
36 // { | |
37 // title: 'Cake', | |
38 // url: 'http://www.google.com', | |
39 // folder: false | |
40 // }, | |
41 // { | |
42 // title: 'Puppies', | |
43 // folder: true, | |
44 // id: '2' | |
45 // } | |
46 // ] | |
47 // } | |
48 class BookmarksHandler : public content::WebUIMessageHandler, | |
49 public BaseBookmarkModelObserver, | |
50 public PartnerBookmarksShim::Observer { | |
51 public: | |
52 BookmarksHandler(); | |
53 virtual ~BookmarksHandler(); | |
54 | |
55 // WebUIMessageHandler override and implementation. | |
56 virtual void RegisterMessages() OVERRIDE; | |
57 | |
58 // Callback for the "getBookmarks" message. | |
59 void HandleGetBookmarks(const ListValue* args); | |
60 // Callback for the "deleteBookmark" message. | |
61 void HandleDeleteBookmark(const ListValue* args); | |
62 // Callback for the "shortcutToBookmark" message. | |
63 void HandleShortcutToBookmark(const base::ListValue* args); | |
Evan Stade
2012/08/15 00:05:10
This purpose function is not obvious. Can you docu
Ted C
2012/08/15 21:21:00
Changed the name to: HandleCreateHomeScreenBookmar
| |
64 | |
65 // Notify the UI that a change occurred to the bookmark model. | |
66 virtual void NotifyModelChanged(const DictionaryValue& status); | |
67 | |
68 // Override the methods of BookmarkModelObserver | |
69 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE; | |
70 virtual void BookmarkModelChanged() OVERRIDE; | |
71 virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE; | |
72 virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) OVERRIDE; | |
73 virtual void BookmarkNodeRemoved(BookmarkModel* model, | |
74 const BookmarkNode* parent, | |
75 int old_index, | |
76 const BookmarkNode* node) OVERRIDE; | |
77 virtual void BookmarkNodeAdded(BookmarkModel* model, | |
78 const BookmarkNode* parent, | |
79 int index) OVERRIDE; | |
80 virtual void BookmarkNodeChanged(BookmarkModel* model, | |
81 const BookmarkNode* node) OVERRIDE; | |
82 | |
83 // Override the methods of PartnerBookmarksShim::Observer | |
84 virtual void PartnerShimLoaded(PartnerBookmarksShim* shim) OVERRIDE; | |
85 virtual void ShimBeingDeleted(PartnerBookmarksShim* shim) OVERRIDE; | |
86 | |
87 private: | |
88 // The bookmark model being observed (if it has been attached). | |
89 BookmarkModel* bookmark_model_; | |
90 | |
91 // Information about the Partner bookmarks (must check for IsLoaded()) | |
92 PartnerBookmarksShim* partner_bookmarks_shim_; | |
93 | |
94 // Whether the bookmark data has been requested by the UI yet. | |
95 bool bookmark_data_requested_; | |
96 | |
97 // Indicates that extensive changes to the BookmarkModel is on-going. | |
98 bool extensive_changes_; | |
99 | |
100 // Indicates that a shortcut is being created. | |
101 bool creating_shortcut_; | |
102 | |
103 // Used for loading bookmark node. | |
104 CancelableRequestConsumerTSimple<BookmarkNode*> cancelable_consumer_; | |
105 | |
106 // Generates the string encoded ID to be used by the NTP. | |
107 std::string GetBookmarkIdForNtp(const BookmarkNode* node); | |
108 | |
109 // Sets the necessary parent information in the response object to be sent | |
110 // to the UI renderer. | |
111 void SetParentInBookmarksResult(const BookmarkNode& parent, | |
112 DictionaryValue* result); | |
113 | |
114 // Convert the given bookmark |node| into a dictionary format to be returned | |
115 // to JavaScript. | |
116 void PopulateBookmark(const BookmarkNode* node, ListValue* result); | |
117 | |
118 // Given a bookmark folder node, |folder|, populate the |result| with the | |
119 // structured JavaScript-formatted data regarding the folder. | |
120 void PopulateBookmarksInFolder(const BookmarkNode* folder, | |
121 const scoped_ptr<DictionaryValue>& result); | |
122 | |
123 // Sends all bookmarks and sub folders in the given folder back to the NTP. | |
124 void QueryBookmarkFolder(const int64& id, bool is_partner_bookmark); | |
125 | |
126 // Sends bookmark bar's bookmarks and sub folders and other folders back to | |
127 // NTP. | |
128 void QueryInitialBookmarks(); | |
129 | |
130 // Sends the result back to Javascript | |
131 void SendResult(const scoped_ptr<DictionaryValue>& result); | |
132 | |
133 // Called once the favicon is loaded and is available for use. | |
134 void OnFaviconDataAvailable(FaviconService::Handle handle, | |
135 history::FaviconData favicon); | |
136 | |
137 DISALLOW_COPY_AND_ASSIGN(BookmarksHandler); | |
138 }; | |
139 | |
140 #endif // CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_BOOKMARKS_HANDLER_H_ | |
OLD | NEW |