Revert "[Contact] Privilege checks moved to JS."
authorTomasz Marciniak <t.marciniak@samsung.com>
Wed, 4 Nov 2015 13:01:29 +0000 (14:01 +0100)
committerTomasz Marciniak <t.marciniak@samsung.com>
Fri, 4 Dec 2015 10:10:05 +0000 (11:10 +0100)
This reverts commit 8ddab5bb72ca965f4312093344c6d6c014c65df2.
This also applies changes from commit 86945f152c2dbb9111d28a3c979c48cf53da9c91

[Verification] Code compiles.

Change-Id: I27c5c3417053a0534b403c10e83faf81d897086f
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
src/contact/contact_instance.cc
src/contact/js/address_book.js
src/contact/js/common.js
src/contact/js/contact_manager.js
src/contact/js/person.js

index dca1d3ae7f7b046b169dfcb5fd05b6c4730e89b6..db68f348737b1b431c300928c2b4d3870fd759e4 100755 (executable)
@@ -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"
 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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<double>();
 
@@ -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<double>();
 
@@ -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<double>();
 
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<double>();
 
   auto get = [=](const std::shared_ptr<JsonValue>& 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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonArray>());
@@ -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<double>();
 
   auto get = [=](const std::shared_ptr<JsonValue>& 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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<double>();
 
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<double>();
 
@@ -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<double>();
 
   auto get = [this, args](const std::shared_ptr<JsonValue>& 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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonObject>());
@@ -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<JsonObject>(args),
                                              val.get<JsonObject>());
@@ -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<JsonObject>(args), val.get<JsonObject>());
index ab61ae4e216d44d113d4107970ba81288c84a483..8c368323bb8dcad04c9aa05878e2c7d597c1c32c 100755 (executable)
@@ -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);
index 1681cdc619505d5da1f5017d34381f1b54a129c1..3415c5248a038fcbf7e2d9a05418f62a9566479f 100755 (executable)
 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;
 
index d24257cf4a2b890b8f3417985c683c1506711580..896d1ed159a95b05232a34bcf8d7728c0060664d 100755 (executable)
@@ -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();
index 0185d90079a09e05debe504e4cfef2565270612a..e812c0279462395c7feeb4f86559c9f7a5e79e33 100755 (executable)
@@ -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,