Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.infobar; | 5 package org.chromium.chrome.browser.infobar; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.support.annotation.StringRes; | |
| 8 import android.view.Gravity; | 9 import android.view.Gravity; |
| 9 import android.view.View; | 10 import android.view.View; |
| 10 import android.view.ViewGroup; | 11 import android.view.ViewGroup; |
| 11 import android.widget.FrameLayout; | 12 import android.widget.FrameLayout; |
| 12 | 13 |
| 13 import org.chromium.base.ObserverList; | 14 import org.chromium.base.ObserverList; |
| 14 import org.chromium.base.VisibleForTesting; | 15 import org.chromium.base.VisibleForTesting; |
| 15 import org.chromium.base.annotations.CalledByNative; | 16 import org.chromium.base.annotations.CalledByNative; |
| 16 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
| 17 import org.chromium.chrome.browser.banners.SwipableOverlayView; | 18 import org.chromium.chrome.browser.banners.SwipableOverlayView; |
| 19 import org.chromium.chrome.browser.feature_engagement_tracker.FeatureEngagementT rackerFactory; | |
| 20 import org.chromium.chrome.browser.profiles.Profile; | |
| 18 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 21 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| 19 import org.chromium.chrome.browser.tab.Tab; | 22 import org.chromium.chrome.browser.tab.Tab; |
| 20 import org.chromium.chrome.browser.tab.TabObserver; | 23 import org.chromium.chrome.browser.tab.TabObserver; |
| 24 import org.chromium.chrome.browser.widget.textbubble.ViewAnchoredTextBubble; | |
| 25 import org.chromium.components.feature_engagement_tracker.FeatureConstants; | |
| 26 import org.chromium.components.feature_engagement_tracker.FeatureEngagementTrack er; | |
| 21 import org.chromium.content.browser.ContentViewCore; | 27 import org.chromium.content.browser.ContentViewCore; |
| 22 import org.chromium.content_public.browser.WebContents; | 28 import org.chromium.content_public.browser.WebContents; |
| 23 import org.chromium.ui.UiUtils; | 29 import org.chromium.ui.UiUtils; |
| 24 import org.chromium.ui.base.DeviceFormFactor; | 30 import org.chromium.ui.base.DeviceFormFactor; |
| 25 | 31 |
| 26 import java.util.ArrayList; | 32 import java.util.ArrayList; |
| 27 | 33 |
| 28 | 34 |
| 29 /** | 35 /** |
| 30 * A container for all the infobars of a specific tab. | 36 * A container for all the infobars of a specific tab. |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 | 256 |
| 251 // We add the infobar immediately to mInfoBars but we wait for the anima tion to end to | 257 // We add the infobar immediately to mInfoBars but we wait for the anima tion to end to |
| 252 // notify it's been added, as tests rely on this notification but expect s the infobar view | 258 // notify it's been added, as tests rely on this notification but expect s the infobar view |
| 253 // to be available when they get the notification. | 259 // to be available when they get the notification. |
| 254 mInfoBars.add(infoBar); | 260 mInfoBars.add(infoBar); |
| 255 infoBar.setContext(getContext()); | 261 infoBar.setContext(getContext()); |
| 256 infoBar.setInfoBarContainer(this); | 262 infoBar.setInfoBarContainer(this); |
| 257 infoBar.createView(); | 263 infoBar.createView(); |
| 258 | 264 |
| 259 mLayout.addInfoBar(infoBar); | 265 mLayout.addInfoBar(infoBar); |
| 266 | |
| 267 showFeatureEngagementForInfoBar(infoBar); | |
|
David Trainor- moved to gerrit
2017/04/12 08:41:20
Hmm this doesn't mean the infobar is showing. Wou
gone
2017/04/12 17:12:44
Maybe see when InfoBarAnimationListener fires?
| |
| 260 } | 268 } |
| 261 | 269 |
| 262 /** | 270 /** |
| 263 * Notifies that an infobar's View ({@link InfoBar#getView}) has changed. If the infobar is | 271 * Notifies that an infobar's View ({@link InfoBar#getView}) has changed. If the infobar is |
|
David Trainor- moved to gerrit
2017/04/12 08:41:20
So in this case I guess the iph would just get dis
gone
2017/04/12 17:12:44
Maybe. This might happen when something like tran
| |
| 264 * visible, a view swapping animation will be run. | 272 * visible, a view swapping animation will be run. |
| 265 */ | 273 */ |
| 266 public void notifyInfoBarViewChanged() { | 274 public void notifyInfoBarViewChanged() { |
| 267 assert !mDestroyed; | 275 assert !mDestroyed; |
| 268 mLayout.notifyInfoBarViewChanged(); | 276 mLayout.notifyInfoBarViewChanged(); |
| 269 } | 277 } |
| 270 | 278 |
| 271 /** | 279 /** |
| 272 * Called by {@link InfoBar} to remove itself from the view hierarchy. | 280 * Called by {@link InfoBar} to remove itself from the view hierarchy. |
| 273 * | 281 * |
| 274 * @param infoBar InfoBar to remove from the View hierarchy. | 282 * @param infoBar InfoBar to remove from the View hierarchy. |
| 275 */ | 283 */ |
| 276 void removeInfoBar(InfoBar infoBar) { | 284 void removeInfoBar(InfoBar infoBar) { |
| 277 assert !mDestroyed; | 285 assert !mDestroyed; |
| 278 | 286 |
| 279 if (!mInfoBars.remove(infoBar)) { | 287 if (!mInfoBars.remove(infoBar)) { |
| 280 assert false : "Trying to remove an InfoBar that is not in this cont ainer."; | 288 assert false : "Trying to remove an InfoBar that is not in this cont ainer."; |
| 281 return; | 289 return; |
| 282 } | 290 } |
| 283 | 291 |
| 284 // Notify observers immediately, before any animations begin. | 292 // Notify observers immediately, before any animations begin. |
| 285 for (InfoBarContainerObserver observer : mObservers) { | 293 for (InfoBarContainerObserver observer : mObservers) { |
| 286 observer.onRemoveInfoBar(this, infoBar, mInfoBars.isEmpty()); | 294 observer.onRemoveInfoBar(this, infoBar, mInfoBars.isEmpty()); |
| 287 } | 295 } |
| 288 | 296 |
| 289 mLayout.removeInfoBar(infoBar); | 297 mLayout.removeInfoBar(infoBar); |
| 290 } | 298 } |
| 291 | 299 |
| 300 private void showFeatureEngagementForInfoBar(InfoBar infoBar) { | |
| 301 String feature = null; | |
| 302 @StringRes | |
| 303 int text = 0; | |
| 304 switch (infoBar.getInfoBarIdentifier()) { | |
| 305 case InfoBarIdentifier.DATA_REDUCTION_PROXY_PREVIEW_INFOBAR_DELEGATE : | |
| 306 feature = FeatureConstants.DATA_SAVER_PREVIEW; | |
| 307 text = R.string.iph_data_saver_preview_text; | |
| 308 break; | |
| 309 } | |
| 310 | |
| 311 if (feature == null) return; | |
| 312 | |
| 313 Profile profile = Profile.getLastUsedProfile(); | |
| 314 final FeatureEngagementTracker tracker = | |
| 315 FeatureEngagementTrackerFactory.getFeatureEngagementTrackerForPr ofile(profile); | |
| 316 if (!tracker.shouldTriggerHelpUI(feature)) return; | |
| 317 | |
| 318 ViewAnchoredTextBubble bubble = | |
| 319 new ViewAnchoredTextBubble(getContext(), infoBar.getView(), text ); | |
| 320 bubble.setDismissOnTouchInteraction(true); | |
| 321 bubble.setOnDismissListener(new OnDismissListener() { | |
| 322 @Override | |
| 323 public void onDismiss() { | |
| 324 tracker.dismissed(); | |
| 325 } | |
| 326 }); | |
| 327 bubble.show(); | |
| 328 } | |
| 329 | |
| 292 /** | 330 /** |
| 293 * @return True when this container has been emptied and its native counterp art has been | 331 * @return True when this container has been emptied and its native counterp art has been |
| 294 * destroyed. | 332 * destroyed. |
| 295 */ | 333 */ |
| 296 public boolean hasBeenDestroyed() { | 334 public boolean hasBeenDestroyed() { |
| 297 return mDestroyed; | 335 return mDestroyed; |
| 298 } | 336 } |
| 299 | 337 |
| 300 public void destroy() { | 338 public void destroy() { |
| 301 mDestroyed = true; | 339 mDestroyed = true; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 } | 429 } |
| 392 | 430 |
| 393 super.onLayout(changed, l, t, r, b); | 431 super.onLayout(changed, l, t, r, b); |
| 394 } | 432 } |
| 395 | 433 |
| 396 private native long nativeInit(); | 434 private native long nativeInit(); |
| 397 private native void nativeSetWebContents( | 435 private native void nativeSetWebContents( |
| 398 long nativeInfoBarContainerAndroid, WebContents webContents); | 436 long nativeInfoBarContainerAndroid, WebContents webContents); |
| 399 private native void nativeDestroy(long nativeInfoBarContainerAndroid); | 437 private native void nativeDestroy(long nativeInfoBarContainerAndroid); |
| 400 } | 438 } |
| OLD | NEW |