Commit dd129363 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Move Contacts Picker code out of UiUtils.

The ui_utils_java target is not a suitable place for this code because
it needs to use WindowAndroid instead of Context (for WebLayer's sake),
and ui_utils_java can't depend on WindowAndroid.

This glue code is moved to org.chromium.content_public.browser.

Bug: 1117536,1016938
Change-Id: Ic18275e2f0eca0739b850418af6c71d2079c6da5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2380343Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804505}
parent 70f09b81
......@@ -35,7 +35,6 @@ import org.chromium.chrome.browser.ChromeBackupAgent;
import org.chromium.chrome.browser.DefaultBrowserInfo;
import org.chromium.chrome.browser.DeferredStartupHandler;
import org.chromium.chrome.browser.DevToolsServer;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.banners.AppBannerManager;
import org.chromium.chrome.browser.bookmarkswidget.BookmarkWidgetProvider;
import org.chromium.chrome.browser.contacts_picker.ChromePickerAdapter;
......@@ -89,10 +88,11 @@ import org.chromium.components.viz.common.VizSwitches;
import org.chromium.components.viz.common.display.DeJellyUtils;
import org.chromium.content_public.browser.BrowserTaskExecutor;
import org.chromium.content_public.browser.ChildProcessLauncherHelper;
import org.chromium.content_public.browser.ContactsPicker;
import org.chromium.content_public.browser.ContactsPickerDelegate;
import org.chromium.content_public.browser.ContactsPickerListener;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.content_public.common.ContentSwitches;
import org.chromium.ui.ContactsPickerListener;
import org.chromium.ui.UiUtils;
import org.chromium.ui.base.Clipboard;
import org.chromium.ui.base.PhotoPicker;
import org.chromium.ui.base.PhotoPickerDelegate;
......@@ -237,19 +237,17 @@ public class ProcessInitializationHandler {
});
}
UiUtils.setContactsPickerDelegate(new UiUtils.ContactsPickerDelegate() {
ContactsPicker.setContactsPickerDelegate(new ContactsPickerDelegate() {
private ContactsPickerDialog mDialog;
@Override
public void showContactsPicker(Context context, ContactsPickerListener listener,
boolean allowMultiple, boolean includeNames, boolean includeEmails,
boolean includeTel, boolean includeAddresses, boolean includeIcons,
String formattedOrigin) {
// TODO(crbug.com/1117536): remove this cast.
ChromeActivity activity = (ChromeActivity) context;
mDialog = new ContactsPickerDialog(activity.getWindowAndroid(),
new ChromePickerAdapter(), listener, allowMultiple, includeNames,
includeEmails, includeTel, includeAddresses, includeIcons, formattedOrigin);
public void showContactsPicker(WindowAndroid windowAndroid,
ContactsPickerListener listener, boolean allowMultiple, boolean includeNames,
boolean includeEmails, boolean includeTel, boolean includeAddresses,
boolean includeIcons, String formattedOrigin) {
mDialog = new ContactsPickerDialog(windowAndroid, new ChromePickerAdapter(),
listener, allowMultiple, includeNames, includeEmails, includeTel,
includeAddresses, includeIcons, formattedOrigin);
mDialog.getWindow().getAttributes().windowAnimations =
R.style.PickerDialogAnimation;
mDialog.show();
......
......@@ -40,6 +40,7 @@ android_library("java") {
"//components/browser_ui/util/android:java",
"//components/browser_ui/widget/android:java",
"//components/payments/mojom:mojom_java",
"//content/public/android:content_java",
"//third_party/android_deps:androidx_annotation_annotation_java",
"//third_party/android_deps:androidx_appcompat_appcompat_java",
"//third_party/android_deps:androidx_core_core_java",
......@@ -95,6 +96,7 @@ android_library("javatests") {
"//components/browser_ui/widget/android:java",
"//components/browser_ui/widget/android:test_support_java",
"//components/payments/mojom:mojom_java",
"//content/public/android:content_java",
"//content/public/test/android:content_java_test_support",
"//third_party/android_deps:androidx_annotation_annotation_java",
"//third_party/android_deps:androidx_appcompat_appcompat_java",
......
......@@ -7,7 +7,7 @@ package org.chromium.components.browser_ui.contacts_picker;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import org.chromium.ui.ContactsPickerListener;
import org.chromium.content_public.browser.ContactsPickerListener;
import org.chromium.ui.base.WindowAndroid;
/**
......
......@@ -32,10 +32,10 @@ import org.chromium.blink.mojom.ContactIconBlob;
import org.chromium.components.browser_ui.widget.RecyclerViewTestUtils;
import org.chromium.components.browser_ui.widget.selectable_list.SelectionDelegate;
import org.chromium.components.browser_ui.widget.selectable_list.SelectionDelegate.SelectionObserver;
import org.chromium.content_public.browser.ContactsPickerListener;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.browser.test.util.TestTouchUtils;
import org.chromium.payments.mojom.PaymentAddress;
import org.chromium.ui.ContactsPickerListener;
import org.chromium.ui.base.ActivityWindowAndroid;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.test.util.DisableAnimationsTestRule;
......
......@@ -28,8 +28,8 @@ import org.chromium.components.browser_ui.widget.selectable_list.SelectableListL
import org.chromium.components.browser_ui.widget.selectable_list.SelectableListToolbar;
import org.chromium.components.browser_ui.widget.selectable_list.SelectionDelegate;
import org.chromium.content.browser.contacts.ContactsPickerPropertiesRequested;
import org.chromium.ui.ContactsPickerListener;
import org.chromium.ui.UiUtils;
import org.chromium.content_public.browser.ContactsPicker;
import org.chromium.content_public.browser.ContactsPickerListener;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.widget.OptimizedFrameLayout;
......@@ -449,7 +449,7 @@ public class PickerCategoryView extends OptimizedFrameLayout
mListener.onContactsPickerUserAction(
action, contacts, percentageShared, propertiesRequested);
mDialog.dismiss();
UiUtils.onContactsPickerDismissed();
ContactsPicker.onContactsPickerDismissed();
recordFinalUmaStats(
umaId, contactCount, selectCount, percentageShared, propertiesRequested);
}
......
......@@ -79,6 +79,7 @@ android_library("content_java") {
"//base:base_java",
"//base:jni_java",
"//components/download/public/common:public_java",
"//components/payments/mojom:mojom_java",
"//device/bluetooth:java",
"//device/gamepad:java",
"//media/base/android:media_java",
......@@ -277,6 +278,9 @@ android_library("content_java") {
"java/src/org/chromium/content_public/browser/BrowserTaskExecutor.java",
"java/src/org/chromium/content_public/browser/ChildProcessCreationParams.java",
"java/src/org/chromium/content_public/browser/ChildProcessLauncherHelper.java",
"java/src/org/chromium/content_public/browser/ContactsPicker.java",
"java/src/org/chromium/content_public/browser/ContactsPickerDelegate.java",
"java/src/org/chromium/content_public/browser/ContactsPickerListener.java",
"java/src/org/chromium/content_public/browser/ContentFeatureList.java",
"java/src/org/chromium/content_public/browser/ContentViewStatics.java",
"java/src/org/chromium/content_public/browser/DeviceUtils.java",
......
......@@ -11,8 +11,8 @@ import android.text.TextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.ui.ContactsPickerListener;
import org.chromium.ui.UiUtils;
import org.chromium.content_public.browser.ContactsPicker;
import org.chromium.content_public.browser.ContactsPickerListener;
import org.chromium.ui.base.WindowAndroid;
import java.nio.ByteBuffer;
......@@ -53,8 +53,8 @@ public class ContactsDialogHost implements ContactsPickerListener {
}
if (mWindowAndroid.hasPermission(Manifest.permission.READ_CONTACTS)) {
if (!UiUtils.showContactsPicker(mWindowAndroid.getActivity().get(), this, multiple,
includeNames, includeEmails, includeTel, includeAddresses, includeIcons,
if (!ContactsPicker.showContactsPicker(mWindowAndroid, this, multiple, includeNames,
includeEmails, includeTel, includeAddresses, includeIcons,
formattedOrigin)) {
ContactsDialogHostJni.get().endWithPermissionDenied(mNativeContactsProviderAndroid);
}
......@@ -71,9 +71,9 @@ public class ContactsDialogHost implements ContactsPickerListener {
if (permissions.length == 1 && grantResults.length == 1
&& TextUtils.equals(permissions[0], Manifest.permission.READ_CONTACTS)
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (!UiUtils.showContactsPicker(mWindowAndroid.getActivity().get(), this,
multiple, includeNames, includeEmails, includeTel,
includeAddresses, includeIcons, formattedOrigin)) {
if (!ContactsPicker.showContactsPicker(mWindowAndroid, this, multiple,
includeNames, includeEmails, includeTel, includeAddresses,
includeIcons, formattedOrigin)) {
ContactsDialogHostJni.get().endWithPermissionDenied(
mNativeContactsProviderAndroid);
}
......
// 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.content_public.browser;
import org.chromium.ui.base.WindowAndroid;
/**
* A utility class that allows the embedder to provide a Contacts Picker implementation to content.
*/
public final class ContactsPicker {
/**
* The current delegate for the contacts picker, or null if navigator.contacts is not
* supported.
*/
private static ContactsPickerDelegate sContactsPickerDelegate;
private ContactsPicker() {}
/**
* Allows setting a delegate for an Android contacts picker.
* @param delegate A {@link ContactsPickerDelegate} instance.
*/
public static void setContactsPickerDelegate(ContactsPickerDelegate delegate) {
sContactsPickerDelegate = delegate;
}
/**
* Called to display the contacts picker.
* @param windowAndroid The window of the Web Contents that triggered this call.
* @param listener The listener that will be notified of the action the user took in the
* picker.
* @param allowMultiple Whether to allow multiple contacts to be selected.
* @param includeNames Whether to include names of the shared contacts.
* @param includeEmails Whether to include emails of the shared contacts.
* @param includeTel Whether to include telephone numbers of the shared contacts.
* @param includeAddresses Whether to include addresses of the shared contacts.
* @param includeIcons Whether to include icons of the shared contacts.
* @param formattedOrigin The origin the data will be shared with, formatted for display with
* the scheme omitted.
* @return whether a contacts picker is successfully shown.
*/
public static boolean showContactsPicker(WindowAndroid windowAndroid,
ContactsPickerListener listener, boolean allowMultiple, boolean includeNames,
boolean includeEmails, boolean includeTel, boolean includeAddresses,
boolean includeIcons, String formattedOrigin) {
if (sContactsPickerDelegate == null) return false;
sContactsPickerDelegate.showContactsPicker(windowAndroid, listener, allowMultiple,
includeNames, includeEmails, includeTel, includeAddresses, includeIcons,
formattedOrigin);
return true;
}
/**
* Called when the contacts picker dialog has been dismissed.
*/
public static void onContactsPickerDismissed() {
if (sContactsPickerDelegate == null) return;
sContactsPickerDelegate.onContactsPickerDismissed();
}
}
// 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.content_public.browser;
import org.chromium.ui.base.WindowAndroid;
/**
* A delegate interface for the contacts picker.
*/
public interface ContactsPickerDelegate {
/**
* Called to display the contacts picker.
* @param windowAndroid The window of the Web Contents that triggered the dialog.
* @param listener The listener that will be notified of the action the user took in the
* picker.
* @param allowMultiple Whether to allow multiple contacts to be picked.
* @param includeNames Whether to include names of the shared contacts.
* @param includeEmails Whether to include emails of the shared contacts.
* @param includeTel Whether to include telephone numbers of the shared contacts.
* @param includeAddresses Whether to include addresses of the shared contacts.
* @param includeIcons Whether to include icons of the shared contacts.
* @param formattedOrigin The origin the data will be shared with, formatted for display
* with the scheme omitted.
*/
void showContactsPicker(WindowAndroid windowAndroid, ContactsPickerListener listener,
boolean allowMultiple, boolean includeNames, boolean includeEmails, boolean includeTel,
boolean includeAddresses, boolean includeIcons, String formattedOrigin);
/**
* Called when the contacts picker dialog has been dismissed.
*/
void onContactsPickerDismissed();
}
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.ui;
package org.chromium.content_public.browser;
import androidx.annotation.IntDef;
......
......@@ -205,19 +205,15 @@ java_group("ui_java") {
# unused JNI functions.
android_library("ui_utils_java") {
sources = [
"java/src/org/chromium/ui/ContactsPickerListener.java",
"java/src/org/chromium/ui/KeyboardVisibilityDelegate.java",
"java/src/org/chromium/ui/UiUtils.java",
]
deps = [
"//base:base_java",
"//components/payments/mojom:mojom_java",
"//third_party/android_deps:androidx_annotation_annotation_java",
"//third_party/android_deps:androidx_appcompat_appcompat_java",
"//third_party/android_deps:androidx_appcompat_appcompat_resources_java",
"//third_party/android_deps:androidx_core_core_java",
"//third_party/blink/public/mojom:android_mojo_bindings_java",
"//third_party/blink/public/mojom:mojom_platform_java",
]
}
......
......@@ -79,78 +79,6 @@ public class UiUtils {
private UiUtils() {
}
/** A delegate for the contacts picker. */
private static ContactsPickerDelegate sContactsPickerDelegate;
/**
* A delegate interface for the contacts picker.
*/
public interface ContactsPickerDelegate {
/**
* Called to display the contacts picker.
* @param context The context to use.
* @param listener The listener that will be notified of the action the user took in the
* picker.
* @param allowMultiple Whether to allow multiple contacts to be picked.
* @param includeNames Whether to include names of the contacts shared.
* @param includeEmails Whether to include emails of the contacts shared.
* @param includeTel Whether to include telephone numbers of the contacts shared.
* @param includeAddresses Whether to include addresses of the contacts shared.
* @param includeIcons Whether to include addresses of the contacts shared.
* @param formattedOrigin The origin the data will be shared with, formatted for display
* with the scheme omitted.
*/
void showContactsPicker(Context context, ContactsPickerListener listener,
boolean allowMultiple, boolean includeNames, boolean includeEmails,
boolean includeTel, boolean includeAddresses, boolean includeIcons,
String formattedOrigin);
/**
* Called when the contacts picker dialog has been dismissed.
*/
void onContactsPickerDismissed();
}
// ContactsPickerDelegate:
/**
* Allows setting a delegate for an Android contacts picker.
* @param delegate A {@link ContactsPickerDelegate} instance.
*/
public static void setContactsPickerDelegate(ContactsPickerDelegate delegate) {
sContactsPickerDelegate = delegate;
}
/**
* Called to display the contacts picker.
* @param context The context to use.
* @param listener The listener that will be notified of the action the user took in the
* picker.
* @param allowMultiple Whether to allow multiple contacts to be selected.
* @param includeNames Whether to include names in the contact data returned.
* @param includeEmails Whether to include emails in the contact data returned.
* @param includeTel Whether to include telephone numbers in the contact data returned.
* @param includeAddresses Whether to include addresses of the contacts shared.
* @param includeIcons Whether to include icons of the contacts shared.
* @param formattedOrigin The origin the data will be shared with.
*/
public static boolean showContactsPicker(Context context, ContactsPickerListener listener,
boolean allowMultiple, boolean includeNames, boolean includeEmails, boolean includeTel,
boolean includeAddresses, boolean includeIcons, String formattedOrigin) {
if (sContactsPickerDelegate == null) return false;
sContactsPickerDelegate.showContactsPicker(context, listener, allowMultiple, includeNames,
includeEmails, includeTel, includeAddresses, includeIcons, formattedOrigin);
return true;
}
/**
* Called when the contacts picker dialog has been dismissed.
*/
public static void onContactsPickerDismissed() {
if (sContactsPickerDelegate == null) return;
sContactsPickerDelegate.onContactsPickerDismissed();
}
/**
* Gets the set of locales supported by the current enabled Input Methods.
* @param context A {@link Context} instance.
......
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