summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/AboutPages.java
blob: 705d700af1062ea02aa19394dcfd447cc27e583c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* -*- 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;

import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.home.HomeConfig;
import org.mozilla.gecko.home.HomeConfig.PanelType;
import org.mozilla.gecko.util.StringUtils;

public class AboutPages {
    // All of our special pages.
    public static final String ACCOUNTS        = "about:accounts";
    public static final String ADDONS          = "about:addons";
    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 LOGINS          = "about:logins";
    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 String PANEL_PARAM = "panel";

    public static final boolean isAboutPage(final String url) {
        return url != null && url.startsWith("about:");
    }

    public static final boolean isTitlelessAboutPage(final String url) {
        return isAboutHome(url) ||
               PRIVATEBROWSING.equals(url);
    }

    public static final boolean isAboutHome(final String url) {
        if (url == null || !url.startsWith(HOME)) {
            return false;
        }
        // We sometimes append a parameter to "about:home" to specify which page to
        // show when we open the home pager. Discard this parameter when checking
        // whether or not this URL is "about:home".
        return HOME.equals(url.split("\\?")[0]);
    }

    public static final String getPanelIdFromAboutHomeUrl(String aboutHomeUrl) {
        return StringUtils.getQueryParameter(aboutHomeUrl, PANEL_PARAM);
    }

    public static boolean isAboutReader(final String url) {
        return isAboutPage(READER, url);
    }

    public static boolean isAboutConfig(final String url) {
        return isAboutPage(CONFIG, url);
    }

    public static boolean isAboutAddons(final String url) {
        return isAboutPage(ADDONS, url);
    }

    public static boolean isAboutPrivateBrowsing(final String url) {
        return isAboutPage(PRIVATEBROWSING, url);
    }

    public static boolean isAboutPage(String page, String url) {
        return url != null && url.toLowerCase().startsWith(page);

    }

    public static final String[] DEFAULT_ICON_PAGES = new String[] {
        HOME,
        ACCOUNTS,
        ADDONS,
        CONFIG,
        DOWNLOADS,
        FIREFOX,
        HEALTHREPORT,
        UPDATER
    };

    public static boolean isBuiltinIconPage(final String url) {
        if (url == null ||
            !url.startsWith("about:")) {
            return false;
        }

        // about:home uses a separate search built-in icon.
        if (isAboutHome(url)) {
            return true;
        }

        // TODO: it'd be quicker to not compare the "about:" part every time.
        for (int i = 0; i < DEFAULT_ICON_PAGES.length; ++i) {
            if (DEFAULT_ICON_PAGES[i].equals(url)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Get a URL that navigates to the specified built-in Home Panel.
     *
     * @param panelType to navigate to.
     * @return URL.
     * @throws IllegalArgumentException if the built-in panel type is not a built-in panel.
     */
    @RobocopTarget
    public static String getURLForBuiltinPanelType(PanelType panelType) throws IllegalArgumentException {
        return HOME + "?panel=" + HomeConfig.getIdForBuiltinPanelType(panelType);
    }
}