OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import org.chromium.base.CalledByNative; | 7 import org.chromium.base.CalledByNative; |
8 import org.chromium.base.ObserverList; | 8 import org.chromium.base.ObserverList; |
| 9 import org.chromium.base.VisibleForTesting; |
9 import org.chromium.chrome.browser.profiles.Profile; | 10 import org.chromium.chrome.browser.profiles.Profile; |
10 import org.chromium.components.bookmarks.BookmarkId; | 11 import org.chromium.components.bookmarks.BookmarkId; |
| 12 import org.chromium.components.bookmarks.BookmarkType; |
11 | 13 |
12 import java.util.ArrayList; | 14 import java.util.ArrayList; |
13 import java.util.List; | 15 import java.util.List; |
14 | 16 |
15 /** | 17 /** |
16 * Provides the communication channel for Android to fetch and manipulate the | 18 * Provides the communication channel for Android to fetch and manipulate the |
17 * bookmark model stored in native. | 19 * bookmark model stored in native. |
18 */ | 20 */ |
19 public class BookmarksBridge { | 21 public class BookmarksBridge { |
20 private final Profile mProfile; | 22 private final Profile mProfile; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 if (mNativeBookmarksBridge != 0) { | 157 if (mNativeBookmarksBridge != 0) { |
156 nativeDestroy(mNativeBookmarksBridge); | 158 nativeDestroy(mNativeBookmarksBridge); |
157 mNativeBookmarksBridge = 0; | 159 mNativeBookmarksBridge = 0; |
158 mIsNativeBookmarkModelLoaded = false; | 160 mIsNativeBookmarkModelLoaded = false; |
159 mDelayedBookmarkCallbacks.clear(); | 161 mDelayedBookmarkCallbacks.clear(); |
160 } | 162 } |
161 mObservers.clear(); | 163 mObservers.clear(); |
162 } | 164 } |
163 | 165 |
164 /** | 166 /** |
| 167 * Load an empty partner bookmark shim for testing. The root node for bookma
rk will be an |
| 168 * empty node. |
| 169 */ |
| 170 @VisibleForTesting |
| 171 public void loadEmptyPartnerBookmarkShimForTesting() { |
| 172 nativeLoadEmptyPartnerBookmarkShimForTesting(mNativeBookmarksBridge); |
| 173 } |
| 174 |
| 175 /** |
165 * Add an observer to bookmark model changes. | 176 * Add an observer to bookmark model changes. |
166 * @param observer The observer to be added. | 177 * @param observer The observer to be added. |
167 */ | 178 */ |
168 public void addObserver(BookmarkModelObserver observer) { | 179 public void addObserver(BookmarkModelObserver observer) { |
169 mObservers.addObserver(observer); | 180 mObservers.addObserver(observer); |
170 } | 181 } |
171 | 182 |
172 /** | 183 /** |
173 * Remove an observer of bookmark model changes. | 184 * Remove an observer of bookmark model changes. |
174 * @param observer The observer to be removed. | 185 * @param observer The observer to be removed. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 267 |
257 /** | 268 /** |
258 * @return The BookmarkId for Mobile folder node | 269 * @return The BookmarkId for Mobile folder node |
259 */ | 270 */ |
260 public BookmarkId getMobileFolderId() { | 271 public BookmarkId getMobileFolderId() { |
261 assert mIsNativeBookmarkModelLoaded; | 272 assert mIsNativeBookmarkModelLoaded; |
262 return nativeGetMobileFolderId(mNativeBookmarksBridge); | 273 return nativeGetMobileFolderId(mNativeBookmarksBridge); |
263 } | 274 } |
264 | 275 |
265 /** | 276 /** |
| 277 * @return Id representing the special "other" folder from bookmark model. |
| 278 */ |
| 279 @VisibleForTesting |
| 280 public BookmarkId getOtherFolderId() { |
| 281 assert mIsNativeBookmarkModelLoaded; |
| 282 return nativeGetOtherFolderId(mNativeBookmarksBridge); |
| 283 } |
| 284 |
| 285 /** |
| 286 * @return BokmarkId representing special "desktop" folder, namely "bookmark
bar". |
| 287 */ |
| 288 @VisibleForTesting |
| 289 public BookmarkId getDesktopFolderId() { |
| 290 assert mIsNativeBookmarkModelLoaded; |
| 291 return nativeGetDesktopFolderId(mNativeBookmarksBridge); |
| 292 } |
| 293 |
| 294 /** |
266 * Reads sub-folder IDs, sub-bookmark IDs, or both of the given folder. | 295 * Reads sub-folder IDs, sub-bookmark IDs, or both of the given folder. |
267 * | 296 * |
268 * @param getFolders Whether sub-folders should be returned. | 297 * @param getFolders Whether sub-folders should be returned. |
269 * @param getBookmarks Whether sub-bookmarks should be returned. | 298 * @param getBookmarks Whether sub-bookmarks should be returned. |
270 * @return Child IDs of the given folder, with the specified type. | 299 * @return Child IDs of the given folder, with the specified type. |
271 */ | 300 */ |
272 public List<BookmarkId> getChildIDs(BookmarkId id, boolean getFolders, boole
an getBookmarks) { | 301 public List<BookmarkId> getChildIDs(BookmarkId id, boolean getFolders, boole
an getBookmarks) { |
273 assert mIsNativeBookmarkModelLoaded; | 302 assert mIsNativeBookmarkModelLoaded; |
274 List<BookmarkId> result = new ArrayList<BookmarkId>(); | 303 List<BookmarkId> result = new ArrayList<BookmarkId>(); |
275 nativeGetChildIDs(mNativeBookmarksBridge, | 304 nativeGetChildIDs(mNativeBookmarksBridge, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 * Move the bookmark to the new index within same folder or to a different f
older. | 404 * Move the bookmark to the new index within same folder or to a different f
older. |
376 * @param bookmarkId The id of the bookmark that is being moved. | 405 * @param bookmarkId The id of the bookmark that is being moved. |
377 * @param newParentId The parent folder id. | 406 * @param newParentId The parent folder id. |
378 * @param index The new index for the bookmark. | 407 * @param index The new index for the bookmark. |
379 */ | 408 */ |
380 public void moveBookmark(BookmarkId bookmarkId, BookmarkId newParentId, int
index) { | 409 public void moveBookmark(BookmarkId bookmarkId, BookmarkId newParentId, int
index) { |
381 nativeMoveBookmark(mNativeBookmarksBridge, bookmarkId, newParentId, inde
x); | 410 nativeMoveBookmark(mNativeBookmarksBridge, bookmarkId, newParentId, inde
x); |
382 } | 411 } |
383 | 412 |
384 /** | 413 /** |
| 414 * Add a new folder to the given parent folder |
| 415 * |
| 416 * @param parent Folder where to add. Must be a normal editable folder, inst
ead of a partner |
| 417 * bookmark folder or a managed bookomark folder or root node
of the entire |
| 418 * bookmark model. |
| 419 * @param index The position to locate the new folder |
| 420 * @param title The title text of the new folder |
| 421 * @return Id of the added node. If adding failed (index is invalid, string
is null, parent is |
| 422 * not editable), returns null. |
| 423 */ |
| 424 public BookmarkId addFolder(BookmarkId parent, int index, String title) { |
| 425 assert parent.getType() == BookmarkType.BOOKMARK_TYPE_NORMAL; |
| 426 assert index >= 0; |
| 427 assert title != null; |
| 428 |
| 429 return nativeAddFolder(mNativeBookmarksBridge, parent, index, title); |
| 430 } |
| 431 |
| 432 /** |
| 433 * Add a new bookmark to a specific position below parent |
| 434 * |
| 435 * @param parent Folder where to add. Must be a normal editable folder, inst
ead of a partner |
| 436 * bookmark folder or a managed bookomark folder or root node
of the entire |
| 437 * bookmark model. |
| 438 * @param index The position where the bookmark will be placed in parent fol
der |
| 439 * @param title Title of the new bookmark |
| 440 * @param url Url of the new bookmark |
| 441 * @return Id of the added node. If adding failed (index is invalid, string
is null, parent is |
| 442 * not editable), returns null. |
| 443 */ |
| 444 public BookmarkId addBookmark(BookmarkId parent, int index, String title, St
ring url) { |
| 445 assert parent.getType() == BookmarkType.BOOKMARK_TYPE_NORMAL; |
| 446 assert index >= 0; |
| 447 assert title != null; |
| 448 assert url != null; |
| 449 |
| 450 return nativeAddBookmark(mNativeBookmarksBridge, parent, index, title, u
rl); |
| 451 } |
| 452 |
| 453 /** |
385 * A bridge function to BookmarkModelFactory::GetForProfile. | 454 * A bridge function to BookmarkModelFactory::GetForProfile. |
386 */ | 455 */ |
387 public static long getNativeBookmarkModel(Profile profile) { | 456 public static long getNativeBookmarkModel(Profile profile) { |
388 return nativeGetNativeBookmarkModel(profile); | 457 return nativeGetNativeBookmarkModel(profile); |
389 } | 458 } |
390 | 459 |
391 public static boolean isEditBookmarksEnabled() { | 460 public static boolean isEditBookmarksEnabled() { |
392 return nativeIsEditBookmarksEnabled(); | 461 return nativeIsEditBookmarksEnabled(); |
393 } | 462 } |
394 | 463 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 List<BookmarkId> bookmarksList); | 587 List<BookmarkId> bookmarksList); |
519 private native void nativeGetTopLevelFolderParentIDs(long nativeBookmarksBri
dge, | 588 private native void nativeGetTopLevelFolderParentIDs(long nativeBookmarksBri
dge, |
520 List<BookmarkId> bookmarksList); | 589 List<BookmarkId> bookmarksList); |
521 private native void nativeGetTopLevelFolderIDs(long nativeBookmarksBridge, b
oolean getSpecial, | 590 private native void nativeGetTopLevelFolderIDs(long nativeBookmarksBridge, b
oolean getSpecial, |
522 boolean getNormal, List<BookmarkId> bookmarksList); | 591 boolean getNormal, List<BookmarkId> bookmarksList); |
523 private native void nativeGetUncategorizedBookmarkIDs(long nativeBookmarksBr
idge, | 592 private native void nativeGetUncategorizedBookmarkIDs(long nativeBookmarksBr
idge, |
524 List<BookmarkId> bookmarksList); | 593 List<BookmarkId> bookmarksList); |
525 private native void nativeGetAllFoldersWithDepths(long nativeBookmarksBridge
, | 594 private native void nativeGetAllFoldersWithDepths(long nativeBookmarksBridge
, |
526 List<BookmarkId> folderList, List<Integer> depthList); | 595 List<BookmarkId> folderList, List<Integer> depthList); |
527 private native BookmarkId nativeGetMobileFolderId(long nativeBookmarksBridge
); | 596 private native BookmarkId nativeGetMobileFolderId(long nativeBookmarksBridge
); |
| 597 private native BookmarkId nativeGetOtherFolderId(long nativeBookmarksBridge)
; |
| 598 private native BookmarkId nativeGetDesktopFolderId(long nativeBookmarksBridg
e); |
528 private native void nativeGetChildIDs(long nativeBookmarksBridge, long id, i
nt type, | 599 private native void nativeGetChildIDs(long nativeBookmarksBridge, long id, i
nt type, |
529 boolean getFolders, boolean getBookmarks, List<BookmarkId> bookmarks
List); | 600 boolean getFolders, boolean getBookmarks, List<BookmarkId> bookmarks
List); |
530 private native void nativeGetAllBookmarkIDsOrderedByCreationDate(long native
BookmarksBridge, | 601 private native void nativeGetAllBookmarkIDsOrderedByCreationDate(long native
BookmarksBridge, |
531 List<BookmarkId> result); | 602 List<BookmarkId> result); |
532 private native void nativeSetBookmarkTitle(long nativeBookmarksBridge, long
id, int type, | 603 private native void nativeSetBookmarkTitle(long nativeBookmarksBridge, long
id, int type, |
533 String title); | 604 String title); |
534 private native void nativeSetBookmarkUrl(long nativeBookmarksBridge, long id
, int type, | 605 private native void nativeSetBookmarkUrl(long nativeBookmarksBridge, long id
, int type, |
535 String url); | 606 String url); |
536 private native boolean nativeDoesBookmarkExist(long nativeBookmarksBridge, l
ong id, int type); | 607 private native boolean nativeDoesBookmarkExist(long nativeBookmarksBridge, l
ong id, int type); |
537 private native void nativeGetBookmarksForFolder(long nativeBookmarksBridge, | 608 private native void nativeGetBookmarksForFolder(long nativeBookmarksBridge, |
538 BookmarkId folderId, BookmarksCallback callback, | 609 BookmarkId folderId, BookmarksCallback callback, |
539 List<BookmarkItem> bookmarksList); | 610 List<BookmarkItem> bookmarksList); |
540 private native void nativeGetCurrentFolderHierarchy(long nativeBookmarksBrid
ge, | 611 private native void nativeGetCurrentFolderHierarchy(long nativeBookmarksBrid
ge, |
541 BookmarkId folderId, BookmarksCallback callback, | 612 BookmarkId folderId, BookmarksCallback callback, |
542 List<BookmarkItem> bookmarksList); | 613 List<BookmarkItem> bookmarksList); |
| 614 private native BookmarkId nativeAddFolder(long nativeBookmarksBridge, Bookma
rkId parent, |
| 615 int index, String title); |
543 private native void nativeDeleteBookmark(long nativeBookmarksBridge, Bookmar
kId bookmarkId); | 616 private native void nativeDeleteBookmark(long nativeBookmarksBridge, Bookmar
kId bookmarkId); |
544 private native void nativeMoveBookmark(long nativeBookmarksBridge, BookmarkI
d bookmarkId, | 617 private native void nativeMoveBookmark(long nativeBookmarksBridge, BookmarkI
d bookmarkId, |
545 BookmarkId newParentId, int index); | 618 BookmarkId newParentId, int index); |
| 619 private native BookmarkId nativeAddBookmark(long nativeBookmarksBridge, Book
markId parent, |
| 620 int index, String title, String url); |
546 private static native long nativeGetNativeBookmarkModel(Profile profile); | 621 private static native long nativeGetNativeBookmarkModel(Profile profile); |
547 private static native boolean nativeIsEnhancedBookmarksFeatureEnabled(Profil
e profile); | 622 private static native boolean nativeIsEnhancedBookmarksFeatureEnabled(Profil
e profile); |
| 623 private native void nativeLoadEmptyPartnerBookmarkShimForTesting(long native
BookmarksBridge); |
548 private native long nativeInit(Profile profile); | 624 private native long nativeInit(Profile profile); |
549 private native boolean nativeIsDoingExtensiveChanges(long nativeBookmarksBri
dge); | 625 private native boolean nativeIsDoingExtensiveChanges(long nativeBookmarksBri
dge); |
550 private native void nativeDestroy(long nativeBookmarksBridge); | 626 private native void nativeDestroy(long nativeBookmarksBridge); |
551 private static native boolean nativeIsEditBookmarksEnabled(); | 627 private static native boolean nativeIsEditBookmarksEnabled(); |
552 | 628 |
553 /** | 629 /** |
554 * Simple object representing the bookmark item. | 630 * Simple object representing the bookmark item. |
555 */ | 631 */ |
556 public static class BookmarkItem { | 632 public static class BookmarkItem { |
557 | 633 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 case GET_CURRENT_FOLDER_HIERARCHY: | 718 case GET_CURRENT_FOLDER_HIERARCHY: |
643 mHandler.getCurrentFolderHierarchy(mFolderId, mCallback); | 719 mHandler.getCurrentFolderHierarchy(mFolderId, mCallback); |
644 break; | 720 break; |
645 default: | 721 default: |
646 assert false; | 722 assert false; |
647 break; | 723 break; |
648 } | 724 } |
649 } | 725 } |
650 } | 726 } |
651 } | 727 } |
OLD | NEW |