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

Unified Diff: chrome/browser/extensions/api/passwords_private/passwords_private_utils.cc

Issue 2844963003: Introduce extensions::CreateUrlCollectionFromForm (Closed)
Patch Set: Revert One-Liner Created 3 years, 7 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/browser/extensions/api/passwords_private/passwords_private_utils.cc
diff --git a/chrome/browser/extensions/api/passwords_private/passwords_private_utils.cc b/chrome/browser/extensions/api/passwords_private/passwords_private_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6e3de33d91eac487f4ac38b7f7066f9bd9732ecf
--- /dev/null
+++ b/chrome/browser/extensions/api/passwords_private/passwords_private_utils.cc
@@ -0,0 +1,63 @@
+// Copyright 2017 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 "chrome/browser/extensions/api/passwords_private/passwords_private_utils.h"
+
+#include "base/strings/string_util.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/autofill/core/common/password_form.h"
+#include "components/password_manager/core/browser/password_ui_utils.h"
+#include "ui/base/l10n/l10n_util.h"
+
+namespace {
+
+constexpr char kAndroidAppScheme[] = "android://";
+constexpr char kPlayStoreAppPrefix[] =
+ "https://play.google.com/store/apps/details?id=";
+
+} // namespace
+
+namespace extensions {
+
+api::passwords_private::UrlCollection CreateUrlCollectionFromForm(
+ const autofill::PasswordForm& form) {
+ bool is_android_uri = false;
+ GURL link_url;
+ bool origin_is_clickable = false;
+ api::passwords_private::UrlCollection urls;
+
+ urls.origin = form.signon_realm;
+ urls.shown = password_manager::GetShownOriginAndLinkUrl(
+ form, &is_android_uri, &link_url, &origin_is_clickable);
+ urls.link = link_url.spec();
+
+ if (is_android_uri) {
+ if (!origin_is_clickable) {
+ // If the origin is not clickable, link to the PlayStore. Use that
+ // |urls.shown| is the result of |GetHumanReadableOriginForAndroidUri| and
+ // does not contain the base64 hash anymore.
+ urls.link = urls.shown;
+ // e.g. android://com.example.r => r.example.com.
+ urls.shown = password_manager::StripAndroidAndReverse(urls.shown);
+ // Turn human unfriendly string into a clickable link to the PlayStore.
+ base::ReplaceFirstSubstringAfterOffset(&urls.link, 0, kAndroidAppScheme,
+ kPlayStoreAppPrefix);
+ }
+
+ // Currently we use "direction=rtl" in CSS to elide long origins from the
+ // left. This does not play nice with appending strings that end in
+ // punctuation symbols, which is why the bidirectional override tag is
+ // necessary.
+ // TODO(crbug.com/679434): Clean this up.
+ // Reference:
+ // https://www.w3.org/International/questions/qa-bidi-unicode-controls
+ urls.shown += "\u202D" + // equivalent to <bdo dir = "ltr">
+ l10n_util::GetStringUTF8(IDS_PASSWORDS_ANDROID_URI_SUFFIX) +
+ "\u202C"; // equivalent to </bdo>
+ }
+
+ return urls;
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698