summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/TabBase.java42
-rw-r--r--chrome/browser/android/tab_android.cc22
-rw-r--r--chrome/browser/android/tab_android.h4
-rw-r--r--content/browser/android/web_contents_observer_android.cc9
-rw-r--r--content/browser/android/web_contents_observer_android.h2
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/WebContentsObserverAndroid.java7
6 files changed, 73 insertions, 13 deletions
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 cf8057c..a5fe835 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/TabBase.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/TabBase.java
@@ -80,11 +80,15 @@ public abstract class TabBase implements NavigationClient {
*/
private ContentViewCore mContentViewCore;
- // Observers and Delegates.
+ /**
+ * A list of TabBase observers. These are used to broadcast TabBase events to listeners.
+ */
+ private final ObserverList<TabObserver> mObservers = new ObserverList<TabObserver>();
+
+ // Content layer Observers and Delegates
private ContentViewClient mContentViewClient;
private WebContentsObserverAndroid mWebContentsObserver;
private TabBaseChromeWebContentsDelegateAndroid mWebContentsDelegate;
- private final ObserverList<TabObserver> mObservers = new ObserverList<TabObserver>();
/**
* A basic {@link ChromeWebContentsDelegateAndroid} that forwards some calls to the registered
@@ -112,6 +116,19 @@ public abstract class TabBase implements NavigationClient {
}
}
+ private class TabBaseWebContentsObserverAndroid extends WebContentsObserverAndroid {
+ public TabBaseWebContentsObserverAndroid(ContentViewCore contentViewCore) {
+ super(contentViewCore);
+ }
+
+ @Override
+ public void navigationEntryCommitted() {
+ if (getNativePage() != null) {
+ pushNativePageStateToNavigationEntry();
+ }
+ }
+ }
+
/**
* Creates an instance of a {@link TabBase} with no id.
* @param incognito Whether or not this tab is incognito.
@@ -415,6 +432,7 @@ public abstract class TabBase implements NavigationClient {
if (mNativePage == nativePage) return;
destroyNativePageInternal();
mNativePage = nativePage;
+ pushNativePageStateToNavigationEntry();
for (TabObserver observer : mObservers) observer.onContentChanged(this);
}
@@ -456,7 +474,7 @@ public abstract class TabBase implements NavigationClient {
mContentViewCore = mContentView.getContentViewCore();
mWebContentsDelegate = createWebContentsDelegate();
- mWebContentsObserver = createWebContentsObserverAndroid(mContentViewCore);
+ mWebContentsObserver = new TabBaseWebContentsObserverAndroid(mContentViewCore);
if (mContentViewClient != null) mContentViewCore.setContentViewClient(mContentViewClient);
@@ -541,16 +559,6 @@ public abstract class TabBase implements NavigationClient {
}
/**
- * A helper method to allow subclasses to build their own observer.
- * @param contentViewCore The {@link ContentViewCore} this observer should be built for.
- * @return An instance of a {@link WebContentsObserverAndroid}.
- */
- protected WebContentsObserverAndroid createWebContentsObserverAndroid(
- ContentViewCore contentViewCore) {
- return null;
- }
-
- /**
* @return The {@link WindowAndroid} associated with this {@link TabBase}.
*/
protected WindowAndroid getWindowAndroid() {
@@ -643,6 +651,12 @@ public abstract class TabBase implements NavigationClient {
return sIdCounter.getAndIncrement();
}
+ private void pushNativePageStateToNavigationEntry() {
+ assert mNativeTabAndroid != 0 && getNativePage() != null;
+ nativeSetActiveNavigationEntryTitleForUrl(mNativeTabAndroid, getNativePage().getUrl(),
+ getNativePage().getTitle());
+ }
+
/**
* Ensures the counter is at least as high as the specified value. The counter should always
* point to an unused ID (which will be handed out next time a request comes in). Exposed so
@@ -665,4 +679,6 @@ public abstract class TabBase implements NavigationClient {
private native Profile nativeGetProfileAndroid(int nativeTabAndroid);
private native void nativeLaunchBlockedPopups(int nativeTabAndroid);
private native int nativeGetSecurityLevel(int nativeTabAndroid);
+ private native void nativeSetActiveNavigationEntryTitleForUrl(int nativeTabAndroid, String url,
+ String title);
}
diff --git a/chrome/browser/android/tab_android.cc b/chrome/browser/android/tab_android.cc
index aa6c684..dcf9a93 100644
--- a/chrome/browser/android/tab_android.cc
+++ b/chrome/browser/android/tab_android.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/android/tab_android.h"
#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
#include "chrome/browser/android/chrome_web_contents_delegate_android.h"
#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
#include "chrome/browser/browser_process.h"
@@ -42,6 +43,7 @@
#include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
#include "components/autofill/content/browser/autofill_driver_impl.h"
#include "content/public/browser/android/content_view_core.h"
+#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/view_type_utils.h"
@@ -331,6 +333,26 @@ ToolbarModel::SecurityLevel TabAndroid::GetSecurityLevel(JNIEnv* env,
return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents());
}
+void TabAndroid::SetActiveNavigationEntryTitleForUrl(JNIEnv* env,
+ jobject obj,
+ jstring jurl,
+ jstring jtitle) {
+ DCHECK(web_contents());
+
+ string16 title;
+ if (jtitle)
+ title = base::android::ConvertJavaStringToUTF16(env, jtitle);
+
+ std::string url;
+ if (jurl)
+ url = base::android::ConvertJavaStringToUTF8(env, jurl);
+
+ content::NavigationEntry* entry =
+ web_contents()->GetController().GetVisibleEntry();
+ if (entry && url == entry->GetVirtualURL().spec())
+ entry->SetTitle(title);
+}
+
bool TabAndroid::RegisterTabAndroid(JNIEnv* env) {
return RegisterNativesImpl(env);
}
diff --git a/chrome/browser/android/tab_android.h b/chrome/browser/android/tab_android.h
index 8083430..e3a6c29 100644
--- a/chrome/browser/android/tab_android.h
+++ b/chrome/browser/android/tab_android.h
@@ -134,6 +134,10 @@ class TabAndroid : public CoreTabHelperDelegate,
jobject obj);
void LaunchBlockedPopups(JNIEnv* env, jobject obj);
ToolbarModel::SecurityLevel GetSecurityLevel(JNIEnv* env, jobject obj);
+ void SetActiveNavigationEntryTitleForUrl(JNIEnv* env,
+ jobject obj,
+ jstring jurl,
+ jstring jtitle);
protected:
virtual ~TabAndroid();
diff --git a/content/browser/android/web_contents_observer_android.cc b/content/browser/android/web_contents_observer_android.cc
index 3e60ef4..73cf7ad 100644
--- a/content/browser/android/web_contents_observer_android.cc
+++ b/content/browser/android/web_contents_observer_android.cc
@@ -203,6 +203,15 @@ void WebContentsObserverAndroid::DidFinishLoad(
env, obj.obj(), frame_id, jstring_url.obj(), is_main_frame);
}
+void WebContentsObserverAndroid::NavigationEntryCommitted(
+ const LoadCommittedDetails& load_details) {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> obj(weak_java_observer_.get(env));
+ if (obj.is_null())
+ return;
+ Java_WebContentsObserverAndroid_navigationEntryCommitted(env, obj.obj());
+}
+
void WebContentsObserverAndroid::DidChangeVisibleSSLState() {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj(weak_java_observer_.get(env));
diff --git a/content/browser/android/web_contents_observer_android.h b/content/browser/android/web_contents_observer_android.h
index e975d79..71aa905 100644
--- a/content/browser/android/web_contents_observer_android.h
+++ b/content/browser/android/web_contents_observer_android.h
@@ -68,6 +68,8 @@ class WebContentsObserverAndroid : public WebContentsObserver {
const GURL& validated_url,
bool is_main_frame,
RenderViewHost* render_view_host) OVERRIDE;
+ virtual void NavigationEntryCommitted(
+ const LoadCommittedDetails& load_details) OVERRIDE;
virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE;
virtual void DidChangeVisibleSSLState() OVERRIDE;
virtual void DidAttachInterstitialPage() OVERRIDE;
diff --git a/content/public/android/java/src/org/chromium/content/browser/WebContentsObserverAndroid.java b/content/public/android/java/src/org/chromium/content/browser/WebContentsObserverAndroid.java
index d48b907..066b58a 100644
--- a/content/public/android/java/src/org/chromium/content/browser/WebContentsObserverAndroid.java
+++ b/content/public/android/java/src/org/chromium/content/browser/WebContentsObserverAndroid.java
@@ -113,6 +113,13 @@ public abstract class WebContentsObserverAndroid {
}
/**
+ * Notifies that a navigation entry has been committed.
+ */
+ @CalledByNative
+ public void navigationEntryCommitted() {
+ }
+
+ /**
* Invoked when visible SSL state changes.
*/
@CalledByNative