Title: [268901] trunk
Revision
268901
Author
[email protected]
Date
2020-10-22 18:32:09 -0700 (Thu, 22 Oct 2020)

Log Message

[Contact Picker API] Add skeleton implementation of ContactsManager.select()
https://bugs.webkit.org/show_bug.cgi?id=218050
<rdar://problem/69862186>

Reviewed by Devin Rousso.

Source/WebCore:

ContactsManager.select() is the interface that allows clients to
present a contact picker. The method should immediately reject when
called from a subframe, when called outside user-interaction and when
called while a contact picker is already being displayed. Furthermore,
the promise is rejected when the supplied properties are empty or
invalid.

After the conditions necessary for the UI to be presented are verified,
ContactsManager.select() calls into the page's Chrome to display the
picker. The UI implementation on macOS and iOS will be done in
forthcoming patches.

See https://wicg.github.io/contact-api/spec/#contacts-manager-select
for more information.

Tests: contact-picker/contacts-select-invalid-properties-and-options.html
       contact-picker/contacts-select-requires-user-gesture.html
       contact-picker/contacts-select-subframe.html

* Headers.cmake:
* Modules/contact-picker/ContactInfo.h: Added encoder and decoder for IPC.
(WebCore::ContactInfo::encode const):
(WebCore::ContactInfo::decode):
* Modules/contact-picker/ContactInfo.idl:
* Modules/contact-picker/ContactProperty.h:
* Modules/contact-picker/ContactsManager.cpp:
(WebCore::ContactsManager::frame const):
(WebCore::ContactsManager::select):
* Modules/contact-picker/ContactsManager.h:
* Modules/contact-picker/ContactsRequestData.h: Added.

ContactsRequestData encapsulates the information required to display a
picker UI. This includes the requested properties, the URL of the
presenting site, and whether multiple contact selection should be allowed.

(WebCore::ContactsRequestData::encode const):
(WebCore::ContactsRequestData::decode):
* WebCore.xcodeproj/project.pbxproj:
* page/Chrome.cpp:
(WebCore::Chrome::showContactPicker):
* page/Chrome.h:
* page/ChromeClient.h:
(WebCore::ChromeClient::showContactPicker):

Source/WebKit:

Added the necessary plumbing in order for the UIProcess to display a
contact picker after a call to ContactsManager.select() is made.

* UIProcess/PageClient.h:
(WebKit::PageClient::showContactPicker):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::showContactPicker):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::showContactPicker):
* WebProcess/WebCoreSupport/WebChromeClient.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::showContactPicker):
* WebProcess/WebPage/WebPage.h:

LayoutTests:

Added tests for failure cases of the API. Note that success cases are
untested since no platforms currently display a picker UI, and the
specification states that the promise should fail in this case. The
success test cases will be added once the UI is implemented for iOS.

* contact-picker/contacts-select-invalid-properties-and-options-expected.txt: Added.
* contact-picker/contacts-select-invalid-properties-and-options.html: Added.
* contact-picker/contacts-select-requires-user-gesture-expected.txt: Added.
* contact-picker/contacts-select-requires-user-gesture.html: Added.
* contact-picker/contacts-select-subframe-expected.txt: Added.
* contact-picker/contacts-select-subframe.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (268900 => 268901)


--- trunk/LayoutTests/ChangeLog	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/LayoutTests/ChangeLog	2020-10-23 01:32:09 UTC (rev 268901)
@@ -1,3 +1,23 @@
+2020-10-22  Aditya Keerthi  <[email protected]>
+
+        [Contact Picker API] Add skeleton implementation of ContactsManager.select()
+        https://bugs.webkit.org/show_bug.cgi?id=218050
+        <rdar://problem/69862186>
+
+        Reviewed by Devin Rousso.
+
+        Added tests for failure cases of the API. Note that success cases are
+        untested since no platforms currently display a picker UI, and the
+        specification states that the promise should fail in this case. The
+        success test cases will be added once the UI is implemented for iOS.
+
+        * contact-picker/contacts-select-invalid-properties-and-options-expected.txt: Added.
+        * contact-picker/contacts-select-invalid-properties-and-options.html: Added.
+        * contact-picker/contacts-select-requires-user-gesture-expected.txt: Added.
+        * contact-picker/contacts-select-requires-user-gesture.html: Added.
+        * contact-picker/contacts-select-subframe-expected.txt: Added.
+        * contact-picker/contacts-select-subframe.html: Added.
+
 2020-10-22  Simon Fraser  <[email protected]>
 
         Twitter Photo gallery incorrectly rendered after opening another modal

Added: trunk/LayoutTests/contact-picker/contacts-select-invalid-properties-and-options-expected.txt (0 => 268901)


--- trunk/LayoutTests/contact-picker/contacts-select-invalid-properties-and-options-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/contact-picker/contacts-select-invalid-properties-and-options-expected.txt	2020-10-23 01:32:09 UTC (rev 268901)
@@ -0,0 +1,34 @@
+This test verifies that navigator.contacts.select fails if invalid properties or options are specified.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Calling navigator.contacts.select().
+PASS Invalid properties and/or options specified.
+PASS exception.name is "TypeError"
+PASS finishedSubtest became true
+
+Calling navigator.contacts.select().
+PASS Invalid properties and/or options specified.
+PASS exception.name is "TypeError"
+PASS finishedSubtest became true
+
+Calling navigator.contacts.select().
+PASS Invalid properties and/or options specified.
+PASS exception.name is "TypeError"
+PASS finishedSubtest became true
+
+Calling navigator.contacts.select().
+PASS Invalid properties and/or options specified.
+PASS exception.name is "TypeError"
+PASS finishedSubtest became true
+
+Calling navigator.contacts.select().
+PASS Invalid properties and/or options specified.
+PASS exception.name is "TypeError"
+PASS finishedSubtest became true
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Show contacts

Added: trunk/LayoutTests/contact-picker/contacts-select-invalid-properties-and-options.html (0 => 268901)


--- trunk/LayoutTests/contact-picker/contacts-select-invalid-properties-and-options.html	                        (rev 0)
+++ trunk/LayoutTests/contact-picker/contacts-select-invalid-properties-and-options.html	2020-10-23 01:32:09 UTC (rev 268901)
@@ -0,0 +1,52 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ experimental:ContactPickerAPIEnabled=true ] -->
+<html>
+    <head>
+        <script src=""
+        <script src=""
+    </head>
+    <script>
+        jsTestIsAsync = true;
+        finishedSubtest = false;
+
+        async function testContactsSelectWithPropertiesAndOptions(properties, options = {})
+        {
+            finishedSubtest = false;
+            debug("Calling navigator.contacts.select().");
+
+            const contactsButton = document.getElementById("contacts");
+            contactsButton.addEventListener("click", async () => {
+                try {
+                    await navigator.contacts.select(properties, options);
+                    testFailed("navigator.contacts.select succeeded with invalid properties and/or options.");
+                } catch (exception) {
+                    window.exception = exception;
+                    testPassed("Invalid properties and/or options specified.");
+                    shouldBeEqualToString("exception.name", "TypeError");
+                }
+
+                finishedSubtest = true;
+            }, { once: true });
+
+            await UIHelper.activateElement(contactsButton);
+            await new Promise(resolve => shouldBecomeEqual("finishedSubtest", "true", resolve));
+
+            debug("");
+        }
+
+        async function runTest()
+        {
+            description("This test verifies that navigator.contacts.select fails if invalid properties or options are specified.\n");
+
+            await testContactsSelectWithPropertiesAndOptions([]);
+            await testContactsSelectWithPropertiesAndOptions(["Invalid"]);
+            await testContactsSelectWithPropertiesAndOptions("String");
+            await testContactsSelectWithPropertiesAndOptions([23]);
+            await testContactsSelectWithPropertiesAndOptions(["name", "email"], 50);
+
+            finishJSTest();
+        }
+    </script>
+    <body _onload_=runTest()>
+        <button id="contacts">Show contacts</button>
+    </body>
+</html>

Added: trunk/LayoutTests/contact-picker/contacts-select-requires-user-gesture-expected.txt (0 => 268901)


--- trunk/LayoutTests/contact-picker/contacts-select-requires-user-gesture-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/contact-picker/contacts-select-requires-user-gesture-expected.txt	2020-10-23 01:32:09 UTC (rev 268901)
@@ -0,0 +1,11 @@
+This test verifies that navigator.contacts.select requires a user gesture.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Did not present contact picker.
+PASS exception.name is "SecurityError"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/contact-picker/contacts-select-requires-user-gesture.html (0 => 268901)


--- trunk/LayoutTests/contact-picker/contacts-select-requires-user-gesture.html	                        (rev 0)
+++ trunk/LayoutTests/contact-picker/contacts-select-requires-user-gesture.html	2020-10-23 01:32:09 UTC (rev 268901)
@@ -0,0 +1,26 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ experimental:ContactPickerAPIEnabled=true ] -->
+<html>
+    <head>
+        <script src=""
+    </head>
+    <script>
+        jsTestIsAsync = true;
+
+        async function runTest()
+        {
+            description("This test verifies that navigator.contacts.select requires a user gesture.");
+
+            try {
+                await navigator.contacts.select(["name", "email", "tel"]);
+                testFailed("Presented contact picker without user gesture.");
+            } catch (exception) {
+                window.exception = exception;
+                testPassed("Did not present contact picker.");
+                shouldBeEqualToString("exception.name", "SecurityError");
+            }
+
+            finishJSTest();
+        }
+    </script>
+    <body _onload_=runTest()></body>
+</html>

Added: trunk/LayoutTests/contact-picker/contacts-select-subframe-expected.txt (0 => 268901)


