OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BOOKMARKS_BOOKMARKS_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BOOKMARKS_BOOKMARKS_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_BOOKMARKS_BOOKMARKS_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_BOOKMARKS_BOOKMARKS_API_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 // Observes BookmarkModel and then routes the notifications as events to | 40 // Observes BookmarkModel and then routes the notifications as events to |
41 // the extension system. | 41 // the extension system. |
42 class BookmarkEventRouter : public BookmarkModelObserver { | 42 class BookmarkEventRouter : public BookmarkModelObserver { |
43 public: | 43 public: |
44 explicit BookmarkEventRouter(Profile* profile); | 44 explicit BookmarkEventRouter(Profile* profile); |
45 virtual ~BookmarkEventRouter(); | 45 virtual ~BookmarkEventRouter(); |
46 | 46 |
47 // BookmarkModelObserver: | 47 // BookmarkModelObserver: |
48 virtual void BookmarkModelLoaded(BookmarkModel* model, | 48 virtual void BookmarkModelLoaded(BookmarkModel* model, |
49 bool ids_reassigned) OVERRIDE; | 49 bool ids_reassigned) override; |
50 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; | 50 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) override; |
51 virtual void BookmarkNodeMoved(BookmarkModel* model, | 51 virtual void BookmarkNodeMoved(BookmarkModel* model, |
52 const BookmarkNode* old_parent, | 52 const BookmarkNode* old_parent, |
53 int old_index, | 53 int old_index, |
54 const BookmarkNode* new_parent, | 54 const BookmarkNode* new_parent, |
55 int new_index) OVERRIDE; | 55 int new_index) override; |
56 virtual void BookmarkNodeAdded(BookmarkModel* model, | 56 virtual void BookmarkNodeAdded(BookmarkModel* model, |
57 const BookmarkNode* parent, | 57 const BookmarkNode* parent, |
58 int index) OVERRIDE; | 58 int index) override; |
59 virtual void BookmarkNodeRemoved(BookmarkModel* model, | 59 virtual void BookmarkNodeRemoved(BookmarkModel* model, |
60 const BookmarkNode* parent, | 60 const BookmarkNode* parent, |
61 int old_index, | 61 int old_index, |
62 const BookmarkNode* node, | 62 const BookmarkNode* node, |
63 const std::set<GURL>& removed_urls) OVERRIDE; | 63 const std::set<GURL>& removed_urls) override; |
64 virtual void BookmarkAllUserNodesRemoved( | 64 virtual void BookmarkAllUserNodesRemoved( |
65 BookmarkModel* model, | 65 BookmarkModel* model, |
66 const std::set<GURL>& removed_urls) OVERRIDE; | 66 const std::set<GURL>& removed_urls) override; |
67 virtual void BookmarkNodeChanged(BookmarkModel* model, | 67 virtual void BookmarkNodeChanged(BookmarkModel* model, |
68 const BookmarkNode* node) OVERRIDE; | 68 const BookmarkNode* node) override; |
69 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model, | 69 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model, |
70 const BookmarkNode* node) OVERRIDE; | 70 const BookmarkNode* node) override; |
71 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, | 71 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, |
72 const BookmarkNode* node) OVERRIDE; | 72 const BookmarkNode* node) override; |
73 virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE; | 73 virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) override; |
74 virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) OVERRIDE; | 74 virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) override; |
75 | 75 |
76 private: | 76 private: |
77 // Helper to actually dispatch an event to extension listeners. | 77 // Helper to actually dispatch an event to extension listeners. |
78 void DispatchEvent(const std::string& event_name, | 78 void DispatchEvent(const std::string& event_name, |
79 scoped_ptr<base::ListValue> event_args); | 79 scoped_ptr<base::ListValue> event_args); |
80 | 80 |
81 content::BrowserContext* browser_context_; | 81 content::BrowserContext* browser_context_; |
82 BookmarkModel* model_; | 82 BookmarkModel* model_; |
83 ChromeBookmarkClient* client_; | 83 ChromeBookmarkClient* client_; |
84 | 84 |
85 DISALLOW_COPY_AND_ASSIGN(BookmarkEventRouter); | 85 DISALLOW_COPY_AND_ASSIGN(BookmarkEventRouter); |
86 }; | 86 }; |
87 | 87 |
88 class BookmarksAPI : public BrowserContextKeyedAPI, | 88 class BookmarksAPI : public BrowserContextKeyedAPI, |
89 public EventRouter::Observer { | 89 public EventRouter::Observer { |
90 public: | 90 public: |
91 explicit BookmarksAPI(content::BrowserContext* context); | 91 explicit BookmarksAPI(content::BrowserContext* context); |
92 virtual ~BookmarksAPI(); | 92 virtual ~BookmarksAPI(); |
93 | 93 |
94 // KeyedService implementation. | 94 // KeyedService implementation. |
95 virtual void Shutdown() OVERRIDE; | 95 virtual void Shutdown() override; |
96 | 96 |
97 // BrowserContextKeyedAPI implementation. | 97 // BrowserContextKeyedAPI implementation. |
98 static BrowserContextKeyedAPIFactory<BookmarksAPI>* GetFactoryInstance(); | 98 static BrowserContextKeyedAPIFactory<BookmarksAPI>* GetFactoryInstance(); |
99 | 99 |
100 // EventRouter::Observer implementation. | 100 // EventRouter::Observer implementation. |
101 virtual void OnListenerAdded( | 101 virtual void OnListenerAdded( |
102 const EventListenerInfo& details) OVERRIDE; | 102 const EventListenerInfo& details) override; |
103 | 103 |
104 private: | 104 private: |
105 friend class BrowserContextKeyedAPIFactory<BookmarksAPI>; | 105 friend class BrowserContextKeyedAPIFactory<BookmarksAPI>; |
106 | 106 |
107 content::BrowserContext* browser_context_; | 107 content::BrowserContext* browser_context_; |
108 | 108 |
109 // BrowserContextKeyedAPI implementation. | 109 // BrowserContextKeyedAPI implementation. |
110 static const char* service_name() { | 110 static const char* service_name() { |
111 return "BookmarksAPI"; | 111 return "BookmarksAPI"; |
112 } | 112 } |
113 static const bool kServiceIsNULLWhileTesting = true; | 113 static const bool kServiceIsNULLWhileTesting = true; |
114 | 114 |
115 // Created lazily upon OnListenerAdded. | 115 // Created lazily upon OnListenerAdded. |
116 scoped_ptr<BookmarkEventRouter> bookmark_event_router_; | 116 scoped_ptr<BookmarkEventRouter> bookmark_event_router_; |
117 }; | 117 }; |
118 | 118 |
119 class BookmarksFunction : public ChromeAsyncExtensionFunction, | 119 class BookmarksFunction : public ChromeAsyncExtensionFunction, |
120 public BaseBookmarkModelObserver { | 120 public BaseBookmarkModelObserver { |
121 public: | 121 public: |
122 // AsyncExtensionFunction: | 122 // AsyncExtensionFunction: |
123 virtual bool RunAsync() OVERRIDE; | 123 virtual bool RunAsync() override; |
124 | 124 |
125 protected: | 125 protected: |
126 virtual ~BookmarksFunction() {} | 126 virtual ~BookmarksFunction() {} |
127 | 127 |
128 // RunAsync semantic equivalent called when the bookmarks are ready. | 128 // RunAsync semantic equivalent called when the bookmarks are ready. |
129 virtual bool RunOnReady() = 0; | 129 virtual bool RunOnReady() = 0; |
130 | 130 |
131 // Helper to get the BookmarkModel. | 131 // Helper to get the BookmarkModel. |
132 BookmarkModel* GetBookmarkModel(); | 132 BookmarkModel* GetBookmarkModel(); |
133 | 133 |
(...skipping 22 matching lines...) Expand all Loading... |
156 bool EditBookmarksEnabled(); | 156 bool EditBookmarksEnabled(); |
157 | 157 |
158 // Helper that checks if |node| can be modified. Returns false if |node| | 158 // Helper that checks if |node| can be modified. Returns false if |node| |
159 // is NULL, or a managed node, or the root node. In these cases the node | 159 // is NULL, or a managed node, or the root node. In these cases the node |
160 // can't be edited, can't have new child nodes appended, and its direct | 160 // can't be edited, can't have new child nodes appended, and its direct |
161 // children can't be moved or reordered. | 161 // children can't be moved or reordered. |
162 bool CanBeModified(const BookmarkNode* node); | 162 bool CanBeModified(const BookmarkNode* node); |
163 | 163 |
164 private: | 164 private: |
165 // BaseBookmarkModelObserver: | 165 // BaseBookmarkModelObserver: |
166 virtual void BookmarkModelChanged() OVERRIDE; | 166 virtual void BookmarkModelChanged() override; |
167 virtual void BookmarkModelLoaded(BookmarkModel* model, | 167 virtual void BookmarkModelLoaded(BookmarkModel* model, |
168 bool ids_reassigned) OVERRIDE; | 168 bool ids_reassigned) override; |
169 }; | 169 }; |
170 | 170 |
171 class BookmarksGetFunction : public BookmarksFunction { | 171 class BookmarksGetFunction : public BookmarksFunction { |
172 public: | 172 public: |
173 DECLARE_EXTENSION_FUNCTION("bookmarks.get", BOOKMARKS_GET) | 173 DECLARE_EXTENSION_FUNCTION("bookmarks.get", BOOKMARKS_GET) |
174 | 174 |
175 protected: | 175 protected: |
176 virtual ~BookmarksGetFunction() {} | 176 virtual ~BookmarksGetFunction() {} |
177 | 177 |
178 // BookmarksFunction: | 178 // BookmarksFunction: |
179 virtual bool RunOnReady() OVERRIDE; | 179 virtual bool RunOnReady() override; |
180 }; | 180 }; |
181 | 181 |
182 class BookmarksGetChildrenFunction : public BookmarksFunction { | 182 class BookmarksGetChildrenFunction : public BookmarksFunction { |
183 public: | 183 public: |
184 DECLARE_EXTENSION_FUNCTION("bookmarks.getChildren", BOOKMARKS_GETCHILDREN) | 184 DECLARE_EXTENSION_FUNCTION("bookmarks.getChildren", BOOKMARKS_GETCHILDREN) |
185 | 185 |
186 protected: | 186 protected: |
187 virtual ~BookmarksGetChildrenFunction() {} | 187 virtual ~BookmarksGetChildrenFunction() {} |
188 | 188 |
189 // BookmarksFunction: | 189 // BookmarksFunction: |
190 virtual bool RunOnReady() OVERRIDE; | 190 virtual bool RunOnReady() override; |
191 }; | 191 }; |
192 | 192 |
193 class BookmarksGetRecentFunction : public BookmarksFunction { | 193 class BookmarksGetRecentFunction : public BookmarksFunction { |
194 public: | 194 public: |
195 DECLARE_EXTENSION_FUNCTION("bookmarks.getRecent", BOOKMARKS_GETRECENT) | 195 DECLARE_EXTENSION_FUNCTION("bookmarks.getRecent", BOOKMARKS_GETRECENT) |
196 | 196 |
197 protected: | 197 protected: |
198 virtual ~BookmarksGetRecentFunction() {} | 198 virtual ~BookmarksGetRecentFunction() {} |
199 | 199 |
200 // BookmarksFunction: | 200 // BookmarksFunction: |
201 virtual bool RunOnReady() OVERRIDE; | 201 virtual bool RunOnReady() override; |
202 }; | 202 }; |
203 | 203 |
204 class BookmarksGetTreeFunction : public BookmarksFunction { | 204 class BookmarksGetTreeFunction : public BookmarksFunction { |
205 public: | 205 public: |
206 DECLARE_EXTENSION_FUNCTION("bookmarks.getTree", BOOKMARKS_GETTREE) | 206 DECLARE_EXTENSION_FUNCTION("bookmarks.getTree", BOOKMARKS_GETTREE) |
207 | 207 |
208 protected: | 208 protected: |
209 virtual ~BookmarksGetTreeFunction() {} | 209 virtual ~BookmarksGetTreeFunction() {} |
210 | 210 |
211 // BookmarksFunction: | 211 // BookmarksFunction: |
212 virtual bool RunOnReady() OVERRIDE; | 212 virtual bool RunOnReady() override; |
213 }; | 213 }; |
214 | 214 |
215 class BookmarksGetSubTreeFunction : public BookmarksFunction { | 215 class BookmarksGetSubTreeFunction : public BookmarksFunction { |
216 public: | 216 public: |
217 DECLARE_EXTENSION_FUNCTION("bookmarks.getSubTree", BOOKMARKS_GETSUBTREE) | 217 DECLARE_EXTENSION_FUNCTION("bookmarks.getSubTree", BOOKMARKS_GETSUBTREE) |
218 | 218 |
219 protected: | 219 protected: |
220 virtual ~BookmarksGetSubTreeFunction() {} | 220 virtual ~BookmarksGetSubTreeFunction() {} |
221 | 221 |
222 // BookmarksFunction: | 222 // BookmarksFunction: |
223 virtual bool RunOnReady() OVERRIDE; | 223 virtual bool RunOnReady() override; |
224 }; | 224 }; |
225 | 225 |
226 class BookmarksSearchFunction : public BookmarksFunction { | 226 class BookmarksSearchFunction : public BookmarksFunction { |
227 public: | 227 public: |
228 DECLARE_EXTENSION_FUNCTION("bookmarks.search", BOOKMARKS_SEARCH) | 228 DECLARE_EXTENSION_FUNCTION("bookmarks.search", BOOKMARKS_SEARCH) |
229 | 229 |
230 protected: | 230 protected: |
231 virtual ~BookmarksSearchFunction() {} | 231 virtual ~BookmarksSearchFunction() {} |
232 | 232 |
233 // BookmarksFunction: | 233 // BookmarksFunction: |
234 virtual bool RunOnReady() OVERRIDE; | 234 virtual bool RunOnReady() override; |
235 }; | 235 }; |
236 | 236 |
237 class BookmarksRemoveFunction : public BookmarksFunction { | 237 class BookmarksRemoveFunction : public BookmarksFunction { |
238 public: | 238 public: |
239 DECLARE_EXTENSION_FUNCTION("bookmarks.remove", BOOKMARKS_REMOVE) | 239 DECLARE_EXTENSION_FUNCTION("bookmarks.remove", BOOKMARKS_REMOVE) |
240 | 240 |
241 // Returns true on successful parse and sets invalid_id to true if conversion | 241 // Returns true on successful parse and sets invalid_id to true if conversion |
242 // from id string to int64 failed. | 242 // from id string to int64 failed. |
243 static bool ExtractIds(const base::ListValue* args, | 243 static bool ExtractIds(const base::ListValue* args, |
244 std::list<int64>* ids, | 244 std::list<int64>* ids, |
245 bool* invalid_id); | 245 bool* invalid_id); |
246 | 246 |
247 protected: | 247 protected: |
248 virtual ~BookmarksRemoveFunction() {} | 248 virtual ~BookmarksRemoveFunction() {} |
249 | 249 |
250 // BookmarksFunction: | 250 // BookmarksFunction: |
251 virtual bool RunOnReady() OVERRIDE; | 251 virtual bool RunOnReady() override; |
252 }; | 252 }; |
253 | 253 |
254 class BookmarksRemoveTreeFunction : public BookmarksRemoveFunction { | 254 class BookmarksRemoveTreeFunction : public BookmarksRemoveFunction { |
255 public: | 255 public: |
256 DECLARE_EXTENSION_FUNCTION("bookmarks.removeTree", BOOKMARKS_REMOVETREE) | 256 DECLARE_EXTENSION_FUNCTION("bookmarks.removeTree", BOOKMARKS_REMOVETREE) |
257 | 257 |
258 protected: | 258 protected: |
259 virtual ~BookmarksRemoveTreeFunction() {} | 259 virtual ~BookmarksRemoveTreeFunction() {} |
260 }; | 260 }; |
261 | 261 |
262 class BookmarksCreateFunction : public BookmarksFunction { | 262 class BookmarksCreateFunction : public BookmarksFunction { |
263 public: | 263 public: |
264 DECLARE_EXTENSION_FUNCTION("bookmarks.create", BOOKMARKS_CREATE) | 264 DECLARE_EXTENSION_FUNCTION("bookmarks.create", BOOKMARKS_CREATE) |
265 | 265 |
266 protected: | 266 protected: |
267 virtual ~BookmarksCreateFunction() {} | 267 virtual ~BookmarksCreateFunction() {} |
268 | 268 |
269 // BookmarksFunction: | 269 // BookmarksFunction: |
270 virtual bool RunOnReady() OVERRIDE; | 270 virtual bool RunOnReady() override; |
271 }; | 271 }; |
272 | 272 |
273 class BookmarksMoveFunction : public BookmarksFunction { | 273 class BookmarksMoveFunction : public BookmarksFunction { |
274 public: | 274 public: |
275 DECLARE_EXTENSION_FUNCTION("bookmarks.move", BOOKMARKS_MOVE) | 275 DECLARE_EXTENSION_FUNCTION("bookmarks.move", BOOKMARKS_MOVE) |
276 | 276 |
277 static bool ExtractIds(const base::ListValue* args, | 277 static bool ExtractIds(const base::ListValue* args, |
278 std::list<int64>* ids, | 278 std::list<int64>* ids, |
279 bool* invalid_id); | 279 bool* invalid_id); |
280 | 280 |
281 protected: | 281 protected: |
282 virtual ~BookmarksMoveFunction() {} | 282 virtual ~BookmarksMoveFunction() {} |
283 | 283 |
284 // BookmarksFunction: | 284 // BookmarksFunction: |
285 virtual bool RunOnReady() OVERRIDE; | 285 virtual bool RunOnReady() override; |
286 }; | 286 }; |
287 | 287 |
288 class BookmarksUpdateFunction : public BookmarksFunction { | 288 class BookmarksUpdateFunction : public BookmarksFunction { |
289 public: | 289 public: |
290 DECLARE_EXTENSION_FUNCTION("bookmarks.update", BOOKMARKS_UPDATE) | 290 DECLARE_EXTENSION_FUNCTION("bookmarks.update", BOOKMARKS_UPDATE) |
291 | 291 |
292 static bool ExtractIds(const base::ListValue* args, | 292 static bool ExtractIds(const base::ListValue* args, |
293 std::list<int64>* ids, | 293 std::list<int64>* ids, |
294 bool* invalid_id); | 294 bool* invalid_id); |
295 | 295 |
296 protected: | 296 protected: |
297 virtual ~BookmarksUpdateFunction() {} | 297 virtual ~BookmarksUpdateFunction() {} |
298 | 298 |
299 // BookmarksFunction: | 299 // BookmarksFunction: |
300 virtual bool RunOnReady() OVERRIDE; | 300 virtual bool RunOnReady() override; |
301 }; | 301 }; |
302 | 302 |
303 class BookmarksIOFunction : public BookmarksFunction, | 303 class BookmarksIOFunction : public BookmarksFunction, |
304 public ui::SelectFileDialog::Listener { | 304 public ui::SelectFileDialog::Listener { |
305 public: | 305 public: |
306 BookmarksIOFunction(); | 306 BookmarksIOFunction(); |
307 | 307 |
308 virtual void FileSelected(const base::FilePath& path, int index, void* params)
= 0; | 308 virtual void FileSelected(const base::FilePath& path, int index, void* params)
= 0; |
309 | 309 |
310 // ui::SelectFileDialog::Listener: | 310 // ui::SelectFileDialog::Listener: |
311 virtual void MultiFilesSelected(const std::vector<base::FilePath>& files, | 311 virtual void MultiFilesSelected(const std::vector<base::FilePath>& files, |
312 void* params) OVERRIDE; | 312 void* params) override; |
313 virtual void FileSelectionCanceled(void* params) OVERRIDE; | 313 virtual void FileSelectionCanceled(void* params) override; |
314 | 314 |
315 void SelectFile(ui::SelectFileDialog::Type type); | 315 void SelectFile(ui::SelectFileDialog::Type type); |
316 | 316 |
317 protected: | 317 protected: |
318 virtual ~BookmarksIOFunction(); | 318 virtual ~BookmarksIOFunction(); |
319 | 319 |
320 private: | 320 private: |
321 void ShowSelectFileDialog( | 321 void ShowSelectFileDialog( |
322 ui::SelectFileDialog::Type type, | 322 ui::SelectFileDialog::Type type, |
323 const base::FilePath& default_path); | 323 const base::FilePath& default_path); |
324 | 324 |
325 protected: | 325 protected: |
326 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; | 326 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; |
327 }; | 327 }; |
328 | 328 |
329 class BookmarksImportFunction : public BookmarksIOFunction { | 329 class BookmarksImportFunction : public BookmarksIOFunction { |
330 public: | 330 public: |
331 DECLARE_EXTENSION_FUNCTION("bookmarks.import", BOOKMARKS_IMPORT) | 331 DECLARE_EXTENSION_FUNCTION("bookmarks.import", BOOKMARKS_IMPORT) |
332 | 332 |
333 // BookmarkManagerIOFunction: | 333 // BookmarkManagerIOFunction: |
334 virtual void FileSelected(const base::FilePath& path, | 334 virtual void FileSelected(const base::FilePath& path, |
335 int index, | 335 int index, |
336 void* params) OVERRIDE; | 336 void* params) override; |
337 | 337 |
338 private: | 338 private: |
339 virtual ~BookmarksImportFunction() {} | 339 virtual ~BookmarksImportFunction() {} |
340 | 340 |
341 // BookmarksFunction: | 341 // BookmarksFunction: |
342 virtual bool RunOnReady() OVERRIDE; | 342 virtual bool RunOnReady() override; |
343 }; | 343 }; |
344 | 344 |
345 class BookmarksExportFunction : public BookmarksIOFunction { | 345 class BookmarksExportFunction : public BookmarksIOFunction { |
346 public: | 346 public: |
347 DECLARE_EXTENSION_FUNCTION("bookmarks.export", BOOKMARKS_EXPORT) | 347 DECLARE_EXTENSION_FUNCTION("bookmarks.export", BOOKMARKS_EXPORT) |
348 | 348 |
349 // BookmarkManagerIOFunction: | 349 // BookmarkManagerIOFunction: |
350 virtual void FileSelected(const base::FilePath& path, | 350 virtual void FileSelected(const base::FilePath& path, |
351 int index, | 351 int index, |
352 void* params) OVERRIDE; | 352 void* params) override; |
353 | 353 |
354 private: | 354 private: |
355 virtual ~BookmarksExportFunction() {} | 355 virtual ~BookmarksExportFunction() {} |
356 | 356 |
357 // BookmarksFunction: | 357 // BookmarksFunction: |
358 virtual bool RunOnReady() OVERRIDE; | 358 virtual bool RunOnReady() override; |
359 }; | 359 }; |
360 | 360 |
361 } // namespace extensions | 361 } // namespace extensions |
362 | 362 |
363 #endif // CHROME_BROWSER_EXTENSIONS_API_BOOKMARKS_BOOKMARKS_API_H_ | 363 #endif // CHROME_BROWSER_EXTENSIONS_API_BOOKMARKS_BOOKMARKS_API_H_ |
OLD | NEW |