Commit 71114945 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Remove Tab.mIsDetached

Detached state of Tab from Activity/WindowAndroid can be obtained
dynamically from Tab. This CL removes the private field that caches
the state.

Bug: 925242
Change-Id: Ib6050875843239d346f46eb7c5a26d1f881c4339
Reviewed-on: https://chromium-review.googlesource.com/c/1474883
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635420}
parent 7e7d48fc
...@@ -311,12 +311,6 @@ public class Tab ...@@ -311,12 +311,6 @@ public class Tab
private FullscreenManager mFullscreenManager; private FullscreenManager mFullscreenManager;
/**
* Indicates whether this tab is detached from any activity and its corresponding
* {@link WindowAndroid}.
*/
private boolean mIsDetached;
/** /**
* The publisher URL for pages hosted on a trusted CDN, or null otherwise. * The publisher URL for pages hosted on a trusted CDN, or null otherwise.
*/ */
...@@ -394,7 +388,6 @@ public class Tab ...@@ -394,7 +388,6 @@ public class Tab
mWindowAndroid = window; mWindowAndroid = window;
mLaunchType = type; mLaunchType = type;
mLaunchTypeAtCreation = type; mLaunchTypeAtCreation = type;
mIsDetached = getActivity() == null;
Resources resources = mThemedApplicationContext.getResources(); Resources resources = mThemedApplicationContext.getResources();
mIdealFaviconSize = resources.getDimensionPixelSize(R.dimen.default_favicon_size); mIdealFaviconSize = resources.getDimensionPixelSize(R.dimen.default_favicon_size);
...@@ -1154,17 +1147,10 @@ public class Tab ...@@ -1154,17 +1147,10 @@ public class Tab
* Detaches a tab from its current activity if any. * Detaches a tab from its current activity if any.
* *
* In details, this function: * In details, this function:
* - Tags the tab using mIsDetached.
* - Removes the tab from its current {@link TabModelSelector}, effectively severing * - Removes the tab from its current {@link TabModelSelector}, effectively severing
* the {@link Activity} to {@link Tab} link. * the {@link Activity} to {@link Tab} link.
*/ */
private void detach() { private void detach() {
mIsDetached = true;
TabModelSelector tabModelSelector = getTabModelSelector();
if (tabModelSelector != null) {
tabModelSelector.getModel(mIncognito).removeTab(this);
}
// TODO(yusufo): We can't call updateWindowAndroid here and set mWindowAndroid to null // TODO(yusufo): We can't call updateWindowAndroid here and set mWindowAndroid to null
// because many code paths (including navigation) expect the tab to always be associated // because many code paths (including navigation) expect the tab to always be associated
// with an activity, and will crash. crbug.com/657007 // with an activity, and will crash. crbug.com/657007
...@@ -1172,6 +1158,11 @@ public class Tab ...@@ -1172,6 +1158,11 @@ public class Tab
if (webContents != null) webContents.setTopLevelNativeWindow(null); if (webContents != null) webContents.setTopLevelNativeWindow(null);
attachTabContentManager(null); attachTabContentManager(null);
TabModelSelector tabModelSelector = getTabModelSelector();
if (tabModelSelector != null) {
tabModelSelector.getModel(mIncognito).removeTab(this);
}
for (TabObserver observer : mObservers) { for (TabObserver observer : mObservers) {
observer.onActivityAttachmentChanged(this, false); observer.onActivityAttachmentChanged(this, false);
} }
...@@ -1210,7 +1201,7 @@ public class Tab ...@@ -1210,7 +1201,7 @@ public class Tab
* @param tabDelegateFactory The new delegate factory this tab should be using. * @param tabDelegateFactory The new delegate factory this tab should be using.
*/ */
public void attach(ChromeActivity activity, TabDelegateFactory tabDelegateFactory) { public void attach(ChromeActivity activity, TabDelegateFactory tabDelegateFactory) {
assert mIsDetached; assert isDetached();
updateWindowAndroid(activity.getWindowAndroid()); updateWindowAndroid(activity.getWindowAndroid());
// Update for the controllers that need the Compositor from the new Activity. // Update for the controllers that need the Compositor from the new Activity.
...@@ -1222,8 +1213,6 @@ public class Tab ...@@ -1222,8 +1213,6 @@ public class Tab
mBrowserControlsVisibilityDelegate = mBrowserControlsVisibilityDelegate =
mDelegateFactory.createBrowserControlsVisibilityDelegate(this); mDelegateFactory.createBrowserControlsVisibilityDelegate(this);
mIsDetached = false;
// Reload the NativePage (if any), since the old NativePage has a reference to the old // Reload the NativePage (if any), since the old NativePage has a reference to the old
// activity. // activity.
maybeShowNativePage(getUrl(), true); maybeShowNativePage(getUrl(), true);
...@@ -1261,7 +1250,13 @@ public class Tab ...@@ -1261,7 +1250,13 @@ public class Tab
* with {@link Tab#attachAndFinishReparenting}. * with {@link Tab#attachAndFinishReparenting}.
*/ */
public boolean isDetached() { public boolean isDetached() {
return mIsDetached; if (getWebContents() == null) return true;
// Should get WindowAndroid from WebContents since the one from |getWindowAndroid()|
// is always non-null even when the tab is in detached state. See the comment in |detach()|.
WindowAndroid window = getWebContents().getTopLevelNativeWindow();
if (window == null) return true;
Activity activity = WindowAndroid.activityFromContext(window.getContext().get());
return !(activity instanceof ChromeActivity);
} }
/** /**
...@@ -1421,8 +1416,8 @@ public class Tab ...@@ -1421,8 +1416,8 @@ public class Tab
} }
assert mNativeTabAndroid != 0; assert mNativeTabAndroid != 0;
nativeInitWebContents(mNativeTabAndroid, mIncognito, mIsDetached, webContents, parentId, nativeInitWebContents(mNativeTabAndroid, mIncognito, isDetached(), webContents,
mWebContentsDelegate, parentId, mWebContentsDelegate,
new TabContextMenuPopulator( new TabContextMenuPopulator(
mDelegateFactory.createContextMenuPopulator(this), this)); mDelegateFactory.createContextMenuPopulator(this), this));
...@@ -1481,7 +1476,7 @@ public class Tab ...@@ -1481,7 +1476,7 @@ public class Tab
// While detached for reparenting we don't have an owning Activity, or TabModelSelector, // While detached for reparenting we don't have an owning Activity, or TabModelSelector,
// so we can't create the native page. The native page will be created once reparenting is // so we can't create the native page. The native page will be created once reparenting is
// completed. // completed.
if (mIsDetached) return false; if (isDetached()) return false;
NativePage candidateForReuse = forceReload ? null : getNativePage(); NativePage candidateForReuse = forceReload ? null : getNativePage();
NativePage nativePage = NativePageFactory.createNativePageForURL(url, candidateForReuse, NativePage nativePage = NativePageFactory.createNativePageForURL(url, candidateForReuse,
this, getTabModelSelector(), getActivity()); this, getTabModelSelector(), getActivity());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment