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

Side by Side 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, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.components.url_formatter;
6
7 import android.text.TextUtils;
8
9 import org.chromium.base.annotations.JNINamespace;
10
11 import java.net.URI;
12
13 /**
14 * Wrapper for utilities in url_formatter.
15 */
16 @JNINamespace("url_formatter::android")
17 public final class UrlFormatter {
18 /**
19 * Refer to url_formatter::FixupURL.
20 *
21 * Given a URL-like string, returns a real URL or null. For example:
22 * - "google.com" -> "http://google.com/"
23 * - "about:" -> "chrome://version/"
24 * - "//mail.google.com:/" -> "file:///mail.google.com:/"
25 * - "..." -> null
26 */
27 public static String fixupUrl(String uri) {
28 return TextUtils.isEmpty(uri) ? null : nativeFixupUrl(uri);
29 }
30
31 /**
32 * Builds a String representation of <code>uri</code> suitable for display t o the user, omitting
33 * the scheme if it is "http://", the username and password, and trailing sl ash on a bare
34 * hostname.
35 *
36 * Some examples:
37 * - "http://user:password@example.com/" -> "example.com"
38 * - "https://example.com/path" -> "https://example.com/path"
39 * - "http://www.xn--frgbolaget-q5a.se" -> "www.färgbolaget.se"
40 *
41 * The IDN hostname is turned to Unicode if the Unicode representation is de emed safe.
42 * For more information, see <code>url_formatter::FormatUrl(const GURL&)</co de>.
43 *
44 * @param uri URI to format.
45 * @return Formatted URL.
46 */
47 public static String formatUrlForDisplay(URI uri) {
48 return formatUrlForDisplay(uri.toString());
49 }
50
51 /**
52 * @see formatUrlForDisplay(java.net.URI)
53 */
54 public static String formatUrlForDisplay(String uri) {
55 return nativeFormatUrlForDisplay(uri);
56 }
57
58 /**
59 * Builds a String that strips down the URL to its scheme, host, and port.
60 * @param uri URI to break down.
61 * @param showScheme Whether or not to show the scheme. If the URL can't be parsed, this value
62 * is ignored.
63 * @return Stripped-down String containing the essential bits of the URL, or the original URL if
64 * it fails to parse it.
65 */
66 public static String formatUrlForSecurityDisplay(URI uri, boolean showScheme ) {
67 return formatUrlForSecurityDisplay(uri.toString(), showScheme);
68 }
69
70 /**
71 * Builds a String that strips down |uri| to its scheme, host, and port.
72 * @param uri The URI to break down.
73 * @param showScheme Whether or not to show the scheme. If the URL can't be parsed, this value
74 * is ignored.
75 * @return Stripped-down String containing the essential bits of the URL, or the original URL if
76 * it fails to parse it.
77 */
78 public static String formatUrlForSecurityDisplay(String uri, boolean showSch eme) {
79 if (showScheme) {
80 return nativeFormatUrlForSecurityDisplay(uri);
81 } else {
82 return nativeFormatUrlForSecurityDisplayOmitScheme(uri);
83 }
84 }
85
86 private static native String nativeFixupUrl(String url);
87 private static native String nativeFormatUrlForDisplay(String url);
88 private static native String nativeFormatUrlForSecurityDisplay(String url);
89 private static native String nativeFormatUrlForSecurityDisplayOmitScheme(Str ing url);
90 }
OLDNEW
« 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