blob: 82a0b0aa78286060567c2e1c91aa953804715469 [file] [log] [blame]
[email protected]288ce6c2012-12-03 21:05:241// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Custom bindings for the Permissions API.
6
7var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
8var sendRequest = require('sendRequest').sendRequest;
9var lastError = require('lastError');
10
11chromeHidden.registerCustomHook('permissions', function(api) {
12 var apiFunctions = api.apiFunctions;
13
14 apiFunctions.setUpdateArgumentsPreValidate('request',
15 function() {
16 if (arguments.length < 1)
17 return arguments;
18
19 var args = arguments[0].permissions;
20 if (!args)
21 return arguments;
22
23 for (var i = 0; i < args.length; i += 1) {
24 if (typeof(args[i]) == 'object') {
25 var a = args[i];
26 var keys = Object.keys(a);
27 if (keys.length != 1) {
28 throw new Error("Too many keys in object-style permission.");
29 }
30 arguments[0].permissions[i] = keys[0] + '|' + a[keys[0]];
31 }
32 }
33
34 return arguments;
35 });
36});