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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/TabBase.java

Issue 11351002: Fix ChromiumTestShellTestBase. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/TabBase.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/TabBase.java b/chrome/android/java/src/org/chromium/chrome/browser/TabBase.java
index 7e1fb81fbad42dfd5228e96286282990de47ab9a..f5333b1ee6102dc773455cb007a19697f1a21211 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/TabBase.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/TabBase.java
@@ -15,6 +15,9 @@ import org.chromium.content.browser.LoadUrlParams;
import org.chromium.content.common.CleanupReference;
import org.chromium.ui.gfx.NativeWindow;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* The basic Java representation of a tab. Contains and manages a {@link ContentView}.
*/
@@ -23,19 +26,20 @@ public class TabBase {
private ContentView mContentView;
private ChromeWebContentsDelegateAndroid mWebContentsDelegate;
private int mNativeTabBaseAndroidImpl;
+ private Set<TabObserver> mObservers = new HashSet<TabObserver>();
private CleanupReference mCleanupReference;
+ // Tab state
+ private boolean mIsLoading = false;
+
/**
* @param context The Context the view is running in.
* @param url The URL to start this tab with.
* @param window The NativeWindow should represent this tab.
- * @param delegate The {@link ChromeWebContentsDelegateAndroid} that should be notified of any
- * WebContents changes.
*/
- public TabBase(Context context, String url, NativeWindow window,
- ChromeWebContentsDelegateAndroid delegate) {
- this(context, 0, window, delegate);
+ public TabBase(Context context, String url, NativeWindow window) {
+ this(context, 0, window);
loadUrlWithSanitization(url);
}
@@ -43,11 +47,8 @@ public class TabBase {
* @param context The Context the view is running in.
* @param nativeWebContents A native pointer to the WebContents this tab represents.
* @param window The NativeWindow should represent this tab.
- * @param delegate The {@link ChromeWebContentsDelegateAndroid} that should be notified
- * of any WebContents changes.
*/
- public TabBase(Context context, int nativeWebContentsPtr,
- NativeWindow window, ChromeWebContentsDelegateAndroid delegate) {
+ public TabBase(Context context, int nativeWebContentsPtr, NativeWindow window) {
mWindow = window;
// Build the WebContents and the ContentView/ContentViewCore
@@ -59,7 +60,7 @@ public class TabBase {
mNativeTabBaseAndroidImpl = nativeInit(nativeWebContentsPtr, window.getNativePointer());
// Build the WebContentsDelegate
- mWebContentsDelegate = delegate == null ? new ChromeWebContentsDelegateAndroid() : delegate;
+ mWebContentsDelegate = new ChromeWebContentsDelegateAndroidImpl();
nativeInitWebContentsDelegate(mNativeTabBaseAndroidImpl, mWebContentsDelegate);
// To be called after everything is initialized.
@@ -80,6 +81,27 @@ public class TabBase {
}
/**
+ * @param observer The {@link TabObserver} that should be notified of changes.
+ */
+ public void addObserver(TabObserver observer) {
+ mObservers.add(observer);
+ }
+
+ /**
+ * @param observer The {@link TabObserver} that should no longer be notified of changes.
+ */
+ public void removeObserver(TabObserver observer) {
+ mObservers.remove(observer);
+ }
+
+ /**
+ * @return Whether or not the tab is currently loading.
+ */
+ public boolean isLoading() {
+ return mIsLoading;
+ }
+
+ /**
* @return The {@link ContentView} represented by this tab.
*/
public ContentView getContentView() {
@@ -131,6 +153,32 @@ public class TabBase {
}
}
+ private class ChromeWebContentsDelegateAndroidImpl extends ChromeWebContentsDelegateAndroid {
Yusuf 2012/10/29 18:46:26 Not sure, but should we be careful about using Imp
David Trainor- moved to gerrit 2012/10/29 21:10:32 Fair enough! Changed to TabBaseChromeWebContentsD
+ @Override
+ public void onLoadProgressChanged(int progress) {
+ for (TabObserver observer : mObservers) {
Ted C 2012/10/29 17:49:18 It would be annoying (about Java not this change)
David Trainor- moved to gerrit 2012/10/29 21:10:32 That is a good point. I'll make this a list as ad
+ observer.onLoadProgressChanged(TabBase.this, progress);
+ }
+ }
+
+ @Override
+ public void onUpdateUrl(String url) {
+ for (TabObserver observer : mObservers) {
+ observer.onUpdateUrl(TabBase.this, url);
+ }
+ }
+
+ @Override
+ public void onLoadStarted() {
+ mIsLoading = true;
+ }
+
+ @Override
+ public void onLoadStopped() {
+ mIsLoading = false;
+ }
+ }
+
private native int nativeInit(int webContentsPtr, int windowAndroidPtr);
private static native void nativeDestroy(int nativeTabBaseAndroidImpl);
private native void nativeInitWebContentsDelegate(int nativeTabBaseAndroidImpl,

Powered by Google App Engine
This is Rietveld 408576698