Commit 6d9b12cf authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

WebLayer: hook up contacts picker for navigator.contacts.

Bug: 1016938
Change-Id: I4e259c8782382305d38834a68f5225b92d28ec2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2386835
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804576}
parent 00883a56
......@@ -582,12 +582,6 @@
<item name="android:windowExitAnimation">@null</item>
</style>
<!-- Contacts Dialog -->
<style name="SuggestionChipContacts" parent="SuggestionChip">
<item name="iconWidth">16dp</item>
<item name="iconHeight">16dp</item>
</style>
<!-- Content and Site Suggestions -->
<style name="SuggestionCardModern" parent="Card">
<item name="android:layout_marginBottom">@dimen/content_suggestions_card_modern_margin</item>
......
......@@ -92,7 +92,6 @@ 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;
......@@ -244,27 +243,19 @@ public class ProcessInitializationHandler {
});
}
ContactsPicker.setContactsPickerDelegate(new ContactsPickerDelegate() {
private ContactsPickerDialog mDialog;
@Override
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();
}
@Override
public void onContactsPickerDismissed() {
mDialog = null;
}
});
ContactsPicker.setContactsPickerDelegate(
(WindowAndroid windowAndroid, ContactsPickerListener listener,
boolean allowMultiple, boolean includeNames, boolean includeEmails,
boolean includeTel, boolean includeAddresses, boolean includeIcons,
String formattedOrigin) -> {
ContactsPickerDialog dialog =
new ContactsPickerDialog(windowAndroid, new ChromePickerAdapter(),
listener, allowMultiple, includeNames, includeEmails,
includeTel, includeAddresses, includeIcons, formattedOrigin);
dialog.getWindow().getAttributes().windowAnimations =
R.style.PickerDialogAnimation;
return dialog;
});
SearchWidgetProvider.initialize();
HistoryDeletionBridge.getInstance().addObserver(
......
......@@ -71,6 +71,7 @@ android_resources("java_resources") {
"java/res/layout/contacts_picker_dialog.xml",
"java/res/layout/contacts_picker_toolbar.xml",
"java/res/layout/top_view.xml",
"java/res/values/styles.xml",
]
deps = [
"//components/browser_ui/strings/android:browser_ui_strings_grd",
......
<?xml version="1.0" encoding="utf-8"?>
<!-- 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. -->
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Contacts Dialog -->
<style name="SuggestionChipContacts" parent="SuggestionChip">
<item name="iconWidth">16dp</item>
<item name="iconHeight">16dp</item>
</style>
</resources>
......@@ -215,11 +215,19 @@ public abstract class PickerAdapter extends Adapter<RecyclerView.ViewHolder>
// Abstract methods:
/** Returns the email for the current user. */
/**
* Called to get the email for the current user.
* The default is null, but some embedder-specific specializations may override this method to
* facilitate showing the owner's contact card at the top of the picker.
* @return the email address of the current user/owner.
*/
@Nullable
protected abstract String findOwnerEmail();
/**
* Adds an entry which represents the current user to the given list.
* Called to add an entry which represents the current user to the given list.
* As with {@link #findOwnerEmail}, embedders may override this to make sure the current user's
* contact card is shown, or may no-op.
* @param contacts the list which is missing an entry for the active user, and to which such an
* entry should be pre-pended.
*/
......
......@@ -16,6 +16,12 @@ public final class ContactsPicker {
*/
private static ContactsPickerDelegate sContactsPickerDelegate;
/**
* The object that represents the currently visible contacts picker UI, or null if none is
* visible.
*/
private static Object sPicker;
private ContactsPicker() {}
/**
......@@ -46,7 +52,8 @@ public final class ContactsPicker {
boolean includeEmails, boolean includeTel, boolean includeAddresses,
boolean includeIcons, String formattedOrigin) {
if (sContactsPickerDelegate == null) return false;
sContactsPickerDelegate.showContactsPicker(windowAndroid, listener, allowMultiple,
assert sPicker == null;
sPicker = sContactsPickerDelegate.showContactsPicker(windowAndroid, listener, allowMultiple,
includeNames, includeEmails, includeTel, includeAddresses, includeIcons,
formattedOrigin);
return true;
......@@ -56,7 +63,7 @@ public final class ContactsPicker {
* Called when the contacts picker dialog has been dismissed.
*/
public static void onContactsPickerDismissed() {
if (sContactsPickerDelegate == null) return;
sContactsPickerDelegate.onContactsPickerDismissed();
assert sPicker != null;
sPicker = null;
}
}
......@@ -23,13 +23,9 @@ public interface ContactsPickerDelegate {
* @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 the contacts picker object.
*/
void showContactsPicker(WindowAndroid windowAndroid, ContactsPickerListener listener,
Object 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();
}
......@@ -574,6 +574,7 @@ source_set("weblayer_lib_base") {
"//components/android_system_error_page",
"//components/autofill/android/provider",
"//components/browser_ui/client_certificate/android",
"//components/browser_ui/contacts_picker/android",
"//components/browser_ui/photo_picker/android",
"//components/browser_ui/site_settings/android",
"//components/browser_ui/sms/android",
......
......@@ -157,6 +157,7 @@ android_library("java") {
"//components/autofill/android/provider:java",
"//components/browser_ui/banners/android:java",
"//components/browser_ui/client_certificate/android:java",
"//components/browser_ui/contacts_picker/android:java",
"//components/browser_ui/display_cutout/android:java",
"//components/browser_ui/http_auth/android:java",
"//components/browser_ui/media/android:java",
......
......@@ -43,6 +43,9 @@ import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.compat.ApiHelperForO;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.components.browser_ui.contacts_picker.ContactDetails;
import org.chromium.components.browser_ui.contacts_picker.ContactsPickerDialog;
import org.chromium.components.browser_ui.contacts_picker.PickerAdapter;
import org.chromium.components.browser_ui.photo_picker.DecoderServiceHost;
import org.chromium.components.browser_ui.photo_picker.ImageDecoder;
import org.chromium.components.browser_ui.photo_picker.PhotoPickerDialog;
......@@ -51,6 +54,8 @@ import org.chromium.components.embedder_support.application.FirebaseConfig;
import org.chromium.components.embedder_support.util.Origin;
import org.chromium.content_public.browser.BrowserStartupController;
import org.chromium.content_public.browser.ChildProcessCreationParams;
import org.chromium.content_public.browser.ContactsPicker;
import org.chromium.content_public.browser.ContactsPickerListener;
import org.chromium.content_public.browser.DeviceUtils;
import org.chromium.content_public.browser.SelectionPopupController;
import org.chromium.net.NetworkChangeNotifier;
......@@ -265,6 +270,28 @@ public final class WebLayerImpl extends IWebLayer.Stub {
MediaStreamManager.onWebLayerInit();
WebLayerNotificationChannels.updateChannelsIfNecessary();
ContactsPicker.setContactsPickerDelegate(
(WindowAndroid windowAndroid, ContactsPickerListener listener,
boolean allowMultiple, boolean includeNames, boolean includeEmails,
boolean includeTel, boolean includeAddresses, boolean includeIcons,
String formattedOrigin) -> {
ContactsPickerDialog dialog = new ContactsPickerDialog(windowAndroid,
// TODO(estade): implement owner email.
new PickerAdapter() {
@Override
protected String findOwnerEmail() {
return null;
}
@Override
protected void addOwnerInfoToContacts(
ArrayList<ContactDetails> contacts) {}
},
listener, allowMultiple, includeNames, includeEmails, includeTel,
includeAddresses, includeIcons, formattedOrigin);
dialog.show();
return dialog;
});
DecoderServiceHost.setIntentSupplier(() -> { return createImageDecoderServiceIntent(); });
SelectFileDialog.setPhotoPickerDelegate(new PhotoPickerDelegate() {
@Override
......
......@@ -16,6 +16,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
......
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