Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / bookmark_manager_private / bookmark_manager_private_api.h
bloba5d93d32b11b8ce7baf401a1d44ee0c5635a1d46
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BOOKMARK_MANAGER_PRIVATE_BOOKMARK_MANAGER_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_BOOKMARK_MANAGER_PRIVATE_BOOKMARK_MANAGER_PRIVATE_API_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
10 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h"
11 #include "chrome/browser/extensions/chrome_extension_function.h"
12 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
13 #include "chrome/browser/undo/bookmark_undo_service_factory.h"
14 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
15 #include "components/bookmarks/browser/bookmark_node_data.h"
16 #include "components/undo/bookmark_undo_service.h"
17 #include "extensions/browser/browser_context_keyed_api_factory.h"
18 #include "extensions/browser/event_router.h"
20 class Profile;
22 namespace bookmarks {
23 struct BookmarkNodeData;
26 namespace content {
27 class BrowserContext;
28 class WebContents;
31 namespace extensions {
33 class BookmarkManagerPrivateEventRouter
34 : public bookmarks::BaseBookmarkModelObserver {
35 public:
36 BookmarkManagerPrivateEventRouter(content::BrowserContext* browser_context,
37 bookmarks::BookmarkModel* bookmark_model);
38 ~BookmarkManagerPrivateEventRouter() override;
40 // bookmarks::BaseBookmarkModelObserver:
41 void BookmarkModelChanged() override;
42 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override;
43 void OnWillChangeBookmarkMetaInfo(
44 bookmarks::BookmarkModel* model,
45 const bookmarks::BookmarkNode* node) override;
46 void BookmarkMetaInfoChanged(bookmarks::BookmarkModel* model,
47 const bookmarks::BookmarkNode* node) override;
49 private:
50 // Helper to actually dispatch an event to extension listeners.
51 void DispatchEvent(events::HistogramValue histogram_value,
52 const std::string& event_name,
53 scoped_ptr<base::ListValue> event_args);
55 // Remembers the previous meta info of a node before it was changed.
56 bookmarks::BookmarkNode::MetaInfoMap prev_meta_info_;
58 content::BrowserContext* browser_context_;
59 bookmarks::BookmarkModel* bookmark_model_;
62 class BookmarkManagerPrivateAPI : public BrowserContextKeyedAPI,
63 public EventRouter::Observer {
64 public:
65 explicit BookmarkManagerPrivateAPI(content::BrowserContext* browser_context);
66 ~BookmarkManagerPrivateAPI() override;
68 // BrowserContextKeyedService implementation.
69 void Shutdown() override;
71 // BrowserContextKeyedAPI implementation.
72 static BrowserContextKeyedAPIFactory<BookmarkManagerPrivateAPI>*
73 GetFactoryInstance();
75 // EventRouter::Observer implementation.
76 void OnListenerAdded(const EventListenerInfo& details) override;
78 private:
79 friend class BrowserContextKeyedAPIFactory<BookmarkManagerPrivateAPI>;
81 // BrowserContextKeyedAPI implementation.
82 static const char* service_name() { return "BookmarkManagerPrivateAPI"; }
83 static const bool kServiceIsNULLWhileTesting = true;
85 content::BrowserContext* browser_context_;
87 // Created lazily upon OnListenerAdded.
88 scoped_ptr<BookmarkManagerPrivateEventRouter> event_router_;
91 // Class that handles the drag and drop related chrome.bookmarkManagerPrivate
92 // events. This class has one instance per bookmark manager tab.
93 class BookmarkManagerPrivateDragEventRouter
94 : public BookmarkTabHelper::BookmarkDrag {
95 public:
96 BookmarkManagerPrivateDragEventRouter(Profile* profile,
97 content::WebContents* web_contents);
98 ~BookmarkManagerPrivateDragEventRouter() override;
100 // BookmarkTabHelper::BookmarkDrag interface
101 void OnDragEnter(const bookmarks::BookmarkNodeData& data) override;
102 void OnDragOver(const bookmarks::BookmarkNodeData& data) override;
103 void OnDragLeave(const bookmarks::BookmarkNodeData& data) override;
104 void OnDrop(const bookmarks::BookmarkNodeData& data) override;
106 // The bookmark drag and drop data. This gets set after a drop was done on
107 // the page. This returns NULL if no data is available.
108 const bookmarks::BookmarkNodeData* GetBookmarkNodeData();
110 // Clears the drag and drop data.
111 void ClearBookmarkNodeData();
113 private:
114 // Helper to actually dispatch an event to extension listeners.
115 void DispatchEvent(events::HistogramValue histogram_value,
116 const std::string& event_name,
117 scoped_ptr<base::ListValue> args);
119 Profile* profile_;
120 content::WebContents* web_contents_;
121 bookmarks::BookmarkNodeData bookmark_drag_data_;
123 DISALLOW_COPY_AND_ASSIGN(BookmarkManagerPrivateDragEventRouter);
126 class ClipboardBookmarkManagerFunction : public extensions::BookmarksFunction {
127 protected:
128 ~ClipboardBookmarkManagerFunction() override {}
130 bool CopyOrCut(bool cut, const std::vector<std::string>& id_list);
133 class BookmarkManagerPrivateCopyFunction
134 : public ClipboardBookmarkManagerFunction {
135 public:
136 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.copy",
137 BOOKMARKMANAGERPRIVATE_COPY)
139 protected:
140 ~BookmarkManagerPrivateCopyFunction() override {}
142 // ExtensionFunction:
143 bool RunOnReady() override;
146 class BookmarkManagerPrivateCutFunction
147 : public ClipboardBookmarkManagerFunction {
148 public:
149 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.cut",
150 BOOKMARKMANAGERPRIVATE_CUT)
152 protected:
153 ~BookmarkManagerPrivateCutFunction() override {}
155 // ExtensionFunction:
156 bool RunOnReady() override;
159 class BookmarkManagerPrivatePasteFunction
160 : public extensions::BookmarksFunction {
161 public:
162 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.paste",
163 BOOKMARKMANAGERPRIVATE_PASTE)
165 protected:
166 ~BookmarkManagerPrivatePasteFunction() override {}
168 // ExtensionFunction:
169 bool RunOnReady() override;
172 class BookmarkManagerPrivateCanPasteFunction
173 : public extensions::BookmarksFunction {
174 public:
175 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.canPaste",
176 BOOKMARKMANAGERPRIVATE_CANPASTE)
178 protected:
179 ~BookmarkManagerPrivateCanPasteFunction() override {}
181 // ExtensionFunction:
182 bool RunOnReady() override;
185 class BookmarkManagerPrivateSortChildrenFunction
186 : public extensions::BookmarksFunction {
187 public:
188 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.sortChildren",
189 BOOKMARKMANAGERPRIVATE_SORTCHILDREN)
191 protected:
192 ~BookmarkManagerPrivateSortChildrenFunction() override {}
194 // ExtensionFunction:
195 bool RunOnReady() override;
198 class BookmarkManagerPrivateGetStringsFunction : public AsyncExtensionFunction {
199 public:
200 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.getStrings",
201 BOOKMARKMANAGERPRIVATE_GETSTRINGS)
203 protected:
204 ~BookmarkManagerPrivateGetStringsFunction() override {}
206 // ExtensionFunction:
207 bool RunAsync() override;
210 class BookmarkManagerPrivateStartDragFunction
211 : public extensions::BookmarksFunction {
212 public:
213 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.startDrag",
214 BOOKMARKMANAGERPRIVATE_STARTDRAG)
216 protected:
217 ~BookmarkManagerPrivateStartDragFunction() override {}
219 // ExtensionFunction:
220 bool RunOnReady() override;
223 class BookmarkManagerPrivateDropFunction
224 : public extensions::BookmarksFunction {
225 public:
226 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.drop",
227 BOOKMARKMANAGERPRIVATE_DROP)
229 protected:
230 ~BookmarkManagerPrivateDropFunction() override {}
232 // ExtensionFunction:
233 bool RunOnReady() override;
236 class BookmarkManagerPrivateGetSubtreeFunction
237 : public extensions::BookmarksFunction {
238 public:
239 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.getSubtree",
240 BOOKMARKMANAGERPRIVATE_GETSUBTREE)
242 protected:
243 ~BookmarkManagerPrivateGetSubtreeFunction() override {}
245 // ExtensionFunction:
246 bool RunOnReady() override;
249 class BookmarkManagerPrivateCanEditFunction
250 : public extensions::BookmarksFunction {
251 public:
252 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.canEdit",
253 BOOKMARKMANAGERPRIVATE_CANEDIT)
255 protected:
256 ~BookmarkManagerPrivateCanEditFunction() override {}
258 // ExtensionFunction:
259 bool RunOnReady() override;
262 class BookmarkManagerPrivateRecordLaunchFunction
263 : public extensions::BookmarksFunction {
264 public:
265 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.recordLaunch",
266 BOOKMARKMANAGERPRIVATE_RECORDLAUNCH)
268 protected:
269 ~BookmarkManagerPrivateRecordLaunchFunction() override {}
271 // ExtensionFunction:
272 bool RunOnReady() override;
275 class BookmarkManagerPrivateCreateWithMetaInfoFunction
276 : public extensions::BookmarksFunction {
277 public:
278 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.createWithMetaInfo",
279 BOOKMARKMANAGERPRIVATE_CREATEWITHMETAINFO)
281 protected:
282 ~BookmarkManagerPrivateCreateWithMetaInfoFunction() override {}
284 // ExtensionFunction:
285 bool RunOnReady() override;
288 class BookmarkManagerPrivateGetMetaInfoFunction
289 : public extensions::BookmarksFunction {
290 public:
291 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.getMetaInfo",
292 BOOKMARKMANAGERPRIVATE_GETMETAINFO)
294 protected:
295 ~BookmarkManagerPrivateGetMetaInfoFunction() override {}
297 // ExtensionFunction:
298 bool RunOnReady() override;
301 class BookmarkManagerPrivateSetMetaInfoFunction
302 : public extensions::BookmarksFunction {
303 public:
304 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.setMetaInfo",
305 BOOKMARKMANAGERPRIVATE_SETMETAINFO)
307 protected:
308 ~BookmarkManagerPrivateSetMetaInfoFunction() override {}
310 // ExtensionFunction:
311 bool RunOnReady() override;
314 class BookmarkManagerPrivateUpdateMetaInfoFunction
315 : public extensions::BookmarksFunction {
316 public:
317 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.updateMetaInfo",
318 BOOKMARKMANAGERPRIVATE_UPDATEMETAINFO)
320 protected:
321 ~BookmarkManagerPrivateUpdateMetaInfoFunction() override {}
323 // ExtensionFunction:
324 bool RunOnReady() override;
327 class BookmarkManagerPrivateCanOpenNewWindowsFunction
328 : public extensions::BookmarksFunction {
329 public:
330 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.canOpenNewWindows",
331 BOOKMARKMANAGERPRIVATE_CANOPENNEWWINDOWS)
333 protected:
334 ~BookmarkManagerPrivateCanOpenNewWindowsFunction() override {}
336 // ExtensionFunction:
337 bool RunOnReady() override;
340 class BookmarkManagerPrivateRemoveTreesFunction
341 : public extensions::BookmarksFunction {
342 public:
343 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.removeTrees",
344 BOOKMARKMANAGERPRIVATE_REMOVETREES)
346 protected:
347 ~BookmarkManagerPrivateRemoveTreesFunction() override {}
349 // ExtensionFunction:
350 bool RunOnReady() override;
353 class BookmarkManagerPrivateUndoFunction
354 : public extensions::BookmarksFunction {
355 public:
356 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.undo",
357 BOOKMARKMANAGERPRIVATE_UNDO)
359 protected:
360 ~BookmarkManagerPrivateUndoFunction() override {}
362 // ExtensionFunction:
363 bool RunOnReady() override;
366 class BookmarkManagerPrivateRedoFunction
367 : public extensions::BookmarksFunction {
368 public:
369 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.redo",
370 BOOKMARKMANAGERPRIVATE_REDO)
372 protected:
373 ~BookmarkManagerPrivateRedoFunction() override {}
375 // ExtensionFunction:
376 bool RunOnReady() override;
379 class BookmarkManagerPrivateGetUndoInfoFunction
380 : public extensions::BookmarksFunction {
381 public:
382 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.getUndoInfo",
383 BOOKMARKMANAGERPRIVATE_UNDOINFO)
385 protected:
386 ~BookmarkManagerPrivateGetUndoInfoFunction() override {}
388 // ExtensionFunction:
389 bool RunOnReady() override;
392 class BookmarkManagerPrivateGetRedoInfoFunction
393 : public extensions::BookmarksFunction {
394 public:
395 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.getRedoInfo",
396 BOOKMARKMANAGERPRIVATE_REDOINFO)
398 protected:
399 ~BookmarkManagerPrivateGetRedoInfoFunction() override {}
401 // ExtensionFunction:
402 bool RunOnReady() override;
405 class BookmarkManagerPrivateSetVersionFunction
406 : public extensions::BookmarksFunction {
407 public:
408 DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.setVersion",
409 BOOKMARKMANAGERPRIVATE_SETVERSION);
411 protected:
412 ~BookmarkManagerPrivateSetVersionFunction() override {}
414 // ExtensionFunction:
415 bool RunOnReady() override;
418 } // namespace extensions
420 #endif // CHROME_BROWSER_EXTENSIONS_API_BOOKMARK_MANAGER_PRIVATE_BOOKMARK_MANAGER_PRIVATE_API_H_