| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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_BOOKMARKS_HANDLER_H_ | |
| 6 #define CHROME_BROWSER_UI_WEBUI_NTP_BOOKMARKS_HANDLER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | |
| 10 #include "content/browser/webui/web_ui.h" | |
| 11 | |
| 12 class PrefService; | |
| 13 | |
| 14 // The handler for Javascript messages related to the "bookmarks" view. | |
| 15 class BookmarksHandler : public WebUIMessageHandler, | |
| 16 public BookmarkModelObserver { | |
| 17 public: | |
| 18 explicit BookmarksHandler(); | |
| 19 virtual ~BookmarksHandler(); | |
| 20 | |
| 21 // WebUIMessageHandler implementation. | |
| 22 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; | |
| 23 virtual void RegisterMessages() OVERRIDE; | |
| 24 | |
| 25 // BookmarkModelObserver implementation. | |
| 26 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE; | |
| 27 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; | |
| 28 virtual void BookmarkNodeMoved(BookmarkModel* model, | |
| 29 const BookmarkNode* old_parent, | |
| 30 int old_index, | |
| 31 const BookmarkNode* new_parent, | |
| 32 int new_index) OVERRIDE; | |
| 33 virtual void BookmarkNodeAdded(BookmarkModel* model, | |
| 34 const BookmarkNode* parent, | |
| 35 int index) OVERRIDE; | |
| 36 virtual void BookmarkNodeRemoved(BookmarkModel* model, | |
| 37 const BookmarkNode* parent, | |
| 38 int old_index, | |
| 39 const BookmarkNode* node) OVERRIDE; | |
| 40 virtual void BookmarkNodeChanged(BookmarkModel* model, | |
| 41 const BookmarkNode* node) OVERRIDE; | |
| 42 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model, | |
| 43 const BookmarkNode* node) OVERRIDE; | |
| 44 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, | |
| 45 const BookmarkNode* node) OVERRIDE; | |
| 46 virtual void BookmarkImportBeginning(BookmarkModel* model) OVERRIDE; | |
| 47 virtual void BookmarkImportEnding(BookmarkModel* model) OVERRIDE; | |
| 48 | |
| 49 // Callback for the "createBookmark" message. This handler could be sent as | |
| 50 // many as four arguments. The first argument is a stringified int64 with the | |
| 51 // parent ID of the node we're going to create the bookmark in. The additional | |
| 52 // 3 optional parameters start with an integer index denoting where the | |
| 53 // bookmark is relative to its siblings, a string for the title (which is | |
| 54 // otherwise blank), and a string of the url (without this we interpret as a | |
| 55 // folder). | |
| 56 void HandleCreateBookmark(const base::ListValue* args); | |
| 57 | |
| 58 // Callback for the "getBoomarksData" message. | |
| 59 void HandleGetBookmarksData(const base::ListValue* args); | |
| 60 | |
| 61 // Callback for the "moveBookmark" message. The arguments passed to this | |
| 62 // handler are the bookmark ID (as a string to be converted to int64), parent | |
| 63 // ID (as a string to be converted to int64), and index to be inserted into | |
| 64 // that level. | |
| 65 void HandleMoveBookmark(const base::ListValue* args); | |
| 66 | |
| 67 // Callback for the "removeBookmark" message. The argument passed to this | |
| 68 // handler is a stringified int64 bookmark ID of the node we want to delete | |
| 69 // (can be either a bookmark or a folder). | |
| 70 void HandleRemoveBookmark(const base::ListValue* args); | |
| 71 | |
| 72 // Convert a BookMark node into a DictionaryValue representation. | |
| 73 base::DictionaryValue* GetNodeDictionary(const BookmarkNode* node); | |
| 74 | |
| 75 // Add a dictionary representation of |node| to the ListValue. | |
| 76 void AddNode(const BookmarkNode* node, base::ListValue* list); | |
| 77 | |
| 78 // Register NTP preferences. | |
| 79 static void RegisterUserPrefs(PrefService* prefs); | |
| 80 | |
| 81 private: | |
| 82 // A weak reference to the current bookmarks model. | |
| 83 BookmarkModel* model_; // weak | |
| 84 | |
| 85 // True if the DOM layer is ready. | |
| 86 bool dom_ready_; | |
| 87 | |
| 88 // True when we are handling a chrome.send call. | |
| 89 bool from_current_page_; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(BookmarksHandler); | |
| 92 }; | |
| 93 | |
| 94 #endif // CHROME_BROWSER_UI_WEBUI_NTP_BOOKMARKS_HANDLER_H_ | |
| OLD | NEW |