Bug 778489 - Keep title and favicon when entering reader mode (r=mfinkle)
This commit is contained in:
@@ -564,6 +564,10 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
|
||||
if (tab != null && "about:empty".equals(tab.getURL()))
|
||||
return;
|
||||
|
||||
// Keep the title unchanged if the tab is entering reader mode
|
||||
if (tab != null && tab.isEnteringReaderMode())
|
||||
return;
|
||||
|
||||
// Setting a null title for about:home will ensure we just see
|
||||
// the "Enter Search or Address" placeholder text
|
||||
if (tab != null && "about:home".equals(tab.getURL()))
|
||||
|
||||
@@ -17,6 +17,51 @@ public class ReaderModeUtils {
|
||||
return url.startsWith("about:reader");
|
||||
}
|
||||
|
||||
public static String getUrlFromAboutReader(String aboutReaderUrl) {
|
||||
if (aboutReaderUrl == null)
|
||||
return null;
|
||||
|
||||
String[] urlParts = aboutReaderUrl.split("\\?");
|
||||
if (urlParts.length < 2)
|
||||
return null;
|
||||
|
||||
String query = urlParts[1];
|
||||
for (String param : query.split("&")) {
|
||||
String pair[] = param.split("=");
|
||||
String key = Uri.decode(pair[0]);
|
||||
|
||||
// Key is empty or not "url", discard
|
||||
if (TextUtils.isEmpty(key) || !key.equals("url"))
|
||||
continue;
|
||||
|
||||
// No value associated with key, discard
|
||||
if (pair.length < 2)
|
||||
continue;
|
||||
|
||||
String url = Uri.decode(pair[1]);
|
||||
if (TextUtils.isEmpty(url))
|
||||
return null;
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isEnteringReaderMode(String currentUrl, String newUrl) {
|
||||
if (currentUrl == null || newUrl == null)
|
||||
return false;
|
||||
|
||||
if (!isAboutReader(newUrl))
|
||||
return false;
|
||||
|
||||
String urlFromAboutReader = getUrlFromAboutReader(newUrl);
|
||||
if (urlFromAboutReader == null)
|
||||
return false;
|
||||
|
||||
return urlFromAboutReader.equals(currentUrl);
|
||||
}
|
||||
|
||||
public static String getAboutReaderForUrl(String url, boolean inReadingList) {
|
||||
return getAboutReaderForUrl(url, -1, inReadingList);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.graphics.Color;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
@@ -65,6 +66,7 @@ public final class Tab {
|
||||
private ByteBuffer mThumbnailBuffer;
|
||||
private Bitmap mThumbnailBitmap;
|
||||
private boolean mDesktopMode;
|
||||
private boolean mEnteringReaderMode;
|
||||
|
||||
public static final int STATE_DELAYED = 0;
|
||||
public static final int STATE_LOADING = 1;
|
||||
@@ -83,6 +85,7 @@ public final class Tab {
|
||||
mFaviconSize = 0;
|
||||
mIdentityData = null;
|
||||
mReaderEnabled = false;
|
||||
mEnteringReaderMode = false;
|
||||
mThumbnail = null;
|
||||
mHistoryIndex = -1;
|
||||
mHistorySize = 0;
|
||||
@@ -268,6 +271,10 @@ public final class Tab {
|
||||
}
|
||||
|
||||
public synchronized void updateTitle(String title) {
|
||||
// Keep the title unchanged while entering reader mode
|
||||
if (mEnteringReaderMode)
|
||||
return;
|
||||
|
||||
mTitle = (title == null ? "" : title);
|
||||
|
||||
Log.d(LOGTAG, "Updated title for tab with id: " + mId);
|
||||
@@ -291,7 +298,10 @@ public final class Tab {
|
||||
|
||||
public void setState(int state) {
|
||||
mState = state;
|
||||
}
|
||||
|
||||
if (mState != Tab.STATE_LOADING)
|
||||
mEnteringReaderMode = false;
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return mState;
|
||||
@@ -341,6 +351,10 @@ public final class Tab {
|
||||
}
|
||||
|
||||
public synchronized void clearFavicon() {
|
||||
// Keep the favicon unchanged while entering reader mode
|
||||
if (mEnteringReaderMode)
|
||||
return;
|
||||
|
||||
mFavicon = null;
|
||||
mFaviconUrl = null;
|
||||
mFaviconSize = 0;
|
||||
@@ -439,9 +453,14 @@ public final class Tab {
|
||||
if (!mReaderEnabled)
|
||||
return;
|
||||
|
||||
mEnteringReaderMode = true;
|
||||
GeckoApp.mAppContext.loadUrl(ReaderModeUtils.getAboutReaderForUrl(getURL(), mId, mReadingListItem));
|
||||
}
|
||||
|
||||
public boolean isEnteringReaderMode() {
|
||||
return mEnteringReaderMode;
|
||||
}
|
||||
|
||||
public void doReload() {
|
||||
GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Reload", "");
|
||||
GeckoAppShell.sendEventToGecko(e);
|
||||
@@ -529,6 +548,7 @@ public final class Tab {
|
||||
|
||||
void handleLocationChange(JSONObject message) throws JSONException {
|
||||
final String uri = message.getString("uri");
|
||||
mEnteringReaderMode = ReaderModeUtils.isEnteringReaderMode(mUrl, uri);
|
||||
updateURL(uri);
|
||||
|
||||
setDocumentURI(message.getString("documentURI"));
|
||||
|
||||
Reference in New Issue
Block a user