Commit ab8c5abf authored by melandory's avatar melandory Committed by Commit bot

[Smart Lock] Make android URL prettifying util available on ios.

Move GetHumanReadableOrigin method to affliation utils in order
to make it available in ios. This CL requires  GetHumanReadableOrigin
on ios: https://chromereviews.googleplex.com/191547013/

BUG=486736

Review URL: https://codereview.chromium.org/1130213004

Cr-Commit-Position: refs/heads/master@{#330343}
parent 3ff0cb0f
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "chrome/browser/ui/passwords/password_bubble_experiment.h" #include "chrome/browser/ui/passwords/password_bubble_experiment.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "components/autofill/core/common/password_form.h" #include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/affiliation_utils.h"
#include "components/password_manager/core/common/experiments.h" #include "components/password_manager/core/common/experiments.h"
#include "components/password_manager/core/common/password_manager_switches.h" #include "components/password_manager/core/common/password_manager_switches.h"
#include "jni/PasswordUIView_jni.h" #include "jni/PasswordUIView_jni.h"
...@@ -77,7 +77,7 @@ PasswordUIViewAndroid::GetSavedPasswordEntry(JNIEnv* env, jobject, int index) { ...@@ -77,7 +77,7 @@ PasswordUIViewAndroid::GetSavedPasswordEntry(JNIEnv* env, jobject, int index) {
ConvertUTF8ToJavaString(env, std::string()).obj(), ConvertUTF8ToJavaString(env, std::string()).obj(),
ConvertUTF16ToJavaString(env, base::string16()).obj()); ConvertUTF16ToJavaString(env, base::string16()).obj());
} }
std::string human_readable_origin = GetHumanReadableOrigin( std::string human_readable_origin = password_manager::GetHumanReadableOrigin(
*form, GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages)); *form, GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
return Java_PasswordUIView_createSavedPasswordEntry( return Java_PasswordUIView_createSavedPasswordEntry(
env, ConvertUTF8ToJavaString(env, human_readable_origin).obj(), env, ConvertUTF8ToJavaString(env, human_readable_origin).obj(),
...@@ -90,7 +90,7 @@ ScopedJavaLocalRef<jstring> PasswordUIViewAndroid::GetSavedPasswordException( ...@@ -90,7 +90,7 @@ ScopedJavaLocalRef<jstring> PasswordUIViewAndroid::GetSavedPasswordException(
password_manager_presenter_.GetPasswordException(index); password_manager_presenter_.GetPasswordException(index);
if (!form) if (!form)
return ConvertUTF8ToJavaString(env, std::string()); return ConvertUTF8ToJavaString(env, std::string());
std::string human_readable_origin = GetHumanReadableOrigin( std::string human_readable_origin = password_manager::GetHumanReadableOrigin(
*form, GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages)); *form, GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
return ConvertUTF8ToJavaString(env, human_readable_origin); return ConvertUTF8ToJavaString(env, human_readable_origin);
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "base/strings/utf_string_conversions.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 "components/password_manager/core/browser/affiliation_utils.h"
#include "net/base/net_util.h" #include "net/base/net_util.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -29,13 +28,3 @@ gfx::ImageSkia ScaleImageForAccountAvatar(gfx::ImageSkia skia_image) { ...@@ -29,13 +28,3 @@ gfx::ImageSkia ScaleImageForAccountAvatar(gfx::ImageSkia skia_image) {
skia::ImageOperations::RESIZE_BEST, skia::ImageOperations::RESIZE_BEST,
gfx::Size(kAvatarImageSize, kAvatarImageSize)); gfx::Size(kAvatarImageSize, kAvatarImageSize));
} }
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));
}
...@@ -5,12 +5,6 @@ ...@@ -5,12 +5,6 @@
#ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_VIEW_UTILS_H_ #ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_VIEW_UTILS_H_
#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_VIEW_UTILS_H_ #define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_VIEW_UTILS_H_
#include <string>
namespace autofill {
struct PasswordForm;
} // namespace autofill
namespace gfx { namespace gfx {
class ImageSkia; class ImageSkia;
} // namespace gfx } // namespace gfx
...@@ -20,12 +14,4 @@ extern const int kAvatarImageSize; ...@@ -20,12 +14,4 @@ extern const int kAvatarImageSize;
// Crops and scales |image_skia| to the desired size for an account avatar. // Crops and scales |image_skia| to the desired size for an account avatar.
gfx::ImageSkia ScaleImageForAccountAvatar(gfx::ImageSkia image_skia); gfx::ImageSkia ScaleImageForAccountAvatar(gfx::ImageSkia image_skia);
// 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_ #endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_VIEW_UTILS_H_
// 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");
}
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
#if defined(OS_WIN) && defined(USE_ASH) #if defined(OS_WIN) && defined(USE_ASH)
#include "chrome/browser/ui/ash/ash_util.h" #include "chrome/browser/ui/ash/ash_util.h"
#endif #endif
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "chrome/browser/ui/passwords/password_bubble_experiment.h" #include "chrome/browser/ui/passwords/password_bubble_experiment.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/autofill/core/common/password_form.h" #include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/affiliation_utils.h"
#include "components/password_manager/core/common/experiments.h" #include "components/password_manager/core/common/experiments.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
...@@ -201,7 +201,8 @@ void PasswordManagerHandler::SetPasswordList( ...@@ -201,7 +201,8 @@ void PasswordManagerHandler::SetPasswordList(
base::string16 placeholder(base::ASCIIToUTF16(" ")); base::string16 placeholder(base::ASCIIToUTF16(" "));
for (size_t i = 0; i < password_list.size(); ++i) { for (size_t i = 0; i < password_list.size(); ++i) {
base::ListValue* entry = new base::ListValue(); base::ListValue* entry = new base::ListValue();
entry->AppendString(GetHumanReadableOrigin(*password_list[i], languages_)); entry->AppendString(password_manager::GetHumanReadableOrigin(
*password_list[i], languages_));
entry->AppendString(password_list[i]->username_value); entry->AppendString(password_list[i]->username_value);
if (show_passwords) { if (show_passwords) {
entry->AppendString(password_list[i]->password_value); entry->AppendString(password_list[i]->password_value);
...@@ -227,8 +228,8 @@ void PasswordManagerHandler::SetPasswordExceptionList( ...@@ -227,8 +228,8 @@ void PasswordManagerHandler::SetPasswordExceptionList(
const ScopedVector<autofill::PasswordForm>& password_exception_list) { const ScopedVector<autofill::PasswordForm>& password_exception_list) {
base::ListValue entries; base::ListValue entries;
for (size_t i = 0; i < password_exception_list.size(); ++i) { for (size_t i = 0; i < password_exception_list.size(); ++i) {
entries.AppendString( entries.AppendString(password_manager::GetHumanReadableOrigin(
GetHumanReadableOrigin(*password_exception_list[i], languages_)); *password_exception_list[i], languages_));
} }
web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", web_ui()->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList",
......
...@@ -522,7 +522,6 @@ ...@@ -522,7 +522,6 @@
'browser/ui/passwords/manage_passwords_icon_mock.cc', 'browser/ui/passwords/manage_passwords_icon_mock.cc',
'browser/ui/passwords/manage_passwords_state_unittest.cc', 'browser/ui/passwords/manage_passwords_state_unittest.cc',
'browser/ui/passwords/manage_passwords_ui_controller_unittest.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_bubble_experiment_unittest.cc',
'browser/ui/passwords/password_manager_presenter_unittest.cc', 'browser/ui/passwords/password_manager_presenter_unittest.cc',
'browser/ui/search_engines/keyword_editor_controller_unittest.cc', 'browser/ui/search_engines/keyword_editor_controller_unittest.cc',
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/common/password_manager_switches.h" #include "components/password_manager/core/common/password_manager_switches.h"
#include "components/variations/variations_associated_data.h" #include "components/variations/variations_associated_data.h"
#include "net/base/escape.h" #include "net/base/escape.h"
...@@ -336,4 +337,13 @@ bool IsValidAndroidFacetURI(const std::string& url) { ...@@ -336,4 +337,13 @@ bool IsValidAndroidFacetURI(const std::string& url) {
return facet.IsValidAndroidFacetURI(); return facet.IsValidAndroidFacetURI();
} }
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));
}
} // namespace password_manager } // namespace password_manager
...@@ -50,9 +50,15 @@ ...@@ -50,9 +50,15 @@
#include "base/containers/hash_tables.h" #include "base/containers/hash_tables.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "net/base/net_util.h"
#include "url/url_parse.h" #include "url/url_parse.h"
namespace autofill {
struct PasswordForm;
} // namespace autofill
namespace base { namespace base {
class CommandLine; class CommandLine;
} // namespace base } // namespace base
...@@ -193,6 +199,13 @@ bool IsPropagatingPasswordChangesToWebCredentialsEnabled( ...@@ -193,6 +199,13 @@ bool IsPropagatingPasswordChangesToWebCredentialsEnabled(
bool IsAffiliationRequestsForDummyFacetsEnabled( bool IsAffiliationRequestsForDummyFacetsEnabled(
const base::CommandLine& command_line); const base::CommandLine& command_line);
// 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);
// For logging use only. // For logging use only.
std::ostream& operator<<(std::ostream& os, const FacetURI& facet_uri); std::ostream& operator<<(std::ostream& os, const FacetURI& facet_uri);
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/common/password_manager_switches.h" #include "components/password_manager/core/common/password_manager_switches.h"
#include "components/variations/variations_associated_data.h" #include "components/variations/variations_associated_data.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -15,6 +17,7 @@ namespace password_manager { ...@@ -15,6 +17,7 @@ namespace password_manager {
namespace { namespace {
const char kFieldTrialName[] = "AffiliationBasedMatching"; const char kFieldTrialName[] = "AffiliationBasedMatching";
const std::string kSchemeHostExample = "http://example.com";
const char kTestFacetURI1[] = "https://alpha.example.com/"; const char kTestFacetURI1[] = "https://alpha.example.com/";
const char kTestFacetURI2[] = "https://beta.example.com/"; const char kTestFacetURI2[] = "https://beta.example.com/";
const char kTestFacetURI3[] = "https://gamma.example.com/"; const char kTestFacetURI3[] = "https://gamma.example.com/";
...@@ -323,4 +326,50 @@ TEST(AffiliationUtilsTest, IsAffiliationRequestsForDummyFacetsEnabled) { ...@@ -323,4 +326,50 @@ TEST(AffiliationUtilsTest, IsAffiliationRequestsForDummyFacetsEnabled) {
} }
} }
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");
}
} // namespace password_manager } // namespace password_manager
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment