gecko-dev/mobile/android/base/AboutPages.java
Nick Alexander cdb092fe66 Bug 1191067 - Add Fennec version of about:accounts. r=antlam,margaret
This is a Fennec version of about:accounts, cribbed largely from
Desktop's implementation.  This implementation serves two purposes:

One, it allows all fxa-content-server pref handling to remain in
Gecko.  Java-side consumers redirect to about:accounts?action=... and
have pref munging and parameter addition (like context=fx_fennec_v1,
etc) handled by about:accounts itself.

Two, it handles network connectivity display and error handling.  When
a request is started, we display an animated spinner.  We transition
smoothly from the spinner to the iframe display if we can, and if not
we hide any network error and offer to retry.  This is more important
in Fennec than it is on Desktop.  This approach agrees with Firefox
for iOS.

Some additional notes:

The spinner to iframe transition uses the WebChannel listener to send
LOADED messages to the appropriate XUL <browser> element.  It's worth
remembering that Fennec's Gecko is single process, so the <browser> in
question is in the same process.  None-the-less, we are close to e10s
safe.

There are four actions: signup/signin/force_reauth, and manage.  The
first three try to produce a LOGIN message.  The last uses the
fxa-content-server to manage the Account settings.  *This is not how
this is arranged on Desktop: Desktop redirects to a new tab, not
wrapped in about:accounts.*

--HG--
extra : commitid : F2waTwe355B
extra : rebase_source : f63c96f676d1300c774d091968ec8d88bb7a86dc
2015-09-18 16:28:14 -04:00

124 lines
4.2 KiB
Java

/* -*- 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);
}
private static final String[] DEFAULT_ICON_PAGES = new String[] {
ACCOUNTS,
ADDONS,
CONFIG,
DOWNLOADS,
FIREFOX,
HEALTHREPORT,
UPDATER
};
/**
* Callers must not modify the returned array.
*/
public static String[] getDefaultIconPages() {
return DEFAULT_ICON_PAGES;
}
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);
}
}