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

Unified Diff: components/password_manager/core/browser/password_ui_utils.cc

Issue 1318523011: [Password Manager] Copiable username and origin. Linkable origin elided from the left. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes with StringPiece Created 5 years, 2 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/password_manager/core/browser/password_ui_utils.cc
diff --git a/components/password_manager/core/browser/password_ui_utils.cc b/components/password_manager/core/browser/password_ui_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2b9d99dc1048b03a4b7c5760c026e6d8bfaaf708
--- /dev/null
+++ b/components/password_manager/core/browser/password_ui_utils.cc
@@ -0,0 +1,38 @@
+// Copyright 2015 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.
+
+#include <components/password_manager/core/browser/password_ui_utils.h>
+
+#include <string>
+
+#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "components/url_formatter/elide_url.h"
+
+namespace password_manager {
+
+namespace {
+
+// The URL prefixes that are removed from shown origin.
+const char* const kRemovedPrefixes[] = {"m.", "mobile.", "www."};
+
+} // namespace
+
+std::string GetShownOrigin(const GURL& url, const std::string& languages) {
+ std::string original = base::UTF16ToUTF8(
+ url_formatter::FormatUrlForSecurityDisplayOmitScheme(url, languages));
+ base::StringPiece result = original;
+ for (base::StringPiece prefix : kRemovedPrefixes) {
+ if (base::StartsWith(result, prefix,
+ base::CompareCase::INSENSITIVE_ASCII)) {
+ result.remove_prefix(prefix.length());
+ break; // Remove only one prefix (e.g. www.mobile.de).
+ }
+ }
+
+ return result.find('.') != base::StringPiece::npos ? result.as_string()
+ : original;
+}
+
+} // namespace password_manager

Powered by Google App Engine
This is Rietveld 408576698