Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java |
| index 9a19635f6b5200dd89e1445b187604bcef6eba5f..0f81f308ba08c6af9ddb8e620416c6fc377480f0 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java |
| @@ -39,6 +39,8 @@ import org.chromium.base.VisibleForTesting; |
| import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.base.metrics.RecordHistogram; |
| import org.chromium.base.metrics.RecordUserAction; |
| +import org.chromium.blimp_public.contents.BlimpContents; |
| +import org.chromium.blimp_public.contents.BlimpContentsObserver; |
| import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.ChromeActivity; |
| import org.chromium.chrome.browser.ChromeApplication; |
| @@ -213,6 +215,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| private ContentViewClient mContentViewClient; |
| private TabWebContentsObserver mWebContentsObserver; |
| private TabWebContentsDelegateAndroid mWebContentsDelegate; |
| + private BlimpContents mBlimpContents; |
| /** |
| * If this tab was opened from another tab, store the id of the tab that |
| @@ -592,6 +595,22 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| } |
| }; |
| + private class TabBlimpContentsObserver implements BlimpContentsObserver { |
|
nyquist
2016/08/16 19:09:20
This doesn't seem to access Tab members. Could thi
shaktisahu
2016/08/16 23:46:13
Acknowledged.
|
| + private Tab mTab; |
| + |
| + public TabBlimpContentsObserver(Tab tab) { |
|
nyquist
2016/08/16 19:09:20
I think I'd vote for splitting this out early, if
shaktisahu
2016/08/16 23:46:13
Done.
|
| + mTab = tab; |
| + } |
| + @Override |
| + public void onNavigationStateChanged() { |
| + mTab.updateTitle(); |
| + RewindableIterator<TabObserver> observers = mTab.getTabObservers(); |
| + while (observers.hasNext()) { |
| + observers.next().onUrlUpdated(mTab); |
| + } |
| + } |
| + } |
| + |
| private TabDelegateFactory mDelegateFactory; |
| private TopControlsVisibilityDelegate mTopControlsVisibilityDelegate; |
| @@ -734,29 +753,50 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| * @return Whether or not this tab has a previous navigation entry. |
| */ |
| public boolean canGoBack() { |
| - return getWebContents() != null && getWebContents().getNavigationController().canGoBack(); |
| + if (isBlimpTab()) { |
| + return getBlimpContents() != null |
| + && getBlimpContents().getNavigationController().canGoBack(); |
| + } else { |
| + return getWebContents() != null |
| + && getWebContents().getNavigationController().canGoBack(); |
| + } |
| } |
| /** |
| * @return Whether or not this tab has a navigation entry after the current one. |
| */ |
| public boolean canGoForward() { |
| - return getWebContents() != null && getWebContents().getNavigationController() |
| - .canGoForward(); |
| + if (isBlimpTab()) { |
| + return getBlimpContents() != null |
| + && getBlimpContents().getNavigationController().canGoForward(); |
| + } else { |
| + return getWebContents() != null |
| + && getWebContents().getNavigationController().canGoForward(); |
| + } |
| } |
| /** |
| * Goes to the navigation entry before the current one. |
| */ |
| public void goBack() { |
| - if (getWebContents() != null) getWebContents().getNavigationController().goBack(); |
| + if (isBlimpTab()) { |
| + if (getBlimpContents() != null) getBlimpContents().getNavigationController().goBack(); |
| + } else { |
| + if (getWebContents() != null) getWebContents().getNavigationController().goBack(); |
| + } |
| } |
| /** |
| * Goes to the navigation entry after the current one. |
| */ |
| public void goForward() { |
| - if (getWebContents() != null) getWebContents().getNavigationController().goForward(); |
| + if (isBlimpTab()) { |
| + if (getBlimpContents() != null) { |
| + getBlimpContents().getNavigationController().goForward(); |
| + } |
| + } else { |
| + if (getWebContents() != null) getWebContents().getNavigationController().goForward(); |
| + } |
| } |
| /** |
| @@ -991,7 +1031,13 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| */ |
| public void reload() { |
| // TODO(dtrainor): Should we try to rebuild the ContentView if it's frozen? |
| - if (getWebContents() != null) getWebContents().getNavigationController().reload(true); |
| + if (isBlimpTab()) { |
| + if (getBlimpContents() != null) { |
| + getBlimpContents().getNavigationController().reload(); |
| + } |
| + } else { |
| + if (getWebContents() != null) getWebContents().getNavigationController().reload(true); |
| + } |
| } |
| /** |
| @@ -1132,6 +1178,20 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| } |
| /** |
| + * @return The blimp contents associated with this tab, if in blimp mode. |
|
nyquist
2016/08/16 19:09:20
{@link BlimpContents}
shaktisahu
2016/08/16 23:46:13
Done.
|
| + */ |
| + public BlimpContents getBlimpContents() { |
| + return mBlimpContents; |
| + } |
| + |
| + /** |
| + * @return Whether or not this tab is running in blimp mode. |
| + */ |
| + public boolean isBlimpTab() { |
| + return true; |
|
nyquist
2016/08/16 19:09:20
Is this really always true? Or should this only be
shaktisahu
2016/08/16 23:46:13
Left it true accidentally. :(
|
| + } |
| + |
| + /** |
| * @return The profile associated with this tab. |
| */ |
| public Profile getProfile() { |
| @@ -1152,6 +1212,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| /** |
| * @return Whether or not this tab is incognito. |
| */ |
| + @CalledByNative |
| public boolean isIncognito() { |
| return mIncognito; |
| } |
| @@ -1188,8 +1249,8 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| */ |
| public void setUseDesktopUserAgent(boolean useDesktop, boolean reloadOnChange) { |
| if (getWebContents() != null) { |
| - getWebContents().getNavigationController() |
| - .setUseDesktopUserAgent(useDesktop, reloadOnChange); |
| + getWebContents().getNavigationController().setUseDesktopUserAgent( |
| + useDesktop, reloadOnChange); |
| } |
| } |
| @@ -1197,8 +1258,8 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| * @return Whether or not the {@link ContentViewCore} is using a desktop user agent. |
| */ |
| public boolean getUseDesktopUserAgent() { |
| - return getWebContents() != null && getWebContents().getNavigationController() |
| - .getUseDesktopUserAgent(); |
| + return getWebContents() != null |
| + && getWebContents().getNavigationController().getUseDesktopUserAgent(); |
| } |
| /** |
| @@ -1450,6 +1511,12 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| return; |
| } |
| + if (isBlimpTab() && getBlimpContents() == null) { |
|
nyquist
2016/08/16 21:42:24
Maybe ask BlimpClientContext.isBlimpEnabled()? Tha
|
| + nativeInitBlimpContents(mNativeTabAndroid); |
| + mBlimpContents = nativeGetBlimpContents(mNativeTabAndroid); |
| + getBlimpContents().addObserver(new TabBlimpContentsObserver(this)); |
| + } |
| + |
| boolean creatingWebContents = webContents == null; |
| if (creatingWebContents) { |
| webContents = WebContentsFactory.createWebContents(isIncognito(), initiallyHidden); |
| @@ -2016,6 +2083,8 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| destroyNativePageInternal(currentNativePage); |
| destroyContentViewCore(true); |
| + mBlimpContents = null; |
| + |
| // Destroys the native tab after destroying the ContentView but before destroying the |
| // InfoBarContainer. The native tab should be destroyed before the infobar container as |
| // destroying the native tab cleanups up any remaining infobars. The infobar container |
| @@ -2050,6 +2119,11 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| public String getUrl() { |
| String url = getWebContents() != null ? getWebContents().getUrl() : ""; |
| + if (isBlimpTab()) { |
|
nyquist
2016/08/16 19:09:20
Should this be moved to the top?
nyquist
2016/08/16 21:42:25
Bah. Ignore.
|
| + url = getBlimpContents() != null ? getBlimpContents().getNavigationController().getUrl() |
| + : ""; |
| + } |
| + |
| // If we have a ContentView, or a NativePage, or the url is not empty, we have a WebContents |
| // so cache the WebContent's url. If not use the cached version. |
|
nyquist
2016/08/16 21:42:24
Maybe check for BlimpContents as well here?
shaktisahu
2016/08/16 23:46:13
Actually TextUtils.isEmpty(url) will do that for y
|
| if (getContentViewCore() != null || getNativePage() != null || !TextUtils.isEmpty(url)) { |
| @@ -2076,6 +2150,8 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| String title = ""; |
| if (mNativePage != null) { |
| title = mNativePage.getTitle(); |
| + } else if (getBlimpContents() != null) { |
| + title = getBlimpContents().getNavigationController().getTitle(); |
| } else if (getWebContents() != null) { |
| title = getWebContents().getTitle(); |
| } |
| @@ -3251,6 +3327,8 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| private native void nativeInitWebContents(long nativeTabAndroid, boolean incognito, |
| WebContents webContents, TabWebContentsDelegateAndroid delegate, |
| ContextMenuPopulator contextMenuPopulator); |
| + private native void nativeInitBlimpContents(long nativeTabAndroid); |
| + private native BlimpContents nativeGetBlimpContents(long nativeTabAndroid); |
| private native void nativeUpdateDelegates(long nativeTabAndroid, |
| TabWebContentsDelegateAndroid delegate, ContextMenuPopulator contextMenuPopulator); |
| private native void nativeDestroyWebContents(long nativeTabAndroid, boolean deleteNative); |