michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko; michael@0: michael@0: import org.mozilla.gecko.util.StringUtils; michael@0: michael@0: import android.net.Uri; michael@0: michael@0: public class ReaderModeUtils { michael@0: private static final String LOGTAG = "ReaderModeUtils"; michael@0: michael@0: public static String getUrlFromAboutReader(String aboutReaderUrl) { michael@0: return StringUtils.getQueryParameter(aboutReaderUrl, "url"); michael@0: } michael@0: michael@0: public static boolean isEnteringReaderMode(String currentUrl, String newUrl) { michael@0: if (currentUrl == null || newUrl == null) { michael@0: return false; michael@0: } michael@0: michael@0: if (!AboutPages.isAboutReader(newUrl)) { michael@0: return false; michael@0: } michael@0: michael@0: String urlFromAboutReader = getUrlFromAboutReader(newUrl); michael@0: if (urlFromAboutReader == null) { michael@0: return false; michael@0: } michael@0: michael@0: return urlFromAboutReader.equals(currentUrl); michael@0: } michael@0: michael@0: public static String getAboutReaderForUrl(String url) { michael@0: return getAboutReaderForUrl(url, -1); michael@0: } michael@0: michael@0: public static String getAboutReaderForUrl(String url, int tabId) { michael@0: String aboutReaderUrl = AboutPages.READER + "?url=" + Uri.encode(url); michael@0: michael@0: if (tabId >= 0) { michael@0: aboutReaderUrl += "&tabId=" + tabId; michael@0: } michael@0: michael@0: return aboutReaderUrl; michael@0: } michael@0: }