Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/suggestions/MostVisitedSitesBridge.java

Issue 2897293002: Adding CrHome-specific implementation for home page tile. (Closed)
Patch Set: Refactor tests and initialization Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5c099100f12c37c93c72404eefc6a489f18f1238 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,27 @@ public class MostVisitedSitesBridge implements MostVisitedSites {
*/
public MostVisitedSitesBridge(Profile profile) {
mNativeMostVisitedSitesBridge = nativeInit(profile);
+ // The first tile replaces the home page button (only) in Chrome Home. To support that,
+ // provide information about the home page.
+ if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_HOME)) {
+ nativeSetHomePageClient(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());
+ }
+ });
+ HomepageManager.getInstance(ContextUtils.getApplicationContext()).addListener(this);
+ }
}
/**
@@ -28,6 +56,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(ContextUtils.getApplicationContext()).removeListener(this);
assert mNativeMostVisitedSitesBridge != 0;
nativeDestroy(mNativeMostVisitedSitesBridge);
mNativeMostVisitedSitesBridge = 0;
@@ -76,10 +106,22 @@ 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(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 nativeSetHomePageClient(
+ long nativeMostVisitedSitesBridge, MostVisitedSites.HomePageClient homePageClient);
private native void nativeAddOrRemoveBlacklistedUrl(
long nativeMostVisitedSitesBridge, String url, boolean addUrl);
private native void nativeRecordPageImpression(

Powered by Google App Engine
This is Rietveld 408576698