--- trunk/LayoutTests/contact-picker/contacts-select-subframe-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/contact-picker/contacts-select-subframe-expected.txt	2020-10-23 01:32:09 UTC (rev 268901)
@@ -0,0 +1,10 @@
+This test verifies that navigator.contacts.select fails if called from a subframe.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Did not present contact picker.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/contact-picker/contacts-select-subframe.html (0 => 268901)


--- trunk/LayoutTests/contact-picker/contacts-select-subframe.html	                        (rev 0)
+++ trunk/LayoutTests/contact-picker/contacts-select-subframe.html	2020-10-23 01:32:09 UTC (rev 268901)
@@ -0,0 +1,45 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ experimental:ContactPickerAPIEnabled=true ] -->
+<html>
+    <head>
+        <script src=""
+        <script src=""
+    </head>
+    <script>
+        jsTestIsAsync = true;
+
+        async function runTest()
+        {
+            description("This test verifies that navigator.contacts.select fails if called from a subframe.");
+
+            window.addEventListener("message", (event) => {
+                if (event.data ="" "didClickOnContactsButtonAndFailedToSelect") {
+                    testPassed("Did not present contact picker.");
+                    finishJSTest();
+                }
+            });
+
+            frame = document.querySelector("iframe");
+
+            await UIHelper.activateElement(frame);
+        }
+    </script>
+    <body _onload_=runTest()>
+        <iframe srcdoc="
+            <body>
+                <button style='width: 100%; height: 134px;'>Show contacts</button>
+                <script>
+                    const button = document.querySelector('button');
+                    button.addEventListener('click', async () => {
+                        try {
+                            await navigator.contacts.select(['name']);
+                        } catch (exception) {
+                            if (exception.name === 'InvalidStateError') {
+                                parent.postMessage('didClickOnContactsButtonAndFailedToSelect', '*');
+                            }
+                        }
+                    });
+                </script>
+            </body>
+        "></iframe>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (268900 => 268901)


--- trunk/Source/WebCore/ChangeLog	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebCore/ChangeLog	2020-10-23 01:32:09 UTC (rev 268901)
@@ -1,3 +1,55 @@
+2020-10-22  Aditya Keerthi  <[email protected]>
+
+        [Contact Picker API] Add skeleton implementation of ContactsManager.select()
+        https://bugs.webkit.org/show_bug.cgi?id=218050
+        <rdar://problem/69862186>
+
+        Reviewed by Devin Rousso.
+
+        ContactsManager.select() is the interface that allows clients to
+        present a contact picker. The method should immediately reject when
+        called from a subframe, when called outside user-interaction and when
+        called while a contact picker is already being displayed. Furthermore,
+        the promise is rejected when the supplied properties are empty or
+        invalid.
+
+        After the conditions necessary for the UI to be presented are verified,
+        ContactsManager.select() calls into the page's Chrome to display the
+        picker. The UI implementation on macOS and iOS will be done in
+        forthcoming patches.
+
+        See https://wicg.github.io/contact-api/spec/#contacts-manager-select
+        for more information.
+
+        Tests: contact-picker/contacts-select-invalid-properties-and-options.html
+               contact-picker/contacts-select-requires-user-gesture.html
+               contact-picker/contacts-select-subframe.html
+
+        * Headers.cmake:
+        * Modules/contact-picker/ContactInfo.h: Added encoder and decoder for IPC.
+        (WebCore::ContactInfo::encode const):
+        (WebCore::ContactInfo::decode):
+        * Modules/contact-picker/ContactInfo.idl:
+        * Modules/contact-picker/ContactProperty.h:
+        * Modules/contact-picker/ContactsManager.cpp:
+        (WebCore::ContactsManager::frame const):
+        (WebCore::ContactsManager::select):
+        * Modules/contact-picker/ContactsManager.h:
+        * Modules/contact-picker/ContactsRequestData.h: Added.
+
+        ContactsRequestData encapsulates the information required to display a
+        picker UI. This includes the requested properties, the URL of the
+        presenting site, and whether multiple contact selection should be allowed.
+
+        (WebCore::ContactsRequestData::encode const):
+        (WebCore::ContactsRequestData::decode):
+        * WebCore.xcodeproj/project.pbxproj:
+        * page/Chrome.cpp:
+        (WebCore::Chrome::showContactPicker):
+        * page/Chrome.h:
+        * page/ChromeClient.h:
+        (WebCore::ChromeClient::showContactPicker):
+
 2020-10-22  Chris Dumez  <[email protected]>
 
         Use WorkerOrWorkletGlobalScope in WebInspector code instead of WorkerGlobalScope

Modified: trunk/Source/WebCore/Headers.cmake (268900 => 268901)


--- trunk/Source/WebCore/Headers.cmake	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebCore/Headers.cmake	2020-10-23 01:32:09 UTC (rev 268901)
@@ -19,6 +19,10 @@
     Modules/cache/DOMCacheEngine.h
     Modules/cache/RetrieveRecordsOptions.h
 
