| 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.favicon; | 5 package org.chromium.chrome.browser.favicon; |
| 6 | 6 |
| 7 import android.graphics.Bitmap; | 7 import android.graphics.Bitmap; |
| 8 import android.graphics.Color; | 8 import android.graphics.Color; |
| 9 | 9 |
| 10 import org.chromium.base.annotations.CalledByNative; | 10 import org.chromium.base.annotations.CalledByNative; |
| 11 import org.chromium.chrome.browser.profiles.Profile; | 11 import org.chromium.chrome.browser.profiles.Profile; |
| 12 import org.chromium.content_public.browser.WebContents; |
| 12 | 13 |
| 13 /** | 14 /** |
| 14 * This is a helper class to use favicon_service.cc's functionality. | 15 * This is a helper class to use favicon_service.cc's functionality. |
| 15 * | 16 * |
| 16 * You can request a favicon image by web page URL. Note that an instance of | 17 * You can request a favicon image by web page URL. Note that an instance of |
| 17 * this class should be created & used & destroyed (by destroy()) in the same | 18 * this class should be created & used & destroyed (by destroy()) in the same |
| 18 * thread due to the C++ base::CancelableTaskTracker class | 19 * thread due to the C++ base::CancelableTaskTracker class |
| 19 * requirement. | 20 * requirement. |
| 20 */ | 21 */ |
| 21 public class FaviconHelper { | 22 public class FaviconHelper { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 35 /** | 36 /** |
| 36 * This method will be called when the result favicon is ready. | 37 * This method will be called when the result favicon is ready. |
| 37 * @param image Favicon image. | 38 * @param image Favicon image. |
| 38 * @param iconUrl Favicon image's icon url. | 39 * @param iconUrl Favicon image's icon url. |
| 39 */ | 40 */ |
| 40 @CalledByNative("FaviconImageCallback") | 41 @CalledByNative("FaviconImageCallback") |
| 41 public void onFaviconAvailable(Bitmap image, String iconUrl); | 42 public void onFaviconAvailable(Bitmap image, String iconUrl); |
| 42 } | 43 } |
| 43 | 44 |
| 44 /** | 45 /** |
| 46 * Callback interface for the result of the ensureFaviconIsAvailable method. |
| 47 */ |
| 48 public interface FaviconAvailabilityCallback { |
| 49 /** |
| 50 * This method will be called when the availability of the favicon has b
een checked. |
| 51 * @param newlyAvailable true if the favicon was downloaded and is now a
vailable, |
| 52 * false if the favicon was already there or the download fai
led. |
| 53 */ |
| 54 @CalledByNative("FaviconAvailabilityCallback") |
| 55 public void onFaviconAvailabilityChecked(boolean newlyAvailable); |
| 56 } |
| 57 |
| 58 /** |
| 45 * Allocate and initialize the C++ side of this class. | 59 * Allocate and initialize the C++ side of this class. |
| 46 */ | 60 */ |
| 47 public FaviconHelper() { | 61 public FaviconHelper() { |
| 48 mNativeFaviconHelper = nativeInit(); | 62 mNativeFaviconHelper = nativeInit(); |
| 49 } | 63 } |
| 50 | 64 |
| 51 /** | 65 /** |
| 52 * Clean up the C++ side of this class. After the call, this class instance
shouldn't be used. | 66 * Clean up the C++ side of this class. After the call, this class instance
shouldn't be used. |
| 53 */ | 67 */ |
| 54 public void destroy() { | 68 public void destroy() { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 * @param profile Profile used for the FaviconService construction. | 131 * @param profile Profile used for the FaviconService construction. |
| 118 * @param pageUrl The target Page URL to get the favicon. | 132 * @param pageUrl The target Page URL to get the favicon. |
| 119 * | 133 * |
| 120 * @return 16x16 favicon Bitmap corresponding to the pageUrl. | 134 * @return 16x16 favicon Bitmap corresponding to the pageUrl. |
| 121 */ | 135 */ |
| 122 public Bitmap getSyncedFaviconImageForURL(Profile profile, String pageUrl) { | 136 public Bitmap getSyncedFaviconImageForURL(Profile profile, String pageUrl) { |
| 123 assert mNativeFaviconHelper != 0; | 137 assert mNativeFaviconHelper != 0; |
| 124 return nativeGetSyncedFaviconImageForURL(mNativeFaviconHelper, profile,
pageUrl); | 138 return nativeGetSyncedFaviconImageForURL(mNativeFaviconHelper, profile,
pageUrl); |
| 125 } | 139 } |
| 126 | 140 |
| 141 public void ensureFaviconIsAvailable( |
| 142 Profile profile, WebContents webContents, String pageUrl, String fav
iconUrl, |
| 143 FaviconAvailabilityCallback callback) { |
| 144 nativeEnsureFaviconIsAvailable( |
| 145 mNativeFaviconHelper, profile, webContents, pageUrl, faviconUrl,
callback); |
| 146 } |
| 147 |
| 127 private static native long nativeInit(); | 148 private static native long nativeInit(); |
| 128 private static native void nativeDestroy(long nativeFaviconHelper); | 149 private static native void nativeDestroy(long nativeFaviconHelper); |
| 129 private static native boolean nativeGetLocalFaviconImageForURL(long nativeFa
viconHelper, | 150 private static native boolean nativeGetLocalFaviconImageForURL(long nativeFa
viconHelper, |
| 130 Profile profile, String pageUrl, int iconTypes, int desiredSizeInDip
, | 151 Profile profile, String pageUrl, int iconTypes, int desiredSizeInDip
, |
| 131 FaviconImageCallback faviconImageCallback); | 152 FaviconImageCallback faviconImageCallback); |
| 132 private static native void nativeGetLargestRawFaviconForUrl(long nativeFavic
onHelper, | 153 private static native void nativeGetLargestRawFaviconForUrl(long nativeFavic
onHelper, |
| 133 Profile profile, String pageUrl, int[] iconTypes, int minSizeThresho
ldPx, | 154 Profile profile, String pageUrl, int[] iconTypes, int minSizeThresho
ldPx, |
| 134 FaviconImageCallback faviconImageCallback); | 155 FaviconImageCallback faviconImageCallback); |
| 135 private static native Bitmap nativeGetSyncedFaviconImageForURL(long nativeFa
viconHelper, | 156 private static native Bitmap nativeGetSyncedFaviconImageForURL(long nativeFa
viconHelper, |
| 136 Profile profile, String pageUrl); | 157 Profile profile, String pageUrl); |
| 137 private static native int nativeGetDominantColorForBitmap(Bitmap image); | 158 private static native int nativeGetDominantColorForBitmap(Bitmap image); |
| 159 private static native void nativeEnsureFaviconIsAvailable( |
| 160 long nativeFaviconHelper, Profile profile, WebContents webContents,
String pageUrl, |
| 161 String faviconUrl, FaviconAvailabilityCallback callback); |
| 138 } | 162 } |
| OLD | NEW |