| // 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 static org.chromium.chrome.browser.password_check.PasswordCheckProperties.CompromisedCredentialProperties.COMPROMISED_CREDENTIAL; |
| import static org.chromium.chrome.browser.password_check.PasswordCheckProperties.CompromisedCredentialProperties.CREDENTIAL_HANDLER; |
| import static org.chromium.chrome.browser.password_check.PasswordCheckProperties.HeaderProperties.CHECK_STATUS; |
| import static org.chromium.chrome.browser.password_check.PasswordCheckProperties.ITEMS; |
| |
| import org.chromium.chrome.browser.password_check.PasswordCheck.CheckStatus; |
| import org.chromium.ui.modelutil.ListModel; |
| import org.chromium.ui.modelutil.MVCListAdapter.ListItem; |
| import org.chromium.ui.modelutil.PropertyModel; |
| |
| import java.util.List; |
| |
| /** |
| * Contains the logic for the PasswordCheck component. It sets the state of the model and reacts to |
| * events like clicks. |
| */ |
| class PasswordCheckMediator implements PasswordCheckCoordinator.CredentialEventHandler { |
| private PropertyModel mModel; |
| private PasswordCheckComponentUi.Delegate mDelegate; |
| |
| void initialize(PropertyModel model, PasswordCheckComponentUi.Delegate delegate) { |
| mModel = model; |
| mDelegate = delegate; |
| } |
| |
| void onCompromisedCredentialsAvailable(List<CompromisedCredential> credentials) { |
| assert credentials != null; |
| ListModel<ListItem> items = mModel.get(ITEMS); |
| assert items.size() == 1; |
| |
| for (CompromisedCredential credential : credentials) { |
| items.add(new ListItem(credential.hasScript() |
| ? PasswordCheckProperties.ItemType.COMPROMISED_CREDENTIAL_WITH_SCRIPT |
| : PasswordCheckProperties.ItemType.COMPROMISED_CREDENTIAL, |
| new PropertyModel |
| .Builder(PasswordCheckProperties.CompromisedCredentialProperties |
| .ALL_KEYS) |
| .with(COMPROMISED_CREDENTIAL, credential) |
| .with(CREDENTIAL_HANDLER, this) |
| .build())); |
| } |
| } |
| |
| void onPasswordCheckStatusChanged(@CheckStatus int status) { |
| ListModel<ListItem> items = mModel.get(ITEMS); |
| if (items.size() == 0) { |
| items.add(new ListItem(PasswordCheckProperties.ItemType.HEADER, |
| new PropertyModel.Builder(PasswordCheckProperties.HeaderProperties.ALL_KEYS) |
| .with(CHECK_STATUS, status) |
| .build())); |
| } else { |
| items.get(0).model.set(CHECK_STATUS, status); |
| } |
| } |
| |
| @Override |
| public void onRemove(CompromisedCredential credential) { |
| mDelegate.removeCredential(credential); |
| } |
| |
| @Override |
| public void onChangePasswordButtonClick(CompromisedCredential credential) { |
| // TODO(crbug.com/1092444): Implement the action for the button. |
| } |
| |
| @Override |
| public void onChangePasswordWithScriptButtonClick(CompromisedCredential credential) { |
| // TODO(crbug.com/1086109): Implement the action for the button. |
| } |
| } |