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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/banners/AppBannerManager.java

Issue 932263002: [App banners] Stop passing JNI barrier to get icon size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing Created 5 years, 10 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 unified diff | Download patch
OLDNEW
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.text.TextUtils; 8 import android.text.TextUtils;
8 9
9 import org.chromium.base.ApplicationStatus;
10 import org.chromium.base.CalledByNative; 10 import org.chromium.base.CalledByNative;
11 import org.chromium.base.JNINamespace; 11 import org.chromium.base.JNINamespace;
12 import org.chromium.base.VisibleForTesting; 12 import org.chromium.base.VisibleForTesting;
13 import org.chromium.chrome.R; 13 import org.chromium.chrome.R;
14 import org.chromium.chrome.browser.EmptyTabObserver; 14 import org.chromium.chrome.browser.EmptyTabObserver;
15 import org.chromium.chrome.browser.Tab; 15 import org.chromium.chrome.browser.Tab;
16 import org.chromium.content_public.browser.WebContents; 16 import org.chromium.content_public.browser.WebContents;
17 17
18 /** 18 /**
19 * Manages an AppBannerInfoBar for a Tab. 19 * Manages an AppBannerInfoBar for a Tab.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 */ 57 */
58 public static void setAppDetailsDelegate(AppDetailsDelegate delegate) { 58 public static void setAppDetailsDelegate(AppDetailsDelegate delegate) {
59 if (sAppDetailsDelegate != null) sAppDetailsDelegate.destroy(); 59 if (sAppDetailsDelegate != null) sAppDetailsDelegate.destroy();
60 sAppDetailsDelegate = delegate; 60 sAppDetailsDelegate = delegate;
61 } 61 }
62 62
63 /** 63 /**
64 * Constructs an AppBannerManager for the given tab. 64 * Constructs an AppBannerManager for the given tab.
65 * @param tab Tab that the AppBannerManager will be attached to. 65 * @param tab Tab that the AppBannerManager will be attached to.
66 */ 66 */
67 public AppBannerManager(Tab tab) { 67 public AppBannerManager(Tab tab, Context context) {
68 mNativePointer = nativeInit(); 68 int iconSize = context.getResources().getDimensionPixelSize(R.dimen.app_ banner_icon_size);
69 mNativePointer = nativeInit(iconSize);
69 mTab = tab; 70 mTab = tab;
70 updatePointers(); 71 updatePointers();
71 } 72 }
72 73
73 @Override 74 @Override
74 public void onWebContentsSwapped(Tab tab, boolean didStartLoad, 75 public void onWebContentsSwapped(Tab tab, boolean didStartLoad,
75 boolean didFinishLoad) { 76 boolean didFinishLoad) {
76 updatePointers(); 77 updatePointers();
77 } 78 }
78 79
79 @Override 80 @Override
80 public void onContentChanged(Tab tab) { 81 public void onContentChanged(Tab tab) {
81 updatePointers(); 82 updatePointers();
82 } 83 }
83 84
84 /** 85 /**
85 * Destroys the native AppBannerManager. 86 * Destroys the native AppBannerManager.
86 */ 87 */
87 public void destroy() { 88 public void destroy() {
88 nativeDestroy(mNativePointer); 89 nativeDestroy(mNativePointer);
89 } 90 }
90 91
91 /** 92 /**
92 * Updates which WebContents the native AppBannerManager is monitoring. 93 * Updates which WebContents the native AppBannerManager is monitoring.
93 */ 94 */
94 private void updatePointers() { 95 private void updatePointers() {
95 nativeReplaceWebContents(mNativePointer, mTab.getWebContents()); 96 nativeReplaceWebContents(mNativePointer, mTab.getWebContents());
96 } 97 }
97 98
98 @CalledByNative
99 private int getPreferredIconSize() {
100 return ApplicationStatus.getApplicationContext().getResources().getDimen sionPixelSize(
101 R.dimen.app_banner_icon_size);
102 }
103
104 /** 99 /**
105 * Grabs package information for the banner asynchronously. 100 * Grabs package information for the banner asynchronously.
106 * @param url URL for the page that is triggering the banner. 101 * @param url URL for the page that is triggering the banner.
107 * @param packageName Name of the package that is being advertised. 102 * @param packageName Name of the package that is being advertised.
108 */ 103 */
109 @CalledByNative 104 @CalledByNative
110 private void fetchAppDetails(String url, String packageName) { 105 private void fetchAppDetails(String url, String packageName, int iconSize) {
111 if (sAppDetailsDelegate == null) return; 106 if (sAppDetailsDelegate == null) return;
112 int iconSize = getPreferredIconSize();
113 sAppDetailsDelegate.getAppDetailsAsynchronously( 107 sAppDetailsDelegate.getAppDetailsAsynchronously(
114 createAppDetailsObserver(), url, packageName, iconSize); 108 createAppDetailsObserver(), url, packageName, iconSize);
115 } 109 }
116 110
117 private AppDetailsDelegate.Observer createAppDetailsObserver() { 111 private AppDetailsDelegate.Observer createAppDetailsObserver() {
118 return new AppDetailsDelegate.Observer() { 112 return new AppDetailsDelegate.Observer() {
119 /** 113 /**
120 * Called when data about the package has been retrieved, which incl udes the url for the 114 * Called when data about the package has been retrieved, which incl udes the url for the
121 * app's icon but not the icon Bitmap itself. 115 * app's icon but not the icon Bitmap itself.
122 * @param data Data about the app. Null if the task failed. 116 * @param data Data about the app. Null if the task failed.
(...skipping 23 matching lines...) Expand all
146 nativeSetTimeDeltaForTesting(days); 140 nativeSetTimeDeltaForTesting(days);
147 } 141 }
148 142
149 /** Returns whether a BitmapFetcher is actively retrieving an app icon. */ 143 /** Returns whether a BitmapFetcher is actively retrieving an app icon. */
150 @VisibleForTesting 144 @VisibleForTesting
151 public boolean isFetcherActiveForTesting() { 145 public boolean isFetcherActiveForTesting() {
152 return nativeIsFetcherActive(mNativePointer); 146 return nativeIsFetcherActive(mNativePointer);
153 } 147 }
154 148
155 private static native boolean nativeIsEnabled(); 149 private static native boolean nativeIsEnabled();
156 private native long nativeInit(); 150 private native long nativeInit(int iconSize);
157 private native void nativeDestroy(long nativeAppBannerManager); 151 private native void nativeDestroy(long nativeAppBannerManager);
158 private native void nativeReplaceWebContents(long nativeAppBannerManager, 152 private native void nativeReplaceWebContents(long nativeAppBannerManager,
159 WebContents webContents); 153 WebContents webContents);
160 private native boolean nativeOnAppDetailsRetrieved(long nativeAppBannerManag er, AppData data, 154 private native boolean nativeOnAppDetailsRetrieved(long nativeAppBannerManag er, AppData data,
161 String title, String packageName, String imageUrl); 155 String title, String packageName, String imageUrl);
162 156
163 // Testing methods. 157 // Testing methods.
164 private static native void nativeSetTimeDeltaForTesting(int days); 158 private static native void nativeSetTimeDeltaForTesting(int days);
165 private native boolean nativeIsFetcherActive(long nativeAppBannerManager); 159 private native boolean nativeIsFetcherActive(long nativeAppBannerManager);
166 } 160 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/Tab.java ('k') | chrome/browser/android/banners/app_banner_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698