| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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.banners; | 5 package org.chromium.chrome.browser.banners; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.text.TextUtils; | 8 import android.text.TextUtils; |
| 9 | 9 |
| 10 import org.chromium.base.ApplicationStatus; | 10 import org.chromium.base.ApplicationStatus; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 /** Retrieves information about a given package. */ | 34 /** Retrieves information about a given package. */ |
| 35 private static AppDetailsDelegate sAppDetailsDelegate; | 35 private static AppDetailsDelegate sAppDetailsDelegate; |
| 36 | 36 |
| 37 /** Whether the banners are enabled. */ | 37 /** Whether the banners are enabled. */ |
| 38 private static Boolean sIsEnabled; | 38 private static Boolean sIsEnabled; |
| 39 | 39 |
| 40 /** Pointer to the native side AppBannerManager. */ | 40 /** Pointer to the native side AppBannerManager. */ |
| 41 private long mNativePointer; | 41 private long mNativePointer; |
| 42 | 42 |
| 43 /** Tab that the AppBannerView/AppBannerManager is owned by. */ | |
| 44 private final Tab mTab; | |
| 45 | |
| 46 /** | 43 /** |
| 47 * Checks if app banners are enabled. | 44 * Checks if app banners are enabled. |
| 48 * @return True if banners are enabled, false otherwise. | 45 * @return True if banners are enabled, false otherwise. |
| 49 */ | 46 */ |
| 50 public static boolean isEnabled() { | 47 public static boolean isEnabled() { |
| 51 if (sIsEnabled == null) { | 48 if (sIsEnabled == null) { |
| 52 Context context = ApplicationStatus.getApplicationContext(); | 49 Context context = ApplicationStatus.getApplicationContext(); |
| 53 sIsEnabled = ShortcutHelper.isAddToHomeIntentSupported(context); | 50 sIsEnabled = ShortcutHelper.isAddToHomeIntentSupported(context); |
| 54 } | 51 } |
| 55 return sIsEnabled; | 52 return sIsEnabled; |
| 56 } | 53 } |
| 57 | 54 |
| 58 /** | 55 /** |
| 59 * Sets the delegate that provides information about a given package. | 56 * Sets the delegate that provides information about a given package. |
| 60 * @param delegate Delegate to use. Previously set ones are destroyed. | 57 * @param delegate Delegate to use. Previously set ones are destroyed. |
| 61 */ | 58 */ |
| 62 public static void setAppDetailsDelegate(AppDetailsDelegate delegate) { | 59 public static void setAppDetailsDelegate(AppDetailsDelegate delegate) { |
| 63 if (sAppDetailsDelegate != null) sAppDetailsDelegate.destroy(); | 60 if (sAppDetailsDelegate != null) sAppDetailsDelegate.destroy(); |
| 64 sAppDetailsDelegate = delegate; | 61 sAppDetailsDelegate = delegate; |
| 65 } | 62 } |
| 66 | 63 |
| 67 /** | 64 /** |
| 68 * Constructs an AppBannerManager for the given tab. | 65 * Constructs an AppBannerManager for the given tab. |
| 69 * @param tab Tab that the AppBannerManager will be attached to. | 66 * @param tab Tab that the AppBannerManager will be attached to. |
| 70 */ | 67 */ |
| 71 public AppBannerManager(Tab tab, Context context) { | 68 public AppBannerManager(Tab tab, Context context) { |
| 72 mNativePointer = nativeInit(); | 69 mNativePointer = nativeInit(); |
| 73 mTab = tab; | 70 updatePointers(tab); |
| 74 updatePointers(); | |
| 75 } | 71 } |
| 76 | 72 |
| 77 @Override | 73 @Override |
| 78 public void onWebContentsSwapped(Tab tab, boolean didStartLoad, | 74 public void onWebContentsSwapped(Tab tab, boolean didStartLoad, |
| 79 boolean didFinishLoad) { | 75 boolean didFinishLoad) { |
| 80 updatePointers(); | 76 updatePointers(tab); |
| 81 } | 77 } |
| 82 | 78 |
| 83 @Override | 79 @Override |
| 84 public void onContentChanged(Tab tab) { | 80 public void onContentChanged(Tab tab) { |
| 85 updatePointers(); | 81 updatePointers(tab); |
| 86 } | 82 } |
| 87 | 83 |
| 88 /** | 84 /** |
| 89 * Destroys the native AppBannerManager. | 85 * Destroys the native AppBannerManager. |
| 90 */ | 86 */ |
| 91 public void destroy() { | 87 public void destroy() { |
| 92 nativeDestroy(mNativePointer); | 88 nativeDestroy(mNativePointer); |
| 93 mNativePointer = 0; | 89 mNativePointer = 0; |
| 94 } | 90 } |
| 95 | 91 |
| 96 /** | 92 /** |
| 97 * Updates which WebContents the native AppBannerManager is monitoring. | 93 * Updates which WebContents the native AppBannerManager is monitoring. |
| 98 */ | 94 */ |
| 99 private void updatePointers() { | 95 private void updatePointers(Tab tab) { |
| 100 nativeReplaceWebContents(mNativePointer, mTab.getWebContents()); | 96 nativeReplaceWebContents(mNativePointer, tab.getWebContents()); |
| 101 } | 97 } |
| 102 | 98 |
| 103 /** | 99 /** |
| 104 * Grabs package information for the banner asynchronously. | 100 * Grabs package information for the banner asynchronously. |
| 105 * @param url URL for the page that is triggering the banner. | 101 * @param url URL for the page that is triggering the banner. |
| 106 * @param packageName Name of the package that is being advertised. | 102 * @param packageName Name of the package that is being advertised. |
| 107 */ | 103 */ |
| 108 @CalledByNative | 104 @CalledByNative |
| 109 private void fetchAppDetails( | 105 private void fetchAppDetails( |
| 110 String url, String packageName, String referrer, int iconSizeInDp) { | 106 String url, String packageName, String referrer, int iconSizeInDp) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 AppData data, String title, String packageName, String imageUrl); | 176 AppData data, String title, String packageName, String imageUrl); |
| 181 private native void nativeRequestAppBanner(long nativeAppBannerManagerAndroi
d); | 177 private native void nativeRequestAppBanner(long nativeAppBannerManagerAndroi
d); |
| 182 | 178 |
| 183 // Testing methods. | 179 // Testing methods. |
| 184 private static native void nativeSetTimeDeltaForTesting(int days); | 180 private static native void nativeSetTimeDeltaForTesting(int days); |
| 185 private static native void nativeDisableSecureSchemeCheckForTesting(); | 181 private static native void nativeDisableSecureSchemeCheckForTesting(); |
| 186 private static native void nativeSetEngagementWeights(double directEngagemen
t, | 182 private static native void nativeSetEngagementWeights(double directEngagemen
t, |
| 187 double indirectEngagement); | 183 double indirectEngagement); |
| 188 private native boolean nativeIsFetcherActive(long nativeAppBannerManagerAndr
oid); | 184 private native boolean nativeIsFetcherActive(long nativeAppBannerManagerAndr
oid); |
| 189 } | 185 } |
| OLD | NEW |