+    Modules/contact-picker/ContactInfo.h
+    Modules/contact-picker/ContactProperty.h
+    Modules/contact-picker/ContactsRequestData.h
+
     Modules/encryptedmedia/CDMClient.h
 
     Modules/fetch/FetchBodyConsumer.h

Modified: trunk/Source/WebCore/Modules/contact-picker/ContactInfo.h (268900 => 268901)


--- trunk/Source/WebCore/Modules/contact-picker/ContactInfo.h	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebCore/Modules/contact-picker/ContactInfo.h	2020-10-23 01:32:09 UTC (rev 268901)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include <wtf/Forward.h>
+#include <wtf/Optional.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -34,6 +35,38 @@
     Vector<String> name;
     Vector<String> email;
     Vector<String> tel;
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static Optional<ContactInfo> decode(Decoder&);
 };
 
+template<class Encoder>
+void ContactInfo::encode(Encoder& encoder) const
+{
+    encoder << name;
+    encoder << email;
+    encoder << tel;
 }
+
+template<class Decoder>
+Optional<ContactInfo> ContactInfo::decode(Decoder& decoder)
+{
+    Optional<Vector<String>> name;
+    decoder >> name;
+    if (!name)
+        return WTF::nullopt;
+
+    Optional<Vector<String>> email;
+    decoder >> email;
+    if (!email)
+        return WTF::nullopt;
+
+    Optional<Vector<String>> tel;
+    decoder >> tel;
+    if (!tel)
+        return WTF::nullopt;
+
+    return {{ *name, *email, *tel }};
+}
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/Modules/contact-picker/ContactInfo.idl (268900 => 268901)


--- trunk/Source/WebCore/Modules/contact-picker/ContactInfo.idl	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebCore/Modules/contact-picker/ContactInfo.idl	2020-10-23 01:32:09 UTC (rev 268901)
@@ -25,7 +25,9 @@
 
 // https://wicg.github.io/contact-api/
 
