2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 var validator_ = xwalk.utils.validator;
18 var type_ = xwalk.utils.type;
19 var types_ = validator_.Types;
20 var native_ = new xwalk.utils.NativeManager(extension);
22 function PPMManager() {}
24 function RequestStatus(privilege, result_) {
25 Object.defineProperties(this, {
26 privilege: { value: privilege, writable: false },
27 result: { value: result_, writable: false }
31 PPMManager.prototype.checkPermission = function() {
32 var args = validator_.validateArgs(arguments, [
33 { name: 'privilege', type: types_.STRING }
37 privilege: args.privilege
40 var result = native_.callSync('PPMManager_checkPermission', callArgs);
42 if (native_.isFailure(result)) {
43 throw native_.getErrorObject(result);
46 return native_.getResultObject(result);
49 PPMManager.prototype.checkPermissions = function() {
50 var args = validator_.validateArgs(arguments, [
51 { name: 'privileges', type: types_.ARRAY, values: types_.STRING }
55 privileges: args.privileges
58 var result = native_.callSync('PPMManager_checkPermissions', callArgs);
62 if (native_.isFailure(result)) {
63 throw native_.getErrorObject(result);
65 var obj = native_.getResultObject(result);
67 obj.forEach(function(o) {
68 data.push({ privilege: o.privilege, type: o.type });
75 PPMManager.prototype.requestPermission = function() {
76 var args = validator_.validateArgs(arguments, [
77 { name: 'privilege', type: types_.STRING },
78 { name: 'successCallback', type: types_.FUNCTION },
79 { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
82 var callback = function(result) {
83 if (native_.isFailure(result)) {
84 native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
86 args.successCallback(result.result, result.privilege);
91 privilege: args.privilege
94 var result = native_.call('PPMManager_requestPermission', callArgs, callback);
96 if (native_.isFailure(result)) {
97 throw native_.getErrorObject(result);
101 PPMManager.prototype.requestPermissions = function() {
102 var args = validator_.validateArgs(arguments, [
103 { name: 'privileges', type: types_.ARRAY, values: types_.STRING },
104 { name: 'successCallback', type: types_.FUNCTION },
105 { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
108 var callback = function(result) {
109 if (native_.isFailure(result)) {
110 native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
113 var obj = native_.getResultObject(result);
115 obj.forEach(function(o) {
116 data.push(new RequestStatus(o.privilege, o.result));
118 args.successCallback(data);
123 privileges: args.privileges
126 var result = native_.call('PPMManager_requestPermissions', callArgs, callback);
128 if (native_.isFailure(result)) {
129 throw native_.getErrorObject(result);
134 exports = new PPMManager();