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 PPMManager.prototype.checkPermission = function() {
25 var args = validator_.validateArgs(arguments, [
26 { name: 'privilege', type: types_.STRING }
30 privilege: args.privilege
33 var result = native_.callSync('PPMManager_checkPermission', callArgs);
35 if (native_.isFailure(result)) {
36 throw native_.getErrorObject(result);
39 return native_.getResultObject(result);
42 PPMManager.prototype.requestPermission = function() {
43 var args = validator_.validateArgs(arguments, [
44 { name: 'privilege', type: types_.STRING },
45 { name: 'successCallback', type: types_.FUNCTION },
46 { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
49 var callback = function(result) {
50 if (native_.isFailure(result)) {
51 native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
53 args.successCallback(result.result, result.privilege);
58 privilege: args.privilege
61 var result = native_.call('PPMManager_requestPermission', callArgs, callback);
63 if (native_.isFailure(result)) {
64 throw native_.getErrorObject(result);
69 exports = new PPMManager();