-dictionary ContactInfo {
+[
+    JSGenerateToJSObject,
+] dictionary ContactInfo {
     sequence<USVString> name;
     sequence<USVString> email;
     sequence<USVString> tel;

Modified: trunk/Source/WebCore/Modules/contact-picker/ContactProperty.h (268900 => 268901)


--- trunk/Source/WebCore/Modules/contact-picker/ContactProperty.h	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebCore/Modules/contact-picker/ContactProperty.h	2020-10-23 01:32:09 UTC (rev 268901)
@@ -25,8 +25,23 @@
 
 #pragma once
 
+#include <wtf/EnumTraits.h>
+
 namespace WebCore {
 
 enum class ContactProperty : uint8_t { Email, Name, Tel };
 
 }
+
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::ContactProperty> {
+    using values = EnumValues<
+        WebCore::ContactProperty,
+        WebCore::ContactProperty::Email,
+        WebCore::ContactProperty::Name,
+        WebCore::ContactProperty::Tel
+    >;
+};
+
+}

Modified: trunk/Source/WebCore/Modules/contact-picker/ContactsManager.cpp (268900 => 268901)


--- trunk/Source/WebCore/Modules/contact-picker/ContactsManager.cpp	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebCore/Modules/contact-picker/ContactsManager.cpp	2020-10-23 01:32:09 UTC (rev 268901)
@@ -26,12 +26,22 @@
 #include "config.h"
 #include "ContactsManager.h"
 
+#include "Chrome.h"
 #include "ContactInfo.h"
 #include "ContactProperty.h"
+#include "ContactsRequestData.h"
 #include "ContactsSelectOptions.h"
+#include "Document.h"
+#include "Frame.h"
+#include "JSContactInfo.h"
 #include "JSDOMPromiseDeferred.h"
 #include "Navigator.h"
+#include "Page.h"
+#include "UserGestureIndicator.h"
+#include <wtf/CompletionHandler.h>
 #include <wtf/IsoMallocInlines.h>
+#include <wtf/Optional.h>
+#include <wtf/URL.h>
 
 namespace WebCore {
 
@@ -49,6 +59,12 @@
 
 ContactsManager::~ContactsManager() = default;
 
+
+Frame* ContactsManager::frame() const
+{
+    return m_navigator ? m_navigator->frame() : nullptr;
+}
+
 Navigator* ContactsManager::navigator()
 {
     return m_navigator.get();
@@ -62,9 +78,43 @@
 
 void ContactsManager::select(const Vector<ContactProperty>& properties, const ContactsSelectOptions& options, Ref<DeferredPromise>&& promise)
 {
-    UNUSED_PARAM(properties);
-    UNUSED_PARAM(options);
-    promise->reject(NotSupportedError);
+    auto* frame = this->frame();
+    if (!frame || !frame->isMainFrame() || !frame->document() || !frame->page()) {
+        promise->reject(InvalidStateError);
+        return;
+    }
+
+    if (!UserGestureIndicator::processingUserGesture()) {
+        promise->reject(SecurityError);
+        return;
+    }
+
+    if (m_contactPickerIsShowing) {
+        promise->reject(InvalidStateError);
+        return;
+    }
+
+    if (properties.isEmpty()) {
+        promise->reject(TypeError);
+        return;
+    }
+
+    ContactsRequestData requestData;
+    requestData.properties = properties;
+    requestData.multiple = options.multiple;
+    requestData.url = ""
+
+    m_contactPickerIsShowing = true;
+
+    frame->page()->chrome().showContactPicker(requestData, [promise = WTFMove(promise), this] (Optional<Vector<ContactInfo>>&& info) {
+        m_contactPickerIsShowing = false;
+        if (info) {
+            promise->resolve<IDLSequence<IDLDictionary<ContactInfo>>>(*info);
+            return;
+        }
+
+        promise->reject(UnknownError);
+    });
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/contact-picker/ContactsManager.h (268900 => 268901)


--- trunk/Source/WebCore/Modules/contact-picker/ContactsManager.h	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebCore/Modules/contact-picker/ContactsManager.h	2020-10-23 01:32:09 UTC (rev 268901)
@@ -33,6 +33,7 @@
 namespace WebCore {
 
 class DeferredPromise;
+class Frame;
 class Navigator;
 
 enum class ContactProperty : uint8_t;
@@ -45,6 +46,7 @@
     static Ref<ContactsManager> create(Navigator&);
     ~ContactsManager();
 
+    Frame* frame() const;
     Navigator* navigator();
 
     void getProperties(Ref<DeferredPromise>&&);
@@ -54,6 +56,7 @@
     ContactsManager(Navigator&);
 
     WeakPtr<Navigator> m_navigator;
+    bool m_contactPickerIsShowing { false };
 };
 
 } // namespace WebCore

Copied: trunk/Source/WebCore/Modules/contact-picker/ContactsRequestData.h (from rev 268900, trunk/Source/WebCore/Modules/contact-picker/ContactInfo.h) (0 => 268901)


--- trunk/Source/WebCore/Modules/contact-picker/ContactsRequestData.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/contact-picker/ContactsRequestData.h	2020-10-23 01:32:09 UTC (rev 268901)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ContactProperty.h"
+#include <wtf/Forward.h>
+#include <wtf/Optional.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+struct ContactsRequestData {
+    Vector<ContactProperty> properties;
+    bool multiple { false };
+    String url;
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static Optional<ContactsRequestData> decode(Decoder&);
+};
+
+template<class Encoder>
+void ContactsRequestData::encode(Encoder& encoder) const
+{
+    encoder << properties;
+    encoder << multiple;
+    encoder << url;
+}
+
+template<class Decoder>
+Optional<ContactsRequestData> ContactsRequestData::decode(Decoder& decoder)
+{
+    Optional<Vector<ContactProperty>> properties;
+    decoder >> properties;
+    if (!properties)
+        return WTF::nullopt;
+
+    Optional<bool> multiple;
+    decoder >> multiple;
+    if (!multiple)
+        return WTF::nullopt;
+
+    Optional<String> url;
+    decoder >> url;
+    if (!url)
+        return WTF::nullopt;
+
+    return {{ *properties, *multiple, *url }};
+}
+
+}

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (268900 => 268901)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-10-23 01:32:09 UTC (rev 268901)
@@ -5107,6 +5107,7 @@
 		E4E8B4F5216B956500B8834D /* FontCascadeDescription.h in Headers */ = {isa = PBXBuildFile; fileRef = E4E8B4F2216B8B6000B8834D /* FontCascadeDescription.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E4E94D6122FF158A00DD191F /* ComplexLineLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = E4A1AC7822FAFD500017B75B /* ComplexLineLayout.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E4F9EEF3156DA00700D23E7E /* StyleSheetContents.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F9EEF1156D84C400D23E7E /* StyleSheetContents.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E50620842540919C00C43091 /* ContactsRequestData.h in Headers */ = {isa = PBXBuildFile; fileRef = E50620832540919B00C43091 /* ContactsRequestData.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E516699120FF9918009D2C27 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = E516698F20FF9916009D2C27 /* [email protected] */; };
 		E517670320B88C1400D41167 /* DataListSuggestionInformation.h in Headers */ = {isa = PBXBuildFile; fileRef = E517670220B88C1400D41167 /* DataListSuggestionInformation.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E51D6A1F24E1E25500891CFA /* DateTimeFieldsState.h in Headers */ = {isa = PBXBuildFile; fileRef = E51D6A1D24E1E25500891CFA /* DateTimeFieldsState.h */; };
@@ -16187,6 +16188,7 @@
 		E4F9EEF0156D84C400D23E7E /* StyleSheetContents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleSheetContents.cpp; sourceTree = "<group>"; };
 		E4F9EEF1156D84C400D23E7E /* StyleSheetContents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleSheetContents.h; sourceTree = "<group>"; };
 		E4FB4B35239BEB10003C336A /* LayoutIntegrationInlineContent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutIntegrationInlineContent.cpp; sourceTree = "<group>"; };
+		E50620832540919B00C43091 /* ContactsRequestData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContactsRequestData.h; sourceTree = "<group>"; };
 		E516698F20FF9916009D2C27 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
 		E517670220B88C1400D41167 /* DataListSuggestionInformation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataListSuggestionInformation.h; sourceTree = "<group>"; };
 		E51A81DE17298D7700BFCA61 /* JSPerformance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPerformance.cpp; sourceTree = "<group>"; };
@@ -28762,6 +28764,7 @@
 				E596DD2E251903EF00C275A7 /* ContactsManager.cpp */,
 				E596DD2D251903EF00C275A7 /* ContactsManager.h */,
 				E596DD2F251903EF00C275A7 /* ContactsManager.idl */,
+				E50620832540919B00C43091 /* ContactsRequestData.h */,
 				E596DD332519041400C275A7 /* ContactsSelectOptions.h */,
 				E596DD342519041400C275A7 /* ContactsSelectOptions.idl */,
 				E596DD28251903D200C275A7 /* Navigator+Contacts.idl */,
@@ -31059,6 +31062,7 @@
 				E596DD5D251BB08200C275A7 /* ContactInfo.h in Headers */,
 				E596DD58251BAC4A00C275A7 /* ContactProperty.h in Headers */,
 				E596DD30251903EF00C275A7 /* ContactsManager.h in Headers */,
+				E50620842540919C00C43091 /* ContactsRequestData.h in Headers */,
 				E596DD352519041400C275A7 /* ContactsSelectOptions.h in Headers */,
 				A818721C0977D3C0005826D9 /* ContainerNode.h in Headers */,
 				E1A1470811102B1500EEC0F3 /* ContainerNodeAlgorithms.h in Headers */,

Modified: trunk/Source/WebCore/page/Chrome.cpp (268900 => 268901)


--- trunk/Source/WebCore/page/Chrome.cpp	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebCore/page/Chrome.cpp	2020-10-23 01:32:09 UTC (rev 268901)
@@ -23,6 +23,8 @@
 #include "Chrome.h"
 
 #include "ChromeClient.h"
+#include "ContactInfo.h"
+#include "ContactsRequestData.h"
 #include "DOMWindow.h"
 #include "Document.h"
 #include "DocumentType.h"
@@ -472,6 +474,11 @@
     m_client.showShareSheet(shareData, WTFMove(callback));
 }
 
+void Chrome::showContactPicker(const ContactsRequestData& requestData, CompletionHandler<void(Optional<Vector<ContactInfo>>&&)>&& callback)
+{
+    m_client.showContactPicker(requestData, WTFMove(callback));
+}
+
 void Chrome::loadIconForFiles(const Vector<String>& filenames, FileIconLoader& loader)
 {
     m_client.loadIconForFiles(filenames, loader);

Modified: trunk/Source/WebCore/page/Chrome.h (268900 => 268901)


--- trunk/Source/WebCore/page/Chrome.h	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebCore/page/Chrome.h	2020-10-23 01:32:09 UTC (rev 268901)
@@ -57,6 +57,8 @@
 class PopupOpeningObserver;
 class SearchPopupMenu;
 
+struct ContactInfo;
+struct ContactsRequestData;
 struct DateTimeChooserParameters;
 struct ShareDataWithParsedURL;
 struct ViewportArguments;
@@ -161,6 +163,7 @@
 
     void runOpenPanel(Frame&, FileChooser&);
     void showShareSheet(ShareDataWithParsedURL&, CompletionHandler<void(bool)>&&);
+    void showContactPicker(const ContactsRequestData&, CompletionHandler<void(Optional<Vector<ContactInfo>>&&)>&&);
     void loadIconForFiles(const Vector<String>&, FileIconLoader&);
 
     void dispatchDisabledAdaptationsDidChange(const OptionSet<DisabledAdaptations>&) const;

Modified: trunk/Source/WebCore/page/ChromeClient.h (268900 => 268901)


--- trunk/Source/WebCore/page/ChromeClient.h	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebCore/page/ChromeClient.h	2020-10-23 01:32:09 UTC (rev 268901)
@@ -23,6 +23,7 @@
 
 #include "AXObjectCache.h"
 #include "AutoplayEvent.h"
+#include "ContactInfo.h"
 #include "Cursor.h"
 #include "DatabaseDetails.h"
 #include "DeviceOrientationOrMotionPermissionState.h"
@@ -113,6 +114,7 @@
 class MediaPlayerRequestInstallMissingPluginsCallback;
 #endif
 
+struct ContactsRequestData;
 struct ContentRuleListResults;
 struct DateTimeChooserParameters;
 struct GraphicsDeviceAdapter;
@@ -302,6 +304,7 @@
 
     virtual void runOpenPanel(Frame&, FileChooser&) = 0;
     virtual void showShareSheet(ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&& callback) { callback(false); }
+    virtual void showContactPicker(const ContactsRequestData&, WTF::CompletionHandler<void(Optional<Vector<ContactInfo>>&&)>&& callback) { callback(WTF::nullopt); }
     
     // Asynchronous request to load an icon for specified filenames.
     virtual void loadIconForFiles(const Vector<String>&, FileIconLoader&) = 0;

Modified: trunk/Source/WebKit/ChangeLog (268900 => 268901)


--- trunk/Source/WebKit/ChangeLog	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebKit/ChangeLog	2020-10-23 01:32:09 UTC (rev 268901)
@@ -1,3 +1,27 @@
+2020-10-22  Aditya Keerthi  <[email protected]>
+
+        [Contact Picker API] Add skeleton implementation of ContactsManager.select()
+        https://bugs.webkit.org/show_bug.cgi?id=218050
+        <rdar://problem/69862186>
+
+        Reviewed by Devin Rousso.
+
+        Added the necessary plumbing in order for the UIProcess to display a
+        contact picker after a call to ContactsManager.select() is made.
+
+        * UIProcess/PageClient.h:
+        (WebKit::PageClient::showContactPicker):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::showContactPicker):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::showContactPicker):
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::showContactPicker):
+        * WebProcess/WebPage/WebPage.h:
+
 2020-10-22  Ryosuke Niwa  <[email protected]>
 
         IPC testing API should have the capability to observe messages being sent and received

