From: Piotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics
Date: Tue, 28 Jul 2020 10:38:04 +0000 (+0200)
Subject: [Common] Added cache for JS privilege checking
X-Git-Tag: submit/tizen/20200730.063627~1^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2f2ead2ced6aab065e045acc7aa7fe6994fdee44;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Common] Added cache for JS privilege checking
Commit improves the performance of asking for application privileges.
Values are cached.
[Verification]
Code compiles without errors.
Privilege TCT passrate 100%
Change-Id: Id1772d9b14e4d4ff07e6a7ca0993027b98a4f2f4
---
diff --git a/src/utils/utils_api.js b/src/utils/utils_api.js
index 70424a53..6e4a3dfe 100644
--- a/src/utils/utils_api.js
+++ b/src/utils/utils_api.js
@@ -253,12 +253,17 @@ Utils.prototype.repackFilter = function(filter) {
return null;
};
+var apiVersion = null;
Utils.prototype.getPkgApiVersion = function() {
+ if (apiVersion) {
+ return apiVersion;
+ }
var result = native_.callSync('UtilsGetPkgApiVersion');
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
- return native_.getResultObject(result);
+ apiVersion = native_.getResultObject(result);
+ return apiVersion;
};
var isPrivilege = function(toCheck) {
@@ -268,6 +273,7 @@ var isPrivilege = function(toCheck) {
return true;
};
+var cachedPrivileges = {};
Utils.prototype.checkPrivilegeAccess = function(privilege) {
if (!isPrivilege(privilege)) {
xwalk.utils.error(
@@ -276,11 +282,15 @@ Utils.prototype.checkPrivilegeAccess = function(privilege) {
throw new WebAPIException(WebAPIException.SECURITY_ERR);
}
+ if (cachedPrivileges[privilege]) {
+ return;
+ }
var result = native_.callSync('UtilsCheckPrivilegeAccess', {
privilege: _toString(privilege)
});
-
- if (native_.isFailure(result)) {
+ var isFailure = native_.isFailure(result);
+ cachedPrivileges[privilege] = !isFailure;
+ if (isFailure) {
throw native_.getErrorObject(result);
}
};