| 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | package org.chromium.chrome.browser.profiles; |
| 6 | |
| 7 | import android.graphics.Bitmap; |
| 8 | |
| 9 | import org.chromium.base.CalledByNative; |
| 10 | |
| 11 | /** |
| 12 | * Methods to bridge into native history to provide most recent urls, titles and thumbnails. |
| 13 | */ |
| 14 | public class MostVisitedSites { |
| 15 | private Profile mProfile; |
| 16 | |
| 17 | /** |
| 18 | * Interface for callback object for fetching most visited urls. |
| 19 | */ |
| 20 | public interface MostVisitedURLsCallback { |
| 21 | /** |
| 22 | * Callback method for fetching most visited URLs. |
| 23 | * Parameters guaranteed to be non-null. |
| 24 | * |
| 25 | * @param titles Array of most visited url page titles. |
| 26 | * @param urls Array of most visited urls. |
| 27 | */ |
| 28 | @CalledByNative("MostVisitedURLsCallback") |
| 29 | public void onMostVisitedURLsAvailable(String[] titles, String[] urls); |
| 30 | } |
| 31 | |
| 32 | public interface ThumbnailCallback { |
| 33 | /** |
| 34 | * Callback method for fetching thumbnail of a most visited URL. |
| 35 | * Parameter may be null. |
| 36 | * |
| 37 | * @param thumbnail The bitmap thumbnail for the requested URL. |
| 38 | */ |
| 39 | @CalledByNative("ThumbnailCallback") |
| 40 | public void onMostVisitedURLsThumbnailAvailable(Bitmap thumbnail); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * MostVisitedSites constructor requires a valid user profile object. |
| 45 | * |
| 46 | * @param profile A valid user profile object. |
| 47 | */ |
| 48 | public MostVisitedSites(Profile profile) { |
| 49 | mProfile = profile; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Asynchronous method that fetches most visited urls and their page titles. |
| 54 | * |
| 55 | * @param callback Instance of a callback object. |
| 56 | * @param numResults Maximum number of results to return. |
| 57 | */ |
| 58 | public void getMostVisitedURLs(MostVisitedURLsCallback callback, int numResults) { |
| 59 | nativeGetMostVisitedURLs(mProfile, callback, numResults); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Fetches thumbnail bitmap for a url returned by getMostVisitedURLs. |
| 64 | * |
| 65 | * @param url String representation of url. |
| 66 | * @param callback Instance of a callback object. |
| 67 | */ |
| 68 | public void getURLThumbnail(String url, ThumbnailCallback callback) { |
| 69 | nativeGetURLThumbnail(mProfile, url, callback); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Blacklist a URL from the most visited URLs list. |
| 74 | * @param url The URL to be blacklisted. |
| 75 | */ |
| 76 | public void blacklistUrl(String url) { |
| 77 | nativeBlacklistUrl(mProfile, url); |
| 78 | } |
| 79 | |
| 80 | private static native void nativeGetMostVisitedURLs( |
| 81 | Profile profile, MostVisitedURLsCallback callback, int numResults); |
| 82 | private static native void nativeGetURLThumbnail( |
| 83 | Profile profile, String url, ThumbnailCallback callback); |
| 84 | private static native void nativeBlacklistUrl(Profile profile, String url); |
| 85 | } |