Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/suggestions/MostVisitedSitesBridge.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/suggestions/MostVisitedSitesBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/suggestions/MostVisitedSitesBridge.java |
| index 78dacb10c4fbd1fb09c033f3f10fc6f0c0a647dc..c02ef2731f4cb8c203c9fdaafeda09544a4b7ce1 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/suggestions/MostVisitedSitesBridge.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/suggestions/MostVisitedSitesBridge.java |
| @@ -4,14 +4,21 @@ |
| package org.chromium.chrome.browser.suggestions; |
| +import android.text.TextUtils; |
| + |
| +import org.chromium.base.ContextUtils; |
| import org.chromium.base.annotations.JNIAdditionalImport; |
| +import org.chromium.chrome.browser.ChromeFeatureList; |
| +import org.chromium.chrome.browser.UrlConstants; |
| +import org.chromium.chrome.browser.partnercustomizations.HomepageManager; |
| import org.chromium.chrome.browser.profiles.Profile; |
| /** |
| * Methods to bridge into native history to provide most recent urls, titles and thumbnails. |
| */ |
| @JNIAdditionalImport(MostVisitedSites.class) // Needed for the Observer usage in the native calls. |
| -public class MostVisitedSitesBridge implements MostVisitedSites { |
| +public class MostVisitedSitesBridge |
| + implements MostVisitedSites, HomepageManager.HomepageStateListener { |
| private long mNativeMostVisitedSitesBridge; |
| /** |
| @@ -21,6 +28,11 @@ public class MostVisitedSitesBridge implements MostVisitedSites { |
| */ |
| public MostVisitedSitesBridge(Profile profile) { |
| mNativeMostVisitedSitesBridge = nativeInit(profile); |
| + // The first tile replaces the home page button (only) in Chrome Home. |
| + if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_HOME)) { |
| + initializeClient(); |
|
mastiz
2017/06/01 08:18:44
Not that I'm against your proposal, but just to cl
fhorschig
2017/06/01 10:12:56
Inlining seems to be the cleanest way (now).
|
| + HomepageManager.getInstance(ContextUtils.getApplicationContext()).addListener(this); |
| + } |
| } |
| /** |
| @@ -28,6 +40,8 @@ public class MostVisitedSitesBridge implements MostVisitedSites { |
| */ |
| @Override |
| public void destroy() { |
| + // Stop listening even if it was not started in the first place. (Handled without errors.) |
| + HomepageManager.getInstance(getApplicationContext()).removeListener(this); |
| assert mNativeMostVisitedSitesBridge != 0; |
| nativeDestroy(mNativeMostVisitedSitesBridge); |
| mNativeMostVisitedSitesBridge = 0; |
| @@ -76,10 +90,40 @@ public class MostVisitedSitesBridge implements MostVisitedSites { |
| nativeRecordOpenedMostVisitedItem(mNativeMostVisitedSitesBridge, index, type, source); |
| } |
| + @Override |
| + public void onHomepageStateUpdated() { |
| + assert mNativeMostVisitedSitesBridge != 0; |
| + // Ensure even a blacklisted home page can be set as tile when (re-)enabling it. |
| + if (HomepageManager.isHomepageEnabled(ContextUtils.getApplicationContext())) { |
| + removeBlacklistedUrl(HomepageManager.getHomepageUri(getApplicationContext())); |
| + } |
| + } |
| + |
| + private void initializeClient() { |
| + nativeSetClient(mNativeMostVisitedSitesBridge, new HomePageClient() { |
| + @Override |
| + public boolean isHomePageEnabled() { |
| + return HomepageManager.isHomepageEnabled(ContextUtils.getApplicationContext()); |
| + } |
| + |
| + @Override |
| + public boolean isNewTabPageUsedAsHomePage() { |
| + return TextUtils.equals(getHomePageUrl(), UrlConstants.NTP_URL); |
| + } |
| + |
| + @Override |
| + public String getHomePageUrl() { |
| + return HomepageManager.getHomepageUri(ContextUtils.getApplicationContext()); |
| + } |
| + }); |
| + } |
| + |
| private native long nativeInit(Profile profile); |
| private native void nativeDestroy(long nativeMostVisitedSitesBridge); |
| private native void nativeSetObserver( |
| long nativeMostVisitedSitesBridge, MostVisitedSites.Observer observer, int numSites); |
| + private native void nativeSetClient( |
| + long nativeMostVisitedSitesBridge, MostVisitedSites.HomePageClient homePageClient); |
| private native void nativeAddOrRemoveBlacklistedUrl( |
| long nativeMostVisitedSitesBridge, String url, boolean addUrl); |
| private native void nativeRecordPageImpression( |