Commit 92f8c5b2 authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

Implement navigator.contacts.select()

This provides support for the Contacts Picker API,

 https://github.com/beverloo/contact-api
 https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/brKChSa9_d0

allowing contact details to be shared with a web page.

A skeleton select() function is implemented (returns a
DOMException).

BUG: 860467

Change-Id: I7cf4c147271179c0f59a7cd455d88b1b570c9891
Reviewed-on: https://chromium-review.googlesource.com/c/1326501
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609994}
parent 24d90b03
......@@ -1087,6 +1087,16 @@ interface ConstantSourceNode : AudioScheduledSourceNode
attribute @@toStringTag
getter offset
method constructor
interface ContactInfo
attribute @@toStringTag
getter email
getter name
getter tel
method constructor
interface ContactsManager
attribute @@toStringTag
method constructor
method select
interface ConvolverNode : AudioNode
attribute @@toStringTag
getter buffer
......@@ -4697,6 +4707,7 @@ interface Navigator
getter appVersion
getter clipboard
getter connection
getter contacts
getter cookieEnabled
getter credentials
getter deviceMemory
......
......@@ -102,6 +102,7 @@ target("jumbo_" + modules_target_type, "modules") {
"//third_party/blink/renderer/modules/cache_storage",
"//third_party/blink/renderer/modules/canvas",
"//third_party/blink/renderer/modules/clipboard",
"//third_party/blink/renderer/modules/contacts_picker",
"//third_party/blink/renderer/modules/cookie_store",
"//third_party/blink/renderer/modules/credentialmanager",
"//third_party/blink/renderer/modules/crypto",
......
# Copyright 2018 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.
import("//third_party/blink/renderer/modules/modules.gni")
blink_modules_sources("contacts_picker") {
sources = [
"contact_info.cc",
"contact_info.h",
"contacts_manager.cc",
"contacts_manager.h",
"navigator_contacts.cc",
"navigator_contacts.h",
]
}
include_rules = [
"-third_party/blink/renderer/modules",
"+third_party/blink/renderer/modules/contacts_picker",
]
finnur@chromium.org
peter@chromium.org
# TEAM: platform-capabilities@chromium.org
# COMPONENT: Blink>Contacts
# Contacts Picker
This directory contains the implementation of [the Contacts Picker API](https://github.com/beverloo/contact-api).
// Copyright 2018 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 "third_party/blink/renderer/modules/contacts_picker/contact_info.h"
namespace blink {
ContactInfo::ContactInfo(base::Optional<Vector<String>> name,
base::Optional<Vector<String>> email,
base::Optional<Vector<String>> tel)
: name_(std::move(name)), email_(std::move(email)), tel_(std::move(tel)) {}
ContactInfo::~ContactInfo() = default;
const Vector<String> ContactInfo::name(bool& is_null) const {
is_null = name_.has_value();
return is_null ? Vector<String>() : name_.value();
}
const Vector<String> ContactInfo::email(bool& is_null) const {
is_null = email_.has_value();
return is_null ? Vector<String>() : email_.value();
}
const Vector<String> ContactInfo::tel(bool& is_null) const {
is_null = tel_.has_value();
return is_null ? Vector<String>() : tel_.value();
}
} // namespace blink
// Copyright 2018 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 THIRD_PARTY_BLINK_RENDERER_MODULES_CONTACTS_PICKER_CONTACT_INFO_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_CONTACTS_PICKER_CONTACT_INFO_H_
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/thread_state.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
// Represents an individual Contact in the Contacts Picker.
class ContactInfo final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
ContactInfo(base::Optional<Vector<String>> name,
base::Optional<Vector<String>> email,
base::Optional<Vector<String>> tel);
~ContactInfo() override;
// Web-exposed attributes defined in the IDL file.
const Vector<String> name(bool& is_null) const;
const Vector<String> email(bool& is_null) const;
const Vector<String> tel(bool& is_null) const;
private:
base::Optional<Vector<String>> name_;
base::Optional<Vector<String>> email_;
base::Optional<Vector<String>> tel_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_CONTACTS_PICKER_CONTACT_INFO_H_
// Copyright 2018 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.
// https://github.com/beverloo/contact-api
[
SecureContext,
Exposed=Window,
RuntimeEnabled=ContactsManager
] interface ContactInfo {
readonly attribute FrozenArray<DOMString>? name;
readonly attribute FrozenArray<DOMString>? email;
readonly attribute FrozenArray<DOMString>? tel;
};
// Copyright 2018 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 "third_party/blink/renderer/modules/contacts_picker/contacts_manager.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/heap/visitor.h"
namespace blink {
ContactsManager::ContactsManager() = default;
ContactsManager::~ContactsManager() = default;
ScriptPromise ContactsManager::select(ScriptState* script_state,
ContactsSelectOptions* options) {
return ScriptPromise::RejectWithDOMException(
script_state,
DOMException::Create(DOMExceptionCode::kNotSupportedError,
"ContactsManager::select is not yet implemented"));
}
} // namespace blink
// Copyright 2018 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 THIRD_PARTY_BLINK_RENDERER_MODULES_CONTACTS_PICKER_CONTACTS_MANAGER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_CONTACTS_PICKER_CONTACTS_MANAGER_H_
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/modules/contacts_picker/contacts_select_options.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/thread_state.h"
namespace blink {
class ScriptState;
// Represents an the ContactManager, providing access to Contacts.
class ContactsManager final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
ContactsManager();
~ContactsManager() override;
// Web-exposed function defined in the IDL file.
ScriptPromise select(ScriptState* script_state,
ContactsSelectOptions* options);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_CONTACTS_PICKER_CONTACTS_MANAGER_H_
// Copyright 2018 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.
// https://github.com/beverloo/contact-api
[
Exposed=Window,
SecureContext,
RuntimeEnabled=ContactsManager
] interface ContactsManager {
[CallWith=ScriptState] Promise<FrozenArray<ContactInfo>> select(ContactsSelectOptions options);
};
// Copyright 2018 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.
// https://github.com/beverloo/contact-api
enum ContactProperty { "email", "name", "tel" };
dictionary ContactsSelectOptions {
sequence<ContactProperty> properties;
boolean multiple = false;
};
// Copyright 2018 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 "third_party/blink/renderer/modules/contacts_picker/navigator_contacts.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/platform/heap/visitor.h"
namespace blink {
// static
const char NavigatorContacts::kSupplementName[] = "NavigatorContacts";
// static
NavigatorContacts& NavigatorContacts::From(Navigator& navigator) {
NavigatorContacts* supplement =
Supplement<Navigator>::From<NavigatorContacts>(navigator);
if (!supplement) {
supplement = new NavigatorContacts(navigator);
ProvideTo(navigator, supplement);
}
return *supplement;
}
// static
ContactsManager* NavigatorContacts::contacts(Navigator& navigator) {
// TODO(finnur): Return null when navigator is detached?
return NavigatorContacts::From(navigator).contacts();
}
ContactsManager* NavigatorContacts::contacts() {
if (!contacts_manager_)
contacts_manager_ = new ContactsManager();
return contacts_manager_;
}
void NavigatorContacts::Trace(Visitor* visitor) {
visitor->Trace(contacts_manager_);
Supplement<Navigator>::Trace(visitor);
}
NavigatorContacts::NavigatorContacts(Navigator& navigator)
: Supplement<Navigator>(navigator) {}
} // namespace blink
// Copyright 2018 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 THIRD_PARTY_BLINK_RENDERER_MODULES_CONTACTS_PICKER_NAVIGATOR_CONTACTS_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_CONTACTS_PICKER_NAVIGATOR_CONTACTS_H_
#include "third_party/blink/renderer/modules/contacts_picker/contacts_manager.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class Navigator;
// Represents a supplement to Navigator, implementing the Contacts Selector.
class NavigatorContacts final : public GarbageCollected<NavigatorContacts>,
public Supplement<Navigator> {
USING_GARBAGE_COLLECTED_MIXIN(NavigatorContacts);
public:
static const char kSupplementName[];
static NavigatorContacts& From(Navigator& navigator);
// Web Exposed attribute defined in the IDL file.
static ContactsManager* contacts(Navigator& navigator);
ContactsManager* contacts();
void Trace(Visitor* visitor) override;
private:
explicit NavigatorContacts(Navigator& navigator);
Member<ContactsManager> contacts_manager_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_CONTACTS_PICKER_NAVIGATOR_CONTACTS_H_
// Copyright 2018 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.
// https://github.com/beverloo/contact-api
[
Exposed=Window,
ImplementedAs=NavigatorContacts
] partial interface Navigator {
[SecureContext, RuntimeEnabled=ContactsManager] readonly attribute ContactsManager contacts;
};
......@@ -93,6 +93,8 @@ modules_idl_files =
"canvas/imagebitmap/image_bitmap_rendering_context.idl",
"canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.idl",
"clipboard/clipboard.idl",
"contacts_picker/contact_info.idl",
"contacts_picker/contacts_manager.idl",
"cookie_store/cookie_change_event.idl",
"cookie_store/cookie_store.idl",
"cookie_store/extendable_cookie_change_event.idl",
......@@ -491,6 +493,7 @@ modules_dictionary_idl_files =
"canvas/canvas2d/canvas_rendering_context_2d_settings.idl",
"canvas/canvas2d/hit_region_options.idl",
"canvas/htmlcanvas/canvas_context_creation_attributes_module.idl",
"contacts_picker/contacts_select_options.idl",
"cookie_store/cookie_change_event_init.idl",
"cookie_store/cookie_list_item.idl",
"cookie_store/cookie_store_delete_options.idl",
......@@ -734,6 +737,7 @@ modules_dependency_idl_files =
"cache_storage/worker_cache_storage.idl",
"canvas/canvas2d/canvas_path.idl",
"clipboard/navigator_clipboard.idl",
"contacts_picker/navigator_contacts.idl",
"cookie_store/service_worker_global_scope_cookie_store.idl",
"cookie_store/window_cookie_store.idl",
"credentialmanager/credential_user_data.idl",
......
......@@ -228,6 +228,10 @@
name: "ConstructableStylesheets",
status: "experimental",
},
{
name: "ContactsManager",
status: "experimental",
},
{
name: "ContextMenu",
status: "experimental",
......
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