Commit da9d289c authored by Ivana Zuzic's avatar Ivana Zuzic Committed by Commit Bot

[PWD Editing Android] Create PasswordEditingDelegate and its provider

An interface called PasswordEditingDelegate has been created, so
the PasswordEditingBridge can implement it in its production and in its
test version.
PasswordEditingDelegateProviders a singleton because it needs to
provide a bridge to the password editing UI. The editing UI can't get
the bridge any other way because it's an object and it can't be sent
to the editing UI through arguments when the UI is started.

Bug: 377410
Change-Id: Iaf46d3e02d089d7ad498257c7b14b6b801592e52
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1809165
Commit-Queue: Ivana Zuzic <izuzic@google.com>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697959}
parent fddf3b7d
......@@ -1355,6 +1355,8 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/preferences/password/PasswordManagerHandlerProvider.java",
"java/src/org/chromium/chrome/browser/preferences/password/PasswordReauthenticationFragment.java",
"java/src/org/chromium/chrome/browser/preferences/password/PasswordEditingBridge.java",
"java/src/org/chromium/chrome/browser/preferences/password/PasswordEditingDelegate.java",
"java/src/org/chromium/chrome/browser/preferences/password/PasswordEditingDelegateProvider.java",
"java/src/org/chromium/chrome/browser/preferences/password/PasswordUIView.java",
"java/src/org/chromium/chrome/browser/preferences/password/ProgressBarDialogFragment.java",
"java/src/org/chromium/chrome/browser/preferences/password/ReauthenticationManager.java",
......
......@@ -16,11 +16,12 @@ import org.chromium.chrome.browser.preferences.PreferencesLauncher;
* launching the PasswordEntryEditor and handling the password changes that happen through the
* PasswordEntryEditor.
*/
public class PasswordEditingBridge {
public class PasswordEditingBridge implements PasswordEditingDelegate {
private long mNativePasswordEditingBridge;
public PasswordEditingBridge(long nativePasswordEditingBridge) {
mNativePasswordEditingBridge = nativePasswordEditingBridge;
PasswordEditingDelegateProvider.getInstance().setPasswordEditingDelegate(this);
}
/**
......@@ -33,6 +34,7 @@ public class PasswordEditingBridge {
* @param newUsername that will replace the old one if it's given.
* @param newPassword that will replace the old one.
*/
@Override
public void editSavedPasswordEntry(String newUsername, String newPassword) {
PasswordEditingBridgeJni.get().handleEditSavedPasswordEntry(
mNativePasswordEditingBridge, PasswordEditingBridge.this, newUsername, newPassword);
......@@ -55,12 +57,13 @@ public class PasswordEditingBridge {
/**
* Destroy the native object.
*/
@Override
public void destroy() {
if (mNativePasswordEditingBridge != 0) {
PasswordEditingBridgeJni.get().destroy(
mNativePasswordEditingBridge, PasswordEditingBridge.this);
mNativePasswordEditingBridge = 0;
}
PasswordEditingDelegateProvider.getInstance().setPasswordEditingDelegate(null);
assert mNativePasswordEditingBridge != 0;
PasswordEditingBridgeJni.get().destroy(
mNativePasswordEditingBridge, PasswordEditingBridge.this);
mNativePasswordEditingBridge = 0;
}
@NativeMethods
......
// Copyright 2019 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.preferences.password;
/**
* Interface for accessing the PasswordEditingBridge. It's used to mock it in tests.
*/
public interface PasswordEditingDelegate {
/**
* Edits the credential record that was loaded in the PasswordEntryEditor.
*
* @param newUsername The new username value.
* @param newPassword The new password value.
*/
void editSavedPasswordEntry(String newUsername, String newPassword);
/**
* Destroy the native object. This needs to be called after using the bridge is done.
*/
void destroy();
}
// Copyright 2019 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.preferences.password;
/**
* A provider for PasswordEditingDelegate implementations, handling the choice of the proper
* one (production vs. testing).
*
* This class is used by the code responsible for Chrome's passwords settings. The
* provider is a singleton because it needs to provide a bridge to the password editing
* UI. The editing UI can't get the bridge any other way because it's an object and
* it can't be sent to the editing UI through bundle arguments when the UI is started.
*/
public class PasswordEditingDelegateProvider {
private static final PasswordEditingDelegateProvider INSTANCE =
new PasswordEditingDelegateProvider();
private PasswordEditingDelegate mPasswordEditingDelegate;
/** Private constructor, use GetInstance() instead. */
private PasswordEditingDelegateProvider() {}
public static PasswordEditingDelegateProvider getInstance() {
return INSTANCE;
}
/**
* Sets an implementation of PasswordEditingDelegate to be used.
*/
public void setPasswordEditingDelegate(PasswordEditingDelegate passwordEditingDelegate) {
mPasswordEditingDelegate = passwordEditingDelegate;
}
/**
* A function to get a PasswordEditingDelegate implementation.
*/
public PasswordEditingDelegate getPasswordEditingDelegate() {
return mPasswordEditingDelegate;
}
}
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