Revert "[CallHistory] Privilege checks moved to JS."
authorPiotr Kosko <p.kosko@samsung.com>
Wed, 4 Nov 2015 12:59:30 +0000 (13:59 +0100)
committerTomasz Marciniak <t.marciniak@samsung.com>
Fri, 4 Dec 2015 09:22:30 +0000 (10:22 +0100)
This reverts commit 5d7a7ee7edb9e6dfb29dd880bb437282280dc962.
This also applies changes from commit 825a2472318d80cb21fcd058d2ace35d1d227bf1

[Verification] Code compiles.

Change-Id: Iecc69c205fb549267162073276d13b220d3cfbef
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/callhistory/callhistory_api.js
src/callhistory/callhistory_instance.cc

index d12b5ab3ee1374055c66c514e90ef31b270fe79b..a31abd8902934a0bf180124b2b2273a0c628fa9b 100755 (executable)
  *    limitations under the License.
  */
 
-var validator_ = xwalk.utils.validator;
-var converter_ = xwalk.utils.converter;
+var privUtils_ = xwalk.utils;
+var privilege_ = privUtils_.privilege;
+var validator_ = privUtils_.validator;
+var converter_ = privUtils_.converter;
 var types_ = validator_.Types;
-var T_ = xwalk.utils.type;
+var T_ = privUtils_.type;
 var native_ = new xwalk.utils.NativeManager(extension);
 
 function _createCallHistoryEntries(e) {
@@ -101,8 +103,6 @@ function CallHistory() {
 };
 
 CallHistory.prototype.find = function() {
-    xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CALLHISTORY_READ);
-
     var args = validator_.validateArgs(arguments, [
         {
             name : 'successCallback',
@@ -159,12 +159,13 @@ CallHistory.prototype.find = function() {
     callArgs.limit = args.limit;
     callArgs.offset = args.offset;
 
-    native_.call('CallHistory_find', callArgs, callback);
+    var result = native_.call('CallHistory_find', callArgs, callback);
+    if (native_.isFailure(result)) {
+      throw native_.getErrorObject(result);
+    }
 };
 
 CallHistory.prototype.remove = function() {
-    xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CALLHISTORY_WRITE);
-
     var args = validator_.validateArgs(arguments, [
         {
             name : 'entry',
@@ -178,16 +179,13 @@ CallHistory.prototype.remove = function() {
 
     var result = native_.callSync('CallHistory_remove', callArgs);
     if (native_.isFailure(result)) {
-        throw new WebAPIException(
-                WebAPIException.INVALID_VALUES_ERR, 'Watch id not found.');
+      throw native_.getErrorObject(result);
     }
 
     return;
 };
 
 CallHistory.prototype.removeBatch = function() {
-    xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CALLHISTORY_WRITE);
-
     var args = validator_.validateArgs(arguments, [
         {
             name : 'entries',
@@ -220,12 +218,13 @@ CallHistory.prototype.removeBatch = function() {
     var callArgs = {};
     callArgs.uid = uid;
 
-    native_.call('CallHistory_removeBatch', callArgs, callback);
+    var result = native_.call('CallHistory_removeBatch', callArgs, callback);
+    if (native_.isFailure(result)) {
+      throw native_.getErrorObject(result);
+    }
 };
 
 CallHistory.prototype.removeAll = function() {
-    xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CALLHISTORY_WRITE);
-
     var args = validator_.validateArgs(arguments, [
         {
             name : 'successCallback',
@@ -249,12 +248,13 @@ CallHistory.prototype.removeAll = function() {
         }
     };
 
-    native_.call('CallHistory_removeAll', {}, callback);
+    var result = native_.call('CallHistory_removeAll', {}, callback);
+    if (native_.isFailure(result)) {
+      throw native_.getErrorObject(result);
+    }
 };
 
 CallHistory.prototype.addChangeListener = function() {
-    xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CALLHISTORY_READ);
-
     var args = validator_.validateArgs(arguments, [
         {
             name : 'eventCallback',
@@ -264,14 +264,19 @@ CallHistory.prototype.addChangeListener = function() {
     ]);
 
     if (T_.isEmptyObject(callHistoryChangeListener.listeners)) {
-        native_.callSync('CallHistory_addChangeListener');
+        var result = native_.callSync('CallHistory_addChangeListener');
+        if (native_.isFailure(result)) {
+          throw native_.getErrorObject(result);
+        }
     }
 
     return callHistoryChangeListener.addListener(args.eventCallback);
 };
 
-CallHistory.prototype.removeChangeListener = function() {
-    xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.CALLHISTORY_READ);
+function removeChangeListener() {
+    if (T_.isEmptyObject(callHistoryChangeListener.listeners)) {
+        privUtils_.checkPrivilegeAccess(privilege_.CALLHISTORY_READ);
+    }
 
     var args = validator_.validateArgs(arguments, [
         {
@@ -283,10 +288,17 @@ CallHistory.prototype.removeChangeListener = function() {
     callHistoryChangeListener.removeListener(args.watchId);
 
     if (T_.isEmptyObject(callHistoryChangeListener.listeners)) {
-        native_.callSync('CallHistory_removeChangeListener');
+        var result = native_.callSync('CallHistory_removeChangeListener');
+        if (native_.isFailure(result)) {
+          throw native_.getErrorObject(result);
+        }
     }
 };
 
+CallHistory.prototype.removeChangeListener = function() {
+  removeChangeListener.apply(this, arguments);
+};
+
 function RemoteParty(data) {
     Object.defineProperties(this, {
         remoteParty: {
index 677433227bc1a13d4fa17fdf16a9a6aa25878b9a..7ceec76b4117165a36c2f410cee441efc88b78bc 100755 (executable)
 
 #include "common/picojson.h"
 #include "common/logger.h"
+#include "common/tools.h"
 #include "common/platform_exception.h"
 
 namespace extension {
 namespace callhistory {
 
+namespace {
+// The privileges that required in CallHistory API
+const std::string kPrivilegeCallHistoryRead = "http://tizen.org/privilege/callhistory.read";
+const std::string kPrivilegeCallHistoryWrite = "http://tizen.org/privilege/callhistory.write";
+}
+
 using namespace common;
 
 CallHistoryInstance::CallHistoryInstance() : history_(*this) {
+  LoggerD("Entered");
   using std::placeholders::_1;
   using std::placeholders::_2;
 
@@ -49,12 +57,14 @@ CallHistoryInstance::~CallHistoryInstance() {
 
 void CallHistoryInstance::Find(const picojson::value& args, picojson::object& out) {
   LoggerD("Entered");
+  CHECK_PRIVILEGE_ACCESS(kPrivilegeCallHistoryRead, &out);
   history_.find(args.get<picojson::object>());
   ReportSuccess(out);
 }
 
 void CallHistoryInstance::Remove(const picojson::value& args, picojson::object& out) {
   LoggerD("Entered");
+  CHECK_PRIVILEGE_ACCESS(kPrivilegeCallHistoryWrite, &out);
   PlatformResult result = history_.remove(args.get<picojson::object>());
   if (result.IsSuccess()) {
     ReportSuccess(out);
@@ -65,6 +75,7 @@ void CallHistoryInstance::Remove(const picojson::value& args, picojson::object&
 
 void CallHistoryInstance::RemoveBatch(const picojson::value& args, picojson::object& out) {
   LoggerD("Entered");
+  CHECK_PRIVILEGE_ACCESS(kPrivilegeCallHistoryWrite, &out);
   PlatformResult result = history_.removeBatch(args.get<picojson::object>());
   if (result.IsSuccess()) {
     ReportSuccess(out);
@@ -75,12 +86,14 @@ void CallHistoryInstance::RemoveBatch(const picojson::value& args, picojson::obj
 
 void CallHistoryInstance::RemoveAll(const picojson::value& args, picojson::object& out) {
   LoggerD("Entered");
+  CHECK_PRIVILEGE_ACCESS(kPrivilegeCallHistoryWrite, &out);
   history_.removeAll(args.get<picojson::object>());
   ReportSuccess(out);
 }
 
 void CallHistoryInstance::AddChangeListener(const picojson::value& args, picojson::object& out) {
   LoggerD("Entered");
+  CHECK_PRIVILEGE_ACCESS(kPrivilegeCallHistoryRead, &out);
   PlatformResult result = history_.startCallHistoryChangeListener();
   if (result.IsSuccess()) {
     ReportSuccess(out);
@@ -91,6 +104,7 @@ void CallHistoryInstance::AddChangeListener(const picojson::value& args, picojso
 
 void CallHistoryInstance::RemoveChangeListener(const picojson::value& args, picojson::object& out) {
   LoggerD("Entered");
+  CHECK_PRIVILEGE_ACCESS(kPrivilegeCallHistoryRead, &out);
   PlatformResult result = history_.stopCallHistoryChangeListener();
   if (result.IsSuccess()) {
     ReportSuccess(out);