[Application] Fixed path of getAppSharedURI
[platform/core/api/webapi-plugins.git] / src / ppm / ppm_api.js
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
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);
21
22 function PPMManager() {}
23
24 PPMManager.prototype.checkPermission = function() {
25     var args = validator_.validateArgs(arguments, [
26         { name: 'privilege', type: types_.STRING }
27     ]);
28
29     var callArgs = {
30         privilege: args.privilege
31     };
32
33     var result = native_.callSync('PPMManager_checkPermission', callArgs);
34
35     if (native_.isFailure(result)) {
36         throw native_.getErrorObject(result);
37     }
38
39     return native_.getResultObject(result);
40 };
41
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 }
47     ]);
48
49     var callback = function(result) {
50         if (native_.isFailure(result)) {
51             native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
52         } else {
53             args.successCallback(result.result, result.privilege);
54         }
55     };
56
57     var callArgs = {
58         privilege: args.privilege
59     };
60
61     var result = native_.call('PPMManager_requestPermission', callArgs, callback);
62
63     if (native_.isFailure(result)) {
64         throw native_.getErrorObject(result);
65     }
66 };
67
68 // Exports
69 exports = new PPMManager();