1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/AboutPages.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko; 1.10 + 1.11 +import org.mozilla.gecko.util.StringUtils; 1.12 + 1.13 +public class AboutPages { 1.14 + // All of our special pages. 1.15 + public static final String ADDONS = "about:addons"; 1.16 + public static final String APPS = "about:apps"; 1.17 + public static final String CONFIG = "about:config"; 1.18 + public static final String DOWNLOADS = "about:downloads"; 1.19 + public static final String FIREFOX = "about:firefox"; 1.20 + public static final String HEALTHREPORT = "about:healthreport"; 1.21 + public static final String HOME = "about:home"; 1.22 + public static final String PRIVATEBROWSING = "about:privatebrowsing"; 1.23 + public static final String READER = "about:reader"; 1.24 + public static final String UPDATER = "about:"; 1.25 + 1.26 + public static final String URL_FILTER = "about:%"; 1.27 + 1.28 + public static final String PANEL_PARAM = "panel"; 1.29 + 1.30 + public static final boolean isAboutPage(final String url) { 1.31 + return url != null && url.startsWith("about:"); 1.32 + } 1.33 + 1.34 + public static final boolean isTitlelessAboutPage(final String url) { 1.35 + return isAboutHome(url) || 1.36 + PRIVATEBROWSING.equals(url); 1.37 + } 1.38 + 1.39 + public static final boolean isAboutHome(final String url) { 1.40 + if (url == null || !url.startsWith(HOME)) { 1.41 + return false; 1.42 + } 1.43 + // We sometimes append a parameter to "about:home" to specify which page to 1.44 + // show when we open the home pager. Discard this parameter when checking 1.45 + // whether or not this URL is "about:home". 1.46 + return HOME.equals(url.split("\\?")[0]); 1.47 + } 1.48 + 1.49 + public static final String getPanelIdFromAboutHomeUrl(String aboutHomeUrl) { 1.50 + return StringUtils.getQueryParameter(aboutHomeUrl, PANEL_PARAM); 1.51 + } 1.52 + 1.53 + public static final boolean isAboutReader(final String url) { 1.54 + if (url == null) { 1.55 + return false; 1.56 + } 1.57 + return url.startsWith(READER); 1.58 + } 1.59 + 1.60 + private static final String[] DEFAULT_ICON_PAGES = new String[] { 1.61 + HOME, 1.62 + 1.63 + ADDONS, 1.64 + CONFIG, 1.65 + DOWNLOADS, 1.66 + FIREFOX, 1.67 + HEALTHREPORT, 1.68 + UPDATER 1.69 + }; 1.70 + 1.71 + /** 1.72 + * Callers must not modify the returned array. 1.73 + */ 1.74 + public static String[] getDefaultIconPages() { 1.75 + return DEFAULT_ICON_PAGES; 1.76 + } 1.77 + 1.78 + public static boolean isDefaultIconPage(final String url) { 1.79 + if (url == null || 1.80 + !url.startsWith("about:")) { 1.81 + return false; 1.82 + } 1.83 + 1.84 + // TODO: it'd be quicker to not compare the "about:" part every time. 1.85 + for (int i = 0; i < DEFAULT_ICON_PAGES.length; ++i) { 1.86 + if (DEFAULT_ICON_PAGES[i].equals(url)) { 1.87 + return true; 1.88 + } 1.89 + } 1.90 + return false; 1.91 + } 1.92 +} 1.93 +