Bug 941982 - Clean up about: page handling. r=mcomella

This commit is contained in:
Richard Newman 2013-11-21 23:33:28 -08:00
parent 9272657a86
commit 9191c54185
14 changed files with 111 additions and 59 deletions

View File

@ -0,0 +1,43 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
public class AboutPages {
// All of our special pages.
public static final String ADDONS = "about:addons";
public static final String APPS = "about:apps";
public static final String CONFIG = "about:config";
public static final String DOWNLOADS = "about:downloads";
public static final String FIREFOX = "about:firefox";
public static final String HEALTHREPORT = "about:healthreport";
public static final String HOME = "about:home";
public static final String PRIVATEBROWSING = "about:privatebrowsing";
public static final String READER = "about:reader";
public static final String UPDATER = "about:";
public static final String URL_FILTER = "about:%";
public static final boolean isAboutPage(final String url) {
return url.startsWith("about:");
}
public static final boolean isTitlelessAboutPage(final String url) {
return HOME.equals(url) ||
PRIVATEBROWSING.equals(url);
}
public static final boolean isAboutHome(final String url) {
return HOME.equals(url);
}
public static final boolean isAboutReader(final String url) {
if (url == null) {
return false;
}
return url.startsWith(READER);
}
}

View File

@ -93,8 +93,6 @@ abstract public class BrowserApp extends GeckoApp
private static final String PREF_CHROME_DYNAMICTOOLBAR = "browser.chrome.dynamictoolbar";
private static final String ABOUT_HOME = "about:home";
private static final int TABS_ANIMATION_DURATION = 450;
private static final int READER_ADD_SUCCESS = 0;
@ -680,8 +678,8 @@ abstract public class BrowserApp extends GeckoApp
return mDynamicToolbarEnabled && !mAccessibilityEnabled;
}
private boolean isAboutHome(Tab tab) {
return TextUtils.equals(ABOUT_HOME, tab.getURL());
private static boolean isAboutHome(final Tab tab) {
return AboutPages.isAboutHome(tab.getURL());
}
@Override
@ -871,15 +869,18 @@ abstract public class BrowserApp extends GeckoApp
private void shareCurrentUrl() {
Tab tab = Tabs.getInstance().getSelectedTab();
if (tab == null)
return;
if (tab == null) {
return;
}
String url = tab.getURL();
if (url == null)
if (url == null) {
return;
}
if (ReaderModeUtils.isAboutReader(url))
if (AboutPages.isAboutReader(url)) {
url = ReaderModeUtils.getUrlFromAboutReader(url);
}
GeckoAppShell.openUriExternal(url, "text/plain", "", "",
Intent.ACTION_SEND, tab.getDisplayTitle());
@ -1211,12 +1212,12 @@ abstract public class BrowserApp extends GeckoApp
@Override
public void addTab() {
Tabs.getInstance().loadUrl("about:home", Tabs.LOADURL_NEW_TAB);
Tabs.getInstance().loadUrl(AboutPages.HOME, Tabs.LOADURL_NEW_TAB);
}
@Override
public void addPrivateTab() {
Tabs.getInstance().loadUrl("about:privatebrowsing", Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_PRIVATE);
Tabs.getInstance().loadUrl(AboutPages.PRIVATEBROWSING, Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_PRIVATE);
}
@Override
@ -1383,7 +1384,7 @@ abstract public class BrowserApp extends GeckoApp
}
private void openReadingList() {
Tabs.getInstance().loadUrl(ABOUT_HOME, Tabs.LOADURL_READING_LIST);
Tabs.getInstance().loadUrl(AboutPages.HOME, Tabs.LOADURL_READING_LIST);
}
/* Favicon stuff. */
@ -1676,7 +1677,7 @@ abstract public class BrowserApp extends GeckoApp
* if a new page is not being loaded.
*/
private void hideHomePager(final String url) {
if (!isHomePagerVisible() || TextUtils.equals(url, ABOUT_HOME)) {
if (!isHomePagerVisible() || AboutPages.isAboutHome(url)) {
return;
}
@ -2022,7 +2023,7 @@ abstract public class BrowserApp extends GeckoApp
return true;
}
bookmark.setEnabled(!tab.getURL().startsWith("about:reader"));
bookmark.setEnabled(!AboutPages.isAboutReader(tab.getURL()));
bookmark.setCheckable(true);
bookmark.setChecked(tab.isBookmark());
bookmark.setIcon(tab.isBookmark() ? R.drawable.ic_menu_bookmark_remove : R.drawable.ic_menu_bookmark_add);
@ -2032,10 +2033,11 @@ abstract public class BrowserApp extends GeckoApp
desktopMode.setIcon(tab.getDesktopMode() ? R.drawable.ic_menu_desktop_mode_on : R.drawable.ic_menu_desktop_mode_off);
String url = tab.getURL();
if (ReaderModeUtils.isAboutReader(url)) {
if (AboutPages.isAboutReader(url)) {
String urlFromReader = ReaderModeUtils.getUrlFromAboutReader(url);
if (urlFromReader != null)
if (urlFromReader != null) {
url = urlFromReader;
}
}
// Disable share menuitem for about:, chrome:, file:, and resource: URIs
@ -2091,11 +2093,11 @@ abstract public class BrowserApp extends GeckoApp
}
}
// Disable save as PDF for about:home and xul pages
saveAsPDF.setEnabled(!(tab.getURL().equals("about:home") ||
// Disable save as PDF for about:home and xul pages.
saveAsPDF.setEnabled(!(isAboutHome(tab) ||
tab.getContentType().equals("application/vnd.mozilla.xul+xml")));
// Disable find in page for about:home, since it won't work on Java content
// Disable find in page for about:home, since it won't work on Java content.
findInPage.setEnabled(!isAboutHome(tab));
charEncoding.setVisible(GeckoPreferences.getCharEncodingState());
@ -2174,17 +2176,17 @@ abstract public class BrowserApp extends GeckoApp
}
if (itemId == R.id.addons) {
Tabs.getInstance().loadUrlInTab("about:addons");
return true;
}
if (itemId == R.id.downloads) {
Tabs.getInstance().loadUrlInTab("about:downloads");
Tabs.getInstance().loadUrlInTab(AboutPages.ADDONS);
return true;
}
if (itemId == R.id.apps) {
Tabs.getInstance().loadUrlInTab("about:apps");
Tabs.getInstance().loadUrlInTab(AboutPages.APPS);
return true;
}
if (itemId == R.id.downloads) {
Tabs.getInstance().loadUrlInTab(AboutPages.DOWNLOADS);
return true;
}
@ -2454,7 +2456,7 @@ abstract public class BrowserApp extends GeckoApp
}
if (AppConstants.MOZ_UPDATER) {
Tabs.getInstance().loadUrlInTab("about:");
Tabs.getInstance().loadUrlInTab(AboutPages.UPDATER);
return true;
}

View File

@ -71,6 +71,8 @@ import android.telephony.TelephonyManager;
import android.telephony.PhoneStateListener;
import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Base64;
import android.util.Log;
@ -1353,7 +1355,7 @@ abstract public class GeckoApp
if (!mShouldRestore) {
// Show about:home if we aren't restoring previous session and
// there's no external URL
Tab tab = Tabs.getInstance().loadUrl("about:home", Tabs.LOADURL_NEW_TAB);
Tab tab = Tabs.getInstance().loadUrl(AboutPages.HOME, Tabs.LOADURL_NEW_TAB);
}
} else {
// If given an external URL, load it
@ -1375,12 +1377,13 @@ abstract public class GeckoApp
String action = intent.getAction();
String passedUri = null;
String uri = getURIFromIntent(intent);
if (uri != null && uri.length() > 0) {
final String uri = getURIFromIntent(intent);
if (!TextUtils.isEmpty(uri)) {
passedUri = uri;
}
final boolean isExternalURL = passedUri != null && !passedUri.equals("about:home");
final boolean isExternalURL = passedUri != null &&
!AboutPages.isAboutHome(passedUri);
StartupAction startupAction;
if (isExternalURL) {
startupAction = StartupAction.URL;

View File

@ -10,13 +10,6 @@ import android.text.TextUtils;
public class ReaderModeUtils {
private static final String LOGTAG = "ReaderModeUtils";
public static boolean isAboutReader(String url) {
if (url == null)
return false;
return url.startsWith("about:reader");
}
public static String getUrlFromAboutReader(String aboutReaderUrl) {
if (aboutReaderUrl == null)
return null;
@ -49,15 +42,18 @@ public class ReaderModeUtils {
}
public static boolean isEnteringReaderMode(String currentUrl, String newUrl) {
if (currentUrl == null || newUrl == null)
if (currentUrl == null || newUrl == null) {
return false;
}
if (!isAboutReader(newUrl))
if (!AboutPages.isAboutReader(newUrl)) {
return false;
}
String urlFromAboutReader = getUrlFromAboutReader(newUrl);
if (urlFromAboutReader == null)
if (urlFromAboutReader == null) {
return false;
}
return urlFromAboutReader.equals(currentUrl);
}
@ -67,10 +63,11 @@ public class ReaderModeUtils {
}
public static String getAboutReaderForUrl(String url, int tabId) {
String aboutReaderUrl = "about:reader?url=" + Uri.encode(url);
String aboutReaderUrl = AboutPages.READER + "?url=" + Uri.encode(url);
if (tabId >= 0)
if (tabId >= 0) {
aboutReaderUrl += "&tabId=" + tabId;
}
return aboutReaderUrl;
}

View File

@ -477,7 +477,7 @@ public class Tab {
}
public void toggleReaderMode() {
if (ReaderModeUtils.isAboutReader(mUrl)) {
if (AboutPages.isAboutReader(mUrl)) {
Tabs.getInstance().loadUrl(ReaderModeUtils.getUrlFromAboutReader(mUrl));
} else if (mReaderEnabled) {
mEnteringReaderMode = true;
@ -649,8 +649,9 @@ public class Tab {
Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.LOCATION_CHANGE, uri);
}
private boolean shouldShowProgress(String url) {
return "about:home".equals(url) || ReaderModeUtils.isAboutReader(url);
private static boolean shouldShowProgress(final String url) {
return AboutPages.isAboutHome(url) ||
AboutPages.isAboutReader(url);
}
void handleDocumentStart(boolean showProgress, String url) {

View File

@ -307,8 +307,9 @@ public class Tabs implements GeckoEventListener {
int tabId = tab.getId();
removeTab(tabId);
if (nextTab == null)
nextTab = loadUrl("about:home", LOADURL_NEW_TAB);
if (nextTab == null) {
nextTab = loadUrl(AboutPages.HOME, LOADURL_NEW_TAB);
}
selectTab(nextTab.getId());
@ -634,7 +635,7 @@ public class Tabs implements GeckoEventListener {
public int getTabIdForUrl(String url, boolean isPrivate) {
for (Tab tab : mOrder) {
String tabUrl = tab.getURL();
if (ReaderModeUtils.isAboutReader(tabUrl)) {
if (AboutPages.isAboutReader(tabUrl)) {
tabUrl = ReaderModeUtils.getUrlFromAboutReader(tabUrl);
}
if (TextUtils.equals(tabUrl, url) && isPrivate == tab.isPrivate()) {

View File

@ -264,12 +264,13 @@ public class TabsTray extends TwoWayView
row.id = tab.getId();
Drawable thumbnailImage = tab.getThumbnail();
if (thumbnailImage != null)
if (thumbnailImage != null) {
row.thumbnail.setImageDrawable(thumbnailImage);
else if (TextUtils.equals(tab.getURL(), ABOUT_HOME))
} else if (AboutPages.isAboutHome(tab.getURL())) {
row.thumbnail.setImageResource(R.drawable.abouthome_thumbnail);
else
} else {
row.thumbnail.setImageResource(R.drawable.tab_thumbnail_default);
}
row.title.setText(tab.getDisplayTitle());
row.close.setTag(row);

View File

@ -59,7 +59,7 @@ public final class ThumbnailHelper {
}
public void getAndProcessThumbnailFor(Tab tab) {
if ("about:home".equals(tab.getURL())) {
if (AboutPages.isAboutHome(tab.getURL())) {
tab.updateThumbnail(null);
return;
}

View File

@ -19,7 +19,6 @@ import android.util.SparseArray;
import java.util.List;
public class BrowserDB {
public static String ABOUT_PAGES_URL_FILTER = "about:%";
private static boolean sAreContentProvidersEnabled = true;
public static interface URLColumns {

View File

@ -5,6 +5,7 @@
package org.mozilla.gecko.db;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.db.BrowserContract.Bookmarks;
import org.mozilla.gecko.db.BrowserContract.Combined;
import org.mozilla.gecko.db.BrowserContract.ExpirePriority;
@ -250,7 +251,7 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
Combined.HISTORY_ID },
"",
limit,
BrowserDB.ABOUT_PAGES_URL_FILTER,
AboutPages.URL_FILTER,
selection,
selectionArgs);
}

View File

@ -5,8 +5,7 @@
package org.mozilla.gecko.favicons;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
@ -17,7 +16,9 @@ import org.mozilla.gecko.util.ThreadUtils;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.util.LruCache;
import android.text.TextUtils;
import android.util.Log;
import java.net.URI;
@ -350,7 +351,7 @@ public class Favicons {
// is bundled in the database, keyed only by page URL, hence the need to return the page URL
// here. If the database ever migrates to stop being silly in this way, this can plausibly
// be removed.
if (pageURL.startsWith("about:") || pageURL.startsWith("jar:")) {
if (AboutPages.isAboutPage(pageURL) || pageURL.startsWith("jar:")) {
return pageURL;
}

View File

@ -5,6 +5,7 @@
package org.mozilla.gecko.home;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.SessionParser;
@ -227,7 +228,7 @@ public class LastTabsPage extends HomeFragment {
final String url = tab.getUrl();
// Don't show last tabs for about:home
if (url.equals("about:home")) {
if (AboutPages.isAboutHome(url)) {
return;
}

View File

@ -84,6 +84,7 @@ if CONFIG['MOZ_WEBRTC']:
gbjar = add_java_jar('gecko-browser')
gbjar.sources += [
'AboutPages.java',
'ActivityHandlerHelper.java',
'AlertNotification.java',
'animation/AnimatorProxy.java',

View File

@ -5,6 +5,7 @@
package org.mozilla.gecko.toolbar;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.BrowserApp;
import org.mozilla.gecko.CustomEditText;
import org.mozilla.gecko.InputMethods;
@ -1108,7 +1109,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
}
// Setting a null title will ensure we just see the "Enter Search or Address" placeholder text.
if ("about:home".equals(url) || "about:privatebrowsing".equals(url)) {
if (AboutPages.isTitlelessAboutPage(url)) {
setTitle(null);
return;
}