1 // Copyright 2014 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 package org.chromium.chrome.browser;
7 import android.graphics.Bitmap;
9 import org.chromium.base.CalledByNative;
10 import org.chromium.chrome.browser.profiles.Profile;
13 * Provides access to the search provider's logo via the C++ LogoService.
15 public class LogoBridge {
18 * A logo for a search provider (e.g. the Yahoo! logo or Google doodle).
20 public static class Logo {
22 * The logo image. Non-null.
24 public final Bitmap image;
27 * The URL to navigate to when the user clicks on the logo. May be null.
29 public final String onClickUrl;
32 * The accessibility text describing the logo. May be null.
34 public final String altText;
36 public Logo(Bitmap image, String onClickUrl, String altText) {
38 this.onClickUrl = onClickUrl;
39 this.altText = altText;
44 * Observer for receiving the logo when it's available.
46 public interface LogoObserver {
48 * Called when the cached or fresh logo is available. This may be called up to two times,
49 * once with the cached logo and once with a freshly downloaded logo.
51 * @param logo The search provider's logo.
52 * @param fromCache Whether the logo was loaded from the cache.
54 @CalledByNative("LogoObserver")
55 public void onLogoAvailable(Logo logo, boolean fromCache);
58 private long mNativeLogoBridge;
61 * Creates a LogoBridge for getting the logo of the default search provider.
63 * @param profile Profile of the tab that will show the logo.
65 public LogoBridge(Profile profile) {
66 mNativeLogoBridge = nativeInit(profile);
70 * Cleans up the C++ side of this class. After calling this, LogoObservers passed to
71 * getCurrentLogo() will no longer receive updates.
73 public void destroy() {
74 assert mNativeLogoBridge != 0;
75 nativeDestroy(mNativeLogoBridge);
76 mNativeLogoBridge = 0;
80 * Gets the current logo for the default search provider.
82 * @param logoObserver The observer to receive the cached and/or fresh logos when they're
83 * available. logoObserver.onLogoAvailable() may be called synchronously if
84 * the cached logo is already available.
86 public void getCurrentLogo(LogoObserver logoObserver) {
87 nativeGetCurrentLogo(mNativeLogoBridge, logoObserver);
91 protected void finalize() {
92 // Ensure that destroy() was called.
93 assert mNativeLogoBridge == 0;
97 private static Logo createLogo(Bitmap image, String onClickUrl, String altText) {
98 return new Logo(image, onClickUrl, altText);
101 private native long nativeInit(Profile profile);
102 private native void nativeGetCurrentLogo(long nativeLogoBridge, LogoObserver logoObserver);
103 private native void nativeDestroy(long nativeLogoBridge);