michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko; michael@0: michael@0: import org.mozilla.gecko.util.StringUtils; michael@0: michael@0: public class AboutPages { michael@0: // All of our special pages. michael@0: public static final String ADDONS = "about:addons"; michael@0: public static final String APPS = "about:apps"; michael@0: public static final String CONFIG = "about:config"; michael@0: public static final String DOWNLOADS = "about:downloads"; michael@0: public static final String FIREFOX = "about:firefox"; michael@0: public static final String HEALTHREPORT = "about:healthreport"; michael@0: public static final String HOME = "about:home"; michael@0: public static final String PRIVATEBROWSING = "about:privatebrowsing"; michael@0: public static final String READER = "about:reader"; michael@0: public static final String UPDATER = "about:"; michael@0: michael@0: public static final String URL_FILTER = "about:%"; michael@0: michael@0: public static final String PANEL_PARAM = "panel"; michael@0: michael@0: public static final boolean isAboutPage(final String url) { michael@0: return url != null && url.startsWith("about:"); michael@0: } michael@0: michael@0: public static final boolean isTitlelessAboutPage(final String url) { michael@0: return isAboutHome(url) || michael@0: PRIVATEBROWSING.equals(url); michael@0: } michael@0: michael@0: public static final boolean isAboutHome(final String url) { michael@0: if (url == null || !url.startsWith(HOME)) { michael@0: return false; michael@0: } michael@0: // We sometimes append a parameter to "about:home" to specify which page to michael@0: // show when we open the home pager. Discard this parameter when checking michael@0: // whether or not this URL is "about:home". michael@0: return HOME.equals(url.split("\\?")[0]); michael@0: } michael@0: michael@0: public static final String getPanelIdFromAboutHomeUrl(String aboutHomeUrl) { michael@0: return StringUtils.getQueryParameter(aboutHomeUrl, PANEL_PARAM); michael@0: } michael@0: michael@0: public static final boolean isAboutReader(final String url) { michael@0: if (url == null) { michael@0: return false; michael@0: } michael@0: return url.startsWith(READER); michael@0: } michael@0: michael@0: private static final String[] DEFAULT_ICON_PAGES = new String[] { michael@0: HOME, michael@0: michael@0: ADDONS, michael@0: CONFIG, michael@0: DOWNLOADS, michael@0: FIREFOX, michael@0: HEALTHREPORT, michael@0: UPDATER michael@0: }; michael@0: michael@0: /** michael@0: * Callers must not modify the returned array. michael@0: */ michael@0: public static String[] getDefaultIconPages() { michael@0: return DEFAULT_ICON_PAGES; michael@0: } michael@0: michael@0: public static boolean isDefaultIconPage(final String url) { michael@0: if (url == null || michael@0: !url.startsWith("about:")) { michael@0: return false; michael@0: } michael@0: michael@0: // TODO: it'd be quicker to not compare the "about:" part every time. michael@0: for (int i = 0; i < DEFAULT_ICON_PAGES.length; ++i) { michael@0: if (DEFAULT_ICON_PAGES[i].equals(url)) { michael@0: return true; michael@0: } michael@0: } michael@0: return false; michael@0: } michael@0: } michael@0: