Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Unified Diff: components/url_formatter/android/java/src/org/chromium/components/url_formatter/UrlFormatter.java

Issue 2110543004: Move JNI bindings for url_formatter from chrome to //components/url_formatter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/url_formatter/android/java/src/org/chromium/components/url_formatter/UrlFormatter.java
diff --git a/components/url_formatter/android/java/src/org/chromium/components/url_formatter/UrlFormatter.java b/components/url_formatter/android/java/src/org/chromium/components/url_formatter/UrlFormatter.java
new file mode 100644
index 0000000000000000000000000000000000000000..98c394e171cb61b992dccbcae89efd445d0960b2
--- /dev/null
+++ b/components/url_formatter/android/java/src/org/chromium/components/url_formatter/UrlFormatter.java
@@ -0,0 +1,90 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.components.url_formatter;
+
+import android.text.TextUtils;
+
+import org.chromium.base.annotations.JNINamespace;
+
+import java.net.URI;
+
+/**
+ * Wrapper for utilities in url_formatter.
+ */
+@JNINamespace("url_formatter::android")
+public final class UrlFormatter {
+ /**
+ * Refer to url_formatter::FixupURL.
+ *
+ * Given a URL-like string, returns a real URL or null. For example:
+ * - "google.com" -> "http://google.com/"
+ * - "about:" -> "chrome://version/"
+ * - "//mail.google.com:/" -> "file:///mail.google.com:/"
+ * - "..." -> null
+ */
+ public static String fixupUrl(String uri) {
+ return TextUtils.isEmpty(uri) ? null : nativeFixupUrl(uri);
+ }
+
+ /**
+ * Builds a String representation of <code>uri</code> suitable for display to the user, omitting
+ * the scheme if it is "http://", the username and password, and trailing slash on a bare
+ * hostname.
+ *
+ * Some examples:
+ * - "http://user:password@example.com/" -> "example.com"
+ * - "https://example.com/path" -> "https://example.com/path"
+ * - "http://www.xn--frgbolaget-q5a.se" -> "www.färgbolaget.se"
+ *
+ * The IDN hostname is turned to Unicode if the Unicode representation is deemed safe.
+ * For more information, see <code>url_formatter::FormatUrl(const GURL&)</code>.
+ *
+ * @param uri URI to format.
+ * @return Formatted URL.
+ */
+ public static String formatUrlForDisplay(URI uri) {
+ return formatUrlForDisplay(uri.toString());
+ }
+
+ /**
+ * @see formatUrlForDisplay(java.net.URI)
+ */
+ public static String formatUrlForDisplay(String uri) {
+ return nativeFormatUrlForDisplay(uri);
+ }
+
+ /**
+ * Builds a String that strips down the URL to its scheme, host, and port.
+ * @param uri URI to break down.
+ * @param showScheme Whether or not to show the scheme. If the URL can't be parsed, this value
+ * is ignored.
+ * @return Stripped-down String containing the essential bits of the URL, or the original URL if
+ * it fails to parse it.
+ */
+ public static String formatUrlForSecurityDisplay(URI uri, boolean showScheme) {
+ return formatUrlForSecurityDisplay(uri.toString(), showScheme);
+ }
+
+ /**
+ * Builds a String that strips down |uri| to its scheme, host, and port.
+ * @param uri The URI to break down.
+ * @param showScheme Whether or not to show the scheme. If the URL can't be parsed, this value
+ * is ignored.
+ * @return Stripped-down String containing the essential bits of the URL, or the original URL if
+ * it fails to parse it.
+ */
+ public static String formatUrlForSecurityDisplay(String uri, boolean showScheme) {
+ if (showScheme) {
+ return nativeFormatUrlForSecurityDisplay(uri);
+ } else {
+ return nativeFormatUrlForSecurityDisplayOmitScheme(uri);
+ }
+ }
+
+ private static native String nativeFixupUrl(String url);
+ private static native String nativeFormatUrlForDisplay(String url);
+ private static native String nativeFormatUrlForSecurityDisplay(String url);
+ private static native String nativeFormatUrlForSecurityDisplayOmitScheme(String url);
+}
« no previous file with comments | « components/url_formatter/android/component_jni_registrar.cc ('k') | components/url_formatter/url_formatter.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698