Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 package org.mozilla.gecko;
8 import org.mozilla.gecko.util.StringUtils;
10 public class AboutPages {
11 // All of our special pages.
12 public static final String ADDONS = "about:addons";
13 public static final String APPS = "about:apps";
14 public static final String CONFIG = "about:config";
15 public static final String DOWNLOADS = "about:downloads";
16 public static final String FIREFOX = "about:firefox";
17 public static final String HEALTHREPORT = "about:healthreport";
18 public static final String HOME = "about:home";
19 public static final String PRIVATEBROWSING = "about:privatebrowsing";
20 public static final String READER = "about:reader";
21 public static final String UPDATER = "about:";
23 public static final String URL_FILTER = "about:%";
25 public static final String PANEL_PARAM = "panel";
27 public static final boolean isAboutPage(final String url) {
28 return url != null && url.startsWith("about:");
29 }
31 public static final boolean isTitlelessAboutPage(final String url) {
32 return isAboutHome(url) ||
33 PRIVATEBROWSING.equals(url);
34 }
36 public static final boolean isAboutHome(final String url) {
37 if (url == null || !url.startsWith(HOME)) {
38 return false;
39 }
40 // We sometimes append a parameter to "about:home" to specify which page to
41 // show when we open the home pager. Discard this parameter when checking
42 // whether or not this URL is "about:home".
43 return HOME.equals(url.split("\\?")[0]);
44 }
46 public static final String getPanelIdFromAboutHomeUrl(String aboutHomeUrl) {
47 return StringUtils.getQueryParameter(aboutHomeUrl, PANEL_PARAM);
48 }
50 public static final boolean isAboutReader(final String url) {
51 if (url == null) {
52 return false;
53 }
54 return url.startsWith(READER);
55 }
57 private static final String[] DEFAULT_ICON_PAGES = new String[] {
58 HOME,
60 ADDONS,
61 CONFIG,
62 DOWNLOADS,
63 FIREFOX,
64 HEALTHREPORT,
65 UPDATER
66 };
68 /**
69 * Callers must not modify the returned array.
70 */
71 public static String[] getDefaultIconPages() {
72 return DEFAULT_ICON_PAGES;
73 }
75 public static boolean isDefaultIconPage(final String url) {
76 if (url == null ||
77 !url.startsWith("about:")) {
78 return false;
79 }
81 // TODO: it'd be quicker to not compare the "about:" part every time.
82 for (int i = 0; i < DEFAULT_ICON_PAGES.length; ++i) {
83 if (DEFAULT_ICON_PAGES[i].equals(url)) {
84 return true;
85 }
86 }
87 return false;
88 }
89 }