|
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/. */ |
|
5 |
|
6 package org.mozilla.gecko; |
|
7 |
|
8 import org.mozilla.gecko.util.StringUtils; |
|
9 |
|
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:"; |
|
22 |
|
23 public static final String URL_FILTER = "about:%"; |
|
24 |
|
25 public static final String PANEL_PARAM = "panel"; |
|
26 |
|
27 public static final boolean isAboutPage(final String url) { |
|
28 return url != null && url.startsWith("about:"); |
|
29 } |
|
30 |
|
31 public static final boolean isTitlelessAboutPage(final String url) { |
|
32 return isAboutHome(url) || |
|
33 PRIVATEBROWSING.equals(url); |
|
34 } |
|
35 |
|
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 } |
|
45 |
|
46 public static final String getPanelIdFromAboutHomeUrl(String aboutHomeUrl) { |
|
47 return StringUtils.getQueryParameter(aboutHomeUrl, PANEL_PARAM); |
|
48 } |
|
49 |
|
50 public static final boolean isAboutReader(final String url) { |
|
51 if (url == null) { |
|
52 return false; |
|
53 } |
|
54 return url.startsWith(READER); |
|
55 } |
|
56 |
|
57 private static final String[] DEFAULT_ICON_PAGES = new String[] { |
|
58 HOME, |
|
59 |
|
60 ADDONS, |
|
61 CONFIG, |
|
62 DOWNLOADS, |
|
63 FIREFOX, |
|
64 HEALTHREPORT, |
|
65 UPDATER |
|
66 }; |
|
67 |
|
68 /** |
|
69 * Callers must not modify the returned array. |
|
70 */ |
|
71 public static String[] getDefaultIconPages() { |
|
72 return DEFAULT_ICON_PAGES; |
|
73 } |
|
74 |
|
75 public static boolean isDefaultIconPage(final String url) { |
|
76 if (url == null || |
|
77 !url.startsWith("about:")) { |
|
78 return false; |
|
79 } |
|
80 |
|
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 } |
|
90 |