Chromium Code Reviews| Index: chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.cc |
| diff --git a/chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.cc b/chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.cc |
| index ee744580d8251a96c6d64567f483748ce5009f4e..48097a220ff886bc10f208abf79b37360b7b7633 100644 |
| --- a/chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.cc |
| +++ b/chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.cc |
| @@ -13,6 +13,7 @@ |
| #include "chrome/common/pref_names.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "components/password_manager/core/browser/affiliation_utils.h" |
| +#include "components/password_manager/core/browser/password_ui_utils.h" |
| #include "components/prefs/pref_service.h" |
| #include "content/public/browser/web_contents.h" |
| #include "ui/base/l10n/l10n_util.h" |
| @@ -25,8 +26,44 @@ std::string LoginPairToMapKey( |
| return origin_url + ',' + username; |
| } |
| +// Conveniece struct that mirrors the UrlCollection dictionary in |
| +// passwords_private.idl. |
| +struct URLs { |
|
hcarmona
2017/04/21 17:52:19
Can we drop the _url from these?
struct URLs {
jdoerrie
2017/04/21 20:08:25
Done.
|
| + std::string origin_url; |
| + std::string shown_url; |
| + std::string link_url; |
| +}; |
| + |
| +// Obtains origin and link URL from the passed in form. In case the origin |
| +// corresponds to the identifier of an Android app, it tries to create a human |
| +// readable version of the origin URL. |
| +URLs GetOriginAndLinkUrlAndPrettifyAndroid(const autofill::PasswordForm& form) { |
|
hcarmona
2017/04/21 17:52:19
Maybe rename to CreateURLFromForm?
jdoerrie
2017/04/21 20:08:25
Done.
|
| + bool is_android_uri = false; |
| + GURL link_url; |
| + bool origin_is_clickable = false; |
| + std::string shown_url = password_manager::GetShownOriginAndLinkUrl( |
| + form, &is_android_uri, &link_url, &origin_is_clickable); |
| + |
| + if (is_android_uri) { |
| + // e.g. android://com.example.r => r.example.com. |
| + if (!origin_is_clickable) |
| + shown_url = password_manager::StripAndroidAndReverse(shown_url); |
| + |
| + // 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. |
| + shown_url += "\u202D" + // equivalent to <bdo dir = "ltr"> |
| + l10n_util::GetStringUTF8(IDS_PASSWORDS_ANDROID_URI_SUFFIX) + |
| + "\u202C"; // equivalent to </bdo> |
| + } |
| + |
| + return {form.signon_realm, shown_url, link_url.spec()}; |
| } |
| +} // namespace |
| + |
| namespace extensions { |
| PasswordsPrivateDelegateImpl::PasswordsPrivateDelegateImpl(Profile* profile) |
| @@ -65,7 +102,7 @@ void PasswordsPrivateDelegateImpl::SendPasswordExceptionsList() { |
| } |
| void PasswordsPrivateDelegateImpl::GetPasswordExceptionsList( |
| - const ExceptionPairsCallback& callback) { |
| + const ExceptionEntriesCallback& callback) { |
| if (current_exceptions_initialized_) |
| callback.Run(current_exceptions_); |
| else |
| @@ -166,22 +203,22 @@ void PasswordsPrivateDelegateImpl::SetPasswordList( |
| const std::vector<std::unique_ptr<autofill::PasswordForm>>& password_list) { |
| // Rebuild |login_pair_to_index_map_| so that it reflects the contents of the |
| // new list. |
| + // Also, create a list of PasswordUiEntry objects to send to observers. |
| login_pair_to_index_map_.clear(); |
| + current_entries_.clear(); |
| + |
| for (size_t i = 0; i < password_list.size(); i++) { |
| + const auto& form = password_list[i]; |
| + URLs urls = GetOriginAndLinkUrlAndPrettifyAndroid(*form); |
| std::string key = LoginPairToMapKey( |
| - password_manager::GetHumanReadableOrigin(*password_list[i]), |
| - base::UTF16ToUTF8(password_list[i]->username_value)); |
| + urls.origin_url, base::UTF16ToUTF8(form->username_value)); |
| login_pair_to_index_map_[key] = i; |
| - } |
| - // Now, create a list of PasswordUiEntry objects to send to observers. |
| - current_entries_.clear(); |
| - for (const auto& form : password_list) { |
| api::passwords_private::PasswordUiEntry entry; |
| - entry.login_pair.origin_url = |
| - password_manager::GetHumanReadableOrigin(*form); |
| + entry.login_pair.urls.origin_url = std::move(urls.origin_url); |
| + entry.login_pair.urls.shown_url = std::move(urls.shown_url); |
| + entry.login_pair.urls.link_url = std::move(urls.link_url); |
| entry.login_pair.username = base::UTF16ToUTF8(form->username_value); |
| - entry.link_url = form->origin.spec(); |
| entry.num_characters_in_password = form->password_value.length(); |
| if (!form->federation_origin.unique()) { |
| @@ -211,20 +248,20 @@ void PasswordsPrivateDelegateImpl::SetPasswordExceptionList( |
| password_exception_list) { |
| // Rebuild |exception_url_to_index_map_| so that it reflects the contents of |
| // the new list. |
| + // Also, create a list of exceptions to send to observers. |
| exception_url_to_index_map_.clear(); |
| - for (size_t i = 0; i < password_exception_list.size(); i++) { |
| - std::string key = password_manager::GetHumanReadableOrigin( |
| - *password_exception_list[i]); |
| - exception_url_to_index_map_[key] = i; |
| - } |
| - |
| - // Now, create a list of exceptions to send to observers. |
| current_exceptions_.clear(); |
| - for (const auto& form : password_exception_list) { |
| - api::passwords_private::ExceptionPair pair; |
| - pair.exception_url = password_manager::GetHumanReadableOrigin(*form); |
| - pair.link_url = form->origin.spec(); |
| - current_exceptions_.push_back(std::move(pair)); |
| + |
| + for (size_t i = 0; i < password_exception_list.size(); i++) { |
| + const auto& form = password_exception_list[i]; |
| + URLs urls = GetOriginAndLinkUrlAndPrettifyAndroid(*form); |
| + exception_url_to_index_map_[urls.origin_url] = i; |
| + |
| + api::passwords_private::ExceptionEntry current_exception_entry; |
| + current_exception_entry.urls.origin_url = std::move(urls.origin_url); |
| + current_exception_entry.urls.shown_url = std::move(urls.shown_url); |
| + current_exception_entry.urls.link_url = std::move(urls.link_url); |
| + current_exceptions_.push_back(std::move(current_exception_entry)); |
| } |
| SendPasswordExceptionsList(); |