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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/TitleUtil.java

Issue 2162653003: Extract TitleUtil from NewTabPageView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Address bauerb's comments. Add unit test. Created 4 years, 5 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: chrome/android/java/src/org/chromium/chrome/browser/ntp/TitleUtil.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/TitleUtil.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/TitleUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..df8190beff64b8350e218e00d6e087687f78f6b3
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/TitleUtil.java
@@ -0,0 +1,35 @@
+// 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.chrome.browser.ntp;
+
+import android.net.Uri;
+import android.text.TextUtils;
+
+import javax.annotation.Nullable;
+
+/**
+ * Provides functions for working with link titles.
+ */
+public final class TitleUtil {
+ private TitleUtil() {}
+
+ /**
+ * Returns a title suitable for display for a link. If |title| is non-empty, this simply returns
+ * it. Otherwise, returns a shortened form of the URL.
+ */
+ static String getTitleForDisplay(@Nullable String title, @Nullable String url) {
+ if (!TextUtils.isEmpty(title) || TextUtils.isEmpty(url)) {
+ return title;
+ }
+
+ Uri uri = Uri.parse(url);
+ String host = uri.getHost();
+ if (host == null) host = "";
+ String path = uri.getPath();
+ if (path == null || path.equals("/")) path = "";
+ title = host + path;
+ return title;
+ }
+}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsRowAdapter.java ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698