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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java

Issue 2124243002: Refactor the Java AppBannerManager to be owned by native code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing reviewer comments Created 4 years, 5 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.tab; 5 package org.chromium.chrome.browser.tab;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.content.res.Resources; 10 import android.content.res.Resources;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 173
174 /** Whether or not this {@link Tab} is initialized and should be interacted with. */ 174 /** Whether or not this {@link Tab} is initialized and should be interacted with. */
175 private boolean mIsInitialized; 175 private boolean mIsInitialized;
176 176
177 /** The current native page (e.g. chrome-native://newtab), or {@code null} i f there is none. */ 177 /** The current native page (e.g. chrome-native://newtab), or {@code null} i f there is none. */
178 private NativePage mNativePage; 178 private NativePage mNativePage;
179 179
180 /** InfoBar container to show InfoBars for this tab. */ 180 /** InfoBar container to show InfoBars for this tab. */
181 private InfoBarContainer mInfoBarContainer; 181 private InfoBarContainer mInfoBarContainer;
182 182
183 /** Manages app banners shown for this tab. */
184 private AppBannerManager mAppBannerManager;
185
186 /** Controls overscroll pull-to-refresh behavior for this tab. */ 183 /** Controls overscroll pull-to-refresh behavior for this tab. */
187 private SwipeRefreshHandler mSwipeRefreshHandler; 184 private SwipeRefreshHandler mSwipeRefreshHandler;
188 185
189 /** The sync id of the Tab if session sync is enabled. */ 186 /** The sync id of the Tab if session sync is enabled. */
190 private int mSyncId; 187 private int mSyncId;
191 188
192 /** {@link ContentViewCore} showing the current page, or {@code null} if the tab is frozen. */ 189 /** {@link ContentViewCore} showing the current page, or {@code null} if the tab is frozen. */
193 private ContentViewCore mContentViewCore; 190 private ContentViewCore mContentViewCore;
194 191
195 /** Listens to gesture events fired by the ContentViewCore. */ 192 /** Listens to gesture events fired by the ContentViewCore. */
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 public final void initialize(WebContents webContents, TabContentManager tabC ontentManager, 1425 public final void initialize(WebContents webContents, TabContentManager tabC ontentManager,
1429 TabDelegateFactory delegateFactory, boolean initiallyHidden, boolean unfreeze) { 1426 TabDelegateFactory delegateFactory, boolean initiallyHidden, boolean unfreeze) {
1430 try { 1427 try {
1431 TraceEvent.begin("Tab.initialize"); 1428 TraceEvent.begin("Tab.initialize");
1432 1429
1433 mDelegateFactory = delegateFactory; 1430 mDelegateFactory = delegateFactory;
1434 initializeNative(); 1431 initializeNative();
1435 1432
1436 RevenueStats.getInstance().tabCreated(this); 1433 RevenueStats.getInstance().tabCreated(this);
1437 1434
1438 if (AppBannerManager.isEnabled()) {
1439 mAppBannerManager = mDelegateFactory.createAppBannerManager(this );
1440 if (mAppBannerManager != null) addObserver(mAppBannerManager);
1441 }
1442
1443 mTopControlsVisibilityDelegate = 1435 mTopControlsVisibilityDelegate =
1444 mDelegateFactory.createTopControlsVisibilityDelegate(this); 1436 mDelegateFactory.createTopControlsVisibilityDelegate(this);
1445 1437
1446 // Attach the TabContentManager if we have one. This will bind this Tab's content layer 1438 // Attach the TabContentManager if we have one. This will bind this Tab's content layer
1447 // to this manager. 1439 // to this manager.
1448 // TODO(dtrainor): Remove this and move to a pull model instead of p ushing the layer. 1440 // TODO(dtrainor): Remove this and move to a pull model instead of p ushing the layer.
1449 attachTabContentManager(tabContentManager); 1441 attachTabContentManager(tabContentManager);
1450 1442
1451 // If there is a frozen WebContents state or a pending lazy load, do n't create a new 1443 // If there is a frozen WebContents state or a pending lazy load, do n't create a new
1452 // WebContents. 1444 // WebContents.
(...skipping 11 matching lines...) Expand all
1464 1456
1465 if (contentViewCore == null) { 1457 if (contentViewCore == null) {
1466 initContentViewCore(webContents); 1458 initContentViewCore(webContents);
1467 } else { 1459 } else {
1468 setContentViewCore(contentViewCore); 1460 setContentViewCore(contentViewCore);
1469 } 1461 }
1470 1462
1471 if (!creatingWebContents && webContents.isLoadingToDifferentDocument ()) { 1463 if (!creatingWebContents && webContents.isLoadingToDifferentDocument ()) {
1472 didStartPageLoad(webContents.getUrl(), false); 1464 didStartPageLoad(webContents.getUrl(), false);
1473 } 1465 }
1466
1467 getAppBannerManager().setIsEnabledForTab(mDelegateFactory.canShowApp Banners(this));
1474 } finally { 1468 } finally {
1475 if (mTimestampMillis == INVALID_TIMESTAMP) { 1469 if (mTimestampMillis == INVALID_TIMESTAMP) {
1476 mTimestampMillis = System.currentTimeMillis(); 1470 mTimestampMillis = System.currentTimeMillis();
1477 } 1471 }
1478 1472
1479 TraceEvent.end("Tab.initialize"); 1473 TraceEvent.end("Tab.initialize");
1480 } 1474 }
1481 } 1475 }
1482 1476
1483 /** 1477 /**
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 mFullscreenManager = activity.getFullscreenManager(); 1548 mFullscreenManager = activity.getFullscreenManager();
1555 activity.getCompositorViewHolder().prepareForTabReparenting(); 1549 activity.getCompositorViewHolder().prepareForTabReparenting();
1556 1550
1557 // Update the delegate factory, then recreate and propagate all delegate s. 1551 // Update the delegate factory, then recreate and propagate all delegate s.
1558 mDelegateFactory = tabDelegateFactory; 1552 mDelegateFactory = tabDelegateFactory;
1559 mWebContentsDelegate = mDelegateFactory.createWebContentsDelegate(this); 1553 mWebContentsDelegate = mDelegateFactory.createWebContentsDelegate(this);
1560 nativeUpdateDelegates(mNativeTabAndroid, 1554 nativeUpdateDelegates(mNativeTabAndroid,
1561 mWebContentsDelegate, mDelegateFactory.createContextMenuPopulato r(this)); 1555 mWebContentsDelegate, mDelegateFactory.createContextMenuPopulato r(this));
1562 mTopControlsVisibilityDelegate = mDelegateFactory.createTopControlsVisib ilityDelegate(this); 1556 mTopControlsVisibilityDelegate = mDelegateFactory.createTopControlsVisib ilityDelegate(this);
1563 setInterceptNavigationDelegate(mDelegateFactory.createInterceptNavigatio nDelegate(this)); 1557 setInterceptNavigationDelegate(mDelegateFactory.createInterceptNavigatio nDelegate(this));
1564 mAppBannerManager = mDelegateFactory.createAppBannerManager(this); 1558 getAppBannerManager().setIsEnabledForTab(mDelegateFactory.canShowAppBann ers(this));
1565 1559
1566 // Reload the NativePage (if any), since the old NativePage has a refere nce to the old 1560 // Reload the NativePage (if any), since the old NativePage has a refere nce to the old
1567 // activity. 1561 // activity.
1568 maybeShowNativePage(getUrl(), true); 1562 maybeShowNativePage(getUrl(), true);
1569 1563
1570 reparentingParams.finalizeTabReparenting(); 1564 reparentingParams.finalizeTabReparenting();
1571 mIsDetachedForReparenting = false; 1565 mIsDetachedForReparenting = false;
1572 1566
1573 for (TabObserver observer : mObservers) { 1567 for (TabObserver observer : mObservers) {
1574 observer.onReparentingFinished(this); 1568 observer.onReparentingFinished(this);
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 // expects all infobars to be cleaned up before its own destruction. 2018 // expects all infobars to be cleaned up before its own destruction.
2025 assert mNativeTabAndroid != 0; 2019 assert mNativeTabAndroid != 0;
2026 nativeDestroy(mNativeTabAndroid); 2020 nativeDestroy(mNativeTabAndroid);
2027 assert mNativeTabAndroid == 0; 2021 assert mNativeTabAndroid == 0;
2028 2022
2029 if (mInfoBarContainer != null) { 2023 if (mInfoBarContainer != null) {
2030 mInfoBarContainer.destroy(); 2024 mInfoBarContainer.destroy();
2031 mInfoBarContainer = null; 2025 mInfoBarContainer = null;
2032 } 2026 }
2033 2027
2034 // Destroy the AppBannerManager after the InfoBarContainer because it mo nitors for infobar
2035 // removals.
2036 if (mAppBannerManager != null) {
2037 mAppBannerManager.destroy();
2038 mAppBannerManager = null;
2039 }
2040
2041 mPreviousFullscreenTopControlsOffsetY = Float.NaN; 2028 mPreviousFullscreenTopControlsOffsetY = Float.NaN;
2042 mPreviousFullscreenContentOffsetY = Float.NaN; 2029 mPreviousFullscreenContentOffsetY = Float.NaN;
2043 2030
2044 mNeedsReload = false; 2031 mNeedsReload = false;
2045 } 2032 }
2046 2033
2047 /** 2034 /**
2048 * @return Whether or not this Tab has a live native component. This will b e true prior to 2035 * @return Whether or not this Tab has a live native component. This will b e true prior to
2049 * {@link #initializeNative()} being called or after {@link #destroy ()}. 2036 * {@link #initializeNative()} being called or after {@link #destroy ()}.
2050 */ 2037 */
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 if (!mContentViewCore.getWebContents().getLastCommittedUrl().equals("")) { 2508 if (!mContentViewCore.getWebContents().getLastCommittedUrl().equals("")) {
2522 ChildProcessLauncher.determinedVisibility(mContentViewCore.getCurren tRenderProcessId()); 2509 ChildProcessLauncher.determinedVisibility(mContentViewCore.getCurren tRenderProcessId());
2523 } 2510 }
2524 2511
2525 destroyNativePageInternal(previousNativePage); 2512 destroyNativePageInternal(previousNativePage);
2526 for (TabObserver observer : mObservers) { 2513 for (TabObserver observer : mObservers) {
2527 observer.onWebContentsSwapped(this, didStartLoad, didFinishLoad); 2514 observer.onWebContentsSwapped(this, didStartLoad, didFinishLoad);
2528 } 2515 }
2529 } 2516 }
2530 2517
2531 /** Requests the app banner. This method is called from the DevTools. */
2532 protected boolean requestAppBanner() {
2533 if (mAppBannerManager == null) return false;
2534 mAppBannerManager.requestAppBanner();
2535 return true;
2536 }
2537
2538 @CalledByNative 2518 @CalledByNative
2539 private void clearNativePtr() { 2519 private void clearNativePtr() {
2540 assert mNativeTabAndroid != 0; 2520 assert mNativeTabAndroid != 0;
2541 mNativeTabAndroid = 0; 2521 mNativeTabAndroid = 0;
2542 } 2522 }
2543 2523
2544 @CalledByNative 2524 @CalledByNative
2545 private void setNativePtr(long nativePtr) { 2525 private void setNativePtr(long nativePtr) {
2546 assert mNativeTabAndroid == 0; 2526 assert mNativeTabAndroid == 0;
2547 mNativeTabAndroid = nativePtr; 2527 mNativeTabAndroid = nativePtr;
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
2996 /** 2976 /**
2997 * @return the TabRedirectHandler for the tab. 2977 * @return the TabRedirectHandler for the tab.
2998 */ 2978 */
2999 public TabRedirectHandler getTabRedirectHandler() { 2979 public TabRedirectHandler getTabRedirectHandler() {
3000 return mTabRedirectHandler; 2980 return mTabRedirectHandler;
3001 } 2981 }
3002 2982
3003 /** 2983 /**
3004 * @return the AppBannerManager. 2984 * @return the AppBannerManager.
3005 */ 2985 */
3006 @VisibleForTesting 2986 public AppBannerManager getAppBannerManager() {
3007 public AppBannerManager getAppBannerManagerForTesting() { 2987 return AppBannerManager.getAppBannerManagerForWebContents(getWebContents ());
3008 return mAppBannerManager;
3009 } 2988 }
3010 2989
3011 @VisibleForTesting 2990 @VisibleForTesting
3012 public boolean hasPrerenderedUrl(String url) { 2991 public boolean hasPrerenderedUrl(String url) {
3013 return nativeHasPrerenderedUrl(mNativeTabAndroid, url); 2992 return nativeHasPrerenderedUrl(mNativeTabAndroid, url);
3014 } 2993 }
3015 2994
3016 /** 2995 /**
3017 * @return the UMA object for the tab. Note that this may be null in some 2996 * @return the UMA object for the tab. Note that this may be null in some
3018 * cases. 2997 * cases.
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
3269 private native void nativeSetInterceptNavigationDelegate(long nativeTabAndro id, 3248 private native void nativeSetInterceptNavigationDelegate(long nativeTabAndro id,
3270 InterceptNavigationDelegate delegate); 3249 InterceptNavigationDelegate delegate);
3271 private native void nativeAttachToTabContentManager(long nativeTabAndroid, 3250 private native void nativeAttachToTabContentManager(long nativeTabAndroid,
3272 TabContentManager tabContentManager); 3251 TabContentManager tabContentManager);
3273 private native void nativeAttachOverlayContentViewCore(long nativeTabAndroid , 3252 private native void nativeAttachOverlayContentViewCore(long nativeTabAndroid ,
3274 ContentViewCore content, boolean visible); 3253 ContentViewCore content, boolean visible);
3275 private native void nativeDetachOverlayContentViewCore(long nativeTabAndroid , 3254 private native void nativeDetachOverlayContentViewCore(long nativeTabAndroid ,
3276 ContentViewCore content); 3255 ContentViewCore content);
3277 private native boolean nativeHasPrerenderedUrl(long nativeTabAndroid, String url); 3256 private native boolean nativeHasPrerenderedUrl(long nativeTabAndroid, String url);
3278 } 3257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698