Chromium Code Reviews| 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.tab; | 5 package org.chromium.chrome.browser.tab; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.app.Application; | 9 import android.app.Application; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 private float mPreviousBottomControlsOffsetY = Float.NaN; | 345 private float mPreviousBottomControlsOffsetY = Float.NaN; |
| 346 private float mPreviousContentOffsetY = Float.NaN; | 346 private float mPreviousContentOffsetY = Float.NaN; |
| 347 | 347 |
| 348 /** | 348 /** |
| 349 * Indicates whether this tab is detached from any activity and its correspo nding | 349 * Indicates whether this tab is detached from any activity and its correspo nding |
| 350 * {@link WindowAndroid}. | 350 * {@link WindowAndroid}. |
| 351 */ | 351 */ |
| 352 private boolean mIsDetached; | 352 private boolean mIsDetached; |
| 353 | 353 |
| 354 /** | 354 /** |
| 355 * Indicates whether the history of this tab should be separated from Chrome history. | |
| 356 * This is true only for startSpeculation in CCT. | |
| 357 */ | |
| 358 private boolean mIsHistoryDetached; | |
| 359 | |
| 360 /** | |
| 355 * The UMA object used to report stats for this tab. Note that this may be n ull under certain | 361 * The UMA object used to report stats for this tab. Note that this may be n ull under certain |
| 356 * conditions, such as incognito mode. | 362 * conditions, such as incognito mode. |
| 357 */ | 363 */ |
| 358 private TabUma mTabUma; | 364 private TabUma mTabUma; |
| 359 | 365 |
| 360 /** | 366 /** |
| 361 * Reference to the current sadTabView if one is defined. | 367 * Reference to the current sadTabView if one is defined. |
| 362 */ | 368 */ |
| 363 private View mSadTabView; | 369 private View mSadTabView; |
| 364 | 370 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 public Tab(int id, int parentId, boolean incognito, Context context, | 491 public Tab(int id, int parentId, boolean incognito, Context context, |
| 486 WindowAndroid window, TabLaunchType type, TabCreationState creationS tate, | 492 WindowAndroid window, TabLaunchType type, TabCreationState creationS tate, |
| 487 TabState frozenState) { | 493 TabState frozenState) { |
| 488 mId = TabIdManager.getInstance().generateValidId(id); | 494 mId = TabIdManager.getInstance().generateValidId(id); |
| 489 mParentId = parentId; | 495 mParentId = parentId; |
| 490 mIncognito = incognito; | 496 mIncognito = incognito; |
| 491 mThemedApplicationContext = context != null ? new ContextThemeWrapper( | 497 mThemedApplicationContext = context != null ? new ContextThemeWrapper( |
| 492 context.getApplicationContext(), ChromeActivity.getThemeId()) : null; | 498 context.getApplicationContext(), ChromeActivity.getThemeId()) : null; |
| 493 mWindowAndroid = window; | 499 mWindowAndroid = window; |
| 494 mLaunchType = type; | 500 mLaunchType = type; |
| 495 if (mLaunchType == TabLaunchType.FROM_DETACHED) mIsDetached = true; | 501 if (mLaunchType == TabLaunchType.FROM_DETACHED_SPECULATE |
| 502 || mLaunchType == TabLaunchType.FROM_DETACHED_USER_ACTION) { | |
| 503 mIsDetached = true; | |
| 504 } | |
| 505 if (mLaunchType == TabLaunchType.FROM_DETACHED_SPECULATE) mIsHistoryDeta ched = true; | |
| 496 if (mThemedApplicationContext != null) { | 506 if (mThemedApplicationContext != null) { |
| 497 Resources resources = mThemedApplicationContext.getResources(); | 507 Resources resources = mThemedApplicationContext.getResources(); |
| 498 mIdealFaviconSize = resources.getDimensionPixelSize(R.dimen.default_ favicon_size); | 508 mIdealFaviconSize = resources.getDimensionPixelSize(R.dimen.default_ favicon_size); |
| 499 mDefaultThemeColor = mIncognito | 509 mDefaultThemeColor = mIncognito |
| 500 ? ApiCompatibilityUtils.getColor(resources, R.color.incognit o_primary_color) | 510 ? ApiCompatibilityUtils.getColor(resources, R.color.incognit o_primary_color) |
| 501 : ApiCompatibilityUtils.getColor(resources, R.color.default_ primary_color); | 511 : ApiCompatibilityUtils.getColor(resources, R.color.default_ primary_color); |
| 502 mThemeColor = calculateThemeColor(false); | 512 mThemeColor = calculateThemeColor(false); |
| 503 } else { | 513 } else { |
| 504 mIdealFaviconSize = 16; | 514 mIdealFaviconSize = 16; |
| 505 mDefaultThemeColor = 0; | 515 mDefaultThemeColor = 0; |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1287 } | 1297 } |
| 1288 } | 1298 } |
| 1289 | 1299 |
| 1290 ContentViewCore contentViewCore = ContentViewCore.fromWebContents(we bContents); | 1300 ContentViewCore contentViewCore = ContentViewCore.fromWebContents(we bContents); |
| 1291 | 1301 |
| 1292 if (contentViewCore == null) { | 1302 if (contentViewCore == null) { |
| 1293 initContentViewCore(webContents); | 1303 initContentViewCore(webContents); |
| 1294 } else { | 1304 } else { |
| 1295 setContentViewCore(contentViewCore); | 1305 setContentViewCore(contentViewCore); |
| 1296 } | 1306 } |
| 1297 | |
| 1298 mContentViewCore.addImeEventObserver(new ImeEventObserver() { | 1307 mContentViewCore.addImeEventObserver(new ImeEventObserver() { |
| 1299 @Override | 1308 @Override |
| 1300 public void onImeEvent() { | 1309 public void onImeEvent() { |
| 1301 // Some text was set in the page. Don't reuse it if a tab is | 1310 // Some text was set in the page. Don't reuse it if a tab is |
| 1302 // open from the same external application, we might lose so me | 1311 // open from the same external application, we might lose so me |
| 1303 // user data. | 1312 // user data. |
| 1304 mAppAssociatedWith = null; | 1313 mAppAssociatedWith = null; |
| 1305 } | 1314 } |
| 1306 | 1315 |
| 1307 @Override | 1316 @Override |
| 1308 public void onNodeAttributeUpdated(boolean editable, boolean pas sword) { | 1317 public void onNodeAttributeUpdated(boolean editable, boolean pas sword) { |
| 1309 if (getFullscreenManager() == null) return; | 1318 if (getFullscreenManager() == null) return; |
| 1310 updateFullscreenEnabledState(); | 1319 updateFullscreenEnabledState(); |
| 1311 } | 1320 } |
| 1312 }); | 1321 }); |
| 1313 | 1322 |
| 1314 if (!creatingWebContents && webContents.isLoadingToDifferentDocument ()) { | 1323 if (!creatingWebContents && webContents.isLoadingToDifferentDocument ()) { |
| 1315 didStartPageLoad(webContents.getUrl(), false); | 1324 didStartPageLoad(webContents.getUrl(), false); |
| 1316 } | 1325 } |
| 1317 | |
| 1318 getAppBannerManager().setIsEnabledForTab(mDelegateFactory.canShowApp Banners(this)); | 1326 getAppBannerManager().setIsEnabledForTab(mDelegateFactory.canShowApp Banners(this)); |
| 1319 } finally { | 1327 } finally { |
| 1320 if (mTimestampMillis == INVALID_TIMESTAMP) { | 1328 if (mTimestampMillis == INVALID_TIMESTAMP) { |
| 1321 mTimestampMillis = System.currentTimeMillis(); | 1329 mTimestampMillis = System.currentTimeMillis(); |
| 1322 } | 1330 } |
| 1323 | 1331 |
| 1324 TraceEvent.end("Tab.initialize"); | 1332 TraceEvent.end("Tab.initialize"); |
| 1325 } | 1333 } |
| 1326 } | 1334 } |
| 1327 | 1335 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1420 mWebContentsDelegate = mDelegateFactory.createWebContentsDelegate(this); | 1428 mWebContentsDelegate = mDelegateFactory.createWebContentsDelegate(this); |
| 1421 nativeUpdateDelegates(mNativeTabAndroid, | 1429 nativeUpdateDelegates(mNativeTabAndroid, |
| 1422 mWebContentsDelegate, mDelegateFactory.createContextMenuPopulato r(this)); | 1430 mWebContentsDelegate, mDelegateFactory.createContextMenuPopulato r(this)); |
| 1423 mBrowserControlsVisibilityDelegate = | 1431 mBrowserControlsVisibilityDelegate = |
| 1424 mDelegateFactory.createBrowserControlsVisibilityDelegate(this); | 1432 mDelegateFactory.createBrowserControlsVisibilityDelegate(this); |
| 1425 setInterceptNavigationDelegate(mDelegateFactory.createInterceptNavigatio nDelegate(this)); | 1433 setInterceptNavigationDelegate(mDelegateFactory.createInterceptNavigatio nDelegate(this)); |
| 1426 getAppBannerManager().setIsEnabledForTab(mDelegateFactory.canShowAppBann ers(this)); | 1434 getAppBannerManager().setIsEnabledForTab(mDelegateFactory.canShowAppBann ers(this)); |
| 1427 | 1435 |
| 1428 reparentingParams.finalizeTabReparenting(); | 1436 reparentingParams.finalizeTabReparenting(); |
| 1429 mIsDetached = false; | 1437 mIsDetached = false; |
| 1438 mIsHistoryDetached = false; | |
| 1430 nativeAttachDetachedTab(mNativeTabAndroid); | 1439 nativeAttachDetachedTab(mNativeTabAndroid); |
| 1431 | 1440 |
| 1432 // Reload the NativePage (if any), since the old NativePage has a refere nce to the old | 1441 // Reload the NativePage (if any), since the old NativePage has a refere nce to the old |
| 1433 // activity. | 1442 // activity. |
| 1434 maybeShowNativePage(getUrl(), true); | 1443 maybeShowNativePage(getUrl(), true); |
| 1435 | 1444 |
| 1436 mIsTabStateDirty = true; | 1445 mIsTabStateDirty = true; |
| 1437 | 1446 |
| 1438 for (TabObserver observer : mObservers) { | 1447 for (TabObserver observer : mObservers) { |
| 1439 observer.onReparentingFinished(this); | 1448 observer.onReparentingFinished(this); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1663 cvc.getContainerView().setOnSystemUiVisibilityChangeListener(this); | 1672 cvc.getContainerView().setOnSystemUiVisibilityChangeListener(this); |
| 1664 | 1673 |
| 1665 mContentView = cvc.getContainerView(); | 1674 mContentView = cvc.getContainerView(); |
| 1666 mWebContentsDelegate = mDelegateFactory.createWebContentsDelegate(th is); | 1675 mWebContentsDelegate = mDelegateFactory.createWebContentsDelegate(th is); |
| 1667 mWebContentsObserver = | 1676 mWebContentsObserver = |
| 1668 new TabWebContentsObserver(mContentViewCore.getWebContents() , this); | 1677 new TabWebContentsObserver(mContentViewCore.getWebContents() , this); |
| 1669 | 1678 |
| 1670 mDownloadDelegate = new ChromeDownloadDelegate(mThemedApplicationCon text, this); | 1679 mDownloadDelegate = new ChromeDownloadDelegate(mThemedApplicationCon text, this); |
| 1671 | 1680 |
| 1672 assert mNativeTabAndroid != 0; | 1681 assert mNativeTabAndroid != 0; |
| 1673 nativeInitWebContents(mNativeTabAndroid, mIncognito, mIsDetached, | 1682 nativeInitWebContents(mNativeTabAndroid, mIncognito, mIsHistoryDetac hed, |
|
Yusuf
2017/07/18 22:59:47
This param is for isBackgroundTab, right? Is that
ltian
2017/08/07 23:24:12
New design will open all tabs in lazy load mode so
| |
| 1674 mContentViewCore.getWebContents(), mWebContentsDelegate, | 1683 mContentViewCore.getWebContents(), mWebContentsDelegate, |
| 1675 new TabContextMenuPopulator( | 1684 new TabContextMenuPopulator( |
| 1676 mDelegateFactory.createContextMenuPopulator(this), t his)); | 1685 mDelegateFactory.createContextMenuPopulator(this), t his)); |
| 1677 | 1686 |
| 1678 // In the case where restoring a Tab or showing a prerendered one we already have a | 1687 // In the case where restoring a Tab or showing a prerendered one we already have a |
| 1679 // valid infobar container, no need to recreate one. | 1688 // valid infobar container, no need to recreate one. |
| 1680 if (mInfoBarContainer == null) { | 1689 if (mInfoBarContainer == null) { |
| 1681 WindowAndroid windowAndroid = getWindowAndroid(); | 1690 WindowAndroid windowAndroid = getWindowAndroid(); |
| 1682 Activity activity = | 1691 Activity activity = |
| 1683 windowAndroid == null ? null : windowAndroid.getActivity ().get(); | 1692 windowAndroid == null ? null : windowAndroid.getActivity ().get(); |
| (...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2947 } | 2956 } |
| 2948 | 2957 |
| 2949 /** | 2958 /** |
| 2950 * Creates an instance of a {@link Tab} that is fully detached from any acti vity. | 2959 * Creates an instance of a {@link Tab} that is fully detached from any acti vity. |
| 2951 * Also performs general tab initialization as well as detached specifics. | 2960 * Also performs general tab initialization as well as detached specifics. |
| 2952 * | 2961 * |
| 2953 * The current application context must allow the creation of a WindowAndroi d. | 2962 * The current application context must allow the creation of a WindowAndroi d. |
| 2954 * | 2963 * |
| 2955 * @return The newly created and initialized tab. | 2964 * @return The newly created and initialized tab. |
| 2956 */ | 2965 */ |
| 2957 public static Tab createDetached(TabDelegateFactory delegateFactory) { | 2966 public static Tab createDetached(TabDelegateFactory delegateFactory, boolean byUserAction) { |
| 2958 Context context = ContextUtils.getApplicationContext(); | 2967 Context context = ContextUtils.getApplicationContext(); |
| 2959 WindowAndroid windowAndroid = new WindowAndroid(context); | 2968 WindowAndroid windowAndroid = new WindowAndroid(context); |
| 2960 Tab tab = new Tab(INVALID_TAB_ID, INVALID_TAB_ID, false, context, window Android, | 2969 TabLaunchType launchType = byUserAction ? TabLaunchType.FROM_DETACHED_US ER_ACTION |
| 2961 TabLaunchType.FROM_DETACHED, null, null); | 2970 : TabLaunchType.FROM_DETACHED_SP ECULATE; |
| 2971 Tab tab = new Tab(INVALID_TAB_ID, INVALID_TAB_ID, false, context, window Android, launchType, | |
| 2972 null, null); | |
| 2962 tab.initialize(null, null, delegateFactory, true, false); | 2973 tab.initialize(null, null, delegateFactory, true, false); |
| 2963 | 2974 |
| 2964 // Resize the webContent to avoid expensive post load resize when attach ing the tab. | 2975 // Resize the webContent to avoid expensive post load resize when attach ing the tab. |
| 2965 Rect bounds = ExternalPrerenderHandler.estimateContentSize((Application) context, false); | 2976 Rect bounds = ExternalPrerenderHandler.estimateContentSize((Application) context, false); |
| 2966 int width = bounds.right - bounds.left; | 2977 int width = bounds.right - bounds.left; |
| 2967 int height = bounds.bottom - bounds.top; | 2978 int height = bounds.bottom - bounds.top; |
| 2968 tab.getContentViewCore().onSizeChanged(width, height, 0, 0); | 2979 tab.getContentViewCore().onSizeChanged(width, height, 0, 0); |
| 2969 | 2980 |
| 2970 tab.detach(null, null); | 2981 tab.detach(null, null); |
| 2971 return tab; | 2982 return tab; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3130 private native long nativeGetBookmarkId(long nativeTabAndroid, boolean onlyE ditable); | 3141 private native long nativeGetBookmarkId(long nativeTabAndroid, boolean onlyE ditable); |
| 3131 private native void nativeSetInterceptNavigationDelegate(long nativeTabAndro id, | 3142 private native void nativeSetInterceptNavigationDelegate(long nativeTabAndro id, |
| 3132 InterceptNavigationDelegate delegate); | 3143 InterceptNavigationDelegate delegate); |
| 3133 private native void nativeAttachToTabContentManager(long nativeTabAndroid, | 3144 private native void nativeAttachToTabContentManager(long nativeTabAndroid, |
| 3134 TabContentManager tabContentManager); | 3145 TabContentManager tabContentManager); |
| 3135 private native boolean nativeHasPrerenderedUrl(long nativeTabAndroid, String url); | 3146 private native boolean nativeHasPrerenderedUrl(long nativeTabAndroid, String url); |
| 3136 private native void nativeSetWebappManifestScope(long nativeTabAndroid, Stri ng scope); | 3147 private native void nativeSetWebappManifestScope(long nativeTabAndroid, Stri ng scope); |
| 3137 private native void nativeEnableEmbeddedMediaExperience(long nativeTabAndroi d, boolean enabled); | 3148 private native void nativeEnableEmbeddedMediaExperience(long nativeTabAndroi d, boolean enabled); |
| 3138 private native void nativeAttachDetachedTab(long nativeTabAndroid); | 3149 private native void nativeAttachDetachedTab(long nativeTabAndroid); |
| 3139 } | 3150 } |
| OLD | NEW |