Modified: trunk/Source/WebKit/UIProcess/PageClient.h (268900 => 268901)


--- trunk/Source/WebKit/UIProcess/PageClient.h	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebKit/UIProcess/PageClient.h	2020-10-23 01:32:09 UTC (rev 268901)
@@ -35,6 +35,8 @@
 #include "WebPopupMenuProxy.h"
 #include <WebCore/ActivityState.h>
 #include <WebCore/AlternativeTextClient.h>
+#include <WebCore/ContactInfo.h>
+#include <WebCore/ContactsRequestData.h>
 #include <WebCore/DragActions.h>
 #include <WebCore/EditorClient.h>
 #include <WebCore/FocusDirection.h>
@@ -256,6 +258,7 @@
 
     virtual bool handleRunOpenPanel(WebPageProxy*, WebFrameProxy*, const FrameInfoData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) { return false; }
     virtual bool showShareSheet(const WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void (bool)>&&) { return false; }
+    virtual void showContactPicker(const WebCore::ContactsRequestData&, WTF::CompletionHandler<void(Optional<Vector<WebCore::ContactInfo>>&&)>&& completionHandler) { completionHandler(WTF::nullopt); }
 
     virtual void didChangeContentSize(const WebCore::IntSize&) = 0;
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (268900 => 268901)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-10-23 01:32:09 UTC (rev 268901)
@@ -5862,6 +5862,12 @@
     MESSAGE_CHECK(m_process, shareData.files.isEmpty() || m_preferences->webShareFileAPIEnabled());
     pageClient().showShareSheet(shareData, WTFMove(completionHandler));
 }
