Commit eaf3b7c0 authored by Eleonora Rocchi's avatar Eleonora Rocchi Committed by Commit Bot

[PwdCheckAndroid] Add help icon handling to Check passwords view.

This CL adds the handling of the click on the help button in the menu bar for the check passwords view.
It also refactor some classes. Particularly, it separates the component UI from the feature component.



Bug: 1092444
Change-Id: Id07a4914a3eb36600a3f0d0da47ac9788d8be2a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2275451Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Commit-Queue: Eleonora Rocchi <erocchi@google.com>
Cr-Commit-Position: refs/heads/master@{#784873}
parent 2a1e964f
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
<string name="help_context_sync_and_services">syncgoogleservices</string> <string name="help_context_sync_and_services">syncgoogleservices</string>
<string name="help_context_passwords">passwords</string> <string name="help_context_passwords">passwords</string>
<string name="help_context_password_leak_detection">leak_detection_android</string> <string name="help_context_password_leak_detection">leak_detection_android</string>
<string name="help_context_check_passwords">check_passwords</string>
<!-- TODO(peconn): Add help section. --> <!-- TODO(peconn): Add help section. -->
<!-- <string name="help_context_suggestions">mobile_content_suggestions</string> --> <!-- <string name="help_context_suggestions">mobile_content_suggestions</string> -->
......
...@@ -29,8 +29,8 @@ import org.chromium.base.StrictModeContext; ...@@ -29,8 +29,8 @@ import org.chromium.base.StrictModeContext;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.help.HelpAndFeedback; import org.chromium.chrome.browser.help.HelpAndFeedback;
import org.chromium.chrome.browser.password_check.PasswordCheckComponent; import org.chromium.chrome.browser.password_check.PasswordCheck;
import org.chromium.chrome.browser.password_check.PasswordCheckComponentFactory; import org.chromium.chrome.browser.password_check.PasswordCheckFactory;
import org.chromium.chrome.browser.password_manager.PasswordManagerLauncher; import org.chromium.chrome.browser.password_manager.PasswordManagerLauncher;
import org.chromium.chrome.browser.preferences.Pref; import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
...@@ -481,9 +481,8 @@ public class PasswordSettings ...@@ -481,9 +481,8 @@ public class PasswordSettings
mCheckPasswords.setSummary(R.string.passwords_check_description); mCheckPasswords.setSummary(R.string.passwords_check_description);
// Add a listener which launches a settings page for the leak password check // Add a listener which launches a settings page for the leak password check
mCheckPasswords.setOnPreferenceClickListener(preference -> { mCheckPasswords.setOnPreferenceClickListener(preference -> {
PasswordCheckComponent passwordCheckComponent = PasswordCheck passwordCheck = PasswordCheckFactory.create();
PasswordCheckComponentFactory.createComponent(); passwordCheck.showUi(getStyledContext());
passwordCheckComponent.initialize(getStyledContext());
// Return true to notify the click was handled // Return true to notify the click was handled
return true; return true;
}); });
......
...@@ -7,7 +7,9 @@ import("//build/config/android/rules.gni") ...@@ -7,7 +7,9 @@ import("//build/config/android/rules.gni")
java_group("public_java") { java_group("public_java") {
deps = [ deps = [
"android:public_java", "android:public_java",
"android:public_ui_java",
"android/internal:public_factory_java", "android/internal:public_factory_java",
"android/internal:public_ui_factory_java",
] ]
} }
...@@ -16,5 +18,6 @@ java_group("internal_java") { ...@@ -16,5 +18,6 @@ java_group("internal_java") {
deps = [ deps = [
"android/internal:internal_factory_java", "android/internal:internal_factory_java",
"android/internal:internal_java", "android/internal:internal_java",
"android/internal:internal_ui_factory_java",
] ]
} }
...@@ -25,16 +25,23 @@ source_set("unit_tests") { ...@@ -25,16 +25,23 @@ source_set("unit_tests") {
android_library("public_java") { android_library("public_java") {
deps = [ deps = [
":java_resources", ":java_resources",
":public_ui_java",
"internal:public_ui_factory_java",
"//base:base_java", "//base:base_java",
"//third_party/android_deps:androidx_fragment_fragment_java", "//third_party/android_deps:androidx_fragment_fragment_java",
"//third_party/android_deps:androidx_preference_preference_java", "//third_party/android_deps:androidx_preference_preference_java",
] ]
sources = [ sources = [
"java/src/org/chromium/chrome/browser/password_check/PasswordCheckComponent.java", "java/src/org/chromium/chrome/browser/password_check/PasswordCheck.java",
"java/src/org/chromium/chrome/browser/password_check/PasswordCheckSettingsView.java", "java/src/org/chromium/chrome/browser/password_check/PasswordCheckFragmentView.java",
] ]
} }
android_library("public_ui_java") {
deps = []
sources = [ "java/src/org/chromium/chrome/browser/password_check/PasswordCheckComponentUi.java" ]
}
android_resources("java_resources") { android_resources("java_resources") {
sources = [] sources = []
deps = [ "//chrome/browser/ui/android/strings:ui_strings_grd" ] deps = [ "//chrome/browser/ui/android/strings:ui_strings_grd" ]
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
import("//chrome/android/features/android_library_factory_tmpl.gni") import("//chrome/android/features/android_library_factory_tmpl.gni")
_factory_sources = [ "java/src/org/chromium/chrome/browser/password_check/PasswordCheckComponentFactory.java" ] _factory_sources = [ "java/src/org/chromium/chrome/browser/password_check/PasswordCheckFactory.java" ]
_public_target = "//chrome/browser/password_check/android:public_java" _public_target = "//chrome/browser/password_check/android:public_java"
android_library_factory("public_factory_java") { android_library_factory("public_factory_java") {
...@@ -22,11 +22,40 @@ android_library("internal_factory_java") { ...@@ -22,11 +22,40 @@ android_library("internal_factory_java") {
sources = _factory_sources sources = _factory_sources
} }
_ui_factory_sources = [ "java/src/org/chromium/chrome/browser/password_check/PasswordCheckComponentUiFactory.java" ]
_public_ui_target = "//chrome/browser/password_check/android:public_ui_java"
android_library_factory("public_ui_factory_java") {
deps = [
"//third_party/android_deps:androidx_fragment_fragment_java",
"//third_party/android_deps:androidx_preference_preference_java",
_public_ui_target,
]
sources = _ui_factory_sources
}
android_library("internal_ui_factory_java") {
deps = [
":internal_java",
_public_target,
]
sources = _ui_factory_sources
}
android_library("internal_java") { android_library("internal_java") {
deps = [ deps = [
"//chrome/android:chrome_app_java_resources",
"//chrome/android:chrome_java", "//chrome/android:chrome_java",
"//chrome/browser/password_check/android:public_ui_java",
"//chrome/browser/profiles/android:java",
"//chrome/browser/settings:java", "//chrome/browser/settings:java",
"//chrome/browser/ui/android/strings:ui_strings_grd",
"//third_party/android_deps:androidx_fragment_fragment_java",
"//third_party/android_deps:androidx_preference_preference_java",
_public_target, _public_target,
] ]
sources = [ "java/src/org/chromium/chrome/browser/password_check/PasswordCheckCoordinator.java" ] sources = [
"java/src/org/chromium/chrome/browser/password_check/PasswordCheckCoordinator.java",
"java/src/org/chromium/chrome/browser/password_check/PasswordCheckImpl.java",
]
} }
// Copyright 2020 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.
package org.chromium.chrome.browser.password_check;
import androidx.preference.PreferenceFragmentCompat;
/**
* Use {@link #create()} to instantiate a {@link PasswordCheckComponentUi}.
*/
class PasswordCheckComponentUiFactory {
private PasswordCheckComponentUiFactory() {}
/**
* Creates a {@link PasswordCheckComponentUi}.
* @param fragmentView the view which will be managed by the coordinator.
* @return A {@link PasswordCheckComponentUi}.
*/
public static PasswordCheckComponentUi create(PreferenceFragmentCompat fragmentView) {
return new PasswordCheckCoordinator((PasswordCheckFragmentView) fragmentView);
}
}
\ No newline at end of file
...@@ -4,19 +4,32 @@ ...@@ -4,19 +4,32 @@
package org.chromium.chrome.browser.password_check; package org.chromium.chrome.browser.password_check;
import android.content.Context; import android.view.MenuItem;
import org.chromium.chrome.browser.settings.SettingsLauncher; import org.chromium.chrome.R;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl; import org.chromium.chrome.browser.help.HelpAndFeedback;
import org.chromium.chrome.browser.profiles.Profile;
/** /**
* Creates the PasswordCheck component. This class is responsible for managing the check of the * Creates the PasswordCheckComponentUi. This class is responsible for managing the UI for the check
* leaked password through the internal components of the feature. * of the leaked password.
*/ */
public class PasswordCheckCoordinator implements PasswordCheckComponent { class PasswordCheckCoordinator implements PasswordCheckComponentUi {
private final PasswordCheckFragmentView mFragmentView;
PasswordCheckCoordinator(PasswordCheckFragmentView fragmentView) {
mFragmentView = fragmentView;
}
// TODO(crbug.com/1101256): Move to view code.
@Override @Override
public void initialize(Context context) { public boolean handleHelp(MenuItem item) {
SettingsLauncher launcher = new SettingsLauncherImpl(); if (item.getItemId() == R.id.menu_id_targeted_help) {
launcher.launchSettingsActivity(context, PasswordCheckSettingsView.class); HelpAndFeedback.getInstance().show(mFragmentView.getActivity(),
mFragmentView.getActivity().getString(R.string.help_context_check_passwords),
Profile.getLastUsedRegularProfile(), null);
return true;
}
return false;
} }
} }
\ No newline at end of file
// Copyright 2020 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.
package org.chromium.chrome.browser.password_check;
/**
* Use {@link #create()} to instantiate a {@link PasswordCheckImpl}.
*/
public class PasswordCheckFactory {
private static PasswordCheck sPasswordCheck;
private PasswordCheckFactory() {}
/**
* Creates a {@link PasswordCheckImpl}.
* @return A {@link PasswordCheckImpl}.
*/
public static PasswordCheck create() {
if (sPasswordCheck == null) {
sPasswordCheck = new PasswordCheckImpl();
}
return sPasswordCheck;
}
}
\ No newline at end of file
// Copyright 2020 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.
package org.chromium.chrome.browser.password_check;
import android.content.Context;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
/**
* This class is responsible for managing the saved passwords check for signed-in users.
*/
class PasswordCheckImpl implements PasswordCheck {
@Override
public void showUi(Context context) {
SettingsLauncher launcher = new SettingsLauncherImpl();
launcher.launchSettingsActivity(context, PasswordCheckFragmentView.class);
}
}
\ No newline at end of file
...@@ -7,13 +7,14 @@ package org.chromium.chrome.browser.password_check; ...@@ -7,13 +7,14 @@ package org.chromium.chrome.browser.password_check;
import android.content.Context; import android.content.Context;
/** /**
* This component allows to check for passwords leak. It launches a settings page which shows the * This component allows to check for compromised passwords. It provides a settings page which shows
* leaked passwords and exposes actions that will help the users to make safer their credentials. * the compromised passwords and exposes actions that will help the users to make safer their
* credentials.
*/ */
public interface PasswordCheckComponent { public interface PasswordCheck {
/** /**
* Initialize the component. * Initializes the PasswordCheck UI and launches it.
* @param context A {@link Context} to create views and retrieve resources. * @param context A {@link Context} to create views and retrieve resources.
*/ */
void initialize(Context context); void showUi(Context context);
} }
...@@ -4,17 +4,14 @@ ...@@ -4,17 +4,14 @@
package org.chromium.chrome.browser.password_check; package org.chromium.chrome.browser.password_check;
import android.view.MenuItem;
/** /**
* Use {@link #createComponent()} to instantiate a {@link PasswordCheckComponent}. * This component is responsible for handling the UI logic for the password check.
*/ */
public class PasswordCheckComponentFactory { interface PasswordCheckComponentUi {
private PasswordCheckComponentFactory() {}
/** /**
* Creates a {@link PasswordCheckCoordinator}. * Handle the request of the user to show the help page for the Check Passwords view.
* @return A {@link PasswordCheckCoordinator}.
*/ */
public static PasswordCheckComponent createComponent() { public boolean handleHelp(MenuItem item);
return new PasswordCheckCoordinator(); }
}
}
\ No newline at end of file
...@@ -6,17 +6,26 @@ package org.chromium.chrome.browser.password_check; ...@@ -6,17 +6,26 @@ package org.chromium.chrome.browser.password_check;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
/** /**
* This class is responsible for rendering the check passwords view in the settings menu. * This class is responsible for rendering the check passwords view in the settings menu.
*/ */
public class PasswordCheckSettingsView extends PreferenceFragmentCompat { public class PasswordCheckFragmentView extends PreferenceFragmentCompat {
private PasswordCheckComponentUi mComponentDelegate;
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getActivity().setTitle(R.string.passwords_check_title); getActivity().setTitle(R.string.passwords_check_title);
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(getStyledContext())); setPreferenceScreen(getPreferenceManager().createPreferenceScreen(getStyledContext()));
mComponentDelegate = PasswordCheckComponentUiFactory.create(this);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return mComponentDelegate.handleHelp(item);
} }
private Context getStyledContext() { private Context getStyledContext() {
......
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