From 56733523e9d9cfd0b03d1918f0dcaddd015440c0 Mon Sep 17 00:00:00 2001 From: melandory Date: Tue, 13 Jan 2015 06:49:20 -0800 Subject: [PATCH] Adds method to PasswordStore which return origin in human readable form. This is needed for Android URL representation. Currently, Android URL's have following form android://m3HSJL1i83hdltRq0-o9czGb-8KJDKra4t_3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==@com.example.android This looks bad on chrome://settings/passwords, so we need to put infrastructure in place which allows us to show android://com.example.android instead. BUG=437865 R=estade@chromium.org,engedy@chromium.org,mkwst@chromium.org Review URL: https://codereview.chromium.org/839803002 Cr-Commit-Position: refs/heads/master@{#311269} --- .../ui/passwords/manage_passwords_view_utils.cc | 21 ++++++++ .../ui/passwords/manage_passwords_view_utils.h | 21 ++++++++ .../manage_passwords_view_utils_unittest.cc | 60 ++++++++++++++++++++++ .../ui/webui/options/password_manager_handler.cc | 12 ++--- chrome/chrome_browser_ui.gypi | 2 + chrome/chrome_tests_unit.gypi | 1 + 6 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 chrome/browser/ui/passwords/manage_passwords_view_utils.cc create mode 100644 chrome/browser/ui/passwords/manage_passwords_view_utils.h create mode 100644 chrome/browser/ui/passwords/manage_passwords_view_utils_unittest.cc diff --git a/chrome/browser/ui/passwords/manage_passwords_view_utils.cc b/chrome/browser/ui/passwords/manage_passwords_view_utils.cc new file mode 100644 index 000000000000..9b2425d44f89 --- /dev/null +++ b/chrome/browser/ui/passwords/manage_passwords_view_utils.cc @@ -0,0 +1,21 @@ +// 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 "chrome/browser/ui/passwords/manage_passwords_view_utils.h" + +#include "base/strings/utf_string_conversions.h" +#include "components/autofill/core/common/password_form.h" +#include "components/password_manager/core/browser/affiliation_utils.h" +#include "net/base/net_util.h" +#include "url/gurl.h" + +std::string GetHumanReadableOrigin(const autofill::PasswordForm& password_form, + const std::string& languages) { + password_manager::FacetURI facet_uri = + password_manager::FacetURI::FromPotentiallyInvalidSpec( + password_form.signon_realm); + if (facet_uri.IsValidAndroidFacetURI()) + return facet_uri.scheme() + "://" + facet_uri.android_package_name(); + return base::UTF16ToUTF8(net::FormatUrl(password_form.origin, languages)); +} diff --git a/chrome/browser/ui/passwords/manage_passwords_view_utils.h b/chrome/browser/ui/passwords/manage_passwords_view_utils.h new file mode 100644 index 000000000000..9f92fa9884bc --- /dev/null +++ b/chrome/browser/ui/passwords/manage_passwords_view_utils.h @@ -0,0 +1,21 @@ +// 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. + +#ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_VIEW_UTILS_H_ +#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_VIEW_UTILS_H_ + +#include + +namespace autofill { +struct PasswordForm; +} + +// Returns the origin URI in a format which can be presented to a user based of +// |password_from| field values. For web URIs |languages| is using in order to +// determine whether a URI is 'comprehensible' to a user who understands +// languages listed. +std::string GetHumanReadableOrigin(const autofill::PasswordForm& password_form, + const std::string& languages); + +#endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_VIEW_UTILS_H_ diff --git a/chrome/browser/ui/passwords/manage_passwords_view_utils_unittest.cc b/chrome/browser/ui/passwords/manage_passwords_view_utils_unittest.cc new file mode 100644 index 000000000000..63f3504e494f --- /dev/null +++ b/chrome/browser/ui/passwords/manage_passwords_view_utils_unittest.cc @@ -0,0 +1,60 @@ +// 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 "chrome/browser/ui/passwords/manage_passwords_view_utils.h" + +#include "base/strings/utf_string_conversions.h" +#include "components/autofill/core/common/password_form.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/url_constants.h" + +namespace { +const std::string kSchemeHostExample = "http://example.com"; +} // namespace + +class GetHumanReadableOriginTest : public testing::Test { + public: + GetHumanReadableOriginTest() { + form_template_.origin = GURL(kSchemeHostExample); + form_template_.action = GURL(kSchemeHostExample); + form_template_.username_element = base::ASCIIToUTF16("Email"); + form_template_.password_element = base::ASCIIToUTF16("Password"); + form_template_.submit_element = base::ASCIIToUTF16("signIn"); + form_template_.signon_realm = kSchemeHostExample; + } + const autofill::PasswordForm& form_remplate() { return form_template_; } + + private: + autofill::PasswordForm form_template_; +}; + +TEST_F(GetHumanReadableOriginTest, OriginFromHtmlForm) { + autofill::PasswordForm html_form(form_remplate()); + html_form.origin = GURL(kSchemeHostExample + "/LoginAuth"); + html_form.action = GURL(kSchemeHostExample + "/Login"); + html_form.scheme = autofill::PasswordForm::SCHEME_HTML; + EXPECT_EQ(GetHumanReadableOrigin(html_form, ""), "example.com/LoginAuth"); +} + +TEST_F(GetHumanReadableOriginTest, OriginFromDigestForm) { + autofill::PasswordForm non_html_form(form_remplate()); + non_html_form.scheme = autofill::PasswordForm::SCHEME_DIGEST; + non_html_form.action = GURL(); + non_html_form.signon_realm = kSchemeHostExample + "42"; + EXPECT_EQ(GetHumanReadableOrigin(non_html_form, ""), "example.com"); +} + +TEST_F(GetHumanReadableOriginTest, OriginFromAndroidForm) { + autofill::PasswordForm android_form(form_remplate()); + android_form.action = GURL(); + android_form.origin = GURL(); + android_form.scheme = autofill::PasswordForm::SCHEME_OTHER; + android_form.signon_realm = + "android://" + "m3HSJL1i83hdltRq0-o9czGb-8KJDKra4t_" + "3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==" + "@com.example.android"; + EXPECT_EQ(GetHumanReadableOrigin(android_form, ""), + "android://com.example.android"); +} diff --git a/chrome/browser/ui/webui/options/password_manager_handler.cc b/chrome/browser/ui/webui/options/password_manager_handler.cc index 1e89e298d1b6..e8751d54d1e4 100644 --- a/chrome/browser/ui/webui/options/password_manager_handler.cc +++ b/chrome/browser/ui/webui/options/password_manager_handler.cc @@ -15,6 +15,7 @@ #if defined(OS_WIN) && defined(USE_ASH) #include "chrome/browser/ui/ash/ash_util.h" #endif +#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "chrome/grit/generated_resources.h" @@ -182,15 +183,14 @@ void PasswordManagerHandler::SetPasswordList( base::string16 placeholder(base::ASCIIToUTF16(" ")); for (size_t i = 0; i < password_list.size(); ++i) { base::ListValue* entry = new base::ListValue(); - entry->Append(new base::StringValue(net::FormatUrl(password_list[i]->origin, - languages_))); - entry->Append(new base::StringValue(password_list[i]->username_value)); + entry->AppendString(GetHumanReadableOrigin(*password_list[i], languages_)); + entry->AppendString(password_list[i]->username_value); if (show_passwords) { - entry->Append(new base::StringValue(password_list[i]->password_value)); + entry->AppendString(password_list[i]->password_value); } else { // Use a placeholder value with the same length as the password. - entry->Append(new base::StringValue( - base::string16(password_list[i]->password_value.length(), ' '))); + entry->AppendString( + base::string16(password_list[i]->password_value.length(), ' ')); } entries.Append(entry); } diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 0c0e3fc18844..938c8a07d98c 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -793,6 +793,8 @@ 'browser/ui/passwords/manage_passwords_icon.h', 'browser/ui/passwords/manage_passwords_ui_controller.cc', 'browser/ui/passwords/manage_passwords_ui_controller.h', + 'browser/ui/passwords/manage_passwords_view_utils.cc', + 'browser/ui/passwords/manage_passwords_view_utils.h', 'browser/ui/passwords/password_bubble_experiment.cc', 'browser/ui/passwords/password_bubble_experiment.h', 'browser/ui/passwords/password_manager_presenter.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index ead2e9e2a7d2..47f70eab6cba 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -527,6 +527,7 @@ 'browser/ui/passwords/manage_passwords_bubble_model_unittest.cc', 'browser/ui/passwords/manage_passwords_icon_mock.cc', 'browser/ui/passwords/manage_passwords_ui_controller_unittest.cc', + 'browser/ui/passwords/manage_passwords_view_utils_unittest.cc', 'browser/ui/passwords/password_bubble_experiment_unittest.cc', 'browser/ui/passwords/password_manager_presenter_unittest.cc', 'browser/ui/search_engines/keyword_editor_controller_unittest.cc', -- 2.11.4.GIT