Chromium Code Reviews| 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. Used when creating a | |
| 63 // shortcut on the home screen that should open the bookmark specified in | |
| 64 // |args|. | |
| 65 void HandleCreateHomeScreenBookmarkShortcut(const base::ListValue* args); | |
| 66 | |
| 67 // Notify the UI that a change occurred to the bookmark model. | |
| 68 virtual void NotifyModelChanged(const DictionaryValue& status); | |
| 69 | |
| 70 // Override the methods of BookmarkModelObserver | |
| 71 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE; | |
| 72 virtual void BookmarkModelChanged() OVERRIDE; | |
| 73 virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE; | |
| 74 virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) OVERRIDE; | |
| 75 virtual void BookmarkNodeRemoved(BookmarkModel* model, | |
| 76 const BookmarkNode* parent, | |
| 77 int old_index, | |
| 78 const BookmarkNode* node) OVERRIDE; | |
| 79 virtual void BookmarkNodeAdded(BookmarkModel* model, | |
| 80 const BookmarkNode* parent, | |
| 81 int index) OVERRIDE; | |
| 82 virtual void BookmarkNodeChanged(BookmarkModel* model, | |
| 83 const BookmarkNode* node) OVERRIDE; | |
| 84 | |
| 85 // Override the methods of PartnerBookmarksShim::Observer | |
| 86 virtual void PartnerShimLoaded(PartnerBookmarksShim* shim) OVERRIDE; | |
| 87 virtual void ShimBeingDeleted(PartnerBookmarksShim* shim) OVERRIDE; | |
| 88 | |
| 89 private: | |
| 90 // The bookmark model being observed (if it has been attached). | |
| 91 BookmarkModel* bookmark_model_; | |
| 92 | |
| 93 // Information about the Partner bookmarks (must check for IsLoaded()) | |
| 94 PartnerBookmarksShim* partner_bookmarks_shim_; | |
| 95 | |
| 96 // Whether the bookmark data has been requested by the UI yet. | |
| 97 bool bookmark_data_requested_; | |
| 98 | |
| 99 // Indicates that extensive changes to the BookmarkModel is on-going. | |
| 100 bool extensive_changes_; | |
| 101 | |
| 102 // Used for loading bookmark node. | |
| 103 CancelableRequestConsumerTSimple<BookmarkNode*> cancelable_consumer_; | |
| 104 | |
| 105 // Generates the string encoded ID to be used by the NTP. | |
| 106 std::string GetBookmarkIdForNtp(const BookmarkNode* node); | |
| 107 | |
| 108 // Sets the necessary parent information in the response object to be sent | |
| 109 // to the UI renderer. | |
| 110 void SetParentInBookmarksResult(const BookmarkNode& parent, | |
| 111 DictionaryValue* result); | |
| 112 | |
| 113 // Convert the given bookmark |node| into a dictionary format to be returned | |
| 114 // to JavaScript. | |
| 115 void PopulateBookmark(const BookmarkNode* node, ListValue* result); | |
| 116 | |
| 117 // Given a bookmark folder node, |folder|, populate the |result| with the | |
| 118 // structured JavaScript-formatted data regarding the folder. | |
| 119 void PopulateBookmarksInFolder(const BookmarkNode* folder, | |
| 120 const scoped_ptr<DictionaryValue>& result); | |
|
Evan Stade
2012/08/15 22:24:00
Out params should be bare pointers.
| |
| 121 | |
| 122 // Sends all bookmarks and sub folders in the given folder back to the NTP. | |
| 123 void QueryBookmarkFolder(const int64& id, bool is_partner_bookmark); | |
| 124 | |
| 125 // Sends bookmark bar's bookmarks and sub folders and other folders back to | |
| 126 // NTP. | |
| 127 void QueryInitialBookmarks(); | |
| 128 | |
| 129 // Sends the result back to Javascript | |
| 130 void SendResult(const scoped_ptr<DictionaryValue>& result); | |
| 131 | |
| 132 // Called once the favicon is loaded during creation of the bookmark shortcuts | |
| 133 // and is available for use. | |
| 134 void OnShortcutFaviconDataAvailable(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 |