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..ce77a390384338bc98de4e8d8285bb7ba283a010 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; |
| @@ -592,6 +594,22 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| } |
| }; |
| + private class TabBlimpContentsObserver implements BlimpContentsObserver { |
|
David Trainor- moved to gerrit
2016/08/11 21:40:19
We could make this a separate file like the TabWeb
shaktisahu
2016/08/12 22:11:49
I think when a nested class starts growing, we sho
|
| + private Tab mTab; |
| + |
| + public TabBlimpContentsObserver(Tab tab) { |
| + 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 +752,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 +1030,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(true); |
|
David Trainor- moved to gerrit
2016/08/11 21:40:19
Do we need the boolean argument for blimp for now?
shaktisahu
2016/08/12 22:11:49
Yea, we don't use this argument right now. It shou
|
| + } |
| + } else { |
| + if (getWebContents() != null) getWebContents().getNavigationController().reload(true); |
| + } |
| } |
| /** |
| @@ -1132,6 +1177,21 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| } |
| /** |
| + * @return The blimp contents associated with this tab, if in blimp mode. |
| + */ |
| + public BlimpContents getBlimpContents() { |
| + if (mNativeTabAndroid == 0) return null; |
| + return nativeGetBlimpContents(mNativeTabAndroid); |
|
David Trainor- moved to gerrit
2016/08/11 21:40:19
JNI calls aren't free. Should we be storing this
shaktisahu
2016/08/12 22:11:49
Done.
|
| + } |
| + |
| + /** |
| + * @return Whether or not this tab is running in blimp mode. |
| + */ |
| + public boolean isBlimpTab() { |
| + return false; |
| + } |
| + |
| + /** |
| * @return The profile associated with this tab. |
| */ |
| public Profile getProfile() { |
| @@ -1188,8 +1248,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 +1257,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 +1510,11 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| return; |
| } |
| + if (isBlimpTab() && getBlimpContents() == null) { |
| + nativeInitBlimpContents(mNativeTabAndroid); |
| + getBlimpContents().addObserver(new TabBlimpContentsObserver(this)); |
| + } |
| + |
| boolean creatingWebContents = webContents == null; |
| if (creatingWebContents) { |
| webContents = WebContentsFactory.createWebContents(isIncognito(), initiallyHidden); |
| @@ -2050,6 +2115,11 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
| public String getUrl() { |
| String url = getWebContents() != null ? getWebContents().getUrl() : ""; |
| + if (isBlimpTab()) { |
| + 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. |
| if (getContentViewCore() != null || getNativePage() != null || !TextUtils.isEmpty(url)) { |
| @@ -2076,6 +2146,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 +3323,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); |