| Index: mobile/android/thirdparty/org/adblockplus/browser/UrlUtils.java | 
| =================================================================== | 
| new file mode 100644 | 
| --- /dev/null | 
| +++ b/mobile/android/thirdparty/org/adblockplus/browser/UrlUtils.java | 
| @@ -0,0 +1,71 @@ | 
| +/* | 
| + * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| + * Copyright (C) 2006-present eyeo GmbH | 
| + * | 
| + * Adblock Plus is free software: you can redistribute it and/or modify | 
| + * it under the terms of the GNU General Public License version 3 as | 
| + * published by the Free Software Foundation. | 
| + * | 
| + * Adblock Plus is distributed in the hope that it will be useful, | 
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| + * GNU General Public License for more details. | 
| + * | 
| + * You should have received a copy of the GNU General Public License | 
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 
| + */ | 
| + | 
| +package org.adblockplus.browser; | 
| + | 
| +import java.net.MalformedURLException; | 
| +import java.net.URL; | 
| + | 
| +public class UrlUtils | 
| +{ | 
| + | 
| + private static final String SCHEME_HTTP = "http"; | 
| + private static final String SCHEME_SEPARATOR = "://"; | 
| + private static final String WWW_HOST_PART = "www."; | 
| + | 
| + public static String formatUrl(String urlStr) | 
| + { | 
| + if (!urlStr.contains(SCHEME_SEPARATOR)) | 
| + { | 
| + urlStr = SCHEME_HTTP + SCHEME_SEPARATOR + urlStr; | 
| + } | 
| + return urlStr; | 
| + } | 
| + | 
| + public static String getHostFromUrl(String urlStr) | 
| + { | 
| + try | 
| + { | 
| + final URL url = new URL(formatUrl(urlStr)); | 
| + String host = url.getHost(); | 
| + if (host != null) | 
| + { | 
| + if (host.startsWith(WWW_HOST_PART)) | 
| + { | 
| + host = host.substring(WWW_HOST_PART.length()); | 
| + } | 
| + return host; | 
| + } | 
| + } | 
| + catch (MalformedURLException e) | 
| + { | 
| + } | 
| + return null; | 
| + } | 
| + | 
| + public static boolean isSchemeHttpOrHttps(String urlStr) | 
| + { | 
| + try | 
| + { | 
| + return new URL(urlStr).getProtocol().contains(SCHEME_HTTP); | 
| + } | 
| + catch (MalformedURLException e) | 
| + { | 
| + } | 
| + return false; | 
| + } | 
| +} |