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); |
| 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 // Indicates that extensive changes to the BookmarkModel is on-going. |
| 95 bool extensive_changes_; |
| 96 |
| 97 // Indicates that a shortcut is being created. |
| 98 bool creating_shortcut_; |
| 99 |
| 100 // Used for loading bookmark node. |
| 101 CancelableRequestConsumerTSimple<BookmarkNode*> cancelable_consumer_; |
| 102 |
| 103 // Generates the string encoded ID to be used by the NTP. |
| 104 std::string GetBookmarkIdForNtp(const BookmarkNode* node); |
| 105 |
| 106 // Sets the necessary parent information in the response object to be sent |
| 107 // to the UI renderer. |
| 108 void SetParentInBookmarksResult(const BookmarkNode& parent, |
| 109 DictionaryValue* result); |
| 110 |
| 111 // Convert the given bookmark |node| into a dictionary format to be returned |
| 112 // to JavaScript. |
| 113 void PopulateBookmark(const BookmarkNode* node, ListValue* result); |
| 114 |
| 115 // Given a bookmark folder node, |folder|, populate the |result| with the |
| 116 // structured JavaScript-formatted data regarding the folder. |
| 117 void PopulateBookmarksInFolder(const BookmarkNode* folder, |
| 118 const scoped_ptr<DictionaryValue>& result); |
| 119 |
| 120 // Sends all bookmarks and sub folders in the given folder back to the NTP. |
| 121 void QueryBookmarkFolder(const int64& id, bool is_partner_bookmark); |
| 122 |
| 123 // Sends bookmark bar's bookmarks and sub folders and other folders back to |
| 124 // NTP. |
| 125 void QueryInitialBookmarks(); |
| 126 |
| 127 // Sends the result back to Javascript |
| 128 void SendResult(const scoped_ptr<DictionaryValue>& result); |
| 129 |
| 130 // Called once the favicon is loaded and is available for use. |
| 131 void OnFaviconDataAvailable(FaviconService::Handle handle, |
| 132 history::FaviconData favicon); |
| 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(BookmarksHandler); |
| 135 }; |
| 136 |
| 137 #endif // CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_BOOKMARKS_HANDLER_H_ |
OLD | NEW |