| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 #include "chrome/browser/extensions/api/passwords_private/passwords_private_util
s.h" |
| 6 |
| 7 #include "base/strings/string_util.h" |
| 8 #include "chrome/grit/generated_resources.h" |
| 9 #include "components/autofill/core/common/password_form.h" |
| 10 #include "components/password_manager/core/browser/password_ui_utils.h" |
| 11 #include "ui/base/l10n/l10n_util.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 constexpr char kAndroidAppScheme[] = "android://"; |
| 16 constexpr char kPlayStoreAppPrefix[] = |
| 17 "https://play.google.com/store/apps/details?id="; |
| 18 |
| 19 } // namespace |
| 20 |
| 21 namespace extensions { |
| 22 |
| 23 api::passwords_private::UrlCollection CreateUrlCollectionFromForm( |
| 24 const autofill::PasswordForm& form) { |
| 25 bool is_android_uri = false; |
| 26 GURL link_url; |
| 27 bool origin_is_clickable = false; |
| 28 api::passwords_private::UrlCollection urls; |
| 29 |
| 30 urls.origin = form.signon_realm; |
| 31 urls.shown = password_manager::GetShownOriginAndLinkUrl( |
| 32 form, &is_android_uri, &link_url, &origin_is_clickable); |
| 33 urls.link = link_url.spec(); |
| 34 |
| 35 if (is_android_uri) { |
| 36 if (!origin_is_clickable) { |
| 37 // If the origin is not clickable, link to the PlayStore. Use that |
| 38 // |urls.shown| is the result of |GetHumanReadableOriginForAndroidUri| and |
| 39 // does not contain the base64 hash anymore. |
| 40 urls.link = urls.shown; |
| 41 // e.g. android://com.example.r => r.example.com. |
| 42 urls.shown = password_manager::StripAndroidAndReverse(urls.shown); |
| 43 // Turn human unfriendly string into a clickable link to the PlayStore. |
| 44 base::ReplaceFirstSubstringAfterOffset(&urls.link, 0, kAndroidAppScheme, |
| 45 kPlayStoreAppPrefix); |
| 46 } |
| 47 |
| 48 // Currently we use "direction=rtl" in CSS to elide long origins from the |
| 49 // left. This does not play nice with appending strings that end in |
| 50 // punctuation symbols, which is why the bidirectional override tag is |
| 51 // necessary. |
| 52 // TODO(crbug.com/679434): Clean this up. |
| 53 // Reference: |
| 54 // https://www.w3.org/International/questions/qa-bidi-unicode-controls |
| 55 urls.shown += "\u202D" + // equivalent to <bdo dir = "ltr"> |
| 56 l10n_util::GetStringUTF8(IDS_PASSWORDS_ANDROID_URI_SUFFIX) + |
| 57 "\u202C"; // equivalent to </bdo> |
| 58 } |
| 59 |
| 60 return urls; |
| 61 } |
| 62 |
| 63 } // namespace extensions |
| OLD | NEW |