Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: mobile/android/thirdparty/org/adblockplus/browser/UrlUtils.java

Issue 29543774: Issue 2801 - Create 'Whitelisted websites' screen and add link to 'Ad blocking' screen (Closed)
Patch Set: Created Sept. 13, 2017, 5:01 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+ }
+}

Powered by Google App Engine
This is Rietveld