+
+void WebPageProxy::showContactPicker(const WebCore::ContactsRequestData& requestData, CompletionHandler<void(Optional<Vector<WebCore::ContactInfo>>&&)>&& completionHandler)
+{
+    MESSAGE_CHECK(m_process, m_preferences->contactPickerAPIEnabled());
+    pageClient().showContactPicker(requestData, WTFMove(completionHandler));
+}
     
 void WebPageProxy::printFrame(FrameIdentifier frameID, CompletionHandler<void()>&& completionHandler)
 {

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (268900 => 268901)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-10-23 01:32:09 UTC (rev 268901)
@@ -245,6 +245,8 @@
 struct AttributedString;
 struct BackForwardItemIdentifier;
 struct CompositionHighlight;
+struct ContactInfo;
+struct ContactsRequestData;
 struct ContentRuleListResults;
 struct DataListSuggestionInformation;
 struct DateTimeChooserParameters;
@@ -1954,6 +1956,7 @@
     void runOpenPanel(WebCore::FrameIdentifier, FrameInfoData&&, const WebCore::FileChooserSettings&);
     bool didChooseFilesForOpenPanelWithImageTranscoding(const Vector<String>& fileURLs, const Vector<String>& allowedMIMETypes);
     void showShareSheet(const WebCore::ShareDataWithParsedURL&, CompletionHandler<void(bool)>&&);
+    void showContactPicker(const WebCore::ContactsRequestData&, CompletionHandler<void(Optional<Vector<WebCore::ContactInfo>>&&)>&&);
     void printFrame(WebCore::FrameIdentifier, CompletionHandler<void()>&&);
     void exceededDatabaseQuota(WebCore::FrameIdentifier, const String& originIdentifier, const String& databaseName, const String& displayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage, Messages::WebPageProxy::ExceededDatabaseQuotaDelayedReply&&);
     void reachedApplicationCacheOriginQuota(const String& originIdentifier, uint64_t currentQuota, uint64_t totalBytesNeeded, Messages::WebPageProxy::ReachedApplicationCacheOriginQuotaDelayedReply&&);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (268900 => 268901)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2020-10-23 01:32:09 UTC (rev 268901)
@@ -69,6 +69,7 @@
     PageDidScroll()
     RunOpenPanel(WebCore::FrameIdentifier frameID, struct WebKit::FrameInfoData frameInfo, struct WebCore::FileChooserSettings parameters)
     ShowShareSheet(struct WebCore::ShareDataWithParsedURL shareData) -> (bool granted) Async
+    ShowContactPicker(struct WebCore::ContactsRequestData requestData) -> (Optional<Vector<WebCore::ContactInfo>> info) Async
     PrintFrame(WebCore::FrameIdentifier frameID) -> () Synchronous
     RunModal()
     NotifyScrollerThumbIsVisibleInRect(WebCore::IntRect scrollerThumb)

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp (268900 => 268901)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp	2020-10-23 01:32:09 UTC (rev 268901)
@@ -822,6 +822,11 @@
     m_page.showShareSheet(shareData, WTFMove(callback));
 }
 
