| Index: chrome/android/java/src/org/chromium/chrome/browser/banners/AppBannerManager.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/banners/AppBannerManager.java b/chrome/android/java/src/org/chromium/chrome/browser/banners/AppBannerManager.java
|
| index 6e85f5f5f46b790747b45180a9599c7eb956e1d0..b8e42298a42a78db4305cf4273ede864350777cb 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/banners/AppBannerManager.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/banners/AppBannerManager.java
|
| @@ -4,7 +4,6 @@
|
|
|
| package org.chromium.chrome.browser.banners;
|
|
|
| -import android.app.PendingIntent;
|
| import android.text.TextUtils;
|
|
|
| import org.chromium.base.ApplicationStatus;
|
| @@ -13,23 +12,21 @@ import org.chromium.base.JNINamespace;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.EmptyTabObserver;
|
| import org.chromium.chrome.browser.Tab;
|
| -import org.chromium.content.browser.ContentViewCore;
|
| import org.chromium.content_public.browser.WebContents;
|
|
|
| /**
|
| - * Manages an AppBannerView for a Tab and its ContentView.
|
| + * Manages an AppBannerInfoBar for a Tab.
|
| *
|
| - * The AppBannerManager manages a single AppBannerView, dismissing it when the user navigates to a
|
| - * new page or creating a new one when it detects that the current webpage is requesting a banner to
|
| - * be built. The actual observation of the WebContents (which triggers the automatic creation and
|
| - * removal of banners, among other things) is done by the native-side AppBannerManager.
|
| + * The AppBannerManager manages a single AppBannerInfoBar, creating a new one when it detects that
|
| + * the current webpage is requesting a banner to be built. The actual observation of the WebContents
|
| + * (which triggers the automatic creation and removal of banners, among other things) is done by the
|
| + * native-side AppBannerManager.
|
| *
|
| * This Java-side class owns its native-side counterpart, which is basically used to grab resources
|
| * from the network.
|
| */
|
| @JNINamespace("banners")
|
| -public class AppBannerManager extends EmptyTabObserver
|
| - implements AppBannerView.Observer, AppDetailsDelegate.Observer {
|
| +public class AppBannerManager extends EmptyTabObserver implements AppDetailsDelegate.Observer {
|
| private static final String TAG = "AppBannerManager";
|
|
|
| /** Retrieves information about a given package. */
|
| @@ -41,15 +38,6 @@ public class AppBannerManager extends EmptyTabObserver
|
| /** Tab that the AppBannerView/AppBannerManager is owned by. */
|
| private final Tab mTab;
|
|
|
| - /** ContentViewCore that the AppBannerView/AppBannerManager is currently attached to. */
|
| - private ContentViewCore mContentViewCore;
|
| -
|
| - /** Current banner being shown. */
|
| - private AppBannerView mBannerView;
|
| -
|
| - /** Data about the app being advertised. */
|
| - private AppData mAppData;
|
| -
|
| /**
|
| * Checks if app banners are enabled.
|
| * @return True if banners are enabled, false otherwise.
|
| @@ -93,15 +81,12 @@ public class AppBannerManager extends EmptyTabObserver
|
| */
|
| public void destroy() {
|
| nativeDestroy(mNativePointer);
|
| - resetState();
|
| }
|
|
|
| /**
|
| - * Updates which ContentView and WebContents the AppBannerView is monitoring.
|
| + * Updates which WebContents the native AppBannerManager is monitoring.
|
| */
|
| private void updatePointers() {
|
| - if (mContentViewCore != mTab.getContentViewCore())
|
| - mContentViewCore = mTab.getContentViewCore();
|
| nativeReplaceWebContents(mNativePointer, mTab.getWebContents());
|
| }
|
|
|
| @@ -117,9 +102,8 @@ public class AppBannerManager extends EmptyTabObserver
|
| * @param packageName Name of the package that is being advertised.
|
| */
|
| @CalledByNative
|
| - private void prepareBanner(String url, String packageName) {
|
| - if (sAppDetailsDelegate == null || !isBannerForCurrentPage(url)) return;
|
| -
|
| + private void fetchAppDetails(String url, String packageName) {
|
| + if (sAppDetailsDelegate == null) return;
|
| int iconSize = getPreferredIconSize();
|
| sAppDetailsDelegate.getAppDetailsAsynchronously(this, url, packageName, iconSize);
|
| }
|
| @@ -131,63 +115,13 @@ public class AppBannerManager extends EmptyTabObserver
|
| */
|
| @Override
|
| public void onAppDetailsRetrieved(AppData data) {
|
| - if (data == null || !isBannerForCurrentPage(data.siteUrl())) return;
|
| + if (data == null) return;
|
|
|
| - mAppData = data;
|
| String imageUrl = data.imageUrl();
|
| - if (TextUtils.isEmpty(imageUrl) || !nativeFetchIcon(mNativePointer, imageUrl)) resetState();
|
| - }
|
| -
|
| - @Override
|
| - public void onBannerRemoved(AppBannerView banner) {
|
| - if (mBannerView != banner) return;
|
| - resetState();
|
| - }
|
| -
|
| - @Override
|
| - public void onBannerBlocked(AppBannerView banner, String url, String packageName) {
|
| - if (mBannerView != banner) return;
|
| - nativeBlockBanner(mNativePointer, url, packageName);
|
| - }
|
| -
|
| - @Override
|
| - public void onBannerDismissEvent(AppBannerView banner, int eventType) {
|
| - if (mBannerView != banner) return;
|
| - nativeRecordDismissEvent(eventType);
|
| - }
|
| + if (TextUtils.isEmpty(imageUrl)) return;
|
|
|
| - @Override
|
| - public void onBannerInstallEvent(AppBannerView banner, int eventType) {
|
| - if (mBannerView != banner) return;
|
| - nativeRecordInstallEvent(eventType);
|
| - }
|
| -
|
| - @Override
|
| - public boolean onFireIntent(AppBannerView banner, PendingIntent intent) {
|
| - if (mBannerView != banner) return false;
|
| - return mTab.getWindowAndroid().showIntent(intent, banner, R.string.low_memory_error);
|
| - }
|
| -
|
| - /**
|
| - * Resets all of the state, killing off any running tasks.
|
| - */
|
| - private void resetState() {
|
| - if (mBannerView != null) {
|
| - mBannerView.destroy();
|
| - mBannerView = null;
|
| - }
|
| -
|
| - mAppData = null;
|
| - }
|
| -
|
| - /**
|
| - * Checks to see if the banner is for the currently displayed page.
|
| - * @param bannerUrl URL that requested a banner.
|
| - * @return True if the user is still on the same page.
|
| - */
|
| - private boolean isBannerForCurrentPage(String bannerUrl) {
|
| - return mContentViewCore != null
|
| - && TextUtils.equals(mContentViewCore.getWebContents().getUrl(), bannerUrl);
|
| + nativeOnAppDetailsRetrieved(
|
| + mNativePointer, data, data.title(), data.packageName(), data.imageUrl());
|
| }
|
|
|
| private static native boolean nativeIsEnabled();
|
| @@ -195,9 +129,8 @@ public class AppBannerManager extends EmptyTabObserver
|
| private native void nativeDestroy(long nativeAppBannerManager);
|
| private native void nativeReplaceWebContents(long nativeAppBannerManager,
|
| WebContents webContents);
|
| - private native void nativeBlockBanner(
|
| - long nativeAppBannerManager, String url, String packageName);
|
| - private native boolean nativeFetchIcon(long nativeAppBannerManager, String imageUrl);
|
| + private native boolean nativeOnAppDetailsRetrieved(long nativeAppBannerManager, AppData data,
|
| + String title, String packageName, String imageUrl);
|
|
|
| // UMA tracking.
|
| private static native void nativeRecordDismissEvent(int metric);
|
|
|