Commit e339e52e authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[PwdCheckAndroid] Replace chrome_java dependencies

(This CL doesn't change behavior.)

An internal/ target should not depend on chrome_java. Therefore, this
CL tries to remove it and replace it with direct dependencies, e.g. to
resources.

Bug: 1101256,1092444
Change-Id: Id6c1ecef944222ab7d85e850f5ec819273c2ca2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2315147Reviewed-by: default avatarNatalie Chouinard <chouinard@chromium.org>
Reviewed-by: default avatarAndrey Zaytsev <andzaytsev@google.com>
Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822618}
parent df694f42
......@@ -12,6 +12,7 @@ import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.password_check.PasswordCheckFactory;
import org.chromium.chrome.browser.password_check.PasswordCheckReferrer;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
import org.chromium.ui.base.WindowAndroid;
/**
......@@ -29,8 +30,8 @@ public class PasswordCheckupLauncher {
private static void launchLocalCheckup(WindowAndroid windowAndroid) {
assert ChromeFeatureList.isEnabled(ChromeFeatureList.PASSWORD_CHECK);
if (windowAndroid.getContext().get() == null) return; // Window not available yet/anymore.
PasswordCheckFactory.getOrCreate().showUi(
windowAndroid.getContext().get(), PasswordCheckReferrer.LEAK_DIALOG);
PasswordCheckFactory.getOrCreate(new SettingsLauncherImpl())
.showUi(windowAndroid.getContext().get(), PasswordCheckReferrer.LEAK_DIALOG);
}
@CalledByNative
......
......@@ -174,7 +174,7 @@ public class PasswordSettings
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPasswordCheck = PasswordCheckFactory.getOrCreate();
mPasswordCheck = PasswordCheckFactory.getOrCreate(new SettingsLauncherImpl());
}
@Override
......@@ -527,7 +527,8 @@ public class PasswordSettings
mCheckPasswords.setOnPreferenceClickListener(preference -> {
getPrefService().setInteger(
Pref.SETTINGS_LAUNCHED_PASSWORD_CHECKS, numCheckLaunched + 1);
PasswordCheck passwordCheck = PasswordCheckFactory.getOrCreate();
PasswordCheck passwordCheck =
PasswordCheckFactory.getOrCreate(new SettingsLauncherImpl());
passwordCheck.showUi(getStyledContext(), PasswordCheckReferrer.PASSWORD_SETTINGS);
// Return true to notify the click was handled
return true;
......
......@@ -102,7 +102,7 @@ public class MainSettings extends PreferenceFragmentCompat
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPasswordCheck = PasswordCheckFactory.getOrCreate();
mPasswordCheck = PasswordCheckFactory.getOrCreate(new SettingsLauncherImpl());
}
@Override
......
......@@ -28,6 +28,8 @@ import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeBaseAppCompatActivity;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.LaunchIntentDispatcher;
import org.chromium.chrome.browser.feedback.FragmentHelpAndFeedbackLauncher;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncherImpl;
import org.chromium.chrome.browser.image_descriptions.ImageDescriptionsController;
......@@ -299,14 +301,18 @@ public class SettingsActivity extends ChromeBaseAppCompatActivity
}
if (fragment instanceof SafetyCheckSettingsFragment) {
SafetyCheckCoordinator.create((SafetyCheckSettingsFragment) fragment,
new SafetyCheckUpdatesDelegateImpl(this), new SettingsLauncherImpl(),
new SafetyCheckUpdatesDelegateImpl(this), mSettingsLauncher,
SigninActivityLauncherImpl.get());
}
if (fragment instanceof PasswordCheckFragmentView) {
PasswordCheckComponentUiFactory.create((PasswordCheckFragmentView) fragment);
PasswordCheckComponentUiFactory.create((PasswordCheckFragmentView) fragment,
HelpAndFeedbackLauncherImpl.getInstance(), mSettingsLauncher,
LaunchIntentDispatcher::createCustomTabActivityIntent,
IntentHandler::addTrustedIntentExtras);
} else if (fragment instanceof PasswordCheckEditFragmentView) {
PasswordCheckEditFragmentView editFragment = (PasswordCheckEditFragmentView) fragment;
editFragment.setCheckProvider(PasswordCheckFactory::getOrCreate);
editFragment.setCheckProvider(
() -> PasswordCheckFactory.getOrCreate(mSettingsLauncher));
}
if (fragment instanceof ImageDescriptionsSettings) {
ImageDescriptionsSettings imageFragment = (ImageDescriptionsSettings) fragment;
......
......@@ -87,6 +87,7 @@ junit_binary("password_check_junit_tests") {
"//chrome/browser/flags:java",
"//chrome/browser/password_check/android:password_check_java_enums",
"//chrome/browser/password_check/android:public_java",
"//chrome/browser/settings:java",
"//chrome/test/android:chrome_java_test_support",
"//third_party/android_deps:androidx_appcompat_appcompat_java",
"//third_party/hamcrest:hamcrest_java",
......@@ -115,10 +116,12 @@ android_library("test_java") {
"//chrome/android:chrome_java",
"//chrome/android:chrome_test_java",
"//chrome/android:chrome_test_util_java",
"//chrome/browser/feedback/android:java",
"//chrome/browser/flags:java",
"//chrome/browser/password_check/android:password_check_java_enums",
"//chrome/browser/password_check/android/internal:public_factory_java",
"//chrome/browser/password_manager/android:java",
"//chrome/browser/settings:java",
"//chrome/browser/settings:test_support_java",
"//chrome/test/android:chrome_java_test_support",
"//components/browser_ui/widget/android:java",
......
......@@ -13,7 +13,10 @@ _public_target = "//chrome/browser/password_check/android:public_java"
android_library_factory("public_factory_java") {
# These deps will be inherited by the resulting android_library target.
deps = [ _public_target ]
deps = [
"//chrome/browser/settings:java",
_public_target,
]
# This internal file will be replaced by a generated file so the resulting
# android_library target does not actually depend on this internal file.
......@@ -24,6 +27,7 @@ android_library("internal_factory_java") {
deps = [
":internal_java",
"//chrome/browser/flags:java",
"//chrome/browser/settings:java",
"//third_party/android_deps:androidx_annotation_annotation_java",
_public_target,
]
......@@ -35,6 +39,8 @@ _public_ui_target = "//chrome/browser/password_check/android:public_ui_java"
android_library_factory("public_ui_factory_java") {
deps = [
"//chrome/browser/feedback/android:java",
"//chrome/browser/settings:java",
"//third_party/android_deps:androidx_fragment_fragment_java",
"//third_party/android_deps:androidx_preference_preference_java",
_public_ui_target,
......@@ -45,8 +51,11 @@ android_library_factory("public_ui_factory_java") {
android_library("internal_ui_factory_java") {
deps = [
":internal_java",
"//chrome/browser/feedback/android:java",
"//chrome/browser/settings:java",
"//third_party/android_deps:androidx_annotation_annotation_java",
_public_target,
_public_ui_target,
]
sources = _ui_factory_sources
}
......@@ -58,7 +67,6 @@ android_library("internal_java") {
"//base:base_java",
"//base:jni_java",
"//chrome/android:chrome_app_java_resources",
"//chrome/android:chrome_java",
"//chrome/browser/feedback/android:java",
"//chrome/browser/password_check/android:password_check_java_enums",
"//chrome/browser/password_check/android:public_ui_java",
......@@ -67,6 +75,8 @@ android_library("internal_java") {
"//chrome/browser/settings:java",
"//chrome/browser/ui/android/favicon:java",
"//chrome/browser/ui/android/strings:ui_strings_grd",
"//components/browser_ui/strings/android:browser_ui_strings_grd",
"//components/browser_ui/styles/android:java_resources",
"//components/browser_ui/widget/android:java",
"//components/embedder_support/android:util_java",
"//components/favicon/android:java",
......
......@@ -7,6 +7,11 @@ package org.chromium.chrome.browser.password_check;
import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceFragmentCompat;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncher;
import org.chromium.chrome.browser.password_check.PasswordCheckComponentUi.CustomTabIntentHelper;
import org.chromium.chrome.browser.password_check.PasswordCheckComponentUi.TrustedIntentHelper;
import org.chromium.chrome.browser.settings.SettingsLauncher;
/**
* Use {@link #create()} to instantiate a {@link PasswordCheckComponentUi}.
*/
......@@ -18,10 +23,15 @@ public class PasswordCheckComponentUiFactory {
/**
* Returns a component that connects to the given fragment and manipulates its data.
* @param fragmentView A {@link PasswordCheckFragmentView}.
* @param helpAndFeedbackLauncher A {@link HelpAndFeedbackLauncher}.
* @return A non-null {@link PasswordCheckComponentUi}.
*/
PasswordCheckComponentUi create(PasswordCheckFragmentView fragmentView);
PasswordCheckComponentUi create(PasswordCheckFragmentView fragmentView,
HelpAndFeedbackLauncher helpAndFeedbackLauncher, SettingsLauncher settingsLauncher,
CustomTabIntentHelper customTabIntentHelper,
TrustedIntentHelper trustedIntentHelper);
}
private static CreationStrategy sCreationStrategy = PasswordCheckCoordinator::new;
private PasswordCheckComponentUiFactory() {}
......@@ -31,8 +41,12 @@ public class PasswordCheckComponentUiFactory {
* @param fragmentView the view which will be managed by the coordinator.
* @return A {@link PasswordCheckComponentUi}.
*/
public static PasswordCheckComponentUi create(PreferenceFragmentCompat fragmentView) {
return sCreationStrategy.create((PasswordCheckFragmentView) fragmentView);
public static PasswordCheckComponentUi create(PreferenceFragmentCompat fragmentView,
HelpAndFeedbackLauncher helpAndFeedbackLauncher, SettingsLauncher settingsLauncher,
CustomTabIntentHelper customTabIntentHelper, TrustedIntentHelper trustedIntentHelper) {
return sCreationStrategy.create((PasswordCheckFragmentView) fragmentView,
helpAndFeedbackLauncher, settingsLauncher, customTabIntentHelper,
trustedIntentHelper);
}
@VisibleForTesting
......
......@@ -9,11 +9,13 @@ import android.view.MenuItem;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.LifecycleObserver;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncherImpl;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncher;
import org.chromium.chrome.browser.password_check.helper.PasswordCheckChangePasswordHelper;
import org.chromium.chrome.browser.password_check.helper.PasswordCheckIconHelper;
import org.chromium.chrome.browser.password_check.helper.PasswordCheckReauthenticationHelper;
import org.chromium.chrome.browser.password_check.internal.R;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.components.favicon.LargeIconBridge;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
......@@ -23,7 +25,9 @@ import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
* of the leaked password.
*/
class PasswordCheckCoordinator implements PasswordCheckComponentUi, LifecycleObserver {
private HelpAndFeedbackLauncher mHelpAndFeedbackLauncher;
private final PasswordCheckFragmentView mFragmentView;
private final SettingsLauncher mSettingsLauncher;
private final PasswordCheckReauthenticationHelper mReauthenticationHelper;
private final PasswordCheckMediator mMediator;
private PropertyModel mModel;
......@@ -64,8 +68,13 @@ class PasswordCheckCoordinator implements PasswordCheckComponentUi, LifecycleObs
void onChangePasswordWithScriptButtonClick(CompromisedCredential credential);
}
PasswordCheckCoordinator(PasswordCheckFragmentView fragmentView) {
PasswordCheckCoordinator(PasswordCheckFragmentView fragmentView,
HelpAndFeedbackLauncher helpAndFeedbackLauncher, SettingsLauncher settingsLauncher,
PasswordCheckComponentUi.CustomTabIntentHelper customTabIntentHelper,
PasswordCheckComponentUi.TrustedIntentHelper trustedIntentHelper) {
mHelpAndFeedbackLauncher = helpAndFeedbackLauncher;
mFragmentView = fragmentView;
mSettingsLauncher = settingsLauncher;
// TODO(crbug.com/1101256): If help is part of the view, make mediator the delegate.
mFragmentView.setComponentDelegate(this);
......@@ -76,18 +85,20 @@ class PasswordCheckCoordinator implements PasswordCheckComponentUi, LifecycleObs
mReauthenticationHelper = new PasswordCheckReauthenticationHelper(
mFragmentView.getActivity(), mFragmentView.getParentFragmentManager());
PasswordCheckChangePasswordHelper changePasswordHelper =
new PasswordCheckChangePasswordHelper(mFragmentView.getActivity(),
mSettingsLauncher, customTabIntentHelper, trustedIntentHelper);
PasswordCheckIconHelper iconHelper = new PasswordCheckIconHelper(
new LargeIconBridge(Profile.getLastUsedRegularProfile()),
mFragmentView.getResources().getDimensionPixelSize(
org.chromium.chrome.browser.ui.favicon.R.dimen.default_favicon_size));
mMediator = new PasswordCheckMediator(
new PasswordCheckChangePasswordHelper(mFragmentView.getActivity()),
mReauthenticationHelper,
new PasswordCheckIconHelper(
new LargeIconBridge(Profile.getLastUsedRegularProfile()),
mFragmentView.getResources().getDimensionPixelSize(
org.chromium.chrome.browser.ui.favicon.R.dimen
.default_favicon_size)));
changePasswordHelper, mReauthenticationHelper, mSettingsLauncher, iconHelper);
}
private void launchCheckupInAccount() {
PasswordCheckFactory.getOrCreate().launchCheckupInAccount(mFragmentView.getActivity());
PasswordCheckFactory.getOrCreate(mSettingsLauncher)
.launchCheckupInAccount(mFragmentView.getActivity());
}
@Override
......@@ -96,7 +107,7 @@ class PasswordCheckCoordinator implements PasswordCheckComponentUi, LifecycleObs
if (mModel == null) {
mModel = PasswordCheckProperties.createDefaultModel();
PasswordCheckCoordinator.setUpModelChangeProcessors(mModel, mFragmentView);
mMediator.initialize(mModel, PasswordCheckFactory.getOrCreate(),
mMediator.initialize(mModel, PasswordCheckFactory.getOrCreate(mSettingsLauncher),
mFragmentView.getReferrer(), this::launchCheckupInAccount);
}
}
......@@ -121,10 +132,9 @@ class PasswordCheckCoordinator implements PasswordCheckComponentUi, LifecycleObs
// TODO(crbug.com/1101256): Move to view code.
@Override
public boolean handleHelp(MenuItem item) {
if (item.getItemId() == org.chromium.chrome.R.id.menu_id_targeted_help) {
HelpAndFeedbackLauncherImpl.getInstance().show(mFragmentView.getActivity(),
mFragmentView.getActivity().getString(
org.chromium.chrome.R.string.help_context_check_passwords),
if (item.getItemId() == R.id.menu_id_targeted_help) {
mHelpAndFeedbackLauncher.show(mFragmentView.getActivity(),
mFragmentView.getActivity().getString(R.string.help_context_check_passwords),
Profile.getLastUsedRegularProfile(), null);
return true;
}
......
......@@ -8,6 +8,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.settings.SettingsLauncher;
/**
* Use {@link #getOrCreate()} to instantiate a {@link PasswordCheckImpl}
......@@ -20,12 +21,13 @@ public class PasswordCheckFactory {
/**
* Creates a {@link PasswordCheckImpl} if none exists. Otherwise it returns the existing
* instance.
* @param settingsLauncher The {@link SettingsLauncher} to open the check page.
* @return A {@link PasswordCheckImpl} or null if the feature is disabled.
*/
public static @Nullable PasswordCheck getOrCreate() {
public static @Nullable PasswordCheck getOrCreate(SettingsLauncher settingsLauncher) {
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.PASSWORD_CHECK)) return null;
if (sPasswordCheck == null) {
sPasswordCheck = new PasswordCheckImpl();
sPasswordCheck = new PasswordCheckImpl(settingsLauncher);
}
return sPasswordCheck;
}
......
......@@ -11,7 +11,6 @@ import android.os.Bundle;
import org.chromium.base.ObserverList;
import org.chromium.chrome.browser.password_check.PasswordCheckBridge.PasswordCheckObserver;
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.
......@@ -19,25 +18,27 @@ import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
class PasswordCheckImpl implements PasswordCheck, PasswordCheckObserver {
private final PasswordCheckBridge mPasswordCheckBridge;
private final ObserverList<Observer> mObserverList;
private final SettingsLauncher mSettingsLauncher;
private boolean mCompromisedCredentialsFetched;
private boolean mSavedPasswordsFetched;
private @PasswordCheckUIStatus int mStatus = PasswordCheckUIStatus.IDLE;
PasswordCheckImpl() {
PasswordCheckImpl(SettingsLauncher settingsLauncher) {
mCompromisedCredentialsFetched = false;
mSavedPasswordsFetched = false;
mPasswordCheckBridge = new PasswordCheckBridge(this);
mObserverList = new ObserverList<>();
mSettingsLauncher = settingsLauncher;
}
@Override
public void showUi(Context context, @PasswordCheckReferrer int passwordCheckReferrer) {
SettingsLauncher launcher = new SettingsLauncherImpl();
Bundle fragmentArgs = new Bundle();
fragmentArgs.putInt(
PasswordCheckFragmentView.PASSWORD_CHECK_REFERRER, passwordCheckReferrer);
launcher.launchSettingsActivity(context, PasswordCheckFragmentView.class, fragmentArgs);
mSettingsLauncher.launchSettingsActivity(
context, PasswordCheckFragmentView.class, fragmentArgs);
mPasswordCheckBridge.refreshScripts();
}
......
......@@ -33,6 +33,7 @@ import org.chromium.chrome.browser.password_check.helper.PasswordCheckChangePass
import org.chromium.chrome.browser.password_check.helper.PasswordCheckIconHelper;
import org.chromium.chrome.browser.password_check.helper.PasswordCheckReauthenticationHelper;
import org.chromium.chrome.browser.password_check.helper.PasswordCheckReauthenticationHelper.ReauthReason;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.ui.modelutil.ListModel;
import org.chromium.ui.modelutil.MVCListAdapter.ListItem;
......@@ -57,15 +58,17 @@ class PasswordCheckMediator
private PasswordCheckComponentUi.Delegate mDelegate;
private Runnable mLaunchCheckupInAccount;
private HashSet<CompromisedCredential> mPreCheckSet;
private final SettingsLauncher mSettingsLauncher;
private final PasswordCheckIconHelper mIconHelper;
private long mLastStatusUpdate;
private boolean mCctIsOpened;
PasswordCheckMediator(PasswordCheckChangePasswordHelper changePasswordDelegate,
PasswordCheckReauthenticationHelper reauthenticationHelper,
PasswordCheckIconHelper passwordCheckIconHelper) {
SettingsLauncher settingsLauncher, PasswordCheckIconHelper passwordCheckIconHelper) {
mChangePasswordDelegate = changePasswordDelegate;
mReauthenticationHelper = reauthenticationHelper;
mSettingsLauncher = settingsLauncher;
mIconHelper = passwordCheckIconHelper;
}
......@@ -348,7 +351,7 @@ class PasswordCheckMediator
}
private PasswordCheck getPasswordCheck() {
PasswordCheck passwordCheck = PasswordCheckFactory.getOrCreate();
PasswordCheck passwordCheck = PasswordCheckFactory.getOrCreate(mSettingsLauncher);
assert passwordCheck != null : "Password Check UI component needs native counterpart!";
return passwordCheck;
}
......
......@@ -306,7 +306,7 @@ class PasswordCheckViewBinder {
assert compromisedCredentialsCount != null;
return compromisedCredentialsCount == 0
? R.drawable.ic_check_circle_filled_green_24dp
: org.chromium.chrome.R.drawable.ic_warning_red_24dp;
: R.drawable.ic_warning_red_24dp;
case PasswordCheckUIStatus.RUNNING:
return 0;
case PasswordCheckUIStatus.ERROR_OFFLINE:
......@@ -315,7 +315,7 @@ class PasswordCheckViewBinder {
case PasswordCheckUIStatus.ERROR_QUOTA_LIMIT:
case PasswordCheckUIStatus.ERROR_QUOTA_LIMIT_ACCOUNT_CHECK:
case PasswordCheckUIStatus.ERROR_UNKNOWN:
return org.chromium.chrome.R.drawable.ic_error_grey800_24dp_filled;
return R.drawable.ic_error_grey800_24dp_filled;
default:
assert false : "Unhandled check status " + status + "on icon update";
}
......@@ -433,14 +433,12 @@ class PasswordCheckViewBinder {
String relativeTime;
if (daysElapsed > 0L) {
relativeTime = res.getQuantityString(
org.chromium.chrome.R.plurals.n_days_ago, daysElapsed, daysElapsed);
relativeTime = res.getQuantityString(R.plurals.n_days_ago, daysElapsed, daysElapsed);
} else if (hoursElapsed > 0L) {
relativeTime = res.getQuantityString(
org.chromium.chrome.R.plurals.n_hours_ago, hoursElapsed, hoursElapsed);
relativeTime = res.getQuantityString(R.plurals.n_hours_ago, hoursElapsed, hoursElapsed);
} else if (minutesElapsed > 0L) {
relativeTime = res.getQuantityString(
org.chromium.chrome.R.plurals.n_minutes_ago, minutesElapsed, minutesElapsed);
relativeTime =
res.getQuantityString(R.plurals.n_minutes_ago, minutesElapsed, minutesElapsed);
} else {
relativeTime = res.getString(R.string.password_check_just_now);
}
......
......@@ -13,12 +13,10 @@ import android.provider.Browser;
import androidx.browser.customtabs.CustomTabsIntent;
import org.chromium.base.IntentUtils;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.LaunchIntentDispatcher;
import org.chromium.chrome.browser.password_check.CompromisedCredential;
import org.chromium.chrome.browser.password_check.PasswordCheckComponentUi;
import org.chromium.chrome.browser.password_check.PasswordCheckEditFragmentView;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
import java.util.Objects;
......@@ -36,9 +34,17 @@ public class PasswordCheckChangePasswordHelper {
private static final String INTENT = "PASSWORD_CHANGE";
private final Context mContext;
private final SettingsLauncher mSettingsLauncher;
private final PasswordCheckComponentUi.CustomTabIntentHelper mCustomTabIntentHelper;
private final PasswordCheckComponentUi.TrustedIntentHelper mTrustedIntentHelper;
public PasswordCheckChangePasswordHelper(Context context) {
public PasswordCheckChangePasswordHelper(Context context, SettingsLauncher settingsLauncher,
PasswordCheckComponentUi.CustomTabIntentHelper customTabIntentHelper,
PasswordCheckComponentUi.TrustedIntentHelper trustedIntentHelper) {
mContext = context;
mSettingsLauncher = settingsLauncher;
mCustomTabIntentHelper = customTabIntentHelper;
mTrustedIntentHelper = trustedIntentHelper;
}
/**
......@@ -83,11 +89,10 @@ public class PasswordCheckChangePasswordHelper {
* @param credential A {@link CompromisedCredential} to change.
*/
public void launchEditPage(CompromisedCredential credential) {
SettingsLauncher launcher = new SettingsLauncherImpl();
Bundle fragmentArgs = new Bundle();
fragmentArgs.putParcelable(
PasswordCheckEditFragmentView.EXTRA_COMPROMISED_CREDENTIAL, credential);
launcher.launchSettingsActivity(
mSettingsLauncher.launchSettingsActivity(
mContext, PasswordCheckEditFragmentView.class, fragmentArgs);
}
......@@ -106,11 +111,11 @@ public class PasswordCheckChangePasswordHelper {
CustomTabsIntent customTabIntent =
new CustomTabsIntent.Builder().setShowTitle(true).build();
customTabIntent.intent.setData(Uri.parse(initialUrl));
Intent intent = LaunchIntentDispatcher.createCustomTabActivityIntent(
Intent intent = mCustomTabIntentHelper.createCustomTabActivityIntent(
mContext, customTabIntent.intent);
intent.setPackage(mContext.getPackageName());
intent.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName());
IntentHandler.addTrustedIntentExtras(intent);
mTrustedIntentHelper.addTrustedIntentExtras(intent);
return intent;
}
......
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.password_check;
import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
/**
......@@ -21,6 +23,28 @@ public interface PasswordCheckComponentUi {
void removeCredential(CompromisedCredential credential);
}
/**
* Functional interface to start a Chrome Custom Tab for the given intent, e.g. by using
* {@link org.chromium.chrome.browser.LaunchIntentDispatcher#createCustomTabActivityIntent}.
* TODO(crbug.com/1092444): Remove this when the LaunchIntentDispatcher is modularized.
*/
interface CustomTabIntentHelper {
/**
* @see org.chromium.chrome.browser.LaunchIntentDispatcher#createCustomTabActivityIntent
*/
Intent createCustomTabActivityIntent(Context context, Intent intent);
}
/**
* Functional interface to append trusted extras to the given intent, e.g. by using
* {@link org.chromium.chrome.browser.IntentHandler#addTrustedIntentExtras(Intent)}.
* TODO(crbug.com/1092444): Remove this when the IntentHandler is available in a module.
*/
interface TrustedIntentHelper {
/** @see org.chromium.chrome.browser.IntentHandler#addTrustedIntentExtras(Intent) */
void addTrustedIntentExtras(Intent intent);
}
/**
* Handle the request of the user to show the help page for the Check Passwords view.
* @param item A {@link MenuItem}.
......
......@@ -55,6 +55,7 @@ import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.password_manager.settings.ReauthenticationManager;
import org.chromium.chrome.browser.settings.SettingsActivityTestRule;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.url.GURL;
......@@ -89,6 +90,8 @@ public class PasswordCheckEditViewTest {
@Mock
private PasswordCheck mPasswordCheck;
@Mock
private SettingsLauncher mMockSettingsLauncher;
@Before
public void setUp() throws InterruptedException {
......@@ -97,7 +100,8 @@ public class PasswordCheckEditViewTest {
setUpUiLaunchedFromSettings();
pollUiThread(() -> mPasswordCheckEditView != null);
mPasswordCheckEditView.setCheckProvider(PasswordCheckFactory::getOrCreate);
mPasswordCheckEditView.setCheckProvider(
() -> PasswordCheckFactory.getOrCreate(mMockSettingsLauncher));
}
@Test
......
......@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.password_check;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import android.app.Activity;
import android.os.Bundle;
import androidx.test.filters.MediumTest;
......@@ -24,8 +25,8 @@ import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.JniMocker;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.settings.SettingsActivity;
import org.chromium.chrome.browser.settings.SettingsActivityTestRule;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
......@@ -50,6 +51,8 @@ public class PasswordCheckIntegrationTest {
@Mock
private PasswordCheckBridge.Natives mPasswordCheckBridge;
@Mock
private SettingsLauncher mMockSettingsLauncher;
@Before
public void setUp() {
......@@ -61,8 +64,8 @@ public class PasswordCheckIntegrationTest {
@MediumTest
@DisabledTest(message = "crbug.com/1110965")
public void testDestroysComponentIfFirstInSettingsStack() {
PasswordCheckFactory.getOrCreate();
SettingsActivity activity = setUpUiLaunchedFromDialog();
PasswordCheckFactory.getOrCreate(mMockSettingsLauncher);
Activity activity = setUpUiLaunchedFromDialog();
activity.finish();
CriteriaHelper.pollInstrumentationThread(() -> activity.isDestroyed());
assertNull(PasswordCheckFactory.getPasswordCheckInstance());
......@@ -72,8 +75,8 @@ public class PasswordCheckIntegrationTest {
@MediumTest
@DisabledTest(message = "crbug.com/1114096")
public void testDoesNotDestroyComponentIfNotFirstInSettingsStack() {
PasswordCheckFactory.getOrCreate();
SettingsActivity activity = setUpUiLaunchedFromSettings();
PasswordCheckFactory.getOrCreate(mMockSettingsLauncher);
Activity activity = setUpUiLaunchedFromSettings();
activity.finish();
CriteriaHelper.pollInstrumentationThread(() -> activity.isDestroyed());
assertNotNull(PasswordCheckFactory.getPasswordCheckInstance());
......@@ -81,21 +84,17 @@ public class PasswordCheckIntegrationTest {
PasswordCheckFactory.destroy();
}
private SettingsActivity setUpUiLaunchedFromSettings() {
private Activity setUpUiLaunchedFromSettings() {
Bundle fragmentArgs = new Bundle();
fragmentArgs.putInt(PasswordCheckFragmentView.PASSWORD_CHECK_REFERRER,
PasswordCheckReferrer.PASSWORD_SETTINGS);
SettingsActivity activity = mTestRule.startSettingsActivity(fragmentArgs);
return activity;
return mTestRule.startSettingsActivity(fragmentArgs);
}
private SettingsActivity setUpUiLaunchedFromDialog() {
private Activity setUpUiLaunchedFromDialog() {
Bundle fragmentArgs = new Bundle();
fragmentArgs.putInt(PasswordCheckFragmentView.PASSWORD_CHECK_REFERRER,
PasswordCheckReferrer.LEAK_DIALOG);
SettingsActivity activity = mTestRule.startSettingsActivity(fragmentArgs);
return activity;
return mTestRule.startSettingsActivity(fragmentArgs);
}
}
......@@ -150,11 +150,13 @@ public class PasswordCheckViewTest {
@Before
public void setUp() throws InterruptedException {
MockitoAnnotations.initMocks(this);
PasswordCheckComponentUiFactory.setCreationStrategy(fragmentView -> {
mPasswordCheckView = (PasswordCheckFragmentView) fragmentView;
mPasswordCheckView.setComponentDelegate(mComponentUi);
return mComponentUi;
});
PasswordCheckComponentUiFactory.setCreationStrategy(
(fragmentView, helpAndFeedbackLauncher, settingsLauncher, customTabIntentHelper,
trustedIntentHelper) -> {
mPasswordCheckView = (PasswordCheckFragmentView) fragmentView;
mPasswordCheckView.setComponentDelegate(mComponentUi);
return mComponentUi;
});
setUpUiLaunchedFromSettings();
runOnUiThreadBlocking(() -> {
PasswordCheckCoordinator.setUpModelChangeProcessors(mModel, mPasswordCheckView);
......
......@@ -67,6 +67,7 @@ import org.chromium.chrome.browser.password_check.helper.PasswordCheckChangePass
import org.chromium.chrome.browser.password_check.helper.PasswordCheckIconHelper;
import org.chromium.chrome.browser.password_check.helper.PasswordCheckReauthenticationHelper;
import org.chromium.chrome.browser.password_check.helper.PasswordCheckReauthenticationHelper.ReauthReason;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.ui.modelutil.ListModel;
......@@ -119,6 +120,8 @@ public class PasswordCheckControllerTest {
@Mock
private PasswordCheckReauthenticationHelper mReauthenticationHelper;
@Mock
private SettingsLauncher mSettingsLauncher;
@Mock
private PasswordCheckIconHelper mIconHelper;
@Mock
private RecordHistogram.Natives mRecordHistogramBridge;
......@@ -136,7 +139,7 @@ public class PasswordCheckControllerTest {
mJniMocker.mock(RecordHistogramJni.TEST_HOOKS, mRecordHistogramBridge);
mModel = PasswordCheckProperties.createDefaultModel();
mMediator = new PasswordCheckMediator(
mChangePasswordDelegate, mReauthenticationHelper, mIconHelper);
mChangePasswordDelegate, mReauthenticationHelper, mSettingsLauncher, mIconHelper);
PasswordCheckFactory.setPasswordCheckForTesting(mPasswordCheck);
mMediator.initialize(mModel, mDelegate, PasswordCheckReferrer.PASSWORD_SETTINGS, () -> {});
PasswordCheckMediator.setStatusUpdateDelayMillis(0);
......
......@@ -253,7 +253,7 @@ class SafetyCheckMediator implements PasswordCheck.Observer, SafetyCheckCommonOb
mModel.set(SafetyCheckProperties.PASSWORDS_STATE, PasswordsState.SIGNED_OUT);
updatePasswordElementClickDestination();
}
PasswordCheckFactory.getOrCreate().addObserver(this, true);
PasswordCheckFactory.getOrCreate(mSettingsLauncher).addObserver(this, true);
if (mPasswordsLoaded && mLeaksLoaded) {
determinePasswordStateOnLoadComplete();
}
......@@ -282,11 +282,11 @@ class SafetyCheckMediator implements PasswordCheck.Observer, SafetyCheckCommonOb
// Start all the checks.
mSafetyCheckBridge.checkSafeBrowsing();
// Start observing the password check events (including data loads).
PasswordCheckFactory.getOrCreate().addObserver(this, false);
PasswordCheckFactory.getOrCreate(mSettingsLauncher).addObserver(this, false);
// This indicates that the results of the initial data load should not be applied even if
// they become available during the check.
mLoadStage = PasswordCheckLoadStage.IDLE;
PasswordCheckFactory.getOrCreate().startCheck();
PasswordCheckFactory.getOrCreate(mSettingsLauncher).startCheck();
mUpdatesClient.checkForUpdates(new WeakReference(mUpdatesCheckCallback));
}
......@@ -413,7 +413,7 @@ class SafetyCheckMediator implements PasswordCheck.Observer, SafetyCheckCommonOb
if (mLoadStage == PasswordCheckLoadStage.IDLE) return;
// If something is blocked, that means the passwords check is being observed. At this point,
// no further events need to be observed.
PasswordCheckFactory.getOrCreate().removeObserver(this);
PasswordCheckFactory.getOrCreate(mSettingsLauncher).removeObserver(this);
// Only delay updating the UI on the user-triggered check and not initially.
if (mLoadStage == PasswordCheckLoadStage.INITIAL_WAIT_FOR_LOAD) {
updatePasswordsStateOnDataLoaded();
......@@ -427,7 +427,8 @@ class SafetyCheckMediator implements PasswordCheck.Observer, SafetyCheckCommonOb
/** Applies the results of the password check to the model. Only called when data is loaded. */
private void updatePasswordsStateOnDataLoaded() {
// Always display the compromised state.
int compromised = PasswordCheckFactory.getOrCreate().getCompromisedCredentialsCount();
int compromised = PasswordCheckFactory.getOrCreate(mSettingsLauncher)
.getCompromisedCredentialsCount();
if (compromised != 0) {
mModel.set(SafetyCheckProperties.COMPROMISED_PASSWORDS, compromised);
mModel.set(SafetyCheckProperties.PASSWORDS_STATE, PasswordsState.COMPROMISED_EXIST);
......@@ -435,7 +436,8 @@ class SafetyCheckMediator implements PasswordCheck.Observer, SafetyCheckCommonOb
&& !mShowSafePasswordState) {
// Cannot show the safe state at the initial load if last run is older than 10 mins.
mModel.set(SafetyCheckProperties.PASSWORDS_STATE, PasswordsState.UNCHECKED);
} else if (PasswordCheckFactory.getOrCreate().getSavedPasswordsCount() == 0) {
} else if (PasswordCheckFactory.getOrCreate(mSettingsLauncher).getSavedPasswordsCount()
== 0) {
// Can show safe state: display no passwords.
mModel.set(SafetyCheckProperties.PASSWORDS_STATE, PasswordsState.NO_PASSWORDS);
} else {
......@@ -474,8 +476,8 @@ class SafetyCheckMediator implements PasswordCheck.Observer, SafetyCheckCommonOb
SafetyCheckInteractions.PASSWORDS_MANAGE,
SafetyCheckInteractions.MAX_VALUE);
// Open the Password Check UI.
PasswordCheckFactory.getOrCreate().showUi(
p.getContext(), PasswordCheckReferrer.SAFETY_CHECK);
PasswordCheckFactory.getOrCreate(mSettingsLauncher)
.showUi(p.getContext(), PasswordCheckReferrer.SAFETY_CHECK);
return true;
};
} else {
......
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