Changes Controller to use Tab.getUrl in more places
Bug: 3342456
Changes Controller to use Tab.getUrl() and then added empty
url checks in places like doUpdateVisitedHistory. Tab already takes
care of filtering URLs, so filtering out most visited URLs is thus
handled.
Change-Id: Iaf60353d7cb924991c5e0a5adf18074fcf13bfe6
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index e707e36..3e0b7f0 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -733,7 +733,7 @@
// WebViewController
@Override
- public void onPageStarted(Tab tab, WebView view, String url, Bitmap favicon) {
+ public void onPageStarted(Tab tab, WebView view, Bitmap favicon) {
// We've started to load a new page. If there was a pending message
// to save a screenshot then we will now take the new page and save
@@ -764,6 +764,7 @@
mUi.onTabDataChanged(tab);
+ String url = tab.getUrl();
// update the bookmark database for favicon
maybeUpdateFavicon(tab, null, url, favicon);
@@ -777,9 +778,10 @@
}
@Override
- public void onPageFinished(Tab tab, String url) {
+ public void onPageFinished(Tab tab) {
mUi.onTabDataChanged(tab);
- if (!tab.isPrivateBrowsingEnabled()) {
+ if (!tab.isPrivateBrowsingEnabled()
+ && !TextUtils.isEmpty(tab.getUrl())) {
if (tab.inForeground() && !didUserStopLoading()
|| !tab.inForeground()) {
// Only update the bookmark screenshot if the user did not
@@ -799,7 +801,7 @@
}
// Performance probe
if (false) {
- Performance.onPageFinished(url);
+ Performance.onPageFinished(tab.getUrl());
}
Performance.tracePageFinished();
@@ -843,7 +845,7 @@
public void onReceivedTitle(Tab tab, final String title) {
mUi.onTabDataChanged(tab);
final String pageUrl = tab.getUrl();
- if (pageUrl == null || pageUrl.length()
+ if (TextUtils.isEmpty(pageUrl) || pageUrl.length()
>= SQLiteDatabase.SQLITE_MAX_LIKE_PATTERN_LENGTH) {
return;
}
@@ -887,12 +889,13 @@
}
@Override
- public void doUpdateVisitedHistory(Tab tab, String url,
- boolean isReload) {
+ public void doUpdateVisitedHistory(Tab tab, boolean isReload) {
// Don't save anything in private browsing mode
if (tab.isPrivateBrowsingEnabled()) return;
+ String url = tab.getUrl();
- if (url.regionMatches(true, 0, "about:", 0, 6)) {
+ if (TextUtils.isEmpty(url)
+ || url.regionMatches(true, 0, "about:", 0, 6)) {
return;
}
mDataController.updateVisitedHistory(url);
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index 5ef7564..d70b0ef 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -16,7 +16,6 @@
package com.android.browser;
-import com.android.browser.homepages.HomeProvider;
import com.android.common.speech.LoggingEvents;
import android.app.Activity;
@@ -533,7 +532,7 @@
}
// finally update the UI in the activity if it is in the foreground
- mWebViewController.onPageStarted(Tab.this, view, url, favicon);
+ mWebViewController.onPageStarted(Tab.this, view, favicon);
updateBookmarkedStatus();
}
@@ -557,7 +556,7 @@
// but before a provisional load occurred
mCurrentState.mLockIcon = LockIcon.LOCK_ICON_UNSECURE;
}
- mWebViewController.onPageFinished(Tab.this, url);
+ mWebViewController.onPageFinished(Tab.this);
}
// return true if want to hijack the url to let another app to handle it
@@ -688,7 +687,7 @@
@Override
public void doUpdateVisitedHistory(WebView view, String url,
boolean isReload) {
- mWebViewController.doUpdateVisitedHistory(Tab.this, url, isReload);
+ mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
}
/**
@@ -1569,10 +1568,7 @@
}
String getUrl() {
- if (HomeProvider.MOST_VISITED.equals(mCurrentState.mUrl)) {
- return "";
- }
- return mCurrentState.mUrl;
+ return UrlUtils.filteredUrl(mCurrentState.mUrl);
}
/**
diff --git a/src/com/android/browser/UrlUtils.java b/src/com/android/browser/UrlUtils.java
index 2df0a61..72ac37b 100644
--- a/src/com/android/browser/UrlUtils.java
+++ b/src/com/android/browser/UrlUtils.java
@@ -16,6 +16,8 @@
package com.android.browser;
+import com.android.browser.homepages.HomeProvider;
+
import android.net.Uri;
import android.util.Patterns;
import android.webkit.URLUtil;
@@ -145,4 +147,15 @@
return inUrl;
}
+ // Returns the filtered URL. Cannot return null, but can return an empty string
+ /* package */ static String filteredUrl(String inUrl) {
+ if (inUrl == null) {
+ return "";
+ }
+ if (inUrl.startsWith(HomeProvider.MOST_VISITED)) {
+ return "";
+ }
+ return inUrl;
+ }
+
}
diff --git a/src/com/android/browser/WebViewController.java b/src/com/android/browser/WebViewController.java
index a187af0..813b63b 100644
--- a/src/com/android/browser/WebViewController.java
+++ b/src/com/android/browser/WebViewController.java
@@ -46,9 +46,9 @@
void createSubWindow(Tab tab);
- void onPageStarted(Tab tab, WebView view, String url, Bitmap favicon);
+ void onPageStarted(Tab tab, WebView view, Bitmap favicon);
- void onPageFinished(Tab tab, String url);
+ void onPageFinished(Tab tab);
void onProgressChanged(Tab tab);
@@ -62,7 +62,7 @@
void onUnhandledKeyEvent(KeyEvent event);
- void doUpdateVisitedHistory(Tab tab, String url, boolean isReload);
+ void doUpdateVisitedHistory(Tab tab, boolean isReload);
void getVisitedHistory(final ValueCallback<String[]> callback);