+void WebChromeClient::showContactPicker(const WebCore::ContactsRequestData& requestData, WTF::CompletionHandler<void(Optional<Vector<WebCore::ContactInfo>>&&)>&& callback)
+{
+    m_page.showContactPicker(requestData, WTFMove(callback));
+}
+
 void WebChromeClient::loadIconForFiles(const Vector<String>& filenames, FileIconLoader& loader)
 {
     loader.iconLoaded(createIconForFiles(filenames));

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h (268900 => 268901)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h	2020-10-23 01:32:09 UTC (rev 268901)
@@ -200,6 +200,7 @@
 
     void runOpenPanel(WebCore::Frame&, WebCore::FileChooser&) final;
     void showShareSheet(WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&) final;
+    void showContactPicker(const WebCore::ContactsRequestData&, WTF::CompletionHandler<void(Optional<Vector<WebCore::ContactInfo>>&&)>&&) final;
     void loadIconForFiles(const Vector<String>&, WebCore::FileIconLoader&) final;
 
     void setCursor(const WebCore::Cursor&) final;

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (268900 => 268901)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-10-23 01:32:09 UTC (rev 268901)
@@ -149,6 +149,7 @@
 #include <WebCore/BackForwardController.h>
 #include <WebCore/Chrome.h>
 #include <WebCore/CommonVM.h>
+#include <WebCore/ContactsRequestData.h>
 #include <WebCore/ContextMenuController.h>
 #include <WebCore/DOMPasteAccess.h>
 #include <WebCore/DataTransfer.h>
@@ -6916,6 +6917,11 @@
     sendWithAsyncReply(Messages::WebPageProxy::ShowShareSheet(WTFMove(shareData)), WTFMove(callback));
 }
 
+void WebPage::showContactPicker(const WebCore::ContactsRequestData& requestData, CompletionHandler<void(Optional<Vector<WebCore::ContactInfo>>&&)>&& callback)
+{
+    sendWithAsyncReply(Messages::WebPageProxy::ShowContactPicker(requestData), WTFMove(callback));
+}
+
 WebCore::DOMPasteAccessResponse WebPage::requestDOMPasteAccess(const String& originIdentifier)
 {
     auto response = WebCore::DOMPasteAccessResponse::DeniedForGesture;

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (268900 => 268901)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2020-10-23 01:00:04 UTC (rev 268900)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2020-10-23 01:32:09 UTC (rev 268901)
@@ -216,6 +216,8 @@
 struct BackForwardItemIdentifier;
 struct CompositionHighlight;
 struct CompositionUnderline;
+struct ContactInfo;
+struct ContactsRequestData;
 struct DictationAlternative;
 struct ElementContext;
 struct GlobalFrameIdentifier;
@@ -1242,6 +1244,7 @@
 #endif
 
     void showShareSheet(WebCore::ShareDataWithParsedURL&, CompletionHandler<void(bool)>&& callback);
+    void showContactPicker(const WebCore::ContactsRequestData&, CompletionHandler<void(Optional<Vector<WebCore::ContactInfo>>&&)>&&);
     
 #if ENABLE(ATTACHMENT_ELEMENT)
     void insertAttachment(const String& identifier, Optional<uint64_t>&& fileSize, const String& fileName, const String& contentType, CallbackID);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to