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

[PWD Editing Android] Create new wiring for the editing activity

Since we're planning to launch the same editing activity in two
different cases, a new generic interface for launching the editing
activity and saving the changes on passwords has been added. It's called
password_change_delegate. Two different delegates will implement it in
two possible use cases.

In the first use case the editing activity is launched from the password
viewing activity or from the password list displayed in the saved
password preferences. In that case the password entry already exists in
the store and needs to be changed.

In the second use case the editing activity is launched from the InfoBar
when a new password was detected and still hasn't been saved in the
store. In that case, another delegate will implement the interface and
it will have to create new password records in the store.

Because we can't rely on PasswordManagerPresenter persisting through the
process, the delegate and the PasswordEntryBridge need to stay alive
while the password editing activity exists. They need to be destroyed
when the password editing activity is destroyed.

Bug: 377410
Change-Id: I53be371375a590c9b928e98800b0be24a36f333d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1768524Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Commit-Queue: Ivana Zuzic <izuzic@google.com>
Cr-Commit-Position: refs/heads/master@{#691602}
parent 951c4399
......@@ -2608,6 +2608,7 @@ generate_jni("chrome_jni_headers") {
"java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java",
"java/src/org/chromium/chrome/browser/preferences/PreferencesLauncher.java",
"java/src/org/chromium/chrome/browser/preferences/autofill/AutofillProfileBridge.java",
"java/src/org/chromium/chrome/browser/preferences/password/PasswordEditingBridge.java",
"java/src/org/chromium/chrome/browser/preferences/password/PasswordUIView.java",
"java/src/org/chromium/chrome/browser/preferences/privacy/BrowsingDataBridge.java",
"java/src/org/chromium/chrome/browser/preferences/privacy/BrowsingDataCounterBridge.java",
......
......@@ -1326,6 +1326,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/preferences/password/PasswordManagerHandler.java",
"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/PasswordUIView.java",
"java/src/org/chromium/chrome/browser/preferences/password/ProgressBarDialogFragment.java",
"java/src/org/chromium/chrome/browser/preferences/password/ReauthenticationManager.java",
......
// 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;
import org.chromium.base.annotations.CalledByNative;
/**
* This is a bridge between PasswordEntryEditor and the C++ code. The bridge is in charge of
* launching the PasswordEntryEditor and handling the password changes that happen through the
* PasswordEntryEditor.
*/
public class PasswordEditingBridge {
private long mNativePasswordEditingBridge;
public PasswordEditingBridge(long nativePasswordEditingBridge) {
mNativePasswordEditingBridge = nativePasswordEditingBridge;
}
@CalledByNative
private static PasswordEditingBridge create(long nativePasswordEditingBridge) {
return new PasswordEditingBridge(nativePasswordEditingBridge);
}
/**
* Destroy the native object.
*/
public void destroy() {
if (mNativePasswordEditingBridge != 0) {
nativeDestroy(mNativePasswordEditingBridge);
mNativePasswordEditingBridge = 0;
}
}
private native void nativeDestroy(long nativePasswordEditingBridge);
}
......@@ -83,4 +83,10 @@ public interface PasswordManagerHandler {
*/
void serializePasswords(
String targetPath, IntStringCallback successCallback, Callback<String> errorCallback);
/**
* Proceed to edit a credential entry.
* @param index is the current id of a credential.
*/
void showPasswordEntryEditingView(int index);
}
......@@ -85,6 +85,11 @@ public final class PasswordUIView implements PasswordManagerHandler {
mNativePasswordUIViewAndroid, targetPath, successCallback, errorCallback);
}
@Override
public void showPasswordEntryEditingView(int index) {
nativeHandleShowPasswordEntryEditingView(mNativePasswordUIViewAndroid, index);
}
/**
* Returns the URL for the website for managing one's passwords without the need to use Chrome
* with the user's profile signed in.
......@@ -129,4 +134,7 @@ public final class PasswordUIView implements PasswordManagerHandler {
private native void nativeHandleSerializePasswords(long nativePasswordUIViewAndroid,
String targetPath, IntStringCallback successCallback, Callback<String> errorCallback);
private native void nativeHandleShowPasswordEntryEditingView(
long nativePasswordUIViewAndroid, int index);
}
......@@ -212,6 +212,11 @@ public class SavePasswordsPreferencesTest {
mExportErrorCallback = errorCallback;
mExportTargetPath = targetPath;
}
@Override
public void showPasswordEntryEditingView(int index) {
assert false : "Define this method before starting to use it in tests.";
}
}
private final static SavedPasswordEntry ZEUS_ON_EARTH =
......
......@@ -2576,8 +2576,13 @@ jumbo_split_static_library("browser") {
"android/oom_intervention/oom_intervention_tab_helper.h",
"android/partner_browser_customizations.cc",
"android/partner_browser_customizations.h",
"android/password_change_delegate.h",
"android/password_editing_bridge.cc",
"android/password_editing_bridge.h",
"android/password_ui_view_android.cc",
"android/password_ui_view_android.h",
"android/password_update_delegate.cc",
"android/password_update_delegate.h",
"android/payments/service_worker_payment_app_bridge.cc",
"android/photo_picker_sandbox_bridge.cc",
"android/policy/policy_auditor.cc",
......
// 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.
#ifndef CHROME_BROWSER_ANDROID_PASSWORD_CHANGE_DELEGATE_H_
#define CHROME_BROWSER_ANDROID_PASSWORD_CHANGE_DELEGATE_H_
// An interface used by the native side to launch the entry editor and
// perform a change on a credential record.
class PasswordChangeDelegate {
public:
virtual ~PasswordChangeDelegate() = default;
};
#endif // CHROME_BROWSER_ANDROID_PASSWORD_CHANGE_DELEGATE_H_
// 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.
#include "chrome/browser/android/password_editing_bridge.h"
#include "chrome/android/chrome_jni_headers/PasswordEditingBridge_jni.h"
using base::android::JavaParamRef;
PasswordEditingBridge::PasswordEditingBridge() {
Java_PasswordEditingBridge_create(base::android::AttachCurrentThread(),
reinterpret_cast<intptr_t>(this));
}
PasswordEditingBridge::~PasswordEditingBridge() = default;
void PasswordEditingBridge::Destroy(JNIEnv* env,
const JavaParamRef<jobject>& obj) {
delete this;
}
void PasswordEditingBridge::SetDelegate(
std::unique_ptr<PasswordChangeDelegate> password_change_delegate) {
password_change_delegate_ = std::move(password_change_delegate);
}
// 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.
#ifndef CHROME_BROWSER_ANDROID_PASSWORD_EDITING_BRIDGE_H_
#define CHROME_BROWSER_ANDROID_PASSWORD_EDITING_BRIDGE_H_
#include <stddef.h>
#include <memory>
#include "base/android/jni_weak_ref.h"
#include "base/macros.h"
#include "chrome/browser/android/password_change_delegate.h"
// A bridge that allows communication between Android UI and the native
// side. It can be used to launch the password editing activity from the
// native side or when the credential change made in the UI needs to
// arrive to the native side to be saved.
class PasswordEditingBridge {
public:
PasswordEditingBridge();
~PasswordEditingBridge();
void SetDelegate(
std::unique_ptr<PasswordChangeDelegate> password_change_delegate);
// This is called when the view is destroyed and must be called because
// it's the only way to destroy the bridge and the delegate with it.
void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
private:
std::unique_ptr<PasswordChangeDelegate> password_change_delegate_;
DISALLOW_COPY_AND_ASSIGN(PasswordEditingBridge);
};
#endif // CHROME_BROWSER_ANDROID_PASSWORD_EDITING_BRIDGE_H_
......@@ -24,6 +24,8 @@
#include "base/task/post_task.h"
#include "base/threading/scoped_blocking_call.h"
#include "chrome/android/chrome_jni_headers/PasswordUIView_jni.h"
#include "chrome/browser/android/password_update_delegate.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/grit/generated_resources.h"
#include "components/autofill/core/common/password_form.h"
......@@ -198,6 +200,17 @@ void PasswordUIViewAndroid::HandleSerializePasswords(
env, error_callback.obj())));
}
void PasswordUIViewAndroid::HandleShowPasswordEntryEditingView(
JNIEnv* env,
const JavaParamRef<jobject>& obj,
int index) {
LaunchPasswordEntryEditor(
PasswordStoreFactory::GetForProfile(GetProfile(),
ServiceAccessType::EXPLICIT_ACCESS)
.get(),
*password_manager_presenter_.GetPassword(index));
}
ScopedJavaLocalRef<jstring> JNI_PasswordUIView_GetAccountDashboardURL(
JNIEnv* env) {
return ConvertUTF16ToJavaString(
......
......@@ -86,6 +86,10 @@ class PasswordUIViewAndroid : public PasswordUIView {
const base::android::JavaRef<jstring>& java_target_directory,
const base::android::JavaRef<jobject>& success_callback,
const base::android::JavaRef<jobject>& error_callback);
void HandleShowPasswordEntryEditingView(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
int index);
// Destroy the native implementation.
void Destroy(JNIEnv*, const base::android::JavaRef<jobject>&);
......
// 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.
#include "chrome/browser/android/password_update_delegate.h"
#include "chrome/browser/android/password_editing_bridge.h"
PasswordUpdateDelegate::PasswordUpdateDelegate(
password_manager::PasswordStore* store,
const autofill::PasswordForm& password_form)
: password_form_(password_form) {}
PasswordUpdateDelegate::~PasswordUpdateDelegate() = default;
void LaunchPasswordEntryEditor(password_manager::PasswordStore* store,
const autofill::PasswordForm& password_form) {
// PasswordEditingBridge will destroy itself when the UI is gone on the Java
// side.
PasswordEditingBridge* password_editing_bridge = new PasswordEditingBridge();
password_editing_bridge->SetDelegate(
std::make_unique<PasswordUpdateDelegate>(store, password_form));
}
// 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.
#ifndef CHROME_BROWSER_ANDROID_PASSWORD_UPDATE_DELEGATE_H_
#define CHROME_BROWSER_ANDROID_PASSWORD_UPDATE_DELEGATE_H_
#include <memory>
#include "chrome/browser/android/password_change_delegate.h"
#include "chrome/browser/android/password_editing_bridge.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/password_store.h"
// An interface used for launching the entry editor and performing a
// change on a credential record that already exists in the password store.
class PasswordUpdateDelegate : public PasswordChangeDelegate {
public:
PasswordUpdateDelegate(password_manager::PasswordStore* store,
const autofill::PasswordForm& password_form);
~PasswordUpdateDelegate() override;
private:
autofill::PasswordForm password_form_;
DISALLOW_COPY_AND_ASSIGN(PasswordUpdateDelegate);
};
// Creates a new PasswordEditingBridge and connects it with the delegate.
void LaunchPasswordEntryEditor(password_manager::PasswordStore* store,
const autofill::PasswordForm& password_form);
#endif // CHROME_BROWSER_ANDROID_PASSWORD_UPDATE_DELEGATE_H_
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