From: Tomasz Marciniak Date: Wed, 4 Nov 2015 13:01:29 +0000 (+0100) Subject: Revert "[Contact] Privilege checks moved to JS." X-Git-Tag: submit/tizen_mobile/20151215.080542^2~21^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d16ca59b4e2e8f69fa30efbe2e16623d223026f8;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git Revert "[Contact] Privilege checks moved to JS." This reverts commit 8ddab5bb72ca965f4312093344c6d6c014c65df2. This also applies changes from commit 86945f152c2dbb9111d28a3c979c48cf53da9c91 [Verification] Code compiles. Change-Id: I27c5c3417053a0534b403c10e83faf81d897086f Signed-off-by: Tomasz Marciniak --- diff --git a/src/contact/contact_instance.cc b/src/contact/contact_instance.cc index dca1d3ae..db68f348 100755 --- a/src/contact/contact_instance.cc +++ b/src/contact/contact_instance.cc @@ -20,6 +20,7 @@ #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" @@ -28,6 +29,11 @@ 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() @@ -92,6 +98,7 @@ ContactInstance::~ContactInstance() { } void ContactInstance::AddressBookGet(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out); JsonValue val{JsonObject{}}; PlatformResult status = AddressBook::AddressBookGet( common::JsonCast(args), val.get()); @@ -102,6 +109,7 @@ void ContactInstance::AddressBookGet(const JsonValue& args, JsonObject& out) { } void ContactInstance::AddressBookAdd(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); JsonValue val{JsonObject{}}; PlatformResult status = AddressBook::AddressBookAdd( common::JsonCast(args), val.get()); @@ -114,6 +122,7 @@ void ContactInstance::AddressBookAdd(const JsonValue& args, JsonObject& out) { void ContactInstance::AddressBookAddBatch(const JsonValue& args, JsonObject& out) { LoggerD("entered"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); const double callback_id = args.get("callbackId").get(); @@ -143,6 +152,7 @@ void ContactInstance::AddressBookAddBatch(const JsonValue& args, void ContactInstance::AddressBookRemoveBatch(const JsonValue& args, JsonObject& out) { LoggerD("entered"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); const double callback_id = args.get("callbackId").get(); @@ -172,6 +182,7 @@ void ContactInstance::AddressBookRemoveBatch(const JsonValue& args, void ContactInstance::AddressBookUpdateBatch(const JsonValue& args, JsonObject& out) { LoggerD("entered"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); const double callback_id = args.get("callbackId").get(); @@ -200,6 +211,7 @@ void ContactInstance::AddressBookUpdateBatch(const JsonValue& args, void ContactInstance::AddressBookUpdate(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); JsonValue val{JsonObject{}}; PlatformResult status = AddressBook::AddressBookUpdate( common::JsonCast(args), val.get()); @@ -211,6 +223,7 @@ void ContactInstance::AddressBookUpdate(const JsonValue& args, void ContactInstance::AddressBookRemove(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); JsonValue val{JsonObject{}}; PlatformResult status = AddressBook::AddressBookRemove( common::JsonCast(args), val.get()); @@ -222,7 +235,7 @@ void ContactInstance::AddressBookRemove(const JsonValue& args, void ContactInstance::AddressBookFind(const JsonValue& args, JsonObject& out) { LoggerD("entered"); - + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out); const double callback_id = args.get("callbackId").get(); auto get = [=](const std::shared_ptr& response) -> void { @@ -250,6 +263,7 @@ void ContactInstance::AddressBookFind(const JsonValue& args, JsonObject& out) { void ContactInstance::AddressBookAddGroup(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); JsonValue val{JsonObject{}}; PlatformResult status = AddressBook::AddressBookAddGroup( common::JsonCast(args), val.get()); @@ -261,6 +275,7 @@ void ContactInstance::AddressBookAddGroup(const JsonValue& args, void ContactInstance::AddressBookGetGroup(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out); JsonValue val{JsonObject{}}; PlatformResult status = AddressBook::AddressBookGetGroup( common::JsonCast(args), val.get()); @@ -272,6 +287,7 @@ void ContactInstance::AddressBookGetGroup(const JsonValue& args, void ContactInstance::AddressBookUpdateGroup(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); JsonValue val{JsonObject{}}; PlatformResult status = AddressBook::AddressBookUpdateGroup( common::JsonCast(args), val.get()); @@ -283,6 +299,7 @@ void ContactInstance::AddressBookUpdateGroup(const JsonValue& args, void ContactInstance::AddressBookRemoveGroup(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); JsonValue val{JsonObject{}}; PlatformResult status = AddressBook::AddressBookRemoveGroup( common::JsonCast(args), val.get()); @@ -294,6 +311,7 @@ void ContactInstance::AddressBookRemoveGroup(const JsonValue& args, void ContactInstance::AddressBookGetGroups(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out); JsonValue val{JsonArray{}}; PlatformResult status = AddressBook::AddressBookGetGroups( common::JsonCast(args), val.get()); @@ -305,6 +323,8 @@ void ContactInstance::AddressBookGetGroups(const JsonValue& args, void ContactInstance::ContactManagerGetAddressBooks(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out); + const double callback_id = args.get("callbackId").get(); auto get = [=](const std::shared_ptr& response) -> void { @@ -333,6 +353,7 @@ void ContactInstance::ContactManagerGetAddressBooks(const JsonValue& args, void ContactInstance::ContactManagerGetAddressBook(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out); JsonValue val{JsonObject{}}; PlatformResult status = ContactManager::ContactManagerGetAddressBook( common::JsonCast(args), val.get()); @@ -344,6 +365,7 @@ void ContactInstance::ContactManagerGetAddressBook(const JsonValue& args, void ContactInstance::ContactManagerAddAddressBook(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); JsonValue val{JsonObject{}}; PlatformResult status = ContactManager::ContactManagerAddAddressBook( common::JsonCast(args), val.get()); @@ -355,6 +377,7 @@ void ContactInstance::ContactManagerAddAddressBook(const JsonValue& args, void ContactInstance::ContactManagerRemoveAddressBook(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); JsonValue val{JsonObject{}}; PlatformResult status = ContactManager::ContactManagerRemoveAddressBook( common::JsonCast(args), val.get()); @@ -366,6 +389,7 @@ void ContactInstance::ContactManagerRemoveAddressBook(const JsonValue& args, void ContactInstance::AddressBookStartListening(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out); JsonValue val{JsonObject{}}; PlatformResult status = AddressBook::AddressBookStartListening( *this, common::JsonCast(args), val.get()); @@ -377,6 +401,7 @@ void ContactInstance::AddressBookStartListening(const JsonValue& args, void ContactInstance::AddressBookStopListening(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out); JsonValue val{JsonObject{}}; PlatformResult status = AddressBook::AddressBookStopListening(*this); if (status.IsSuccess()) @@ -387,6 +412,7 @@ void ContactInstance::AddressBookStopListening(const JsonValue& args, void ContactInstance::ContactManagerGet(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out); JsonValue val{JsonObject{}}; PlatformResult status = ContactManager::ContactManagerGet( common::JsonCast(args), val.get()); @@ -398,6 +424,7 @@ void ContactInstance::ContactManagerGet(const JsonValue& args, void ContactInstance::ContactManagerUpdate(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); JsonValue val{JsonObject{}}; PlatformResult status = ContactManager::ContactManagerUpdate( common::JsonCast(args), val.get()); @@ -410,6 +437,7 @@ void ContactInstance::ContactManagerUpdate(const JsonValue& args, void ContactInstance::ContactManagerUpdateBatch(const JsonValue& args, JsonObject& out) { LoggerD("entered"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); const double callback_id = args.get("callbackId").get(); @@ -438,6 +466,7 @@ void ContactInstance::ContactManagerUpdateBatch(const JsonValue& args, void ContactInstance::ContactManagerRemove(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); JsonValue val{JsonObject{}}; PlatformResult status = ContactManager::ContactManagerRemove( common::JsonCast(args), val.get()); @@ -450,6 +479,7 @@ void ContactInstance::ContactManagerRemove(const JsonValue& args, void ContactInstance::ContactManagerRemoveBatch(const JsonValue& args, JsonObject& out) { LoggerD("entered"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); const double callback_id = args.get("callbackId").get(); @@ -478,6 +508,7 @@ void ContactInstance::ContactManagerRemoveBatch(const JsonValue& args, void ContactInstance::ContactManagerFind(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out); const double callback_id = args.get("callbackId").get(); auto get = [this, args](const std::shared_ptr& response) -> void { @@ -518,6 +549,7 @@ void ContactInstance::ContactManagerImportFromVCard(const JsonValue& args, void ContactInstance::ContactManagerStartListening(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out); JsonValue val{JsonObject{}}; PlatformResult status = ContactManager::ContactManagerStartListening( *this, common::JsonCast(args), val.get()); @@ -529,6 +561,7 @@ void ContactInstance::ContactManagerStartListening(const JsonValue& args, void ContactInstance::ContactManagerStopListening(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactRead, &out); JsonValue val{JsonObject{}}; PlatformResult status = ContactManager::ContactManagerStopListening( *this, common::JsonCast(args), val.get()); @@ -539,6 +572,7 @@ void ContactInstance::ContactManagerStopListening(const JsonValue& args, } void ContactInstance::PersonLink(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); JsonValue val{JsonObject{}}; PlatformResult status = Person::PersonLink(common::JsonCast(args), val.get()); @@ -549,6 +583,7 @@ void ContactInstance::PersonLink(const JsonValue& args, JsonObject& out) { } void ContactInstance::PersonUnlink(const JsonValue& args, JsonObject& out) { + CHECK_PRIVILEGE_ACCESS(kPrivilegeContactWrite, &out); JsonValue val{JsonObject{}}; PlatformResult status = Person::PersonUnlink( common::JsonCast(args), val.get()); diff --git a/src/contact/js/address_book.js b/src/contact/js/address_book.js index ab61ae4e..8c368323 100755 --- a/src/contact/js/address_book.js +++ b/src/contact/js/address_book.js @@ -162,8 +162,6 @@ var AddressBook = function(accountId, name) { }; AddressBook.prototype.get = function() { - xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ); - var args = validator_.validateArgs(arguments, [{ name: 'id', type: types_.STRING, @@ -209,8 +207,6 @@ AddressBook.prototype.get = function() { }; AddressBook.prototype.add = function() { - xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE); - var args = validator_.validateArgs(arguments, [ { name: 'contact', @@ -256,8 +252,6 @@ AddressBook.prototype.add = function() { }; AddressBook.prototype.addBatch = function() { - xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE); - var args = validator_.validateArgs(arguments, [ { name: 'contacts', @@ -301,15 +295,17 @@ AddressBook.prototype.addBatch = function() { 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', @@ -343,8 +339,6 @@ AddressBook.prototype.update = function() { }; AddressBook.prototype.updateBatch = function() { - xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE); - var args = validator_.validateArgs(arguments, [ { name: 'contacts', @@ -400,14 +394,16 @@ AddressBook.prototype.updateBatch = function() { } }); - 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, @@ -430,8 +426,6 @@ AddressBook.prototype.remove = function() { }; AddressBook.prototype.removeBatch = function(ids, successCallback, errorCallback) { - xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE); - var args = validator_.validateArgs(arguments, [ { name: 'ids', @@ -463,14 +457,16 @@ AddressBook.prototype.removeBatch = function(ids, successCallback, errorCallback 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', @@ -522,16 +518,18 @@ AddressBook.prototype.find = function(successCallback, errorCallback, filter, so 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, @@ -545,6 +543,7 @@ AddressBook.prototype.addChangeListener = function() { nullable: true }]); + // always on first registration checking privileges is done if (type_.isEmptyObject(_contactCallbackMap)) { var result = native_.callSync('AddressBook_startListening', {}); @@ -572,9 +571,10 @@ AddressBook.prototype.addChangeListener = function() { 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', @@ -613,9 +613,11 @@ AddressBook.prototype.removeChangeListener = function(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, @@ -642,8 +644,6 @@ AddressBook.prototype.getGroup = function() { }; AddressBook.prototype.addGroup = function() { - xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE); - var args = validator_.validateArgs(arguments, [ { name: 'group', @@ -668,8 +668,6 @@ AddressBook.prototype.addGroup = function() { }; AddressBook.prototype.updateGroup = function() { - xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE); - var args = validator_.validateArgs(arguments, [ { name: 'group', @@ -688,8 +686,6 @@ AddressBook.prototype.updateGroup = function() { }; AddressBook.prototype.removeGroup = function() { - xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE); - var args = validator_.validateArgs(arguments, [{ name: 'groupId', type: types_.STRING, @@ -710,8 +706,6 @@ AddressBook.prototype.removeGroup = function() { }; 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); diff --git a/src/contact/js/common.js b/src/contact/js/common.js index 1681cdc6..3415c524 100755 --- a/src/contact/js/common.js +++ b/src/contact/js/common.js @@ -17,11 +17,12 @@ 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; diff --git a/src/contact/js/contact_manager.js b/src/contact/js/contact_manager.js index d24257cf..896d1ed1 100755 --- a/src/contact/js/contact_manager.js +++ b/src/contact/js/contact_manager.js @@ -40,8 +40,6 @@ var ContactManager = function() {}; // Gets the available address books ContactManager.prototype.getAddressBooks = function() { - xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_READ); - var args = validator_.validateArgs(arguments, [ { name: 'successCallback', @@ -85,8 +83,8 @@ ContactManager.prototype.getAddressBooks = function() { }; // 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'); @@ -97,6 +95,10 @@ ContactManager.prototype.getUnifiedAddressBook = function() { }); }; +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 @@ -105,8 +107,6 @@ ContactManager.prototype.getDefaultAddressBook = 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, @@ -139,8 +139,6 @@ ContactManager.prototype.getAddressBook = function() { }; ContactManager.prototype.addAddressBook = function() { - xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CONTACT_WRITE); - var args = validator_.validateArgs(arguments, [{ name: 'addressBook', type: types_.PLATFORM_OBJECT, @@ -168,8 +166,6 @@ ContactManager.prototype.addAddressBook = function() { }; 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); @@ -203,8 +199,6 @@ ContactManager.prototype.removeAddressBook = function() { // 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, [ { @@ -232,8 +226,6 @@ ContactManager.prototype.get = function() { // 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', @@ -255,8 +247,6 @@ ContactManager.prototype.update = function() { // 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', @@ -298,8 +288,6 @@ ContactManager.prototype.updateBatch = function() { // 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', @@ -319,8 +307,6 @@ ContactManager.prototype.remove = function() { // 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', @@ -363,8 +349,6 @@ ContactManager.prototype.removeBatch = function() { // 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', @@ -423,8 +407,6 @@ ContactManager.prototype.find = function() { // 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', @@ -456,8 +438,10 @@ ContactManager.prototype.addChangeListener = function() { }; // 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, [ { @@ -499,5 +483,9 @@ ContactManager.prototype.removeChangeListener = function() { } }; +ContactManager.prototype.removeChangeListener = function() { + ContactManager_removeChangeListener.apply(this, arguments); +}; + // exports ///////////////////////////////////////////////////////////////// exports = new ContactManager(); diff --git a/src/contact/js/person.js b/src/contact/js/person.js index 0185d900..e812c027 100755 --- a/src/contact/js/person.js +++ b/src/contact/js/person.js @@ -137,8 +137,6 @@ var Person = function(data) { // 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, @@ -166,8 +164,6 @@ Person.prototype.link = function() { // 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,