|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 package org.mozilla.gecko; |
|
6 |
|
7 import org.mozilla.gecko.util.StringUtils; |
|
8 |
|
9 import android.net.Uri; |
|
10 |
|
11 public class ReaderModeUtils { |
|
12 private static final String LOGTAG = "ReaderModeUtils"; |
|
13 |
|
14 public static String getUrlFromAboutReader(String aboutReaderUrl) { |
|
15 return StringUtils.getQueryParameter(aboutReaderUrl, "url"); |
|
16 } |
|
17 |
|
18 public static boolean isEnteringReaderMode(String currentUrl, String newUrl) { |
|
19 if (currentUrl == null || newUrl == null) { |
|
20 return false; |
|
21 } |
|
22 |
|
23 if (!AboutPages.isAboutReader(newUrl)) { |
|
24 return false; |
|
25 } |
|
26 |
|
27 String urlFromAboutReader = getUrlFromAboutReader(newUrl); |
|
28 if (urlFromAboutReader == null) { |
|
29 return false; |
|
30 } |
|
31 |
|
32 return urlFromAboutReader.equals(currentUrl); |
|
33 } |
|
34 |
|
35 public static String getAboutReaderForUrl(String url) { |
|
36 return getAboutReaderForUrl(url, -1); |
|
37 } |
|
38 |
|
39 public static String getAboutReaderForUrl(String url, int tabId) { |
|
40 String aboutReaderUrl = AboutPages.READER + "?url=" + Uri.encode(url); |
|
41 |
|
42 if (tabId >= 0) { |
|
43 aboutReaderUrl += "&tabId=" + tabId; |
|
44 } |
|
45 |
|
46 return aboutReaderUrl; |
|
47 } |
|
48 } |