#include "common/task-queue.h"
#include "common/logger.h"
#include "common/platform_exception.h"
+#include "common/tools.h"
#include "contact/addressbook.h"
#include "contact/contact_manager.h"
namespace extension {
namespace contact {
+namespace {
+const std::string kPrivilegeContactRead = "http://tizen.org/privilege/contact.read";
+const std::string kPrivilegeContactWrite = "http://tizen.org/privilege/contact.write";
+}
+
using namespace common;
ContactInstance::ContactInstance()
}
void ContactInstance::AddressBookGet(const JsonValue& args, JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out);
JsonValue val{JsonObject{}};
PlatformResult status = AddressBook::AddressBookGet(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
}
void ContactInstance::AddressBookAdd(const JsonValue& args, JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
JsonValue val{JsonObject{}};
PlatformResult status = AddressBook::AddressBookAdd(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::AddressBookAddBatch(const JsonValue& args,
JsonObject& out) {
LoggerD("entered");
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
const double callback_id = args.get("callbackId").get<double>();
void ContactInstance::AddressBookRemoveBatch(const JsonValue& args,
JsonObject& out) {
LoggerD("entered");
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
const double callback_id = args.get("callbackId").get<double>();
void ContactInstance::AddressBookUpdateBatch(const JsonValue& args,
JsonObject& out) {
LoggerD("entered");
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
const double callback_id = args.get("callbackId").get<double>();
void ContactInstance::AddressBookUpdate(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
JsonValue val{JsonObject{}};
PlatformResult status = AddressBook::AddressBookUpdate(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::AddressBookRemove(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
JsonValue val{JsonObject{}};
PlatformResult status = AddressBook::AddressBookRemove(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::AddressBookFind(const JsonValue& args, JsonObject& out) {
LoggerD("entered");
-
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out);
const double callback_id = args.get("callbackId").get<double>();
auto get = [=](const std::shared_ptr<JsonValue>& response) -> void {
void ContactInstance::AddressBookAddGroup(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
JsonValue val{JsonObject{}};
PlatformResult status = AddressBook::AddressBookAddGroup(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::AddressBookGetGroup(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out);
JsonValue val{JsonObject{}};
PlatformResult status = AddressBook::AddressBookGetGroup(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::AddressBookUpdateGroup(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
JsonValue val{JsonObject{}};
PlatformResult status = AddressBook::AddressBookUpdateGroup(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::AddressBookRemoveGroup(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
JsonValue val{JsonObject{}};
PlatformResult status = AddressBook::AddressBookRemoveGroup(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::AddressBookGetGroups(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out);
JsonValue val{JsonArray{}};
PlatformResult status = AddressBook::AddressBookGetGroups(
common::JsonCast<JsonObject>(args), val.get<JsonArray>());
void ContactInstance::ContactManagerGetAddressBooks(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out);
+
const double callback_id = args.get("callbackId").get<double>();
auto get = [=](const std::shared_ptr<JsonValue>& response) -> void {
void ContactInstance::ContactManagerGetAddressBook(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out);
JsonValue val{JsonObject{}};
PlatformResult status = ContactManager::ContactManagerGetAddressBook(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::ContactManagerAddAddressBook(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
JsonValue val{JsonObject{}};
PlatformResult status = ContactManager::ContactManagerAddAddressBook(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::ContactManagerRemoveAddressBook(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
JsonValue val{JsonObject{}};
PlatformResult status = ContactManager::ContactManagerRemoveAddressBook(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::AddressBookStartListening(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out);
JsonValue val{JsonObject{}};
PlatformResult status = AddressBook::AddressBookStartListening(
*this, common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::AddressBookStopListening(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out);
JsonValue val{JsonObject{}};
PlatformResult status = AddressBook::AddressBookStopListening(*this);
if (status.IsSuccess())
void ContactInstance::ContactManagerGet(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out);
JsonValue val{JsonObject{}};
PlatformResult status = ContactManager::ContactManagerGet(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::ContactManagerUpdate(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
JsonValue val{JsonObject{}};
PlatformResult status = ContactManager::ContactManagerUpdate(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::ContactManagerUpdateBatch(const JsonValue& args,
JsonObject& out) {
LoggerD("entered");
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
const double callback_id = args.get("callbackId").get<double>();
void ContactInstance::ContactManagerRemove(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
JsonValue val{JsonObject{}};
PlatformResult status = ContactManager::ContactManagerRemove(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::ContactManagerRemoveBatch(const JsonValue& args,
JsonObject& out) {
LoggerD("entered");
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
const double callback_id = args.get("callbackId").get<double>();
void ContactInstance::ContactManagerFind(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out);
const double callback_id = args.get("callbackId").get<double>();
auto get = [this, args](const std::shared_ptr<JsonValue>& response) -> void {
void ContactInstance::ContactManagerStartListening(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out);
JsonValue val{JsonObject{}};
PlatformResult status = ContactManager::ContactManagerStartListening(
*this, common::JsonCast<JsonObject>(args), val.get<JsonObject>());
void ContactInstance::ContactManagerStopListening(const JsonValue& args,
JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out);
JsonValue val{JsonObject{}};
PlatformResult status = ContactManager::ContactManagerStopListening(
*this, common::JsonCast<JsonObject>(args), val.get<JsonObject>());
}
void ContactInstance::PersonLink(const JsonValue& args, JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
JsonValue val{JsonObject{}};
PlatformResult status = Person::PersonLink(common::JsonCast<JsonObject>(args),
val.get<JsonObject>());
}
void ContactInstance::PersonUnlink(const JsonValue& args, JsonObject& out) {
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out);
JsonValue val{JsonObject{}};
PlatformResult status = Person::PersonUnlink(
common::JsonCast<JsonObject>(args), val.get<JsonObject>());
};
AddressBook.prototype.get = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
-
var args = validator_.validateArgs(arguments, [{
name: 'id',
type: types_.STRING,
};
AddressBook.prototype.add = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [
{
name: 'contact',
};
AddressBook.prototype.addBatch = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [
{
name: 'contacts',
native_.callIfPossible(args.successCallback, args.contacts);
};
- native_.call('AddressBook_addBatch', {
+ var result = native_.call('AddressBook_addBatch', {
addressBookId: this.id,
batchArgs: _toJsonObject(args.contacts)
}, callback);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
};
AddressBook.prototype.update = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [
{
name: 'contact',
};
AddressBook.prototype.updateBatch = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [
{
name: 'contacts',
}
});
- native_.call('AddressBook_updateBatch', {
+ var result = native_.call('AddressBook_updateBatch', {
batchArgs: _toJsonObject(args.contacts)
}, callback);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
};
AddressBook.prototype.remove = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [{
name: 'id',
type: types_.STRING,
};
AddressBook.prototype.removeBatch = function(ids, successCallback, errorCallback) {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [
{
name: 'ids',
native_.callIfPossible(args.successCallback);
};
- native_.call('AddressBook_removeBatch', {
+ var result = native_.call('AddressBook_removeBatch', {
batchArgs: args.ids
}, callback);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
};
AddressBook.prototype.find = function(successCallback, errorCallback, filter, sortMode) {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
-
var args = validator_.validateArgs(arguments, [
{
name: 'successCallback',
native_.callIfPossible(successCallback, _contacts);
};
- native_.call('AddressBook_find', {
+ var result = native_.call('AddressBook_find', {
addressBookId: this.id,
filter: utils_.repackFilter(filter),
sortMode: sortMode
}, callback);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
};
AddressBook.prototype.addChangeListener = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
-
var args = validator_.validateArgs(arguments, [{
name: 'successCallback',
type: types_.LISTENER,
nullable: true
}]);
+ // always on first registration checking privileges is done
if (type_.isEmptyObject(_contactCallbackMap)) {
var result = native_.callSync('AddressBook_startListening', {});
return currentWatchId;
};
-AddressBook.prototype.removeChangeListener = function(watchId) {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
-
+var AddressBook_removeChangeListener = function(watchId) {
+ if (type_.isEmptyObject(_contactCallbackMap)) {
+ utils_.checkPrivilegeAccess(privilege_.CONTACT_READ);
+ }
var args = validator_.validateArgs(arguments, [
{
name: 'watchId',
}
};
-AddressBook.prototype.getGroup = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
+AddressBook.prototype.removeChangeListener = function(watchId) {
+ AddressBook_removeChangeListener.apply(this, arguments);
+};
+AddressBook.prototype.getGroup = function() {
var args = validator_.validateArgs(arguments, [{
name: 'groupId',
type: types_.STRING,
};
AddressBook.prototype.addGroup = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [
{
name: 'group',
};
AddressBook.prototype.updateGroup = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [
{
name: 'group',
};
AddressBook.prototype.removeGroup = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [{
name: 'groupId',
type: types_.STRING,
};
AddressBook.prototype.getGroups = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
-
var result = native_.callSync('AddressBook_getGroups', {addressBook: this});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
var _global = window || global || {};
var utils_ = xwalk.utils;
+var privilege_ = xwalk.utils.privilege;
var type_ = utils_.type;
var converter_ = utils_.converter;
var validator_ = utils_.validator;
var types_ = validator_.Types;
-var native_ = new xwalk.utils.NativeManager(extension);
+var native_ = new utils_.NativeManager(extension);
var _currentWatchId = 1;
// Gets the available address books
ContactManager.prototype.getAddressBooks = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
-
var args = validator_.validateArgs(arguments, [
{
name: 'successCallback',
};
// Gets the aggregation of all address books.
-ContactManager.prototype.getUnifiedAddressBook = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
+var ContactManager_getUnifiedAddressBook = function() {
+ utils_.checkPrivilegeAccess(privilege_.CONTACT_READ);
return _editGuard.run(function() {
var addressBook = new AddressBook(0, 'Unified address book');
});
};
+ContactManager.prototype.getUnifiedAddressBook = function() {
+ return ContactManager_getUnifiedAddressBook.apply(this, arguments);
+};
+
// Gets the default address book.
ContactManager.prototype.getDefaultAddressBook = function() {
//privileges are checked in getAddressBook function
// Gets the address book with the specified identifier.
ContactManager.prototype.getAddressBook = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
-
var args = validator_.validateArgs(arguments, [{
name: 'addressBookId',
type: types_.STRING,
};
ContactManager.prototype.addAddressBook = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [{
name: 'addressBook',
type: types_.PLATFORM_OBJECT,
};
ContactManager.prototype.removeAddressBook = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
// TCT: ContactManager_removeAddressBook_misarg
if (type_.isNullOrUndefined(arguments[0])) {
throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
// Gets the person with the specified identifier.
ContactManager.prototype.get = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
-
// validation
var args = validator_.validateArgs(arguments, [
{
// Updates a person in the address book synchronously.
ContactManager.prototype.update = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
// validation
var args = validator_.validateArgs(arguments, [{
name: 'person',
// Updates several existing persons in the contact DB asynchronously.
ContactManager.prototype.updateBatch = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [
{
name: 'persons',
// Removes a person from the contact DB synchronously.
ContactManager.prototype.remove = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
// validation
var args = validator_.validateArgs(arguments, [{
name: 'personId',
// Removes persons from contact DB asynchronously.
ContactManager.prototype.removeBatch = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [
{
name: 'personIds',
// Gets an array of all Person objects from the contact DB or the ones that match the
// optionally supplied filter.
ContactManager.prototype.find = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
-
var args = validator_.validateArgs(arguments, [
{
name: 'successCallback',
// Subscribes to receive notifications about persons' changes.
ContactManager.prototype.addChangeListener = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
-
var args = validator_.validateArgs(arguments, [
{
name: 'successCallback',
};
// Unsubscribes a persons' changes watch operation.
-ContactManager.prototype.removeChangeListener = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ);
+var ContactManager_removeChangeListener = function() {
+ if (type_.isEmptyObject(_personCallbackMap)) {
+ utils_.checkPrivilegeAccess(privilege_.CONTACT_READ);
+ }
var args = validator_.validateArgs(arguments, [
{
}
};
+ContactManager.prototype.removeChangeListener = function() {
+ ContactManager_removeChangeListener.apply(this, arguments);
+};
+
// exports /////////////////////////////////////////////////////////////////
exports = new ContactManager();
// Aggregates another person to this person.
Person.prototype.link = function() {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [{
name: 'personId',
type: types_.STRING,
// Separates a contact from this person.
Person.prototype.unlink = function(contactId) {
- xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE);
-
var args = validator_.validateArgs(arguments, [{
name: 'contactId',
type: types_.STRING,